diff --git a/CMakeLists.txt b/CMakeLists.txt index 621587447..0f0deaf07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,13 @@ find_package(Qt5Widgets REQUIRED) option(VST_USE_BUNDLED_HEADERS "Build with Bundled Headers" ON) if(VST_USE_BUNDLED_HEADERS) - message(STATUS "Using the built-in VST header.") + message(STATUS "Using the bundled VST header.") include_directories(vst_header) set(vst_HEADER vst_header/aeffectx.h) else() set(VST_INCLUDE_DIR "" CACHE PATH "Path to Steinburg headers (e.g. C:/VST3 SDK/pluginterfaces/vst2.x)") - message(WARNING "You should only use the steinburg headers for debugging or local builds. It is illegal to distribute the steinburg headers with anything, and possibly against the GPL to distribute the binaries from the resultant compile.") + message(WARNING "You should only use the Steinburg headers for debugging or local builds. It is illegal to distribute the Steinburg headers with anything, and possibly against the GPL to distribute the binaries from the resultant compile.") include_directories(${VST_INCLUDE_DIR}) set(vst_HEADER ${VST_INCLUDE_DIR}/aeffectx.h) diff --git a/VSTPlugin.cpp b/VSTPlugin.cpp index 0ef27d5ea..5af1c62bf 100644 --- a/VSTPlugin.cpp +++ b/VSTPlugin.cpp @@ -1,7 +1,7 @@ #include "headers/VSTPlugin.h" VSTPlugin::VSTPlugin(obs_source_t *sourceContext) : sourceContext{sourceContext} { - int numChannels = 8; + int numChannels = VST_MAX_CHANNELS; int blocksize = 512; inputs = (float **) malloc(sizeof(float **) * numChannels); @@ -27,21 +27,21 @@ void VSTPlugin::loadEffectFromPath(std::string path) { return; } - // Check plugin's magic number + // Check plug-in's magic number // If incorrect, then the file either was not loaded properly, is not a - // real VST plugin, or is otherwise corrupt. + // real VST plug-in, or is otherwise corrupt. if (effect->magic != kEffectMagic) { - blog(LOG_WARNING, "VST Plugin's magic number is bad"); + blog(LOG_WARNING, "VST Plug-in's magic number is bad"); return; } - effect->dispatcher(effect, effOpen, 0, 0, NULL, 0.0f); + effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f); // Set some default properties size_t sampleRate = audio_output_get_sample_rate(obs_get_audio()); - effect->dispatcher(effect, effSetSampleRate, 0, 0, NULL, sampleRate); + effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, sampleRate); int blocksize = 512; - effect->dispatcher(effect, effSetBlockSize, 0, blocksize, NULL, 0.0f); + effect->dispatcher(effect, effSetBlockSize, 0, blocksize, nullptr, 0.0f); effect->dispatcher(effect, effMainsChanged, 0, 1, 0, 0); @@ -59,16 +59,16 @@ void silenceChannel(float **channelData, int numChannels, long numFrames) { obs_audio_data *VSTPlugin::process(struct obs_audio_data *audio) { if (effect && effectReady) { - silenceChannel(outputs, 8, audio->frames); + silenceChannel(outputs, VST_MAX_CHANNELS, audio->frames); - float *adata[8] = {(float *) audio->data[0], (float *) audio->data[1], - (float *) audio->data[2], (float *) audio->data[3], - (float *) audio->data[4], (float *) audio->data[5], - (float *) audio->data[6], (float *) audio->data[7]}; + float *adata[VST_MAX_CHANNELS]; + for (size_t d = 0; d < VST_MAX_CHANNELS; d++) { + adata[d] = (float *) audio->data[d]; + }; effect->processReplacing(effect, adata, outputs, audio->frames); - for (size_t c = 0; c < 8; c++) { + for (size_t c = 0; c < VST_MAX_CHANNELS; c++) { if (audio->data[c]) { for (size_t i = 0; i < audio->frames; i++) { adata[c][i] = outputs[c][i]; @@ -84,18 +84,18 @@ void VSTPlugin::unloadEffect() { effectReady = false; if (effect) { - effect->dispatcher(effect, effMainsChanged, 0, 0, 0, 0); - effect->dispatcher(effect, effClose, 0, 0, NULL, 0.0f); + effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0); + effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f); } - effect = NULL; + effect = nullptr; unloadLibrary(); } void VSTPlugin::openEditor() { if (effect && !editorWidget) { - editorWidget = new EditorWidget(0, this); + editorWidget = new EditorWidget(nullptr, this); editorWidget->buildEffectContainer(effect); @@ -105,7 +105,7 @@ void VSTPlugin::openEditor() { void VSTPlugin::closeEditor() { if (effect) { - effect->dispatcher(effect, effEditClose, 0, 0, 0, 0); + effect->dispatcher(effect, effEditClose, 0, 0, nullptr, 0); } if (editorWidget) { editorWidget->close(); @@ -151,7 +151,7 @@ std::string VSTPlugin::getChunk() { return ""; } if (effect->flags & effFlagsProgramChunks) { - void *buf = NULL; + void *buf = nullptr; intptr_t chunkSize = effect->dispatcher(effect, effGetChunk, 1, 0, &buf, 0.0); @@ -179,7 +179,7 @@ void VSTPlugin::setChunk(std::string data) { QByteArray base64Data = QByteArray(data.c_str(), data.length()); QByteArray chunkData = QByteArray::fromBase64(base64Data); - void *buf = NULL; + void *buf = nullptr; buf = chunkData.data(); effect->dispatcher(effect, effSetChunk, 0, chunkData.length(), buf, 0); diff --git a/headers/VSTPlugin.h b/headers/VSTPlugin.h index 4849d226b..661777c1f 100644 --- a/headers/VSTPlugin.h +++ b/headers/VSTPlugin.h @@ -1,6 +1,8 @@ #ifndef OBS_STUDIO_VSTPLUGIN_H #define OBS_STUDIO_VSTPLUGIN_H +#define VST_MAX_CHANNELS 8 + #include #include "aeffectx.h" #include @@ -14,14 +16,14 @@ class EditorWidget; class VSTPlugin { - AEffect *effect = NULL; + AEffect *effect = nullptr; obs_source_t *sourceContext; std::string pluginPath; float **inputs; float **outputs; - EditorWidget *editorWidget = NULL; + EditorWidget *editorWidget = nullptr; AEffect* loadEffect(); @@ -30,7 +32,7 @@ class VSTPlugin { #ifdef __APPLE__ CFBundleRef bundle = NULL; #elif WIN32 - HINSTANCE dllHandle = NULL; + HINSTANCE dllHandle = nullptr; #endif void unloadLibrary(); diff --git a/obs-vst.cpp b/obs-vst.cpp index e78a4c67d..f2159ae0a 100644 --- a/obs-vst.cpp +++ b/obs-vst.cpp @@ -81,8 +81,10 @@ static struct obs_audio_data *vst_filter_audio(void *data, static void fill_out_plugins(obs_property_t *list) { QStringList dir_list; + #ifdef __APPLE__ dir_list << "/Library/Audio/Plug-Ins/VST/"; + dir_list << "~/Library/Audio/Plug-ins/VST/"; #elif WIN32 dir_list << "C:/Program Files/Steinberg/VstPlugins/" << "C:/Program Files/Common Files/Steinberg/Shared Components/" @@ -91,10 +93,18 @@ static void fill_out_plugins(obs_property_t *list) << "C:/Program Files/VSTPlugins/"; // If VST3 support is added.... // << "C:/Program Files/Common Files/VST3"; + #elif LINUX + dir_list << "/usr/lib/vst" + dir_list << "/usr/lib/lxvst" + dir_list << "/usr/local/lib/vst" + dir_list << "/usr/local/lib/lxvst" + dir_list << "~/.vst" + dir_list << "~/.lxvst"; #endif QStringList filters; - filters << "*.vst" << "*.dll"; + obs_property_list_add_string(list, "{Please select a plugin}", nullptr); + filters << "*.vst" << "*.dll" << "*.so"; for (int a = 0; a < dir_list.size(); ++a) { QDir search_dir(dir_list[a]); diff --git a/win/EditorWidget-win.cpp b/win/EditorWidget-win.cpp index a3d75c7a3..85c323996 100644 --- a/win/EditorWidget-win.cpp +++ b/win/EditorWidget-win.cpp @@ -22,7 +22,7 @@ void EditorWidget::buildEffectContainer(AEffect *effect) { effect->dispatcher(effect, effEditOpen, 0, 0, hwnd, 0); - VstRect* vstRect = 0; + VstRect* vstRect = nullptr; effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0); if (vstRect) { diff --git a/win/VSTPlugin-win.cpp b/win/VSTPlugin-win.cpp index 7c3fe7022..6d117efa9 100644 --- a/win/VSTPlugin-win.cpp +++ b/win/VSTPlugin-win.cpp @@ -5,26 +5,26 @@ #include AEffect* VSTPlugin::loadEffect() { - AEffect *plugin = NULL; + AEffect *plugin = nullptr; wchar_t *wpath; os_utf8_to_wcs_ptr(pluginPath.c_str(), 0, &wpath); dllHandle = LoadLibraryW(wpath); bfree(wpath); - if(dllHandle == NULL) { + if(dllHandle == nullptr) { printf("Failed trying to load VST from '%s', error %d\n", pluginPath, GetLastError()); - return NULL; + return nullptr; } vstPluginMain mainEntryPoint = (vstPluginMain)GetProcAddress(dllHandle, "VSTPluginMain"); if (!mainEntryPoint) { - return NULL; + return nullptr; } - // Instantiate the plugin + // Instantiate the plug-in plugin = mainEntryPoint(hostCallback_static); plugin->user = this; return plugin; @@ -33,6 +33,6 @@ AEffect* VSTPlugin::loadEffect() { void VSTPlugin::unloadLibrary() { if (dllHandle) { FreeLibrary(dllHandle); - dllHandle = NULL; + dllHandle = nullptr; } } \ No newline at end of file