diff --git a/.gitignore b/.gitignore index 5e36b900..e6373523 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ clients/sfizz_jack clients/sfzprint /plugins/vst/download/ +/plugins/vst/external/vstsdk2.4/ /plugins/editor/external/fluentui-system-icons/ diff --git a/CMakeLists.txt b/CMakeLists.txt index e021f748..d73e9287 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option_ex (SFIZZ_LV2 "Enable LV2 plug-in build" ON) option_ex (SFIZZ_LV2_UI "Enable LV2 plug-in user interface" ON) option_ex (SFIZZ_VST "Enable VST plug-in build" ON) option_ex (SFIZZ_AU "Enable AU plug-in build" APPLE) +option_ex (SFIZZ_VST2 "Enable VST2 plug-in build (unsupported)" OFF) option_ex (SFIZZ_BENCHMARKS "Enable benchmarks build" OFF) option_ex (SFIZZ_TESTS "Enable tests build" OFF) option_ex (SFIZZ_DEMOS "Enable feature demos build" OFF) diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index f3cdc809..21d71585 100644 --- a/cmake/SfizzConfig.cmake +++ b/cmake/SfizzConfig.cmake @@ -17,7 +17,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C++ compatibility level if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND CMAKE_CXX_STANDARD LESS 17) set(CMAKE_CXX_STANDARD 17) -elseif((SFIZZ_LV2_UI OR SFIZZ_VST OR SFIZZ_AU) AND CMAKE_CXX_STANDARD LESS 14) +elseif((SFIZZ_LV2_UI OR SFIZZ_VST OR SFIZZ_AU OR SFIZZ_VST2) AND CMAKE_CXX_STANDARD LESS 14) # if the UI is part of the build, make it 14 set(CMAKE_CXX_STANDARD 14) endif() diff --git a/plugins/vst/CMakeLists.txt b/plugins/vst/CMakeLists.txt index c8226d82..b80f9946 100644 --- a/plugins/vst/CMakeLists.txt +++ b/plugins/vst/CMakeLists.txt @@ -37,6 +37,7 @@ add_library(sfizz-vst3-core STATIC SfizzVstParameters.h SfizzVstUpdates.h SfizzVstUpdates.cpp + SfizzVstIDs.h SfizzFileScan.h SfizzFileScan.cpp SfizzForeignPaths.h @@ -65,13 +66,14 @@ if(APPLE) endif() target_include_directories(sfizz-vst3-core PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") -target_link_libraries(sfizz-vst3-core PRIVATE +target_link_libraries(sfizz-vst3-core PRIVATE sfizz::sfizz PRIVATE sfizz::import PRIVATE sfizz::editor PRIVATE sfizz::plugins-common PRIVATE sfizz::pugixml sfizz::filesystem PRIVATE sfizz::ring-buffer + PRIVATE absl::strings absl::optional absl::container_common vst3sdk vst3sdk_vstgui) gw_target_warn(sfizz-vst3-core PRIVATE @@ -309,3 +311,72 @@ elseif(SFIZZ_AU) COMPONENT "au") endif() endif() + +# --- VST2 wrapper --- # + +if(SFIZZ_VST2) + set(VST2PLUGIN_PRJ_NAME "${PROJECT_NAME}_vst2") + set(VST2PLUGIN_BUNDLE_NAME "${PROJECT_NAME}.vst2") + + set(VST2SDK_BASEDIR "${CMAKE_CURRENT_SOURCE_DIR}/external/vstsdk2.4") + set(VST2WRAPPER_BASEDIR "${CMAKE_CURRENT_SOURCE_DIR}/external/VST_SDK/VST3_SDK/public.sdk/source/vst/vst2wrapper") + + if(NOT EXISTS "${VST2SDK_BASEDIR}/pluginterfaces/vst2.x/aeffect.h") + message(FATAL_ERROR "VST SDK 2.4 is missing. Make it available in the following folder: ${VST2SDK_BASEDIR}") + endif() + + add_library(${VST2PLUGIN_PRJ_NAME} MODULE + "Vst2PluginFactory.cpp" + "${VST2WRAPPER_BASEDIR}/vst2wrapper.cpp" + "${VST2WRAPPER_BASEDIR}/../basewrapper/basewrapper.cpp" + "${VST2SDK_BASEDIR}/public.sdk/source/vst2.x/audioeffect.cpp" + "${VST2SDK_BASEDIR}/public.sdk/source/vst2.x/audioeffectx.cpp") + target_include_directories(${VST2PLUGIN_PRJ_NAME} PRIVATE + "${VST2SDK_BASEDIR}") + + if(NOT WIN32) + target_compile_definitions(${VST2PLUGIN_PRJ_NAME} PRIVATE "__cdecl=") + endif() + + target_link_libraries(${VST2PLUGIN_PRJ_NAME} + PRIVATE sfizz-vst3-core) + set_target_properties(${VST2PLUGIN_PRJ_NAME} PROPERTIES + OUTPUT_NAME "${PROJECT_NAME}" + PREFIX "") + + plugin_add_vst3sdk(${VST2PLUGIN_PRJ_NAME}) + plugin_add_vstgui(${VST2PLUGIN_PRJ_NAME}) + + # Add VST hosting classes + target_link_libraries(${VST2PLUGIN_PRJ_NAME} PRIVATE vst3sdk_hosting) + + sfizz_enable_lto_if_needed(${VST2PLUGIN_PRJ_NAME}) + + # Create the bundle + execute_process( + COMMAND "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/${VST2PLUGIN_BUNDLE_NAME}/Contents/Resources") + copy_editor_resources( + "${CMAKE_CURRENT_SOURCE_DIR}/../editor/resources" + "${PROJECT_BINARY_DIR}/${VST2PLUGIN_BUNDLE_NAME}/Contents/Resources") + set_target_properties(${VST2PLUGIN_PRJ_NAME} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${VST2PLUGIN_BUNDLE_NAME}/Contents/Binary/$<0:>") + + file(COPY "gpl-3.0.txt" + DESTINATION "${PROJECT_BINARY_DIR}/${VST2PLUGIN_BUNDLE_NAME}") + + if(MINGW) + set_target_properties(${VST2PLUGIN_PRJ_NAME} PROPERTIES LINK_FLAGS "-static") + endif() + + # Installation + if(VST2PLUGIN_INSTALL_DIR) + install(DIRECTORY "${PROJECT_BINARY_DIR}/${VST2PLUGIN_BUNDLE_NAME}" + DESTINATION "${VST2PLUGIN_INSTALL_DIR}" + COMPONENT "vst2") + if(APPLE) + bundle_dylibs(vst2 + "${VST2PLUGIN_INSTALL_DIR}/${VST2PLUGIN_BUNDLE_NAME}/Contents/Binary/sfizz.${CMAKE_SHARED_MODULE_SUFFIX}" + COMPONENT "vst2") + endif() + endif() +endif() diff --git a/plugins/vst/SfizzVstController.cpp b/plugins/vst/SfizzVstController.cpp index 27ed99d5..50d28603 100644 --- a/plugins/vst/SfizzVstController.cpp +++ b/plugins/vst/SfizzVstController.cpp @@ -7,6 +7,7 @@ #include "SfizzVstController.h" #include "SfizzVstEditor.h" #include "SfizzVstParameters.h" +#include "SfizzVstIDs.h" #include "base/source/fstreamer.h" #include "base/source/updatehandler.h" @@ -337,4 +338,4 @@ FUnknown* SfizzVstController::createInstance(void*) Note(jpc) Generated at random with uuidgen. Can't find docs on it... maybe it's to register somewhere? */ -FUID SfizzVstController::cid(0x7129736c, 0xbc784134, 0xbb899d56, 0x2ebafe4f); +FUID SfizzVstController::cid = SfizzVstController_cid; diff --git a/plugins/vst/SfizzVstIDs.h b/plugins/vst/SfizzVstIDs.h new file mode 100644 index 00000000..e8175a80 --- /dev/null +++ b/plugins/vst/SfizzVstIDs.h @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#pragma once +#include + +#define SfizzVstProcessor_cid \ + Steinberg::FUID(0xe8fab718, 0x15ed46e3, 0x8b598310, 0x1e12993f) +#define SfizzVstController_cid \ + Steinberg::FUID(0x7129736c, 0xbc784134, 0xbb899d56, 0x2ebafe4f) diff --git a/plugins/vst/SfizzVstProcessor.cpp b/plugins/vst/SfizzVstProcessor.cpp index 445b582c..dee37c41 100644 --- a/plugins/vst/SfizzVstProcessor.cpp +++ b/plugins/vst/SfizzVstProcessor.cpp @@ -8,6 +8,7 @@ #include "SfizzVstController.h" #include "SfizzVstState.h" #include "SfizzVstParameters.h" +#include "SfizzVstIDs.h" #include "SfizzFileScan.h" #include "sfizz/import/ForeignInstrument.h" #include "plugin/InstrumentDescription.h" @@ -866,4 +867,4 @@ bool SfizzVstProcessor::writeMessage(Ring_Buffer& fifo, const char* type, const Note(jpc) Generated at random with uuidgen. Can't find docs on it... maybe it's to register somewhere? */ -FUID SfizzVstProcessor::cid(0xe8fab718, 0x15ed46e3, 0x8b598310, 0x1e12993f); +FUID SfizzVstProcessor::cid = SfizzVstProcessor_cid; diff --git a/plugins/vst/Vst2PluginFactory.cpp b/plugins/vst/Vst2PluginFactory.cpp new file mode 100644 index 00000000..98b6981a --- /dev/null +++ b/plugins/vst/Vst2PluginFactory.cpp @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#include "SfizzVstIDs.h" +#include "public.sdk/source/vst/vst2wrapper/vst2wrapper.h" + +//------------------------------------------------------------------------ +::AudioEffect* createEffectInstance(audioMasterCallback audioMaster) +{ + return Steinberg::Vst::Vst2Wrapper::create( + GetPluginFactory(), + SfizzVstProcessor_cid, + 'Sfzz', + audioMaster); +} diff --git a/plugins/vst/cmake/Vst3.cmake b/plugins/vst/cmake/Vst3.cmake index d1c6a7c3..2545655c 100644 --- a/plugins/vst/cmake/Vst3.cmake +++ b/plugins/vst/cmake/Vst3.cmake @@ -18,6 +18,7 @@ add_library(vst3sdk STATIC EXCLUDE_FROM_ALL "${VST3SDK_BASEDIR}/pluginterfaces/base/funknown.cpp" "${VST3SDK_BASEDIR}/pluginterfaces/base/ustring.cpp" "${VST3SDK_BASEDIR}/public.sdk/source/common/commoniids.cpp" + "${VST3SDK_BASEDIR}/public.sdk/source/common/memorystream.cpp" "${VST3SDK_BASEDIR}/public.sdk/source/common/pluginview.cpp" "${VST3SDK_BASEDIR}/public.sdk/source/main/pluginfactory.cpp" "${VST3SDK_BASEDIR}/public.sdk/source/vst/vstaudioeffect.cpp"