Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Fixes, clean up, and an attempt at Linux support. #26

Merged
merged 10 commits into from
Jan 28, 2017
41 changes: 35 additions & 6 deletions linux/VSTPlugin-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
AEffect* VSTPlugin::loadEffect() {
AEffect *plugin = nullptr;

wchar_t *wpath;
os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath);
soHandle = LoadLibraryW(wpath);
// Why is this a (non-portable) wide char?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's copied from the windows code. Windows needs a wchar because the filesystem APIs for unicode accept a wchar. On linux and osx you should just be able to pass the string to the os_dlopen. So you can remove all this extra stuff here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for merging. Am working on it now. Will have a new PR for you soon-ish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also my next PR will include formatting fixes (if you haven't already done it) for everything.

wchar_t *wpath = NULL;

// We need to convert the above wide char to a 'normal' char
// 4096 elements should be enough to contain it... I hope.
// We also initialize the array with NULLs to prevent issues
// down the road.
char charPath[4096] = {NULL};
uint32_t wcs_returnValue;
//os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath);
wcs_returnValue = wcstombs(charPath, wpath, sizeof(charPath));

// Now check for errors in the conversion before trying to open
// the file/path.
if (wcs_returnValue < 4) {
wprintf(L"Path conversion error from '%s'", wpath);
printf(", to '%s'\n", charPath);
return nullptr;
}

soHandle = os_dlopen(charPath);
bfree(wpath);
bfree(charPath);
if(soHandle == nullptr) {
printf("Failed trying to load VST from '%s', error %d\n",
pluginPath, GetLastError());
pluginPath.c_str(), errno);
return nullptr;
}

vstPluginMain mainEntryPoint =
(vstPluginMain)GetProcAddress(soHandle, "VSTPluginMain");
(vstPluginMain)(soHandle, "VSTPluginMain");

if (mainEntryPoint == nullptr) {
mainEntryPoint =
(vstPluginMain)os_dlsym(soHandle, "VstPluginMain()");
}

if (mainEntryPoint == nullptr) {
mainEntryPoint = (vstPluginMain)os_dlsym(soHandle, "main");
}

if (!mainEntryPoint) {
if (mainEntryPoint == nullptr) {
printf("Couldn't get a pointer to plugin's main()");
return nullptr;
}

Expand Down