From cf4f12a452611e46d29e4549ce69adac345706b7 Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 11 Jun 2018 12:49:00 +0100 Subject: [PATCH] Replaced our VST2 interface headers with official VST3 SDK --- .../Builds/Android/app/CMakeLists.txt | 2 - .../VisualStudio2013/DemoRunner_App.vcxproj | 1 - .../DemoRunner_App.vcxproj.filters | 3 - .../VisualStudio2015/DemoRunner_App.vcxproj | 1 - .../DemoRunner_App.vcxproj.filters | 3 - .../VisualStudio2017/DemoRunner_App.vcxproj | 1 - .../DemoRunner_App.vcxproj.filters | 3 - .../Builds/Android/app/CMakeLists.txt | 2 - .../AudioPerformanceTest_App.vcxproj | 1 - .../AudioPerformanceTest_App.vcxproj.filters | 3 - .../Builds/Android/app/CMakeLists.txt | 2 - .../Builds/LinuxMakefile/Makefile | 4 +- .../AudioPluginHost_App.vcxproj | 1 - .../AudioPluginHost_App.vcxproj.filters | 3 - .../AudioPluginHost_App.vcxproj | 1 - .../AudioPluginHost_App.vcxproj.filters | 3 - .../AudioPluginHost_App.vcxproj | 1 - .../AudioPluginHost_App.vcxproj.filters | 3 - .../Builds/Android/app/CMakeLists.txt | 2 - .../NetworkGraphicsDemo_App.vcxproj | 1 - .../NetworkGraphicsDemo_App.vcxproj.filters | 3 - .../NetworkGraphicsDemo_App.vcxproj | 1 - .../NetworkGraphicsDemo_App.vcxproj.filters | 3 - .../jucer_GlobalPathsWindowComponent.h | 13 +- .../jucer_CompileEngineClient.cpp | 27 +- .../Projucer/Source/Project/jucer_Project.cpp | 26 +- .../ProjectSaving/jucer_ProjectExport_MSVC.h | 10 +- .../ProjectSaving/jucer_ProjectExport_Make.h | 7 +- .../ProjectSaving/jucer_ProjectExport_Xcode.h | 10 +- .../ProjectSaving/jucer_ProjectExporter.cpp | 19 +- .../ProjectSaving/jucer_ProjectExporter.h | 1 + .../Source/Settings/jucer_StoredSettings.cpp | 27 +- .../Source/Settings/jucer_StoredSettings.h | 17 + .../Utility/PIPs/jucer_PIPGenerator.cpp | 2 +- .../UnitTestRunner_ConsoleApp.vcxproj | 1 - .../UnitTestRunner_ConsoleApp.vcxproj.filters | 3 - .../WindowsDLL_StaticLibrary.vcxproj | 1 - .../WindowsDLL_StaticLibrary.vcxproj.filters | 3 - .../VST/juce_VST_Wrapper.cpp | 611 +-- .../VST3/juce_VST3_Wrapper.cpp | 35 +- .../format_types/VST3_SDK/LICENSE.txt | 41 + .../format_types/VST3_SDK/README.md | 153 + .../format_types/VST3_SDK/base/LICENSE.txt | 27 + .../VST3_SDK/base/source/baseiids.cpp | 52 + .../base/source/classfactoryhelpers.h | 87 + .../VST3_SDK/base/source/fbuffer.cpp | 644 +++ .../VST3_SDK/base/source/fbuffer.h | 306 ++ .../VST3_SDK/base/source/fdebug.cpp | 314 ++ .../VST3_SDK/base/source/fdebug.h | 233 + .../VST3_SDK/base/source/fobject.cpp | 184 + .../VST3_SDK/base/source/fobject.h | 518 +++ .../VST3_SDK/base/source/fstreamer.cpp | 726 +++ .../VST3_SDK/base/source/fstreamer.h | 242 + .../VST3_SDK/base/source/fstring.cpp | 3996 +++++++++++++++++ .../VST3_SDK/base/source/fstring.h | 747 +++ .../VST3_SDK/base/source/updatehandler.cpp | 721 +++ .../VST3_SDK/base/source/updatehandler.h | 139 + .../VST3_SDK/base/thread/include/flock.h | 183 + .../VST3_SDK/base/thread/source/flock.cpp | 146 + .../VST3_SDK/pluginterfaces/LICENSE.txt | 41 + .../pluginterfaces/base/conststringtable.cpp | 106 + .../pluginterfaces/base/conststringtable.h | 45 + .../VST3_SDK/pluginterfaces/base/coreiids.cpp | 36 + .../VST3_SDK/pluginterfaces/base/falignpop.h | 31 + .../VST3_SDK/pluginterfaces/base/falignpush.h | 36 + .../VST3_SDK/pluginterfaces/base/fplatform.h | 208 + .../VST3_SDK/pluginterfaces/base/fstrdefs.h | 291 ++ .../VST3_SDK/pluginterfaces/base/ftypes.h | 192 + .../VST3_SDK/pluginterfaces/base/funknown.cpp | 453 ++ .../VST3_SDK/pluginterfaces/base/funknown.h | 466 ++ .../VST3_SDK/pluginterfaces/base/futils.h | 92 + .../VST3_SDK/pluginterfaces/base/fvariant.h | 297 ++ .../VST3_SDK/pluginterfaces/base/ibstream.h | 89 + .../VST3_SDK/pluginterfaces/base/icloneable.h | 42 + .../pluginterfaces/base/ipersistent.h | 161 + .../pluginterfaces/base/ipluginbase.h | 436 ++ .../pluginterfaces/base/istringresult.h | 80 + .../pluginterfaces/base/iupdatehandler.h | 100 + .../pluginterfaces/base/smartpointer.h | 370 ++ .../VST3_SDK/pluginterfaces/base/ustring.cpp | 272 ++ .../VST3_SDK/pluginterfaces/base/ustring.h | 110 + .../VST3_SDK/pluginterfaces/gui/iplugview.h | 281 ++ .../gui/iplugviewcontentscalesupport.h | 64 + .../pluginterfaces/vst/ivstattributes.h | 145 + .../pluginterfaces/vst/ivstaudioprocessor.h | 353 ++ .../pluginterfaces/vst/ivstautomationstate.h | 67 + .../vst/ivstchannelcontextinfo.h | 226 + .../pluginterfaces/vst/ivstcomponent.h | 201 + .../pluginterfaces/vst/ivstcontextmenu.h | 212 + .../pluginterfaces/vst/ivsteditcontroller.h | 427 ++ .../VST3_SDK/pluginterfaces/vst/ivstevents.h | 179 + .../pluginterfaces/vst/ivsthostapplication.h | 118 + .../pluginterfaces/vst/ivstinterappaudio.h | 143 + .../VST3_SDK/pluginterfaces/vst/ivstmessage.h | 94 + .../pluginterfaces/vst/ivstmidicontrollers.h | 112 + .../pluginterfaces/vst/ivstnoteexpression.h | 248 + .../pluginterfaces/vst/ivstparameterchanges.h | 140 + .../pluginterfaces/vst/ivstplugview.h | 61 + .../vst/ivstprefetchablesupport.h | 87 + .../pluginterfaces/vst/ivstprocesscontext.h | 142 + .../pluginterfaces/vst/ivstrepresentation.h | 372 ++ .../VST3_SDK/pluginterfaces/vst/ivstunits.h | 264 ++ .../VST3_SDK/pluginterfaces/vst/vstspeaker.h | 812 ++++ .../VST3_SDK/pluginterfaces/vst/vsttypes.h | 102 + .../VST3_SDK/pluginterfaces/vst2.x/aeffect.h | 392 ++ .../VST3_SDK/pluginterfaces/vst2.x/aeffectx.h | 1170 +++++ .../pluginterfaces/vst2.x/vstfxstore.h | 128 + .../VST3_SDK/public.sdk/LICENSE.txt | 27 + .../public.sdk/source/common/memorystream.cpp | 319 ++ .../public.sdk/source/common/memorystream.h | 80 + .../public.sdk/source/common/pluginview.cpp | 99 + .../public.sdk/source/common/pluginview.h | 102 + .../source/vst/hosting/hostclasses.cpp | 316 ++ .../source/vst/hosting/hostclasses.h | 112 + .../VST3_SDK/public.sdk/source/vst/vstbus.cpp | 98 + .../VST3_SDK/public.sdk/source/vst/vstbus.h | 164 + .../public.sdk/source/vst/vstcomponent.cpp | 216 + .../public.sdk/source/vst/vstcomponent.h | 117 + .../source/vst/vstcomponentbase.cpp | 180 + .../public.sdk/source/vst/vstcomponentbase.h | 107 + .../source/vst/vsteditcontroller.cpp | 721 +++ .../public.sdk/source/vst/vsteditcontroller.h | 374 ++ .../public.sdk/source/vst/vstinitiids.cpp | 118 + .../public.sdk/source/vst/vstparameters.cpp | 436 ++ .../public.sdk/source/vst/vstparameters.h | 238 + .../public.sdk/source/vst/vstpresetfile.cpp | 935 ++++ .../public.sdk/source/vst/vstpresetfile.h | 305 ++ .../format_types/juce_VST3Common.h | 134 +- .../format_types/juce_VSTCommon.h | 264 +- .../format_types/juce_VSTInterface.h | 530 --- .../format_types/juce_VSTMidiEventList.h | 86 +- .../format_types/juce_VSTPluginFormat.cpp | 538 +-- 132 files changed, 25964 insertions(+), 1466 deletions(-) create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/LICENSE.txt create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/README.md create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/LICENSE.txt create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/baseiids.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/classfactoryhelpers.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/thread/include/flock.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/base/thread/source/flock.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/LICENSE.txt create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/coreiids.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpop.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpush.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fplatform.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fstrdefs.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ftypes.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/futils.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fvariant.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ibstream.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/icloneable.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipersistent.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipluginbase.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/istringresult.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/iupdatehandler.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/smartpointer.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ustring.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ustring.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/gui/iplugview.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/gui/iplugviewcontentscalesupport.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstattributes.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstaudioprocessor.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstautomationstate.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstchannelcontextinfo.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstcomponent.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstcontextmenu.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivsteditcontroller.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstevents.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivsthostapplication.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstinterappaudio.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstmessage.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstmidicontrollers.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstnoteexpression.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstparameterchanges.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstplugview.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstprefetchablesupport.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstprocesscontext.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstrepresentation.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/ivstunits.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/vstspeaker.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst/vsttypes.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst2.x/aeffect.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst2.x/aeffectx.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst2.x/vstfxstore.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/LICENSE.txt create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/common/memorystream.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/common/memorystream.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/common/pluginview.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/common/pluginview.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/hosting/hostclasses.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/hosting/hostclasses.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstbus.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstbus.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstcomponent.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstcomponent.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstcomponentbase.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstcomponentbase.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vsteditcontroller.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vsteditcontroller.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstinitiids.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstparameters.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstparameters.h create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstpresetfile.cpp create mode 100644 modules/juce_audio_processors/format_types/VST3_SDK/public.sdk/source/vst/vstpresetfile.h delete mode 100644 modules/juce_audio_processors/format_types/juce_VSTInterface.h diff --git a/examples/DemoRunner/Builds/Android/app/CMakeLists.txt b/examples/DemoRunner/Builds/Android/app/CMakeLists.txt index 57fdd259dd..cc51f51b8e 100644 --- a/examples/DemoRunner/Builds/Android/app/CMakeLists.txt +++ b/examples/DemoRunner/Builds/Android/app/CMakeLists.txt @@ -330,7 +330,6 @@ add_library( ${BINARY_NAME} "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" - "../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" @@ -1796,7 +1795,6 @@ set_source_files_properties("../../../../../modules/juce_audio_processors/format set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" PROPERTIES HEADER_FILE_ONLY TRUE) -set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) diff --git a/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj b/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj index f004cd121c..c883af0627 100644 --- a/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj +++ b/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj @@ -2266,7 +2266,6 @@ - diff --git a/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj.filters b/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj.filters index 04adb13e15..28e002f7f2 100644 --- a/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj.filters +++ b/examples/DemoRunner/Builds/VisualStudio2013/DemoRunner_App.vcxproj.filters @@ -3105,9 +3105,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj b/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj index a9d23c0699..5d8c375ec1 100644 --- a/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj +++ b/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj @@ -2266,7 +2266,6 @@ - diff --git a/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj.filters b/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj.filters index 98462b557d..8a16d56051 100644 --- a/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj.filters +++ b/examples/DemoRunner/Builds/VisualStudio2015/DemoRunner_App.vcxproj.filters @@ -3105,9 +3105,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj b/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj index dabbf0de7b..1cba6437c1 100644 --- a/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj +++ b/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj @@ -2266,7 +2266,6 @@ - diff --git a/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj.filters b/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj.filters index 1f0deb70e9..c24550f621 100644 --- a/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj.filters +++ b/examples/DemoRunner/Builds/VisualStudio2017/DemoRunner_App.vcxproj.filters @@ -3105,9 +3105,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/AudioPerformanceTest/Builds/Android/app/CMakeLists.txt b/extras/AudioPerformanceTest/Builds/Android/app/CMakeLists.txt index f688f097d1..fa407ef81f 100644 --- a/extras/AudioPerformanceTest/Builds/Android/app/CMakeLists.txt +++ b/extras/AudioPerformanceTest/Builds/Android/app/CMakeLists.txt @@ -311,7 +311,6 @@ add_library( ${BINARY_NAME} "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" - "../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" @@ -1479,7 +1478,6 @@ set_source_files_properties("../../../../../modules/juce_audio_processors/format set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" PROPERTIES HEADER_FILE_ONLY TRUE) -set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) diff --git a/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj b/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj index 0f7d6fad65..c0e8834801 100644 --- a/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj +++ b/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj @@ -1907,7 +1907,6 @@ - diff --git a/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj.filters b/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj.filters index f593065254..1c0d1e5da8 100644 --- a/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj.filters +++ b/extras/AudioPerformanceTest/Builds/VisualStudio2017/AudioPerformanceTest_App.vcxproj.filters @@ -2547,9 +2547,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/AudioPluginHost/Builds/Android/app/CMakeLists.txt b/extras/AudioPluginHost/Builds/Android/app/CMakeLists.txt index bfa191b627..1dbf288a4b 100644 --- a/extras/AudioPluginHost/Builds/Android/app/CMakeLists.txt +++ b/extras/AudioPluginHost/Builds/Android/app/CMakeLists.txt @@ -327,7 +327,6 @@ add_library( ${BINARY_NAME} "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" - "../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" @@ -1568,7 +1567,6 @@ set_source_files_properties("../../../../../modules/juce_audio_processors/format set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" PROPERTIES HEADER_FILE_ONLY TRUE) -set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) diff --git a/extras/AudioPluginHost/Builds/LinuxMakefile/Makefile b/extras/AudioPluginHost/Builds/LinuxMakefile/Makefile index 70dba40d72..42ce57d4c4 100644 --- a/extras/AudioPluginHost/Builds/LinuxMakefile/Makefile +++ b/extras/AudioPluginHost/Builds/LinuxMakefile/Makefile @@ -35,7 +35,7 @@ ifeq ($(CONFIG),Debug) TARGET_ARCH := -march=native endif - JUCE_CPPFLAGS := $(DEPFLAGS) -DLINUX=1 -DDEBUG=1 -D_DEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 $(shell pkg-config --cflags alsa freetype2 libcurl x11 xext xinerama) -pthread -I../../JuceLibraryCode -I../../../../modules $(CPPFLAGS) + JUCE_CPPFLAGS := $(DEPFLAGS) -DLINUX=1 -DDEBUG=1 -D_DEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 $(shell pkg-config --cflags alsa freetype2 libcurl x11 xext xinerama) -pthread -I$(HOME)/SDKs/VST_SDK/VST3_SDK -I../../JuceLibraryCode -I../../../../modules $(CPPFLAGS) JUCE_CPPFLAGS_APP := -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_RTAS=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=0 -DJucePlugin_Build_Unity=0 JUCE_TARGET_APP := AudioPluginHost @@ -56,7 +56,7 @@ ifeq ($(CONFIG),Release) TARGET_ARCH := -march=native endif - JUCE_CPPFLAGS := $(DEPFLAGS) -DLINUX=1 -DNDEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 $(shell pkg-config --cflags alsa freetype2 libcurl x11 xext xinerama) -pthread -I../../JuceLibraryCode -I../../../../modules $(CPPFLAGS) + JUCE_CPPFLAGS := $(DEPFLAGS) -DLINUX=1 -DNDEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 $(shell pkg-config --cflags alsa freetype2 libcurl x11 xext xinerama) -pthread -I$(HOME)/SDKs/VST_SDK/VST3_SDK -I../../JuceLibraryCode -I../../../../modules $(CPPFLAGS) JUCE_CPPFLAGS_APP := -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_RTAS=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=0 -DJucePlugin_Build_Unity=0 JUCE_TARGET_APP := AudioPluginHost diff --git a/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj b/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj index 9a586ae1e8..028636a3a1 100644 --- a/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj +++ b/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj @@ -1981,7 +1981,6 @@ - diff --git a/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj.filters b/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj.filters index 55370d1444..642bbf01ab 100644 --- a/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj.filters +++ b/extras/AudioPluginHost/Builds/VisualStudio2013/AudioPluginHost_App.vcxproj.filters @@ -2700,9 +2700,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj b/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj index 071fbf1ace..613f6905fe 100644 --- a/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj +++ b/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj @@ -1981,7 +1981,6 @@ - diff --git a/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj.filters b/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj.filters index cb33a88a63..4e518d4c2b 100644 --- a/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj.filters +++ b/extras/AudioPluginHost/Builds/VisualStudio2015/AudioPluginHost_App.vcxproj.filters @@ -2700,9 +2700,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj b/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj index 2edcb9ef79..c080303a49 100644 --- a/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj +++ b/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj @@ -1981,7 +1981,6 @@ - diff --git a/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj.filters b/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj.filters index 12b15f3ee3..c89e76140d 100644 --- a/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj.filters +++ b/extras/AudioPluginHost/Builds/VisualStudio2017/AudioPluginHost_App.vcxproj.filters @@ -2700,9 +2700,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/NetworkGraphicsDemo/Builds/Android/app/CMakeLists.txt b/extras/NetworkGraphicsDemo/Builds/Android/app/CMakeLists.txt index 0b94bf62c4..7c96c1efaa 100644 --- a/extras/NetworkGraphicsDemo/Builds/Android/app/CMakeLists.txt +++ b/extras/NetworkGraphicsDemo/Builds/Android/app/CMakeLists.txt @@ -315,7 +315,6 @@ add_library( ${BINARY_NAME} "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" - "../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" "../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" @@ -1558,7 +1557,6 @@ set_source_files_properties("../../../../../modules/juce_audio_processors/format set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VST3PluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTCommon.h" PROPERTIES HEADER_FILE_ONLY TRUE) -set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTInterface.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp" PROPERTIES HEADER_FILE_ONLY TRUE) set_source_files_properties("../../../../../modules/juce_audio_processors/format_types/juce_VSTPluginFormat.h" PROPERTIES HEADER_FILE_ONLY TRUE) diff --git a/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj b/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj index 75bbab4c23..ae1541f52f 100644 --- a/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj +++ b/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj @@ -1992,7 +1992,6 @@ - diff --git a/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj.filters b/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj.filters index fdeb11f148..c87b71b200 100644 --- a/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj.filters +++ b/extras/NetworkGraphicsDemo/Builds/VisualStudio2013/NetworkGraphicsDemo_App.vcxproj.filters @@ -2682,9 +2682,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj b/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj index 4aab3c7c16..de67b5ca56 100644 --- a/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj +++ b/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj @@ -1992,7 +1992,6 @@ - diff --git a/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj.filters b/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj.filters index 70136663bb..8ff758fd23 100644 --- a/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj.filters +++ b/extras/NetworkGraphicsDemo/Builds/VisualStudio2017/NetworkGraphicsDemo_App.vcxproj.filters @@ -2682,9 +2682,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/Projucer/Source/Application/Windows/jucer_GlobalPathsWindowComponent.h b/extras/Projucer/Source/Application/Windows/jucer_GlobalPathsWindowComponent.h index a6c9a7c511..86ed55fd58 100644 --- a/extras/Projucer/Source/Application/Windows/jucer_GlobalPathsWindowComponent.h +++ b/extras/Projucer/Source/Application/Windows/jucer_GlobalPathsWindowComponent.h @@ -190,9 +190,6 @@ private: pathPropertyComponents.add (nullptr); - addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::vst3Path), - "VST3 SDK", true))); - if (getSelectedOS() == TargetOS::linux) { addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent ({}, "RTAS SDK", true))); @@ -214,6 +211,9 @@ private: addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::androidNDKPath), "Android NDK", true))); + addAndMakeVisible (pathPropertyComponents.add (new FilePathPropertyComponent (settings.getStoredPath (Ids::vst3Path), + "Custom VST3 SDK", true))); + pathPropertyComponents.add (nullptr); #if JUCE_MAC @@ -240,9 +240,6 @@ private: pathPropertyComponents.add (nullptr); - addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::vst3Path, selectedOS), - "VST3 SDK", maxChars, false))); - if (selectedOS == TargetOS::linux) { addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (Value(), "RTAS SDK", maxChars, false))); @@ -259,10 +256,14 @@ private: "AAX SDK", maxChars, false))); } + addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::androidSDKPath, selectedOS), "Android SDK", maxChars, false))); addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::androidNDKPath, selectedOS), "Android NDK", maxChars, false))); + + addAndMakeVisible (pathPropertyComponents.add (new TextPropertyComponent (settings.getFallbackPathForOS (Ids::vst3Path, selectedOS), + "Custom VST3 SDK", maxChars, false))); } resized(); diff --git a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp index fd7d4bcd0c..10fc8d06c0 100644 --- a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp +++ b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp @@ -370,8 +370,8 @@ private: scanProjectItem (proj.getMainGroup(), compileUnits, userFiles); { - auto isVST3Host = project.getModules().isModuleEnabled ("juce_audio_processors") - && project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3"); + auto isVSTHost = project.getModules().isModuleEnabled ("juce_audio_processors") + && (project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3") || project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST")); auto isPluginProject = proj.getProjectType().isAudioPlugin(); @@ -390,10 +390,10 @@ private: m->findAndAddCompiledUnits (*exporter, nullptr, compileUnits, - isPluginProject || isVST3Host ? ProjectType::Target::SharedCodeTarget - : ProjectType::Target::unspecified); + isPluginProject || isVSTHost ? ProjectType::Target::SharedCodeTarget + : ProjectType::Target::unspecified); - if (isPluginProject || isVST3Host) + if (isPluginProject || isVSTHost) m->findAndAddCompiledUnits (*exporter, nullptr, compileUnits, ProjectType::Target::StandalonePlugIn); } @@ -458,18 +458,27 @@ private: StringArray paths; paths.addArray (getSearchPathsFromString (project.getCompileEngineSettings().getSystemHeaderPathString())); - auto isVST3Host = project.getModules().isModuleEnabled ("juce_audio_processors") - && project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3"); + auto isVSTHost = project.getModules().isModuleEnabled ("juce_audio_processors") + && (project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3") + || project.isConfigFlagEnabled ("JUCE_PLUGINHOST_VST")); - if (project.getProjectType().isAudioPlugin() || isVST3Host) - paths.add (getAppSettings().getStoredPath (Ids::vst3Path).toString()); + auto customVst3Path = getAppSettings().getStoredPath (Ids::vst3Path).toString(); + + if (customVst3Path.isNotEmpty() && (project.getProjectType().isAudioPlugin() || isVSTHost)) + paths.add (customVst3Path); OwnedArray modules; project.getModules().createRequiredModules (modules); for (auto* module : modules) + { paths.addIfNotAlreadyThere (module->getFolder().getParentDirectory().getFullPathName()); + if (customVst3Path.isEmpty() && (project.getProjectType().isAudioPlugin() || isVSTHost)) + if (module->getID() == "juce_audio_processors") + paths.addIfNotAlreadyThere (module->getFolder().getChildFile ("format_types").getChildFile ("VST3_SDK").getFullPathName()); + } + return convertSearchPathsToAbsolute (paths); } diff --git a/extras/Projucer/Source/Project/jucer_Project.cpp b/extras/Projucer/Source/Project/jucer_Project.cpp index 599348af1e..f1e44d72d7 100644 --- a/extras/Projucer/Source/Project/jucer_Project.cpp +++ b/extras/Projucer/Source/Project/jucer_Project.cpp @@ -235,7 +235,7 @@ void Project::initialiseProjectValues() void Project::initialiseAudioPluginValues() { pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(), - Array (Ids::buildVST.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()), ","); + Array (Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()), ","); pluginCharacteristicsValue.referTo (projectRoot, Ids::pluginCharacteristicsValue, getUndoManager(), Array (), ","); pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString()); @@ -1026,10 +1026,10 @@ void Project::createPropertyEditors (PropertyListBuilder& props) void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props) { props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats", - { "VST", "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Unity", "Enable IAA" }, - { Ids::buildVST.toString(), Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(), + { "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Unity", "Enable IAA", "VST (legacy)" }, + { Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(), Ids::buildRTAS.toString(), Ids::buildAAX.toString(), Ids::buildStandalone.toString(), Ids::buildUnity.toString(), - Ids::enableIAA.toString() }), + Ids::enableIAA.toString(), Ids::buildVST.toString() }), "Plugin formats to build."); props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics", { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus", @@ -1062,15 +1062,6 @@ void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props) props.add (new MultiChoicePropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", getAllAUMainTypeStrings(), getAllAUMainTypeVars(), 1), "AU main type."); - { - Array vstCategoryVars; - for (auto s : getAllVSTCategoryStrings()) - vstCategoryVars.add (s); - - props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST Category", getAllVSTCategoryStrings(), vstCategoryVars, 1), - "VST category."); - } - { Array vst3CategoryVars; for (auto s : getAllVST3CategoryStrings()) @@ -1084,6 +1075,15 @@ void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props) "RTAS category."); props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()), "AAX category."); + + { + Array vstCategoryVars; + for (auto s : getAllVSTCategoryStrings()) + vstCategoryVars.add (s); + + props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST (legacy) Category", getAllVSTCategoryStrings(), vstCategoryVars, 1), + "VST category."); + } } //============================================================================== diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h index 49c07a1733..a1689db6b3 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h @@ -330,11 +330,6 @@ public: props.add (new ChoicePropertyComponent (pluginBinaryCopyStepValue, "Enable Plugin Copy Step"), "Enable this to copy plugin binaries to a specified folder after building."); - if (project.shouldBuildVST()) - props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepValue, "VST Binary Location", - 1024, false), - "The folder in which the compiled VST binary should be placed."); - if (project.shouldBuildVST3()) props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepValue, "VST3 Binary Location", 1024, false), @@ -355,6 +350,11 @@ public: 1024, false), "The folder in which the compiled Unity plugin binary and associated C# GUI script should be placed."); + if (project.shouldBuildVST()) + props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepValue, "VST (legacy) Binary Location", + 1024, false), + "The folder in which the compiled lehacy VST binary should be placed."); + } void setPluginBinaryCopyLocationDefaults() diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h index b6ad1b384e..5b30f2ef4e 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Make.h @@ -422,7 +422,12 @@ public: } //============================================================================== - void initialiseDependencyPathValues() override {} + void initialiseDependencyPathValues() override + { + vst3Path.referTo (Value (new DependencyPathValueSource (getSetting (Ids::vst3Folder), + Ids::vst3Path, + TargetOS::linux))); + } private: ValueWithDefault extraPkgConfigValue; diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h index bdb534b45a..b605f055fb 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h @@ -574,11 +574,6 @@ protected: props.add (new ChoicePropertyComponent (pluginBinaryCopyStepEnabled, "Enable Plugin Copy Step"), "Enable this to copy plugin binaries to the specified folder after building."); - if (project.shouldBuildVST()) - props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepEnabled, "VST Binary Location", - 1024, false), - "The folder in which the compiled VST binary should be placed."); - if (project.shouldBuildVST3()) props.add (new TextPropertyComponentWithEnablement (vst3BinaryLocation, pluginBinaryCopyStepEnabled, "VST3 Binary Location", 1024, false), @@ -603,6 +598,11 @@ protected: props.add (new TextPropertyComponentWithEnablement (unityPluginBinaryLocation, pluginBinaryCopyStepEnabled, "Unity Binary Location", 1024, false), "The folder in which the compiled Unity plugin binary and associated C# GUI script should be placed."); + + if (project.shouldBuildVST()) + props.add (new TextPropertyComponentWithEnablement (vstBinaryLocation, pluginBinaryCopyStepEnabled, "VST Binary Location", + 1024, false), + "The folder in which the compiled legacy VST binary should be placed."); } void updateOldPluginBinaryLocations() diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp index 655970c362..cbc216c34d 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.cpp @@ -329,13 +329,6 @@ void ProjectExporter::createPropertyEditors (PropertyListBuilder& props) void ProjectExporter::createDependencyPathProperties (PropertyListBuilder& props) { - if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) || project.isVST3PluginHost()) - { - if (dynamic_cast (&getVST3PathValue().getValueSource()) != nullptr) - props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), getVST3PathValue(), "VST3 SDK Folder"), - "If you're building a VST3 plugin or host, this must be the folder containing the VST3 SDK. This can be an absolute path, or a path relative to the Projucer project file."); - } - if (shouldBuildTargetType (ProjectType::Target::AAXPlugIn) && project.shouldBuildAAX()) { if (dynamic_cast (&getAAXPathValue().getValueSource()) != nullptr) @@ -388,7 +381,8 @@ void ProjectExporter::addSettingsForProjectType (const ProjectType& type) void ProjectExporter::addVSTPathsIfPluginOrHost() { - if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) || project.isVST3PluginHost()) + if (shouldBuildTargetType (ProjectType::Target::VST3PlugIn) || project.isVST3PluginHost() + || shouldBuildTargetType (ProjectType::Target::VSTPlugIn) || project.isVSTPluginHost()) addVST3FolderToPath(); } @@ -400,12 +394,21 @@ void ProjectExporter::addCommonAudioPluginSettings() // Note: RTAS paths are platform-dependent, impl -> addPlatformSpecificSettingsForProjectType } +RelativePath ProjectExporter::getInternalVST3SDKPath() +{ + return getModuleFolderRelativeToProject ("juce_audio_processors") + .getChildFile ("format_types") + .getChildFile ("VST3_SDK"); +} + void ProjectExporter::addVST3FolderToPath() { auto vst3Folder = getVST3PathValue().toString(); if (vst3Folder.isNotEmpty()) addToExtraSearchPaths (RelativePath (vst3Folder, RelativePath::projectFolder), 0); + else + addToExtraSearchPaths (getInternalVST3SDKPath(), 0); } void ProjectExporter::addAAXFoldersToPath() diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h index a42f94a50e..14c2b07d41 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExporter.h @@ -445,6 +445,7 @@ private: void createIconProperties (PropertyListBuilder&); void addVSTPathsIfPluginOrHost(); void addCommonAudioPluginSettings(); + RelativePath getInternalVST3SDKPath(); void addVST3FolderToPath(); void addAAXFoldersToPath(); diff --git a/extras/Projucer/Source/Settings/jucer_StoredSettings.cpp b/extras/Projucer/Source/Settings/jucer_StoredSettings.cpp index acdd050444..def6cf3b2c 100644 --- a/extras/Projucer/Source/Settings/jucer_StoredSettings.cpp +++ b/extras/Projucer/Source/Settings/jucer_StoredSettings.cpp @@ -297,17 +297,9 @@ Value StoredSettings::getStoredPath (const Identifier& key) Value StoredSettings::getFallbackPathForOS (const Identifier& key, DependencyPathOS os) { - auto id = Identifier(); - - if (os == TargetOS::osx) id = Ids::osxFallback; - else if (os == TargetOS::windows) id = Ids::windowsFallback; - else if (os == TargetOS::linux) id = Ids::linuxFallback; - - if (id == Identifier()) - jassertfalse; - - auto v = fallbackPaths.getOrCreateChildWithName (id, nullptr) - .getPropertyAsValue (key, nullptr); + auto id = identifierForOS (os); + auto osFallback = fallbackPaths.getOrCreateChildWithName (id, nullptr); + auto v = osFallback.getPropertyAsValue (key, nullptr); if (v.toString().isEmpty()) { @@ -328,8 +320,7 @@ Value StoredSettings::getFallbackPathForOS (const Identifier& key, DependencyPat } else if (key == Ids::vst3Path) { - v = (os == TargetOS::windows ? "C:\\SDKs\\VST_SDK\\VST3_SDK" - : "~/SDKs/VST_SDK/VST3_SDK"); + v = ""; } else if (key == Ids::rtasPath) { @@ -379,6 +370,16 @@ Value StoredSettings::getFallbackPathForOS (const Identifier& key, DependencyPat return v; } +Identifier StoredSettings::identifierForOS (DependencyPathOS os) noexcept +{ + if (os == TargetOS::osx) return Ids::osxFallback; + else if (os == TargetOS::windows) return Ids::windowsFallback; + else if (os == TargetOS::linux) return Ids::linuxFallback; + + jassertfalse; + return {}; +} + static bool doesSDKPathContainFile (const File& relativeTo, const String& path, const String& fileToCheckFor) noexcept { auto actualPath = path.replace ("${user.home}", File::getSpecialLocation (File::userHomeDirectory).getFullPathName()); diff --git a/extras/Projucer/Source/Settings/jucer_StoredSettings.h b/extras/Projucer/Source/Settings/jucer_StoredSettings.h index 26435b858b..e174c2550f 100644 --- a/extras/Projucer/Source/Settings/jucer_StoredSettings.h +++ b/extras/Projucer/Source/Settings/jucer_StoredSettings.h @@ -89,8 +89,25 @@ private: propertyFiles.getUnchecked (0)->setValue (isProjectDefaults ? "PROJECT_DEFAULT_SETTINGS" : "FALLBACK_PATHS", data.get()); + + // also override the fallback settings if we are editing the project defaults + if (isProjectDefaults) + { + auto v = fallbackPaths.getOrCreateChildWithName (identifierForOS (TargetOS::getThisOS()), nullptr); + auto n = projectDefaults.getNumProperties(); + + for (int i = 0; i < n; ++i) + { + auto name = projectDefaults.getPropertyName (i); + v.setProperty (name, projectDefaults.getProperty(name), nullptr); + } + + changed (false); + } } + static Identifier identifierForOS (DependencyPathOS os) noexcept; + void updateGlobalPreferences(); void updateRecentFiles(); void updateLastWizardFolder(); diff --git a/extras/Projucer/Source/Utility/PIPs/jucer_PIPGenerator.cpp b/extras/Projucer/Source/Utility/PIPs/jucer_PIPGenerator.cpp index 0424f5ffd0..50e405d1aa 100644 --- a/extras/Projucer/Source/Utility/PIPs/jucer_PIPGenerator.cpp +++ b/extras/Projucer/Source/Utility/PIPs/jucer_PIPGenerator.cpp @@ -461,7 +461,7 @@ Result PIPGenerator::setProjectSettings (ValueTree& jucerTree) jucerTree.setProperty (Ids::projectType, "audioplug", nullptr); jucerTree.setProperty (Ids::pluginManufacturer, metadata[Ids::vendor], nullptr); - StringArray pluginFormatsToBuild (Ids::buildVST.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()); + StringArray pluginFormatsToBuild (Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()); pluginFormatsToBuild.addArray (getExtraPluginFormatsToBuild()); jucerTree.setProperty (Ids::pluginFormats, pluginFormatsToBuild.joinIntoString (","), nullptr); diff --git a/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj b/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj index 3e28810fd5..08a655536a 100644 --- a/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj +++ b/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj @@ -2116,7 +2116,6 @@ - diff --git a/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj.filters b/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj.filters index 99ec1e7330..be1b23a31b 100644 --- a/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj.filters +++ b/extras/UnitTestRunner/Builds/VisualStudio2017/UnitTestRunner_ConsoleApp.vcxproj.filters @@ -2895,9 +2895,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj b/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj index 8529654d2c..dcf84bf5f1 100644 --- a/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj +++ b/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj @@ -1968,7 +1968,6 @@ - diff --git a/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj.filters b/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj.filters index 00a85ee174..bfb64850f8 100644 --- a/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj.filters +++ b/extras/WindowsDLL/Builds/VisualStudio2017/WindowsDLL_StaticLibrary.vcxproj.filters @@ -2649,9 +2649,6 @@ JUCE Modules\juce_audio_processors\format_types - - JUCE Modules\juce_audio_processors\format_types - JUCE Modules\juce_audio_processors\format_types diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 1a22827283..3c18c978df 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -34,6 +34,7 @@ #endif #include "../utility/juce_IncludeSystemHeaders.h" +#include #ifdef PRAGMA_ALIGN_SUPPORTED #undef PRAGMA_ALIGN_SUPPORTED @@ -59,8 +60,15 @@ #pragma warning (disable : 4458) #endif -#include -#include "../../juce_audio_processors/format_types/juce_VSTInterface.h" +#define VST_FORCE_DEPRECATED 0 + +namespace Vst2 +{ +#include "../../juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst2.x/aeffect.h" +#include "../../juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst2.x/aeffectx.h" +} + +using namespace juce; #ifdef _MSC_VER #pragma warning (pop) @@ -75,6 +83,8 @@ #pragma pack (push, 8) #endif +#define JUCE_VSTINTERFACE_H_INCLUDED 1 + #include "../utility/juce_IncludeModuleHeaders.h" #include "../utility/juce_FakeMouseMoveGenerator.h" #include "../utility/juce_WindowsHooks.h" @@ -82,6 +92,12 @@ #include "../../juce_audio_processors/format_types/juce_LegacyAudioParameter.cpp" #include "../../juce_audio_processors/format_types/juce_VSTCommon.h" +#if JUCE_BIG_ENDIAN + #define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (a | (((uint32) b) << 8) | (((uint32) c) << 16) | (((uint32) d) << 24)) +#else + #define JUCE_MULTICHAR_CONSTANT(a, b, c, d) (d | (((uint32) c) << 8) | (((uint32) b) << 16) | (((uint32) a) << 24)) +#endif + #ifdef _MSC_VER #pragma pack (pop) #endif @@ -258,7 +274,7 @@ private: public: //============================================================================== - JuceVSTWrapper (VstHostCallback cb, AudioProcessor* af) + JuceVSTWrapper (Vst2::audioMasterCallback cb, AudioProcessor* af) : hostCallback (cb), processor (af) { @@ -289,41 +305,41 @@ public: juceParameters.update (*processor, false); memset (&vstEffect, 0, sizeof (vstEffect)); - vstEffect.interfaceIdentifier = juceVstInterfaceIdentifier; - vstEffect.dispatchFunction = dispatcherCB; - vstEffect.processAudioFunction = nullptr; - vstEffect.setParameterValueFunction = setParameterCB; - vstEffect.getParameterValueFunction = getParameterCB; + vstEffect.magic = 0x56737450 /* 'VstP' */; + vstEffect.dispatcher = (Vst2::AEffectDispatcherProc) dispatcherCB; + vstEffect.process = nullptr; + vstEffect.setParameter = (Vst2::AEffectSetParameterProc) setParameterCB; + vstEffect.getParameter = (Vst2::AEffectGetParameterProc) getParameterCB; vstEffect.numPrograms = jmax (1, af->getNumPrograms()); - vstEffect.numParameters = juceParameters.getNumParameters(); - vstEffect.numInputChannels = maxNumInChannels; - vstEffect.numOutputChannels = maxNumOutChannels; - vstEffect.latency = processor->getLatencySamples(); - vstEffect.effectPointer = this; - vstEffect.plugInIdentifier = JucePlugin_VSTUniqueID; + vstEffect.numParams = juceParameters.getNumParameters(); + vstEffect.numInputs = maxNumInChannels; + vstEffect.numOutputs = maxNumOutChannels; + vstEffect.initialDelay = processor->getLatencySamples(); + vstEffect.object = this; + vstEffect.uniqueID = JucePlugin_VSTUniqueID; #ifdef JucePlugin_VSTChunkStructureVersion - vstEffect.plugInVersion = JucePlugin_VSTChunkStructureVersion; + vstEffect.version = JucePlugin_VSTChunkStructureVersion; #else - vstEffect.plugInVersion = JucePlugin_VersionCode; + vstEffect.version = JucePlugin_VersionCode; #endif - vstEffect.processAudioInplaceFunction = processReplacingCB; - vstEffect.processDoubleAudioInplaceFunction = processDoubleReplacingCB; + vstEffect.processReplacing = (Vst2::AEffectProcessProc) processReplacingCB; + vstEffect.processDoubleReplacing = (Vst2::AEffectProcessDoubleProc) processDoubleReplacingCB; - vstEffect.flags |= vstEffectFlagHasEditor; + vstEffect.flags |= Vst2::effFlagsHasEditor; - vstEffect.flags |= vstEffectFlagInplaceAudio; + vstEffect.flags |= Vst2::effFlagsCanReplacing; if (processor->supportsDoublePrecisionProcessing()) - vstEffect.flags |= vstEffectFlagInplaceDoubleAudio; + vstEffect.flags |= Vst2::effFlagsCanDoubleReplacing; - vstEffect.flags |= vstEffectFlagDataInChunks; + vstEffect.flags |= Vst2::effFlagsProgramChunks; #if JucePlugin_IsSynth - vstEffect.flags |= vstEffectFlagIsSynth; + vstEffect.flags |= effFlagsIsSynth; #else if (processor->getTailLengthSeconds() == 0.0) - vstEffect.flags |= vstEffectFlagSilenceInProducesSilenceOut; + vstEffect.flags |= Vst2::effFlagsNoSoundInStop; #endif activePlugins.add (this); @@ -367,7 +383,7 @@ public: } } - VstEffectInterface* getVstEffectInterface() noexcept { return &vstEffect; } + Vst2::AEffect* getAEffect() noexcept { return &vstEffect; } template void internalProcessReplacing (FloatType** inputs, FloatType** outputs, @@ -506,7 +522,7 @@ public: // Send VST events to the host. if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodePreAudioProcessingEvents, 0, 0, outgoingEvents.events, 0); + hostCallback (&vstEffect, Vst2::audioMasterProcessEvents, 0, 0, outgoingEvents.events, 0); #elif JUCE_DEBUG /* This assertion is caused when you've added some events to the midiMessages array in your processBlock() method, which usually means @@ -535,7 +551,7 @@ public: internalProcessReplacing (inputs, outputs, sampleFrames, floatTempBuffers); } - static void processReplacingCB (VstEffectInterface* vstInterface, float** inputs, float** outputs, int32 sampleFrames) + static void processReplacingCB (Vst2::AEffect* vstInterface, float** inputs, float** outputs, int32 sampleFrames) { getWrapper (vstInterface)->processReplacing (inputs, outputs, sampleFrames); } @@ -546,7 +562,7 @@ public: internalProcessReplacing (inputs, outputs, sampleFrames, doubleTempBuffers); } - static void processDoubleReplacingCB (VstEffectInterface* vstInterface, double** inputs, double** outputs, int32 sampleFrames) + static void processDoubleReplacingCB (Vst2::AEffect* vstInterface, double** inputs, double** outputs, int32 sampleFrames) { getWrapper (vstInterface)->processDoubleReplacing (inputs, outputs, sampleFrames); } @@ -558,7 +574,7 @@ public: { isProcessing = true; - auto numInAndOutChannels = static_cast (vstEffect.numInputChannels + vstEffect.numOutputChannels); + auto numInAndOutChannels = static_cast (vstEffect.numInputs + vstEffect.numOutputs); floatTempBuffers .channels.calloc (numInAndOutChannels); doubleTempBuffers.channels.calloc (numInAndOutChannels); @@ -577,16 +593,16 @@ public: midiEvents.ensureSize (2048); midiEvents.clear(); - vstEffect.latency = processor->getLatencySamples(); + vstEffect.initialDelay = processor->getLatencySamples(); /** If this plug-in is a synth or it can receive midi events we need to tell the host that we want midi. In the SDK this method is marked as deprecated, but some hosts rely on this behaviour. */ - if (vstEffect.flags & vstEffectFlagIsSynth || JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect) + if (vstEffect.flags & Vst2::effFlagsIsSynth || JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect) { if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodePlugInWantsMidi, 0, 1, 0, 0); + hostCallback (&vstEffect, Vst2::audioMasterWantMidi, 0, 1, 0, 0); } if (getHostType().isAbletonLive() @@ -600,7 +616,7 @@ public: hostCmd.commandSize = sizeof (int); hostCmd.flags = AbletonLiveHostSpecific::KCantBeSuspended; - hostCallback (&vstEffect, hostOpcodeManufacturerSpecific, 0, 0, &hostCmd, 0.0f); + hostCallback (&vstEffect, Vst2::audioMasterVendorSpecific, 0, 0, &hostCmd, 0.0f); } #if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect @@ -627,28 +643,28 @@ public: //============================================================================== bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) override { - const VstTimingInformation* ti = nullptr; + const Vst2::VstTimeInfo* ti = nullptr; if (hostCallback != nullptr) { - int32 flags = vstTimingInfoFlagMusicalPositionValid | vstTimingInfoFlagTempoValid - | vstTimingInfoFlagLastBarPositionValid | vstTimingInfoFlagLoopPositionValid - | vstTimingInfoFlagTimeSignatureValid | vstTimingInfoFlagSmpteValid - | vstTimingInfoFlagNearestClockValid; + int32 flags = Vst2::kVstPpqPosValid | Vst2::kVstTempoValid + | Vst2::kVstBarsValid | Vst2::kVstCyclePosValid + | Vst2::kVstTimeSigValid | Vst2::kVstSmpteValid + | Vst2::kVstClockValid; - auto result = hostCallback (&vstEffect, hostOpcodeGetTimingInfo, 0, flags, 0, 0); - ti = reinterpret_cast (result); + auto result = hostCallback (&vstEffect, Vst2::audioMasterGetTime, 0, flags, 0, 0); + ti = reinterpret_cast (result); } if (ti == nullptr || ti->sampleRate <= 0) return false; - info.bpm = (ti->flags & vstTimingInfoFlagTempoValid) != 0 ? ti->tempoBPM : 0.0; + info.bpm = (ti->flags & Vst2::kVstTempoValid) != 0 ? ti->tempo : 0.0; - if ((ti->flags & vstTimingInfoFlagTimeSignatureValid) != 0) + if ((ti->flags & Vst2::kVstTimeSigValid) != 0) { - info.timeSigNumerator = ti->timeSignatureNumerator; - info.timeSigDenominator = ti->timeSignatureDenominator; + info.timeSigNumerator = ti->timeSigNumerator; + info.timeSigDenominator = ti->timeSigDenominator; } else { @@ -656,34 +672,34 @@ public: info.timeSigDenominator = 4; } - info.timeInSamples = (int64) (ti->samplePosition + 0.5); - info.timeInSeconds = ti->samplePosition / ti->sampleRate; - info.ppqPosition = (ti->flags & vstTimingInfoFlagMusicalPositionValid) != 0 ? ti->musicalPosition : 0.0; - info.ppqPositionOfLastBarStart = (ti->flags & vstTimingInfoFlagLastBarPositionValid) != 0 ? ti->lastBarPosition : 0.0; + info.timeInSamples = (int64) (ti->samplePos + 0.5); + info.timeInSeconds = ti->samplePos / ti->sampleRate; + info.ppqPosition = (ti->flags & Vst2::kVstPpqPosValid) != 0 ? ti->ppqPos : 0.0; + info.ppqPositionOfLastBarStart = (ti->flags & Vst2::kVstBarsValid) != 0 ? ti->barStartPos : 0.0; - if ((ti->flags & vstTimingInfoFlagSmpteValid) != 0) + if ((ti->flags & Vst2::kVstSmpteValid) != 0) { AudioPlayHead::FrameRateType rate = AudioPlayHead::fpsUnknown; double fps = 1.0; - switch (ti->smpteRate) + switch (ti->smpteFrameRate) { - case vstSmpteRateFps239: rate = AudioPlayHead::fps23976; fps = 24.0 * 1000.0 / 1001.0; break; - case vstSmpteRateFps24: rate = AudioPlayHead::fps24; fps = 24.0; break; - case vstSmpteRateFps25: rate = AudioPlayHead::fps25; fps = 25.0; break; - case vstSmpteRateFps2997: rate = AudioPlayHead::fps2997; fps = 30.0 * 1000.0 / 1001.0; break; - case vstSmpteRateFps30: rate = AudioPlayHead::fps30; fps = 30.0; break; - case vstSmpteRateFps2997drop: rate = AudioPlayHead::fps2997drop; fps = 30.0 * 1000.0 / 1001.0; break; - case vstSmpteRateFps30drop: rate = AudioPlayHead::fps30drop; fps = 30.0; break; + case Vst2::kVstSmpte239fps: rate = AudioPlayHead::fps23976; fps = 24.0 * 1000.0 / 1001.0; break; + case Vst2::kVstSmpte24fps: rate = AudioPlayHead::fps24; fps = 24.0; break; + case Vst2::kVstSmpte25fps: rate = AudioPlayHead::fps25; fps = 25.0; break; + case Vst2::kVstSmpte2997fps: rate = AudioPlayHead::fps2997; fps = 30.0 * 1000.0 / 1001.0; break; + case Vst2::kVstSmpte30fps: rate = AudioPlayHead::fps30; fps = 30.0; break; + case Vst2::kVstSmpte2997dfps: rate = AudioPlayHead::fps2997drop; fps = 30.0 * 1000.0 / 1001.0; break; + case Vst2::kVstSmpte30dfps: rate = AudioPlayHead::fps30drop; fps = 30.0; break; - case vstSmpteRate16mmFilm: - case vstSmpteRate35mmFilm: fps = 24.0; break; + case Vst2::kVstSmpteFilm16mm: + case Vst2::kVstSmpteFilm35mm: fps = 24.0; break; - case vstSmpteRateFps249: fps = 25.0 * 1000.0 / 1001.0; break; - case vstSmpteRateFps599: fps = 60.0 * 1000.0 / 1001.0; break; - case vstSmpteRateFps60: fps = 60; break; + case Vst2::kVstSmpte249fps: fps = 25.0 * 1000.0 / 1001.0; break; + case Vst2::kVstSmpte599fps: fps = 60.0 * 1000.0 / 1001.0; break; + case Vst2::kVstSmpte60fps: fps = 60; break; - default: jassertfalse; // unknown frame-rate.. + default: jassertfalse; // unknown frame-rate.. } info.frameRate = rate; @@ -695,14 +711,14 @@ public: info.editOriginTime = 0; } - info.isRecording = (ti->flags & vstTimingInfoFlagCurrentlyRecording) != 0; - info.isPlaying = (ti->flags & (vstTimingInfoFlagCurrentlyRecording | vstTimingInfoFlagCurrentlyPlaying)) != 0; - info.isLooping = (ti->flags & vstTimingInfoFlagLoopActive) != 0; + info.isRecording = (ti->flags & Vst2::kVstTransportRecording) != 0; + info.isPlaying = (ti->flags & (Vst2::kVstTransportRecording | Vst2::kVstTransportPlaying)) != 0; + info.isLooping = (ti->flags & Vst2::kVstTransportCycleActive) != 0; - if ((ti->flags & vstTimingInfoFlagLoopPositionValid) != 0) + if ((ti->flags & Vst2::kVstCyclePosValid) != 0) { - info.ppqLoopStart = ti->loopStartPosition; - info.ppqLoopEnd = ti->loopEndPosition; + info.ppqLoopStart = ti->cycleStartPos; + info.ppqLoopEnd = ti->cycleEndPos; } else { @@ -722,7 +738,7 @@ public: return 0.0f; } - static float getParameterCB (VstEffectInterface* vstInterface, int32 index) + static float getParameterCB (Vst2::AEffect* vstInterface, int32 index) { return getWrapper (vstInterface)->getParameter (index); } @@ -738,7 +754,7 @@ public: } } - static void setParameterCB (VstEffectInterface* vstInterface, int32 index, float value) + static void setParameterCB (Vst2::AEffect* vstInterface, int32 index, float value) { getWrapper (vstInterface)->setParameter (index, value); } @@ -752,19 +768,19 @@ public: } if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodeParameterChanged, index, 0, 0, newValue); + hostCallback (&vstEffect, Vst2::audioMasterAutomate, index, 0, 0, newValue); } void audioProcessorParameterChangeGestureBegin (AudioProcessor*, int index) override { if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodeParameterChangeGestureBegin, index, 0, 0, 0); + hostCallback (&vstEffect, Vst2::audioMasterBeginEdit, index, 0, 0, 0); } void audioProcessorParameterChangeGestureEnd (AudioProcessor*, int index) override { if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodeParameterChangeGestureEnd, index, 0, 0, 0); + hostCallback (&vstEffect, Vst2::audioMasterEndEdit, index, 0, 0, 0); } void parameterValueChanged (int, float newValue) override @@ -777,10 +793,10 @@ public: void audioProcessorChanged (AudioProcessor*) override { - vstEffect.latency = processor->getLatencySamples(); + vstEffect.initialDelay = processor->getLatencySamples(); if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodeUpdateView, 0, 0, 0, 0); + hostCallback (&vstEffect, Vst2::audioMasterUpdateDisplay, 0, 0, 0, 0); triggerAsyncUpdate(); } @@ -788,10 +804,10 @@ public: void handleAsyncUpdate() override { if (hostCallback != nullptr) - hostCallback (&vstEffect, hostOpcodeIOModified, 0, 0, 0, 0); + hostCallback (&vstEffect, Vst2::audioMasterIOChanged, 0, 0, 0, 0); } - bool getPinProperties (VstPinInfo& properties, bool direction, int index) const + bool getPinProperties (Vst2::VstPinProperties& properties, bool direction, int index) const { if (processor->isMidiEffect()) return false; @@ -800,9 +816,9 @@ public: // fill with default properties.flags = 0; - properties.text[0] = 0; - properties.shortText[0] = 0; - properties.configurationType = vstSpeakerConfigTypeEmpty; + properties.label[0] = 0; + properties.shortLabel[0] = 0; + properties.arrangementType = Vst2::kSpeakerArrEmpty; if ((channelIdx = processor->getOffsetInBusBufferForAbsoluteChannelIndex (direction, index, busIdx)) >= 0) { @@ -810,8 +826,8 @@ public: auto& channelSet = bus.getCurrentLayout(); auto channelType = channelSet.getTypeOfChannel (channelIdx); - properties.flags = vstPinInfoFlagIsActive | vstPinInfoFlagValid; - properties.configurationType = SpeakerMappings::channelSetToVstArrangementType (channelSet); + properties.flags = Vst2::kVstPinIsActive | Vst2::kVstPinUseSpeaker; + properties.arrangementType = SpeakerMappings::channelSetToVstArrangementType (channelSet); String label = bus.getName(); #ifdef JucePlugin_PreferredChannelConfigurations @@ -821,8 +837,8 @@ public: label += " " + AudioChannelSet::getAbbreviatedChannelTypeName (channelType); #endif - label.copyToUTF8 (properties.text, (size_t) (vstMaxParameterOrPinLabelLength + 1)); - label.copyToUTF8 (properties.shortText, (size_t) (vstMaxParameterOrPinShortLabelLength + 1)); + label.copyToUTF8 (properties.label, (size_t) (Vst2::kVstMaxLabelLen + 1)); + label.copyToUTF8 (properties.shortLabel, (size_t) (Vst2::kVstMaxShortLabelLen + 1)); if (channelType == AudioChannelSet::left || channelType == AudioChannelSet::leftSurround @@ -832,7 +848,7 @@ public: || channelType == AudioChannelSet::topRearLeft || channelType == AudioChannelSet::leftSurroundRear || channelType == AudioChannelSet::wideLeft) - properties.flags |= vstPinInfoFlagIsStereo; + properties.flags |= Vst2::kVstPinIsStereo; return true; } @@ -865,27 +881,27 @@ public: } }; - static AudioChannelSet vstArrangementTypeToChannelSet (const VstSpeakerConfiguration& arr) + static AudioChannelSet vstArrangementTypeToChannelSet (const Vst2::VstSpeakerArrangement& arr) { - if (arr.type == vstSpeakerConfigTypeEmpty) return AudioChannelSet::disabled(); - if (arr.type == vstSpeakerConfigTypeMono) return AudioChannelSet::mono(); - if (arr.type == vstSpeakerConfigTypeLR) return AudioChannelSet::stereo(); - if (arr.type == vstSpeakerConfigTypeLRC) return AudioChannelSet::createLCR(); - if (arr.type == vstSpeakerConfigTypeLRS) return AudioChannelSet::createLRS(); - if (arr.type == vstSpeakerConfigTypeLRCS) return AudioChannelSet::createLCRS(); - if (arr.type == vstSpeakerConfigTypeLRCLsRs) return AudioChannelSet::create5point0(); - if (arr.type == vstSpeakerConfigTypeLRCLfeLsRs) return AudioChannelSet::create5point1(); - if (arr.type == vstSpeakerConfigTypeLRCLsRsCs) return AudioChannelSet::create6point0(); - if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsCs) return AudioChannelSet::create6point1(); - if (arr.type == vstSpeakerConfigTypeLRLsRsSlSr) return AudioChannelSet::create6point0Music(); - if (arr.type == vstSpeakerConfigTypeLRLfeLsRsSlSr) return AudioChannelSet::create6point1Music(); - if (arr.type == vstSpeakerConfigTypeLRCLsRsSlSr) return AudioChannelSet::create7point0(); - if (arr.type == vstSpeakerConfigTypeLRCLsRsLcRc) return AudioChannelSet::create7point0SDDS(); - if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsSlSr) return AudioChannelSet::create7point1(); - if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsLcRc) return AudioChannelSet::create7point1SDDS(); - if (arr.type == vstSpeakerConfigTypeLRLsRs) return AudioChannelSet::quadraphonic(); + if (arr.type == Vst2::kSpeakerArrEmpty) return AudioChannelSet::disabled(); + if (arr.type == Vst2::kSpeakerArrMono) return AudioChannelSet::mono(); + if (arr.type == Vst2::kSpeakerArrStereo) return AudioChannelSet::stereo(); + if (arr.type == Vst2::kSpeakerArr30Cine) return AudioChannelSet::createLCR(); + if (arr.type == Vst2::kSpeakerArr30Music) return AudioChannelSet::createLRS(); + if (arr.type == Vst2::kSpeakerArr40Cine) return AudioChannelSet::createLCRS(); + if (arr.type == Vst2::kSpeakerArr50) return AudioChannelSet::create5point0(); + if (arr.type == Vst2::kSpeakerArr51) return AudioChannelSet::create5point1(); + if (arr.type == Vst2::kSpeakerArr60Cine) return AudioChannelSet::create6point0(); + if (arr.type == Vst2::kSpeakerArr61Cine) return AudioChannelSet::create6point1(); + if (arr.type == Vst2::kSpeakerArr60Music) return AudioChannelSet::create6point0Music(); + if (arr.type == Vst2::kSpeakerArr61Music) return AudioChannelSet::create6point1Music(); + if (arr.type == Vst2::kSpeakerArr70Music) return AudioChannelSet::create7point0(); + if (arr.type == Vst2::kSpeakerArr70Cine) return AudioChannelSet::create7point0SDDS(); + if (arr.type == Vst2::kSpeakerArr71Music) return AudioChannelSet::create7point1(); + if (arr.type == Vst2::kSpeakerArr71Cine) return AudioChannelSet::create7point1SDDS(); + if (arr.type == Vst2::kSpeakerArr40Music) return AudioChannelSet::quadraphonic(); - for (auto* m = getMappings(); m->vst2 != vstSpeakerConfigTypeEmpty; ++m) + for (auto* m = getMappings(); m->vst2 != Vst2::kSpeakerArrEmpty; ++m) { if (m->vst2 == arr.type) { @@ -898,51 +914,51 @@ public: } } - return AudioChannelSet::discreteChannels (arr.numberOfChannels); + return AudioChannelSet::discreteChannels (arr.numChannels); } static int32 channelSetToVstArrangementType (AudioChannelSet channels) { - if (channels == AudioChannelSet::disabled()) return vstSpeakerConfigTypeEmpty; - if (channels == AudioChannelSet::mono()) return vstSpeakerConfigTypeMono; - if (channels == AudioChannelSet::stereo()) return vstSpeakerConfigTypeLR; - if (channels == AudioChannelSet::createLCR()) return vstSpeakerConfigTypeLRC; - if (channels == AudioChannelSet::createLRS()) return vstSpeakerConfigTypeLRS; - if (channels == AudioChannelSet::createLCRS()) return vstSpeakerConfigTypeLRCS; - if (channels == AudioChannelSet::create5point0()) return vstSpeakerConfigTypeLRCLsRs; - if (channels == AudioChannelSet::create5point1()) return vstSpeakerConfigTypeLRCLfeLsRs; - if (channels == AudioChannelSet::create6point0()) return vstSpeakerConfigTypeLRCLsRsCs; - if (channels == AudioChannelSet::create6point1()) return vstSpeakerConfigTypeLRCLfeLsRsCs; - if (channels == AudioChannelSet::create6point0Music()) return vstSpeakerConfigTypeLRLsRsSlSr; - if (channels == AudioChannelSet::create6point1Music()) return vstSpeakerConfigTypeLRLfeLsRsSlSr; - if (channels == AudioChannelSet::create7point0()) return vstSpeakerConfigTypeLRCLsRsSlSr; - if (channels == AudioChannelSet::create7point0SDDS()) return vstSpeakerConfigTypeLRCLsRsLcRc; - if (channels == AudioChannelSet::create7point1()) return vstSpeakerConfigTypeLRCLfeLsRsSlSr; - if (channels == AudioChannelSet::create7point1SDDS()) return vstSpeakerConfigTypeLRCLfeLsRsLcRc; - if (channels == AudioChannelSet::quadraphonic()) return vstSpeakerConfigTypeLRLsRs; + if (channels == AudioChannelSet::disabled()) return Vst2::kSpeakerArrEmpty; + if (channels == AudioChannelSet::mono()) return Vst2::kSpeakerArrMono; + if (channels == AudioChannelSet::stereo()) return Vst2::kSpeakerArrStereo; + if (channels == AudioChannelSet::createLCR()) return Vst2::kSpeakerArr30Cine; + if (channels == AudioChannelSet::createLRS()) return Vst2::kSpeakerArr30Music; + if (channels == AudioChannelSet::createLCRS()) return Vst2::kSpeakerArr40Cine; + if (channels == AudioChannelSet::create5point0()) return Vst2::kSpeakerArr50; + if (channels == AudioChannelSet::create5point1()) return Vst2::kSpeakerArr51; + if (channels == AudioChannelSet::create6point0()) return Vst2::kSpeakerArr60Cine; + if (channels == AudioChannelSet::create6point1()) return Vst2::kSpeakerArr61Cine; + if (channels == AudioChannelSet::create6point0Music()) return Vst2::kSpeakerArr60Music; + if (channels == AudioChannelSet::create6point1Music()) return Vst2::kSpeakerArr61Music; + if (channels == AudioChannelSet::create7point0()) return Vst2::kSpeakerArr70Music; + if (channels == AudioChannelSet::create7point0SDDS()) return Vst2::kSpeakerArr70Cine; + if (channels == AudioChannelSet::create7point1()) return Vst2::kSpeakerArr71Music; + if (channels == AudioChannelSet::create7point1SDDS()) return Vst2::kSpeakerArr71Cine; + if (channels == AudioChannelSet::quadraphonic()) return Vst2::kSpeakerArr40Music; if (channels == AudioChannelSet::disabled()) - return vstSpeakerConfigTypeEmpty; + return Vst2::kSpeakerArrEmpty; auto chans = channels.getChannelTypes(); - for (auto* m = getMappings(); m->vst2 != vstSpeakerConfigTypeEmpty; ++m) + for (auto* m = getMappings(); m->vst2 != Vst2::kSpeakerArrEmpty; ++m) if (m->matches (chans)) return m->vst2; - return vstSpeakerConfigTypeUser; + return Vst2::kSpeakerArrUserDefined; } - static void channelSetToVstArrangement (const AudioChannelSet& channels, VstSpeakerConfiguration& result) + static void channelSetToVstArrangement (const AudioChannelSet& channels, Vst2::VstSpeakerArrangement& result) { result.type = channelSetToVstArrangementType (channels); - result.numberOfChannels = channels.size(); + result.numChannels = channels.size(); - for (int i = 0; i < result.numberOfChannels; ++i) + for (int i = 0; i < result.numChannels; ++i) { auto& speaker = result.speakers[i]; - zeromem (&speaker, sizeof (VstIndividualSpeakerInfo)); + zeromem (&speaker, sizeof (Vst2::VstSpeakerProperties)); speaker.type = getSpeakerType (channels.getTypeOfChannel (i)); } } @@ -951,36 +967,36 @@ public: { static const Mapping mappings[] = { - { vstSpeakerConfigTypeMono, { centre, unknown } }, - { vstSpeakerConfigTypeLR, { left, right, unknown } }, - { vstSpeakerConfigTypeLsRs, { leftSurround, rightSurround, unknown } }, - { vstSpeakerConfigTypeLcRc, { leftCentre, rightCentre, unknown } }, - { vstSpeakerConfigTypeSlSr, { leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeCLfe, { centre, LFE, unknown } }, - { vstSpeakerConfigTypeLRC, { left, right, centre, unknown } }, - { vstSpeakerConfigTypeLRS, { left, right, surround, unknown } }, - { vstSpeakerConfigTypeLRCLfe, { left, right, centre, LFE, unknown } }, - { vstSpeakerConfigTypeLRLfeS, { left, right, LFE, surround, unknown } }, - { vstSpeakerConfigTypeLRCS, { left, right, centre, surround, unknown } }, - { vstSpeakerConfigTypeLRLsRs, { left, right, leftSurround, rightSurround, unknown } }, - { vstSpeakerConfigTypeLRCLfeS, { left, right, centre, LFE, surround, unknown } }, - { vstSpeakerConfigTypeLRLfeLsRs, { left, right, LFE, leftSurround, rightSurround, unknown } }, - { vstSpeakerConfigTypeLRCLsRs, { left, right, centre, leftSurround, rightSurround, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRs, { left, right, centre, LFE, leftSurround, rightSurround, unknown } }, - { vstSpeakerConfigTypeLRCLsRsCs, { left, right, centre, leftSurround, rightSurround, surround, unknown } }, - { vstSpeakerConfigTypeLRLsRsSlSr, { left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRsCs, { left, right, centre, LFE, leftSurround, rightSurround, surround, unknown } }, - { vstSpeakerConfigTypeLRLfeLsRsSlSr, { left, right, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeLRCLsRsLcRc, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } }, - { vstSpeakerConfigTypeLRCLsRsSlSr, { left, right, centre, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRsLcRc, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRsSlSr, { left, right, centre, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeLRCLsRsLcRcCs, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } }, - { vstSpeakerConfigTypeLRCLsRsCsSlSr, { left, right, centre, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRsLcRcCs, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRsCsSlSr, { left, right, centre, LFE, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } }, - { vstSpeakerConfigTypeLRCLfeLsRsTflTfcTfrTrlTrrLfe2, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontCentre, topFrontRight, topRearLeft, topRearRight, LFE2, unknown } }, - { vstSpeakerConfigTypeEmpty, { unknown } } + { Vst2::kSpeakerArrMono, { centre, unknown } }, + { Vst2::kSpeakerArrStereo, { left, right, unknown } }, + { Vst2::kSpeakerArrStereoSurround, { leftSurround, rightSurround, unknown } }, + { Vst2::kSpeakerArrStereoCenter, { leftCentre, rightCentre, unknown } }, + { Vst2::kSpeakerArrStereoSide, { leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArrStereoCLfe, { centre, LFE, unknown } }, + { Vst2::kSpeakerArr30Cine, { left, right, centre, unknown } }, + { Vst2::kSpeakerArr30Music, { left, right, surround, unknown } }, + { Vst2::kSpeakerArr31Cine, { left, right, centre, LFE, unknown } }, + { Vst2::kSpeakerArr31Music, { left, right, LFE, surround, unknown } }, + { Vst2::kSpeakerArr40Cine, { left, right, centre, surround, unknown } }, + { Vst2::kSpeakerArr40Music, { left, right, leftSurround, rightSurround, unknown } }, + { Vst2::kSpeakerArr41Cine, { left, right, centre, LFE, surround, unknown } }, + { Vst2::kSpeakerArr41Music, { left, right, LFE, leftSurround, rightSurround, unknown } }, + { Vst2::kSpeakerArr50, { left, right, centre, leftSurround, rightSurround, unknown } }, + { Vst2::kSpeakerArr51, { left, right, centre, LFE, leftSurround, rightSurround, unknown } }, + { Vst2::kSpeakerArr60Cine, { left, right, centre, leftSurround, rightSurround, surround, unknown } }, + { Vst2::kSpeakerArr60Music, { left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArr61Cine, { left, right, centre, LFE, leftSurround, rightSurround, surround, unknown } }, + { Vst2::kSpeakerArr61Music, { left, right, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArr70Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } }, + { Vst2::kSpeakerArr70Music, { left, right, centre, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArr71Cine, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, unknown } }, + { Vst2::kSpeakerArr71Music, { left, right, centre, LFE, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArr80Cine, { left, right, centre, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } }, + { Vst2::kSpeakerArr80Music, { left, right, centre, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArr81Cine, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, surround, unknown } }, + { Vst2::kSpeakerArr81Music, { left, right, centre, LFE, leftSurround, rightSurround, surround, leftSurroundRear, rightSurroundRear, unknown } }, + { Vst2::kSpeakerArr102, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontCentre, topFrontRight, topRearLeft, topRearRight, LFE2, unknown } }, + { Vst2::kSpeakerArrEmpty, { unknown } } }; return mappings; @@ -990,25 +1006,25 @@ public: { switch (type) { - case AudioChannelSet::left: return vstIndividualSpeakerTypeLeft; - case AudioChannelSet::right: return vstIndividualSpeakerTypeRight; - case AudioChannelSet::centre: return vstIndividualSpeakerTypeCentre; - case AudioChannelSet::LFE: return vstIndividualSpeakerTypeLFE; - case AudioChannelSet::leftSurround: return vstIndividualSpeakerTypeLeftSurround; - case AudioChannelSet::rightSurround: return vstIndividualSpeakerTypeRightSurround; - case AudioChannelSet::leftCentre: return vstIndividualSpeakerTypeLeftCentre; - case AudioChannelSet::rightCentre: return vstIndividualSpeakerTypeRightCentre; - case AudioChannelSet::surround: return vstIndividualSpeakerTypeSurround; - case AudioChannelSet::leftSurroundRear: return vstIndividualSpeakerTypeLeftRearSurround; - case AudioChannelSet::rightSurroundRear: return vstIndividualSpeakerTypeRightRearSurround; - case AudioChannelSet::topMiddle: return vstIndividualSpeakerTypeTopMiddle; - case AudioChannelSet::topFrontLeft: return vstIndividualSpeakerTypeTopFrontLeft; - case AudioChannelSet::topFrontCentre: return vstIndividualSpeakerTypeTopFrontCentre; - case AudioChannelSet::topFrontRight: return vstIndividualSpeakerTypeTopFrontRight; - case AudioChannelSet::topRearLeft: return vstIndividualSpeakerTypeTopRearLeft; - case AudioChannelSet::topRearCentre: return vstIndividualSpeakerTypeTopRearCentre; - case AudioChannelSet::topRearRight: return vstIndividualSpeakerTypeTopRearRight; - case AudioChannelSet::LFE2: return vstIndividualSpeakerTypeLFE2; + case AudioChannelSet::left: return Vst2::kSpeakerL; + case AudioChannelSet::right: return Vst2::kSpeakerR; + case AudioChannelSet::centre: return Vst2::kSpeakerC; + case AudioChannelSet::LFE: return Vst2::kSpeakerLfe; + case AudioChannelSet::leftSurround: return Vst2::kSpeakerLs; + case AudioChannelSet::rightSurround: return Vst2::kSpeakerRs; + case AudioChannelSet::leftCentre: return Vst2::kSpeakerLc; + case AudioChannelSet::rightCentre: return Vst2::kSpeakerRc; + case AudioChannelSet::surround: return Vst2::kSpeakerS; + case AudioChannelSet::leftSurroundRear: return Vst2::kSpeakerSl; + case AudioChannelSet::rightSurroundRear: return Vst2::kSpeakerSr; + case AudioChannelSet::topMiddle: return Vst2::kSpeakerTm; + case AudioChannelSet::topFrontLeft: return Vst2::kSpeakerTfl; + case AudioChannelSet::topFrontCentre: return Vst2::kSpeakerTfc; + case AudioChannelSet::topFrontRight: return Vst2::kSpeakerTfr; + case AudioChannelSet::topRearLeft: return Vst2::kSpeakerTrl; + case AudioChannelSet::topRearCentre: return Vst2::kSpeakerTrc; + case AudioChannelSet::topRearRight: return Vst2::kSpeakerTrr; + case AudioChannelSet::LFE2: return Vst2::kSpeakerLfe2; default: break; } @@ -1019,25 +1035,25 @@ public: { switch (type) { - case vstIndividualSpeakerTypeLeft: return AudioChannelSet::left; - case vstIndividualSpeakerTypeRight: return AudioChannelSet::right; - case vstIndividualSpeakerTypeCentre: return AudioChannelSet::centre; - case vstIndividualSpeakerTypeLFE: return AudioChannelSet::LFE; - case vstIndividualSpeakerTypeLeftSurround: return AudioChannelSet::leftSurround; - case vstIndividualSpeakerTypeRightSurround: return AudioChannelSet::rightSurround; - case vstIndividualSpeakerTypeLeftCentre: return AudioChannelSet::leftCentre; - case vstIndividualSpeakerTypeRightCentre: return AudioChannelSet::rightCentre; - case vstIndividualSpeakerTypeSurround: return AudioChannelSet::surround; - case vstIndividualSpeakerTypeLeftRearSurround: return AudioChannelSet::leftSurroundRear; - case vstIndividualSpeakerTypeRightRearSurround: return AudioChannelSet::rightSurroundRear; - case vstIndividualSpeakerTypeTopMiddle: return AudioChannelSet::topMiddle; - case vstIndividualSpeakerTypeTopFrontLeft: return AudioChannelSet::topFrontLeft; - case vstIndividualSpeakerTypeTopFrontCentre: return AudioChannelSet::topFrontCentre; - case vstIndividualSpeakerTypeTopFrontRight: return AudioChannelSet::topFrontRight; - case vstIndividualSpeakerTypeTopRearLeft: return AudioChannelSet::topRearLeft; - case vstIndividualSpeakerTypeTopRearCentre: return AudioChannelSet::topRearCentre; - case vstIndividualSpeakerTypeTopRearRight: return AudioChannelSet::topRearRight; - case vstIndividualSpeakerTypeLFE2: return AudioChannelSet::LFE2; + case Vst2::kSpeakerL: return AudioChannelSet::left; + case Vst2::kSpeakerR: return AudioChannelSet::right; + case Vst2::kSpeakerC: return AudioChannelSet::centre; + case Vst2::kSpeakerLfe: return AudioChannelSet::LFE; + case Vst2::kSpeakerLs: return AudioChannelSet::leftSurround; + case Vst2::kSpeakerRs: return AudioChannelSet::rightSurround; + case Vst2::kSpeakerLc: return AudioChannelSet::leftCentre; + case Vst2::kSpeakerRc: return AudioChannelSet::rightCentre; + case Vst2::kSpeakerS: return AudioChannelSet::surround; + case Vst2::kSpeakerSl: return AudioChannelSet::leftSurroundRear; + case Vst2::kSpeakerSr: return AudioChannelSet::rightSurroundRear; + case Vst2::kSpeakerTm: return AudioChannelSet::topMiddle; + case Vst2::kSpeakerTfl: return AudioChannelSet::topFrontLeft; + case Vst2::kSpeakerTfc: return AudioChannelSet::topFrontCentre; + case Vst2::kSpeakerTfr: return AudioChannelSet::topFrontRight; + case Vst2::kSpeakerTrl: return AudioChannelSet::topRearLeft; + case Vst2::kSpeakerTrc: return AudioChannelSet::topRearCentre; + case Vst2::kSpeakerTrr: return AudioChannelSet::topRearRight; + case Vst2::kSpeakerLfe2: return AudioChannelSet::LFE2; default: break; } @@ -1074,7 +1090,7 @@ public: { if (auto* ed = processor->createEditorIfNeeded()) { - vstEffect.flags |= vstEffectFlagHasEditor; + vstEffect.flags |= Vst2::effFlagsHasEditor; editorComp.reset (new EditorCompWrapper (*this, *ed)); #if ! (JUCE_MAC || JUCE_IOS) @@ -1083,7 +1099,7 @@ public: } else { - vstEffect.flags &= ~vstEffectFlagHasEditor; + vstEffect.flags &= ~Vst2::effFlagsHasEditor; } } @@ -1133,59 +1149,59 @@ public: switch (opCode) { - case plugInOpcodeOpen: return handleOpen (args); - case plugInOpcodeClose: return handleClose (args); - case plugInOpcodeSetCurrentProgram: return handleSetCurrentProgram (args); - case plugInOpcodeGetCurrentProgram: return handleGetCurrentProgram (args); - case plugInOpcodeSetCurrentProgramName: return handleSetCurrentProgramName (args); - case plugInOpcodeGetCurrentProgramName: return handleGetCurrentProgramName (args); - case plugInOpcodeGetParameterLabel: return handleGetParameterLabel (args); - case plugInOpcodeGetParameterText: return handleGetParameterText (args); - case plugInOpcodeGetParameterName: return handleGetParameterName (args); - case plugInOpcodeSetSampleRate: return handleSetSampleRate (args); - case plugInOpcodeSetBlockSize: return handleSetBlockSize (args); - case plugInOpcodeResumeSuspend: return handleResumeSuspend (args); - case plugInOpcodeGetEditorBounds: return handleGetEditorBounds (args); - case plugInOpcodeOpenEditor: return handleOpenEditor (args); - case plugInOpcodeCloseEditor: return handleCloseEditor (args); - case plugInOpcodeIdentify: return (pointer_sized_int) ByteOrder::bigEndianInt ("NvEf"); - case plugInOpcodeGetData: return handleGetData (args); - case plugInOpcodeSetData: return handleSetData (args); - case plugInOpcodePreAudioProcessingEvents: return handlePreAudioProcessingEvents (args); - case plugInOpcodeIsParameterAutomatable: return handleIsParameterAutomatable (args); - case plugInOpcodeParameterValueForText: return handleParameterValueForText (args); - case plugInOpcodeGetProgramName: return handleGetProgramName (args); - case plugInOpcodeGetInputPinProperties: return handleGetInputPinProperties (args); - case plugInOpcodeGetOutputPinProperties: return handleGetOutputPinProperties (args); - case plugInOpcodeGetPlugInCategory: return handleGetPlugInCategory (args); - case plugInOpcodeSetSpeakerConfiguration: return handleSetSpeakerConfiguration (args); - case plugInOpcodeSetBypass: return handleSetBypass (args); - case plugInOpcodeGetPlugInName: return handleGetPlugInName (args); - case plugInOpcodeGetManufacturerProductName: return handleGetPlugInName (args); - case plugInOpcodeGetManufacturerName: return handleGetManufacturerName (args); - case plugInOpcodeGetManufacturerVersion: return handleGetManufacturerVersion (args); - case plugInOpcodeManufacturerSpecific: return handleManufacturerSpecific (args); - case plugInOpcodeCanPlugInDo: return handleCanPlugInDo (args); - case plugInOpcodeGetTailSize: return handleGetTailSize (args); - case plugInOpcodeKeyboardFocusRequired: return handleKeyboardFocusRequired (args); - case plugInOpcodeGetVstInterfaceVersion: return handleGetVstInterfaceVersion (args); - case plugInOpcodeGetCurrentMidiProgram: return handleGetCurrentMidiProgram (args); - case plugInOpcodeGetSpeakerArrangement: return handleGetSpeakerConfiguration (args); - case plugInOpcodeSetNumberOfSamplesToProcess: return handleSetNumberOfSamplesToProcess (args); - case plugInOpcodeSetSampleFloatType: return handleSetSampleFloatType (args); - case pluginOpcodeGetNumMidiInputChannels: return handleGetNumMidiInputChannels(); - case pluginOpcodeGetNumMidiOutputChannels: return handleGetNumMidiOutputChannels(); - default: return 0; + case Vst2::effOpen: return handleOpen (args); + case Vst2::effClose: return handleClose (args); + case Vst2::effSetProgram: return handleSetCurrentProgram (args); + case Vst2::effGetProgram: return handleGetCurrentProgram (args); + case Vst2::effSetProgramName: return handleSetCurrentProgramName (args); + case Vst2::effGetProgramName: return handleGetCurrentProgramName (args); + case Vst2::effGetParamLabel: return handleGetParameterLabel (args); + case Vst2::effGetParamDisplay: return handleGetParameterText (args); + case Vst2::effGetParamName: return handleGetParameterName (args); + case Vst2::effSetSampleRate: return handleSetSampleRate (args); + case Vst2::effSetBlockSize: return handleSetBlockSize (args); + case Vst2::effMainsChanged: return handleResumeSuspend (args); + case Vst2::effEditGetRect: return handleGetEditorBounds (args); + case Vst2::effEditOpen: return handleOpenEditor (args); + case Vst2::effEditClose: return handleCloseEditor (args); + case Vst2::effIdentify: return (pointer_sized_int) ByteOrder::bigEndianInt ("NvEf"); + case Vst2::effGetChunk: return handleGetData (args); + case Vst2::effSetChunk: return handleSetData (args); + case Vst2::effProcessEvents: return handlePreAudioProcessingEvents (args); + case Vst2::effCanBeAutomated: return handleIsParameterAutomatable (args); + case Vst2::effString2Parameter: return handleParameterValueForText (args); + case Vst2::effGetProgramNameIndexed: return handleGetProgramName (args); + case Vst2::effGetInputProperties: return handleGetInputPinProperties (args); + case Vst2::effGetOutputProperties: return handleGetOutputPinProperties (args); + case Vst2::effGetPlugCategory: return handleGetPlugInCategory (args); + case Vst2::effSetSpeakerArrangement: return handleSetSpeakerConfiguration (args); + case Vst2::effSetBypass: return handleSetBypass (args); + case Vst2::effGetEffectName: return handleGetPlugInName (args); + case Vst2::effGetProductString: return handleGetPlugInName (args); + case Vst2::effGetVendorString: return handleGetManufacturerName (args); + case Vst2::effGetVendorVersion: return handleGetManufacturerVersion (args); + case Vst2::effVendorSpecific: return handleManufacturerSpecific (args); + case Vst2::effCanDo: return handleCanPlugInDo (args); + case Vst2::effGetTailSize: return handleGetTailSize (args); + case Vst2::effKeysRequired: return handleKeyboardFocusRequired (args); + case Vst2::effGetVstVersion: return handleGetVstInterfaceVersion (args); + case Vst2::effGetCurrentMidiProgram: return handleGetCurrentMidiProgram (args); + case Vst2::effGetSpeakerArrangement: return handleGetSpeakerConfiguration (args); + case Vst2::effSetTotalSampleToProcess: return handleSetNumberOfSamplesToProcess (args); + case Vst2::effSetProcessPrecision: return handleSetSampleFloatType (args); + case Vst2::effGetNumMidiInputChannels: return handleGetNumMidiInputChannels(); + case Vst2::effGetNumMidiOutputChannels: return handleGetNumMidiOutputChannels(); + default: return 0; } } - static pointer_sized_int dispatcherCB (VstEffectInterface* vstInterface, int32 opCode, int32 index, + static pointer_sized_int dispatcherCB (Vst2::AEffect* vstInterface, int32 opCode, int32 index, pointer_sized_int value, void* ptr, float opt) { auto* wrapper = getWrapper (vstInterface); VstOpCodeArguments args = { index, value, ptr, opt }; - if (opCode == plugInOpcodeClose) + if (opCode == Vst2::effClose) { wrapper->dispatcher (opCode, args); delete wrapper; @@ -1229,14 +1245,14 @@ public: void paint (Graphics&) override {} - void getEditorBounds (VstEditorBounds& bounds) + void getEditorBounds (Vst2::ERect& bounds) { auto b = getSizeToContainChild(); - bounds.upper = 0; - bounds.leftmost = 0; - bounds.lower = (int16) b.getHeight(); - bounds.rightmost = (int16) b.getWidth(); + bounds.top = 0; + bounds.left = 0; + bounds.bottom = (int16) b.getHeight(); + bounds.right = (int16) b.getWidth(); } void attachToHost (VstOpCodeArguments args) @@ -1359,12 +1375,12 @@ public: if (auto host = wrapper.hostCallback) { - auto status = host (wrapper.getVstEffectInterface(), hostOpcodeCanHostDo, 0, 0, const_cast ("sizeWindow"), 0); + auto status = host (wrapper.getAEffect(), Vst2::audioMasterCanDo, 0, 0, const_cast ("sizeWindow"), 0); if (status == (pointer_sized_int) 1 || getHostType().isAbletonLive()) { isInSizeWindow = true; - sizeWasSuccessful = (host (wrapper.getVstEffectInterface(), hostOpcodeWindowSize, newWidth, newHeight, 0, 0) != 0); + sizeWasSuccessful = (host (wrapper.getAEffect(), Vst2::audioMasterSizeWindow, newWidth, newHeight, 0, 0) != 0); isInSizeWindow = false; } } @@ -1477,15 +1493,15 @@ public: //============================================================================== private: - VstHostCallback hostCallback; + Vst2::audioMasterCallback hostCallback; AudioProcessor* processor = {}; double sampleRate = 44100.0; int32 blockSize = 1024; - VstEffectInterface vstEffect; + Vst2::AEffect vstEffect; juce::MemoryBlock chunkMemory; juce::uint32 chunkMemoryTime = 0; std::unique_ptr editorComp; - VstEditorBounds editorBounds; + Vst2::ERect editorBounds; MidiBuffer midiEvents; VSTMidiEventList outgoingEvents; float editorScaleFactor = 1.0f; @@ -1505,16 +1521,16 @@ private: VstTempBuffers doubleTempBuffers; int maxNumInChannels = 0, maxNumOutChannels = 0; - HeapBlock cachedInArrangement, cachedOutArrangement; + HeapBlock cachedInArrangement, cachedOutArrangement; ThreadLocalValue inParameterChangedCallback; - static JuceVSTWrapper* getWrapper (VstEffectInterface* v) noexcept { return static_cast (v->effectPointer); } + static JuceVSTWrapper* getWrapper (Vst2::AEffect* v) noexcept { return static_cast (v->object); } bool isProcessLevelOffline() { return hostCallback != nullptr - && (int32) hostCallback (&vstEffect, hostOpcodeGetCurrentAudioProcessingLevel, 0, 0, 0, 0) == 4; + && (int32) hostCallback (&vstEffect, Vst2::audioMasterGetCurrentProcessLevel, 0, 0, 0, 0) == 4; } static inline int32 convertHexVersionToDecimal (const unsigned int hexVersion) @@ -1582,8 +1598,8 @@ private: tmpBuffers.release(); if (processor != nullptr) - tmpBuffers.tempChannels.insertMultiple (0, nullptr, vstEffect.numInputChannels - + vstEffect.numOutputChannels); + tmpBuffers.tempChannels.insertMultiple (0, nullptr, vstEffect.numInputs + + vstEffect.numOutputs); } void deleteTempChannels() @@ -1635,9 +1651,9 @@ private: { // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here. if (processor->hasEditor()) - vstEffect.flags |= vstEffectFlagHasEditor; + vstEffect.flags |= Vst2::effFlagsHasEditor; else - vstEffect.flags &= ~vstEffectFlagHasEditor; + vstEffect.flags &= ~Vst2::effFlagsHasEditor; return 0; } @@ -1746,7 +1762,7 @@ private: if (editorComp != nullptr) { editorComp->getEditorBounds (editorBounds); - *((VstEditorBounds**) args.ptr) = &editorBounds; + *((Vst2::ERect**) args.ptr) = &editorBounds; return (pointer_sized_int) &editorBounds; } @@ -1830,7 +1846,7 @@ private: pointer_sized_int handlePreAudioProcessingEvents (VstOpCodeArguments args) { #if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect - VSTMidiEventList::addEventsToMidiBuffer ((VstEventBlock*) args.ptr, midiEvents); + VSTMidiEventList::addEventsToMidiBuffer ((Vst2::VstEvents*) args.ptr, midiEvents); return 1; #else ignoreUnused (args); @@ -1881,23 +1897,23 @@ private: pointer_sized_int handleGetInputPinProperties (VstOpCodeArguments args) { - return (processor != nullptr && getPinProperties (*(VstPinInfo*) args.ptr, true, args.index)) ? 1 : 0; + return (processor != nullptr && getPinProperties (*(Vst2::VstPinProperties*) args.ptr, true, args.index)) ? 1 : 0; } pointer_sized_int handleGetOutputPinProperties (VstOpCodeArguments args) { - return (processor != nullptr && getPinProperties (*(VstPinInfo*) args.ptr, false, args.index)) ? 1 : 0; + return (processor != nullptr && getPinProperties (*(Vst2::VstPinProperties*) args.ptr, false, args.index)) ? 1 : 0; } pointer_sized_int handleGetPlugInCategory (VstOpCodeArguments) { - return JucePlugin_VSTCategory; + return Vst2::JucePlugin_VSTCategory; } pointer_sized_int handleSetSpeakerConfiguration (VstOpCodeArguments args) { - auto* pluginInput = reinterpret_cast (args.value); - auto* pluginOutput = reinterpret_cast (args.ptr); + auto* pluginInput = reinterpret_cast (args.value); + auto* pluginOutput = reinterpret_cast (args.ptr); if (processor->isMidiEffect()) return 0; @@ -1908,29 +1924,29 @@ private: if (pluginInput != nullptr && pluginInput->type >= 0) { // inconsistent request? - if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput).size() != pluginInput->numberOfChannels) + if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput).size() != pluginInput->numChannels) return 0; } if (pluginOutput != nullptr && pluginOutput->type >= 0) { // inconsistent request? - if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput).size() != pluginOutput->numberOfChannels) + if (SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput).size() != pluginOutput->numChannels) return 0; } - if (pluginInput != nullptr && pluginInput->numberOfChannels > 0 && numIns == 0) + if (pluginInput != nullptr && pluginInput->numChannels > 0 && numIns == 0) return 0; - if (pluginOutput != nullptr && pluginOutput->numberOfChannels > 0 && numOuts == 0) + if (pluginOutput != nullptr && pluginOutput->numChannels > 0 && numOuts == 0) return 0; auto layouts = processor->getBusesLayout(); - if (pluginInput != nullptr && pluginInput-> numberOfChannels >= 0 && numIns > 0) + if (pluginInput != nullptr && pluginInput-> numChannels >= 0 && numIns > 0) layouts.getChannelSet (true, 0) = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput); - if (pluginOutput != nullptr && pluginOutput->numberOfChannels >= 0 && numOuts > 0) + if (pluginOutput != nullptr && pluginOutput->numChannels >= 0 && numOuts > 0) layouts.getChannelSet (false, 0) = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput); #ifdef JucePlugin_PreferredChannelConfigurations @@ -1974,10 +1990,11 @@ private: if (handleManufacturerSpecificVST2Opcode (args.index, args.value, args.ptr, args.opt)) return 1; - if (args.index == presonusVendorID && args.value == presonusSetContentScaleFactor) + if (args.index == JUCE_MULTICHAR_CONSTANT ('P', 'r', 'e', 'S') + && args.value == JUCE_MULTICHAR_CONSTANT ('A', 'e', 'C', 's')) return handleSetContentScaleFactor (args.opt); - if (args.index == plugInOpcodeGetParameterText) + if (args.index == Vst2::effGetParamDisplay) return handleCockosGetParameterText (args.value, args.ptr, args.opt); if (auto callbackHandler = dynamic_cast (processor)) @@ -2072,7 +2089,7 @@ private: pointer_sized_int handleGetVstInterfaceVersion (VstOpCodeArguments) { - return juceVstInterfaceVersion; + return kVstVersion; } pointer_sized_int handleGetCurrentMidiProgram (VstOpCodeArguments) @@ -2082,8 +2099,8 @@ private: pointer_sized_int handleGetSpeakerConfiguration (VstOpCodeArguments args) { - auto** pluginInput = reinterpret_cast (args.value); - auto** pluginOutput = reinterpret_cast (args.ptr); + auto** pluginInput = reinterpret_cast (args.value); + auto** pluginOutput = reinterpret_cast (args.ptr); if (pluginHasSidechainsOrAuxs() || processor->isMidiEffect()) return false; @@ -2091,10 +2108,10 @@ private: auto inputLayout = processor->getChannelLayoutOfBus (true, 0); auto outputLayout = processor->getChannelLayoutOfBus (false, 0); - auto speakerBaseSize = sizeof (VstSpeakerConfiguration) - (sizeof (VstIndividualSpeakerInfo) * 8); + auto speakerBaseSize = sizeof (Vst2::VstSpeakerArrangement) - (sizeof (Vst2::VstSpeakerProperties) * 8); - cachedInArrangement .malloc (speakerBaseSize + (static_cast (inputLayout. size()) * sizeof (VstSpeakerConfiguration)), 1); - cachedOutArrangement.malloc (speakerBaseSize + (static_cast (outputLayout.size()) * sizeof (VstSpeakerConfiguration)), 1); + cachedInArrangement .malloc (speakerBaseSize + (static_cast (inputLayout. size()) * sizeof (Vst2::VstSpeakerArrangement)), 1); + cachedOutArrangement.malloc (speakerBaseSize + (static_cast (outputLayout.size()) * sizeof (Vst2::VstSpeakerArrangement)), 1); *pluginInput = cachedInArrangement. getData(); *pluginOutput = cachedOutArrangement.getData(); @@ -2116,7 +2133,7 @@ private: { if (processor != nullptr) { - processor->setProcessingPrecision ((args.value == vstProcessingSampleTypeDouble + processor->setProcessingPrecision ((args.value == Vst2::kVstProcessPrecision64 && processor->supportsDoublePrecisionProcessing()) ? AudioProcessor::doublePrecision : AudioProcessor::singlePrecision); @@ -2196,7 +2213,7 @@ private: //============================================================================== namespace { - VstEffectInterface* pluginEntryPoint (VstHostCallback audioMaster) + Vst2::AEffect* pluginEntryPoint (Vst2::audioMasterCallback audioMaster) { JUCE_AUTORELEASEPOOL { @@ -2204,7 +2221,7 @@ namespace try { - if (audioMaster (0, hostOpcodeVstVersion, 0, 0, 0, 0) != 0) + if (audioMaster (0, Vst2::audioMasterVersion, 0, 0, 0, 0) != 0) { #if JUCE_LINUX MessageManagerLock mmLock; @@ -2212,7 +2229,7 @@ namespace auto* processor = createPluginFilterOfType (AudioProcessor::wrapperType_VST); auto* wrapper = new JuceVSTWrapper (audioMaster, processor); - return wrapper->getVstEffectInterface(); + return wrapper->getAEffect(); } } catch (...) @@ -2231,8 +2248,8 @@ namespace // Mac startup code.. #if JUCE_MAC - JUCE_EXPORTED_FUNCTION VstEffectInterface* VSTPluginMain (VstHostCallback audioMaster); - JUCE_EXPORTED_FUNCTION VstEffectInterface* VSTPluginMain (VstHostCallback audioMaster) + JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster); + JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster) { PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST; @@ -2240,8 +2257,8 @@ namespace return pluginEntryPoint (audioMaster); } - JUCE_EXPORTED_FUNCTION VstEffectInterface* main_macho (VstHostCallback audioMaster); - JUCE_EXPORTED_FUNCTION VstEffectInterface* main_macho (VstHostCallback audioMaster) + JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster); + JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster) { PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST; @@ -2253,8 +2270,8 @@ namespace // Linux startup code.. #elif JUCE_LINUX - JUCE_EXPORTED_FUNCTION VstEffectInterface* VSTPluginMain (VstHostCallback audioMaster); - JUCE_EXPORTED_FUNCTION VstEffectInterface* VSTPluginMain (VstHostCallback audioMaster) + JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster); + JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster) { PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST; @@ -2262,8 +2279,8 @@ namespace return pluginEntryPoint (audioMaster); } - JUCE_EXPORTED_FUNCTION VstEffectInterface* main_plugin (VstHostCallback audioMaster) asm ("main"); - JUCE_EXPORTED_FUNCTION VstEffectInterface* main_plugin (VstHostCallback audioMaster) + JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_plugin (Vst2::audioMasterCallback audioMaster) asm ("main"); + JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_plugin (Vst2::audioMasterCallback audioMaster) { PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST; @@ -2278,7 +2295,7 @@ namespace // Win32 startup code.. #else - extern "C" __declspec (dllexport) VstEffectInterface* VSTPluginMain (VstHostCallback audioMaster) + extern "C" __declspec (dllexport) Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster) { PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST; @@ -2286,7 +2303,7 @@ namespace } #ifndef JUCE_64BIT // (can't compile this on win64, but it's not needed anyway with VST2.4) - extern "C" __declspec (dllexport) int main (VstHostCallback audioMaster) + extern "C" __declspec (dllexport) int main (Vst2::audioMasterCallback audioMaster) { PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_VST; diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 89b2f21ea0..5c2c5ba2c6 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -50,7 +50,10 @@ #endif #if JUCE_VST3_CAN_REPLACE_VST2 -#include "../../juce_audio_processors/format_types/juce_VSTInterface.h" +namespace Vst2 +{ +#include "../../juce_audio_processors/format_types/VST3_SDK/pluginterfaces/vst2.x/vstfxstore.h" +} #endif #ifndef JUCE_VST3_EMULATE_MIDI_CC_WITH_PARAMETERS @@ -1440,16 +1443,16 @@ public: bool loadVST2CcnKBlock (const char* data, int size) { - auto bank = (const vst2FxBank*) data; + auto bank = (const Vst2::fxBank*) data; - jassert ('CcnK' == htonl (bank->magic1)); - jassert ('FBCh' == htonl (bank->magic2)); - jassert (htonl (bank->version1) == 1 || htonl (bank->version1) == 2); + jassert ('CcnK' == htonl (bank->chunkMagic)); + jassert ('FBCh' == htonl (bank->fxMagic)); + jassert (htonl (bank->version) == 1 || htonl (bank->version) == 2); jassert (JucePlugin_VSTUniqueID == htonl (bank->fxID)); - setStateInformation (bank->chunk, - jmin ((int) (size - (bank->chunk - data)), - (int) htonl (bank->chunkSize))); + setStateInformation (bank->content.data.chunk, + jmin ((int) (size - (bank->content.data.chunk - data)), + (int) htonl (bank->content.data.size))); return true; } @@ -1642,16 +1645,16 @@ public: return status; const int bankBlockSize = 160; - vst2FxBank bank; + Vst2::fxBank bank; zerostruct (bank); - bank.magic1 = (int32) htonl ('CcnK'); - bank.size = (int32) htonl (bankBlockSize - 8 + (unsigned int) mem.getSize()); - bank.magic2 = (int32) htonl ('FBCh'); - bank.version1 = (int32) htonl (2); - bank.fxID = (int32) htonl (JucePlugin_VSTUniqueID); - bank.version2 = (int32) htonl (JucePlugin_VersionCode); - bank.chunkSize = (int32) htonl ((unsigned int) mem.getSize()); + bank.chunkMagic = (int32) htonl ('CcnK'); + bank.byteSize = (int32) htonl (bankBlockSize - 8 + (unsigned int) mem.getSize()); + bank.fxMagic = (int32) htonl ('FBCh'); + bank.version = (int32) htonl (2); + bank.fxID = (int32) htonl (JucePlugin_VSTUniqueID); + bank.fxVersion = (int32) htonl (JucePlugin_VersionCode); + bank.content.data.size = (int32) htonl ((unsigned int) mem.getSize()); status = state->write (&bank, bankBlockSize); diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/LICENSE.txt b/modules/juce_audio_processors/format_types/VST3_SDK/LICENSE.txt new file mode 100644 index 0000000000..c653a2ef70 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/LICENSE.txt @@ -0,0 +1,41 @@ +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +This license applies only to files referencing this license, +for other files of the Software Development Kit the respective embedded license text +is applicable. The license can be found at: www.steinberg.net/sdklicenses_vst3 + +This Software Development Kit is licensed under the terms of the Steinberg VST3 License, +or alternatively under the terms of the General Public License (GPL) Version 3. +You may use the Software Development Kit according to either of these licenses as it is +most appropriate for your project on a case-by-case basis (commercial or not). + +a) Proprietary Steinberg VST3 License +The Software Development Kit may not be distributed in parts or its entirety +without prior written agreement by Steinberg Media Technologies GmbH. +The SDK must not be used to re-engineer or manipulate any technology used +in any Steinberg or Third-party application or software module, +unless permitted by law. +Neither the name of the Steinberg Media Technologies GmbH nor the names of its +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. +Before publishing a software under the proprietary license, you need to obtain a copy +of the License Agreement signed by Steinberg Media Technologies GmbH. +The Steinberg VST SDK License Agreement can be found at: +www.steinberg.net/en/company/developers.html + +THE SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + +b) General Public License (GPL) Version 3 +Details of these licenses can be found at: www.gnu.org/licenses/gpl-3.0.html +//---------------------------------------------------------------------------------- diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/README.md b/modules/juce_audio_processors/format_types/VST3_SDK/README.md new file mode 100644 index 0000000000..f208d870ca --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/README.md @@ -0,0 +1,153 @@ +# Welcome to VST SDK 3.6.9 + +## Table Of Contents +1. [The VST SDK package](#100) +1. [System requirements](#200) +1. [About VST Plug-ins in general](#300) +1. [About VST 3](#400) +1. [How to build VST 3](#How_to_build_VST_3) +1. [License & Usage guidelines](#license_&_usage_guidelines) + +
+ +## The VST SDK package contains: +- The VST 3 API +- VST 3 Implementation Helper Classes +- AAX, AU and VST 2 wrappers +- VST 3 Plug-ins Examples + +The full VST 3 SDK is available [here!](https://www.steinberg.net/en/company/developers.html). It contains a VST 3 Plug-in Test Host Application/Validator. + +
+ +## System requirements + +Supported OS: + +- Microsoft Windows 7-10 +- Apple OSX 10.7-10.13 +- Apple iOS 8-9 +- Linux (Beta version) + +Supported IDE: +- Visual Studio 2015/2017 +- minimum Xcode 7 +- Qt Creator + +--- +
+ +## About VST Plug-ins in general +A VST Plug-in is an audio processing component that is utilized within a host application. This host application provides the audio or/and event streams that are processed by the Plug-in's code. Generally speaking, a VST Plug-in can take a stream of audio data, apply a process to the audio, and return the result to the host application. A VST Plug-in performs its process normally using the processor of the computer. The audio stream is broken down into a series of blocks. The host supplies the blocks in sequence. The host and its current environment control the block-size. The VST Plug-in maintains the status of all its own parameters relating to the running process: The host does not maintain any information about what the Plug-in did with the last block of data it processed. + +From the host application's point of view, a VST Plug-in is a black box with an arbitrary number of inputs, outputs (Event (MIDI) or Audio), and associated parameters. The host needs no implicit knowledge of the Plug-in's process to be able to use it. The Plug-in process can use whatever parameters it wishes, internally to the process, but depending on the capabilities of the host, it can allow the changes to user parameters to be automated by the host. + +The source code of a VST Plug-in is platform independent, but the delivery system depends on the platform architecture: +- On **Windows**, a VST Plug-in is a multi-threaded DLL (Dynamic Link Library). +- On **Mac OS X**, a VST Plug-in is a Mach-O Bundle +- On **Linux**, a VST Plug-in is a package + +To learn more about VST you can subscribe to the [VST Developer Forum](https://sdk.steinberg.net) - check the 3rd Party Developer Support section at [www.steinberg.net](http://www.steinberg.net). + + --- +
+ +## About VST 3 +VST 3 is a general rework of the long-serving VST Plug-in interface. It is not compatible with the older VST versions, but it includes some new features and possibilities. We have redesigned the API to make it not only far easier and more reliable for developers to work with, but have also provided completely new possibilities for Plug-ins. These include: + +### 1. Improved Performance with the Silence Flag +Processing can optionally be applied to Plug-ins only when audio signals are present on their respective inputs, so VST 3 Plug-ins can apply their processing economically and only when it is needed. + +### 2. Multiple Dynamic I/Os +VST 3 Plug-ins are no longer limited to a fixed number of inputs and outputs, and their I/O configuration can dynamically adapt to the channel configuration. Side-chains are also very easily realizable. This includes the possibility to deactivate unused buses after loading and even reactivate those when needed. This cleans up the mixer and further helps to reduce CPU load. + +### 3. Sample-accurate Automation +VST 3 also features vastly improved parameter automation with sample accuracy and support for ramped automation data, allowing completely accurate and rapid parameter automation changes. + +### 4. Logical Parameter Organization +The VST 3 Plug-in parameters are displayed in a tree structure. Parameters are grouped into sections which represent the structure of the Plug-in. Plug-ins can communicate their internal structure for the purpose of overview, but also for some associated functionality (eg. program-lists). + +### 5. Resizeable UI Editor +VST 3 defines a way to allow resizing of the Plug-in editor by a user. + +### 6. Mouse Over Support +The Host could ask the Plug-in which parameter is under the mouse. + +### 7. Context Menu Support +VST 3 defines a way to allow the host to add its own entries in the Plug-in context menu of a specific parameter. + +### 8. Channel Context Information +A VST 3 Plug-in could access some channel information where it is instantiated: name, color,... + +### 9. Note Expression +VST 3 defines with Note Expression a new way of event controller editing. The Plug-in is able to break free from the limitations of MIDI controller events by providing access to new VST 3 controller events that circumvent the laws of MIDI and provide articulation information for each individual note (event) in a polyphonic arrangement according to its noteId. + +### 10. 3D Support +VST 3 supports new speaker configurations like Ambisonic, Atmos, Auro 3D or 22.2. + +### 11. Factory Concept +VST 3 Plug-in library could export multiple Plug-ins and in this way replaces the shell concept of VST 2 (kPlugCategShell). + +### 12. Support Remote control Representation +VST 3 Plug-in can deliver a specific parameter mapping for remote controls like Nuage. + +### 13. Others +While designing VST 3, we performed a careful analysis of the existing functionality of VST and rewrote the interfaces from scratch. In doing so, we focused a lot on providing clear interfaces and their documentation in order to avoid usage errors from the deepest possible layer. +Some more features implemented specifically for developers include: +- More stable technical Host/Plug-in environment +- Advanced technical definition of the standard +- Modular approach +- Separation of UI and processing +- Advanced Preset System +- Multiple Plug-ins per Library +- Test Host included +- Automated Testing Environment +- Validator (small command line Test Host) and Plug-in examples code included + +--- +
+ +## How to build + +### Get the source code from GitHub +
git clone --recursive https://github.com/steinbergmedia/vst3sdk.git
+
+ +### Build the examples on Linux +
+mkdir build
+cd build
+cmake ../vst3sdk
+make  (or alternatively cmake --build .)
+
+ +### Build the examples on macOS +
+mkdir build
+cd build
+cmake -GXcode ../vst3sdk
+xcodebuild  (or alternatively cmake --build .)
+
+ +### Build the examples on Windows +
+mkdir build
+cd build
+cmake.exe -G"Visual Studio 15 2017 Win64" ../vst3sdk
+msbuild.exe vstsdk.sln   (or alternatively cmake --build .)
+
+ +### Build using cmake-gui +
+* start the cmake-gui Application
+* "Browse Source...": select the folder VST3_SDK
+* "Browse Build...": select a folder where the outputs (projects/...) will be created. Typically a folder named "build"
+* you can check the SMTG Options
+* Press "Configure"
+* Press "Generate" and the project will be created
+
+
+--- + +## License & Usage guidelines +More details are found at [www.steinberg.net/sdklicenses_vst3](http://www.steinberg.net/sdklicenses_vst3) \ No newline at end of file diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/LICENSE.txt b/modules/juce_audio_processors/format_types/VST3_SDK/base/LICENSE.txt new file mode 100644 index 0000000000..1f195a9088 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/LICENSE.txt @@ -0,0 +1,27 @@ +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/baseiids.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/baseiids.cpp new file mode 100644 index 0000000000..09dcfb0cae --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/baseiids.cpp @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/baseidds.cpp +// Created by : Steinberg, 01/2008 +// Description : Basic Interface +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "pluginterfaces/base/funknown.h" +#include "pluginterfaces/base/istringresult.h" +#include "pluginterfaces/base/ipersistent.h" + + +namespace Steinberg { + +DEF_CLASS_IID (IString) +DEF_CLASS_IID (IStringResult) + +DEF_CLASS_IID (IPersistent) +DEF_CLASS_IID (IAttributes) +DEF_CLASS_IID (IAttributes2) +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/classfactoryhelpers.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/classfactoryhelpers.h new file mode 100644 index 0000000000..f331dedbb4 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/classfactoryhelpers.h @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/classfactoryhelpers.h +// Created by : Steinberg, 03/2017 +// Description : Class factory +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#pragma once + +//------------------------------------------------------------------------------ +// Helper Macros. Not intended for direct use. +// Use: +// META_CLASS(className), +// META_CLASS_IFACE(className,Interface), +// META_CLASS_SINGLE(className,Interface) +// instead. +//------------------------------------------------------------------------------ +#define META_CREATE_FUNC(funcName) static FUnknown* funcName () + +#define CLASS_CREATE_FUNC(className) \ + namespace Meta { \ + META_CREATE_FUNC (make##className) { return (NEW className)->unknownCast (); } \ + } + +#define SINGLE_CREATE_FUNC(className) \ + namespace Meta { \ + META_CREATE_FUNC (make##className) { return className::instance ()->unknownCast (); } \ + } + +#define _META_CLASS(className) \ + namespace Meta { \ + static Steinberg::MetaClass meta##className ((#className), Meta::make##className); \ + } + +#define _META_CLASS_IFACE(className, Interface) \ + namespace Meta { \ + static Steinberg::MetaClass meta##Interface##className ((#className), Meta::make##className, \ + Interface##_iid); \ + } + +/** TODO + */ +#define META_CLASS(className) \ + CLASS_CREATE_FUNC (className) \ + _META_CLASS (className) + +/** TODO + */ +#define META_CLASS_IFACE(className, Interface) \ + CLASS_CREATE_FUNC (className) \ + _META_CLASS_IFACE (className, Interface) + +/** TODO + */ +#define META_CLASS_SINGLE(className, Interface) \ + SINGLE_CREATE_FUNC (className) \ + _META_CLASS_IFACE (className, Interface) diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.cpp new file mode 100644 index 0000000000..8de06dac98 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.cpp @@ -0,0 +1,644 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fbuffer.cpp +// Created by : Steinberg, 2008 +// Description : +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "base/source/fbuffer.h" +#include "base/source/fstring.h" +#include + +namespace Steinberg { + +//------------------------------------------------------------------------------------- +Buffer::Buffer () +: buffer (0) +, memSize (0) +, fillSize (0) +, delta (defaultDelta) +{} + +//------------------------------------------------------------------------------------- +Buffer::Buffer (uint32 s, uint8 initVal) +: buffer (0) +, memSize (s) +, fillSize (0) +, delta (defaultDelta) +{ + if (memSize == 0) + return; + buffer = (int8*)::malloc (memSize); + if (buffer) + memset (buffer, initVal, memSize); + else + memSize = 0; +} + +//------------------------------------------------------------------------------------- +Buffer::Buffer (uint32 s) +: buffer (0) +, memSize (s) +, fillSize (0) +, delta (defaultDelta) +{ + if (memSize == 0) + return; + buffer = (int8*)::malloc (memSize); + if (!buffer) + memSize = 0; +} + +//------------------------------------------------------------------------------------- +Buffer::Buffer (const void* b , uint32 s) +: buffer (0) +, memSize (s) +, fillSize (s) +, delta (defaultDelta) +{ + if (memSize == 0) + return; + buffer = (int8*)::malloc (memSize); + if (buffer) + memcpy (buffer, b, memSize); + else + { + memSize = 0; + fillSize = 0; + } +} + +//------------------------------------------------------------------------------------- +Buffer::Buffer (const Buffer& bufferR) +: buffer (0) +, memSize (bufferR.memSize) +, fillSize (bufferR.fillSize) +, delta (bufferR.delta) +{ + if (memSize == 0) + return; + + buffer = (int8*)::malloc (memSize); + if (buffer) + memcpy (buffer, bufferR.buffer, memSize); + else + memSize = 0; +} + +//------------------------------------------------------------------------------------- +Buffer::~Buffer () +{ + if (buffer) + ::free (buffer); + buffer = 0; +} + +//------------------------------------------------------------------------------------- +void Buffer::operator = (const Buffer& b2) +{ + if (&b2 != this) + { + setSize (b2.memSize); + if (b2.memSize > 0 && buffer) + memcpy (buffer, b2.buffer, b2.memSize); + fillSize = b2.fillSize; + delta = b2.delta; + } +} + +//------------------------------------------------------------------------------------- +bool Buffer::operator == (const Buffer& b2)const +{ + if (&b2 == this) + return true; + if (b2.getSize () != getSize ()) + return false; + return memcmp (this->int8Ptr (), b2.int8Ptr (), getSize ()) == 0 ? true : false; +} + +//------------------------------------------------------------------------------------- +uint32 Buffer::get (void* b, uint32 size) +{ + uint32 maxGet = memSize - fillSize; + if (size > maxGet) + size = maxGet; + if (size > 0) + memcpy (b, buffer + fillSize, size); + fillSize += size; + return size; +} + +//------------------------------------------------------------------------------------- +bool Buffer::put (char16 c) +{ + return put ((const void*)&c, sizeof (c)); +} + +//------------------------------------------------------------------------------------- +bool Buffer::put (uint8 byte) +{ + if (grow (fillSize + 1) == false) + return false; + + buffer [fillSize++] = byte; + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::put (char c) +{ + if (grow (fillSize + 1) == false) + return false; + + buffer [fillSize++] = c; + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::put (const void* toPut, uint32 s) +{ + if (!toPut) + return false; + + if (grow (fillSize + s) == false) + return false; + + memcpy (buffer + fillSize, toPut, s); + fillSize += s; + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::put (const String& str) +{ + return put ((const void*)str.text () , (str.length () + 1) * sizeof (tchar)); +} + +//------------------------------------------------------------------------------------- +bool Buffer::appendString8 (const char8* s) +{ + if (!s) + return false; + + uint32 len = (uint32) strlen (s); + return put (s, len); +} + +//------------------------------------------------------------------------------------- +bool Buffer::appendString16 (const char16* s) +{ + if (!s) + return false; + ConstString str (s); + uint32 len = (uint32) str.length () * sizeof (char16); + return put (s, len); +} + +//------------------------------------------------------------------------------------- +bool Buffer::prependString8 (const char8* s) +{ + if (!s) + return false; + + uint32 len = (uint32) strlen (s); + + if (len > 0) + { + shiftStart (len); + memcpy (buffer, s, len); + return true; + } + return false; +} + +//------------------------------------------------------------------------------------- +bool Buffer::prependString16 (const char16* s) +{ + if (!s) + return false; + + ConstString str (s); + uint32 len = (uint32) str.length () * sizeof (char16); + + if (len > 0) + { + shiftStart (len); + memcpy (buffer, s, len); + return true; + } + return false; +} + +//------------------------------------------------------------------------------------- +bool Buffer::prependString8 (char8 c) +{ + shiftStart (sizeof (char)); + char* b = (char*)buffer; + b [0] = c; + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::prependString16 (char16 c) +{ + shiftStart (sizeof (char16)); + char16* b = (char16*)buffer; + b [0] = c; + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::copy (uint32 from, uint32 to, uint32 bytes) +{ + if (from + bytes > memSize || bytes == 0) + return false; + + if (to + bytes > memSize) + setSize (to + bytes); + + if (from + bytes > to && from < to) + { // overlap + Buffer tmp (buffer + from, bytes); + memcpy (buffer + to, tmp, bytes); + } + else + memcpy (buffer + to, buffer + from, bytes); + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::makeHexString (String& result) +{ + unsigned char* data = uint8Ptr (); + uint32 bytes = getSize (); + + if (data == 0 || bytes == 0) + return false; + + char8* stringBuffer = (char8*)malloc ((bytes * 2) + 1); + if (!stringBuffer) + return false; + + int32 count = 0; + while (bytes > 0) + { + unsigned char t1 = ((*data) >> 4) & 0x0F; + unsigned char t2 = (*data) & 0x0F; + if (t1 < 10) + t1 += '0'; + else + t1 = t1 - 10 + 'A'; + if (t2 < 10) + t2 += '0'; + else + t2 = t2 - 10 + 'A'; + + stringBuffer [count++] = t1; + stringBuffer [count++] = t2; + data++; + bytes--; + } + stringBuffer [count] = 0; + + result.take ((void*)stringBuffer, false); + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::fromHexString (const char8* string) +{ + flush (); + if (string == 0) + return false; + + int32 len = strlen8 (string); + if (len == 0 || ((len & 1) == 1)/*odd number*/ ) + return false; + + setSize (len / 2); + unsigned char* data = uint8Ptr (); + + bool upper = true; + int32 count = 0; + while (count < len) + { + char c = string [count]; + + unsigned char d = 0; + if (c >= '0' && c <= '9') d += c - '0'; + else if (c >= 'A' && c <= 'F') d += c - 'A' + 10; + else if (c >= 'a' && c <= 'f') d += c - 'a' + 10; + else return false; // no hex string + + if (upper) + data [count >> 1] = d << 4; + else + data [count >> 1] += d; + + upper = !upper; + count++; + } + setFillSize (len / 2); + return true; +} + +//------------------------------------------------------------------------ +void Buffer::set (uint8 value) +{ + if (buffer) + memset (buffer, value, memSize); +} + +//------------------------------------------------------------------------------------- +bool Buffer::setFillSize (uint32 c) +{ + if (c <= memSize) + { + fillSize = c; + return true; + } + return false; +} + +//------------------------------------------------------------------------------------- +bool Buffer::truncateToFillSize () +{ + if (fillSize < memSize) + setSize (fillSize); + + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::grow (uint32 newSize) +{ + if (newSize > memSize) + { + if (delta == 0) + delta = defaultDelta; + uint32 s = ((newSize + delta - 1) / delta) * delta; + return setSize (s); + } + return true; +} + +//------------------------------------------------------------------------ +void Buffer::shiftAt (uint32 position, int32 amount) +{ + if (amount > 0) + { + if (grow (fillSize + amount)) + { + if (position < fillSize) + memmove (buffer + amount + position, buffer + position, fillSize - position); + + fillSize += amount; + } + } + else if (amount < 0 && fillSize > 0) + { + uint32 toRemove = -amount; + + if (toRemove < fillSize) + { + if (position < fillSize) + memmove (buffer + position, buffer + toRemove + position, fillSize - position - toRemove); + fillSize -= toRemove; + } + } +} + +//------------------------------------------------------------------------------------- +void Buffer::move (int32 amount, uint8 initVal) +{ + if (memSize == 0) + return; + + if (amount > 0) + { + if ((uint32)amount < memSize) + { + memmove (buffer + amount, buffer, memSize - amount); + memset (buffer, initVal, amount); + } + else + memset (buffer, initVal, memSize); + } + else + { + uint32 toRemove = -amount; + if (toRemove < memSize) + { + memmove (buffer, buffer + toRemove, memSize - toRemove); + memset (buffer + memSize - toRemove, initVal, toRemove); + } + else + memset (buffer, initVal, memSize); + } +} + +//------------------------------------------------------------------------------------- +bool Buffer::setSize (uint32 newSize) +{ + if (memSize != newSize) + { + if (buffer) + { + if (newSize > 0) + { + int8* newBuffer = (int8*) ::realloc (buffer, newSize); + if (newBuffer == 0) + { + newBuffer = (int8*)::malloc (newSize); + if (newBuffer) + { + uint32 tmp = newSize; + if (tmp > memSize) + tmp = memSize; + memcpy (newBuffer, buffer, tmp); + ::free (buffer); + buffer = newBuffer; + } + else + { + ::free (buffer); + buffer = 0; + } + } + else + buffer = newBuffer; + } + else + { + ::free (buffer); + buffer = 0; + } + } + else + buffer = (int8*)::malloc (newSize); + + if (newSize > 0 && !buffer) + memSize = 0; + else + memSize = newSize; + if (fillSize > memSize) + fillSize = memSize; + } + + return (newSize > 0) == (buffer != 0); +} + +//------------------------------------------------------------------------------------- +void Buffer::fillup (uint8 value) +{ + if (getFree () > 0) + memset (buffer + fillSize, value, getFree ()); +} + +//------------------------------------------------------------------------------------- +int8* Buffer::operator + (uint32 i) +{ + if (i < memSize) + return buffer + i; + else + { + static int8 eof; + eof = 0; + return &eof; + } +} + +//------------------------------------------------------------------------------------- +bool Buffer::swap (int16 swapSize) +{ + return swap (buffer, memSize, swapSize); +} + +//------------------------------------------------------------------------------------- +bool Buffer::swap (void* buffer, uint32 bufferSize, int16 swapSize) +{ + if (swapSize != kSwap16 && swapSize != kSwap32 && swapSize != kSwap64) + return false; + + if (swapSize == kSwap16) + { + for (uint32 count = 0 ; count < bufferSize ; count += 2) + { + SWAP_16 ( * (((int16*)buffer) + count) ); + } + } + else if (swapSize == kSwap32) + { + for (uint32 count = 0 ; count < bufferSize ; count += 4) + { + SWAP_32 ( * (((int32*)buffer) + count) ); + } + } + else if (swapSize == kSwap64) + { + for (uint32 count = 0 ; count < bufferSize ; count += 8) + { + SWAP_64 ( * (((int64*)buffer) + count) ); + } + } + + return true; +} + +//------------------------------------------------------------------------------------- +void Buffer::take (Buffer& from) +{ + setSize (0); + memSize = from.memSize; + fillSize = from.fillSize; + buffer = from.buffer; + from.buffer = 0; + from.memSize = 0; + from.fillSize = 0; +} + +//------------------------------------------------------------------------------------- +int8* Buffer::pass () +{ + int8* res = buffer; + buffer = 0; + memSize = 0; + fillSize = 0; + return res; +} + +//------------------------------------------------------------------------------------- +bool Buffer::toWideString (int32 sourceCodePage) +{ + if (getFillSize () > 0) + { + if (str8 () [getFillSize () - 1] != 0) // multiByteToWideString only works with 0-terminated strings + endString8 (); + + Buffer dest (getFillSize () * sizeof (char16)); + int32 result = String::multiByteToWideString (dest.str16 (), buffer, dest.getFree () / sizeof (char16), sourceCodePage); + if (result > 0) + { + dest.setFillSize ((result - 1) * sizeof (char16)); + take (dest); + return true; + } + return false; + } + return true; +} + +//------------------------------------------------------------------------------------- +bool Buffer::toMultibyteString (int32 destCodePage) +{ + if (getFillSize () > 0) + { + int32 textLength = getFillSize () / sizeof (char16); // wideStringToMultiByte only works with 0-terminated strings + if (str16 () [textLength - 1] != 0) + endString16 (); + + Buffer dest (getFillSize ()); + int32 result = String::wideStringToMultiByte (dest.str8 (), str16 (), dest.getFree (), destCodePage); + if (result > 0) + { + dest.setFillSize (result - 1); + take (dest); + return true; + } + return false; + } + return true; +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.h new file mode 100644 index 0000000000..e8dd936a84 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fbuffer.h @@ -0,0 +1,306 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fbuffer.h +// Created by : Steinberg, 2008 +// Description : +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/ftypes.h" +#include + +namespace Steinberg { +class String; + +//------------------------------------------------------------------------ +/** Buffer. +@ingroup adt + +A Buffer is an object-oriented wrapper for a piece of memory. +It adds several utility functions, e.g. for managing the size of the Buffer, +appending or prepending values or strings to it. +Internally it uses the standard memory functions malloc(), free(), etc. */ +//------------------------------------------------------------------------ +class Buffer +{ +public: +//--------------------------------------------------------------------- + + /** Default constructor, allocates no memory at all. + */ + Buffer (); + + /** Constructor - creates a new Buffer with a given size and copies contents from optional memory pointer. + \param[in] b : optional memory pointer with the size of at least the given size + \param[in] size : the size of the new Buffer to be allocated, in bytes. + */ + Buffer (const void* b, uint32 size); + + /** Constructor - creates a new Buffer with a given size and fills it all with a given value. + \param[in] size : the size of the new Buffer to be allocated, in bytes. + \param[in] initVal : the initial value the Buffer will be completely filled with + */ + Buffer (uint32 size, uint8 initVal); + + /** Constructor - creates a new Buffer with a given size. + \param[in] size : the size of the new Buffer to be allocated, in bytes. + */ + Buffer (uint32 size); + + /** Copy constructor - creates a new Buffer from a given Buffer. + \param[in] buff : the Buffer from which all memory will be copied to the new one + */ + Buffer (const Buffer& buff); + + /** Destructor - deallocates the internal memory. + */ + ~Buffer (); + + /** Assignment operator - copies contents from a given Buffer and increases the size if necessary. + \param[in] buff : the Buffer from which all memory will be copied + */ + void operator = (const Buffer& buff); + + /** Comparison operator - copies contents from a given Buffer and increases the size if necessary. + \param[in] buff : the Buffer to be compared to + \return true, if the given Buffer's content is equal to this one, else false + */ + bool operator == (const Buffer& buff)const; + + uint32 getSize () const {return memSize;} ///< \return the actual size of the Buffer's memory, in bytes. + + /** Sets a new size for this Buffer, keeping as much content as possible. + \param[in] newSize : the new size for the Buffer, in bytes, newSize maybe zero + \return true, if the new size could be adapted, else false + */ + bool setSize (uint32 newSize); + + /** Increases the Buffer to the next block, block size given by delta. + \param[in] memSize : the new minimum size of the Buffer, newSize maybe zero + \return true, if the Buffer could be grown successfully, else false + */ + bool grow (uint32 memSize); + bool setMaxSize (uint32 size) {return grow (size);} ///< see \ref grow() + + void fillup (uint8 initVal = 0); ///< set from fillSize to end + uint32 getFillSize ()const {return fillSize;} ///< \return the actual fill size + bool setFillSize (uint32 c); ///< sets a new fill size, does not change any memory + inline void flush () {setFillSize (0);} ///< sets fill size to zero + bool truncateToFillSize (); ///< \return always true, truncates the size of the Buffer to the actual fill size + + bool isFull () const { return (fillSize == memSize); } ///< \return true, if all memory is filled up, else false + uint32 getFree () const { return (memSize - fillSize); }///< \return remaining memory + + inline void shiftStart (int32 amount) {return shiftAt (0, amount);} ///< moves all memory by given amount, grows the Buffer if necessary + void shiftAt (uint32 position, int32 amount); ///< moves memory starting at the given position + void move (int32 amount, uint8 initVal = 0); ///< shifts memory at start without growing the buffer, so data is lost and initialized with init val + + bool copy (uint32 from, uint32 to, uint32 bytes); ///< copies a number of bytes from one position to another, the size may be adapted + uint32 get (void* b, uint32 size); ///< copy to buffer from fillSize, and shift fillSize + + void setDelta (uint32 d) {delta = d;} ///< define the block size by which the Buffer grows, see \ref grow() + + bool put (uint8); ///< append value at end, grows Buffer if necessary + bool put (char16 c); ///< append value at end, grows Buffer if necessary + bool put (char c); ///< append value at end, grows Buffer if necessary + bool put (const void* , uint32 size); ///< append bytes from a given buffer, grows Buffer if necessary + bool put (void* , uint32 size); ///< append bytes from a given buffer, grows Buffer if necessary + bool put (uint8* , uint32 size); ///< append bytes from a given buffer, grows Buffer if necessary + bool put (char8* , uint32 size); ///< append bytes from a given buffer, grows Buffer if necessary + bool put (const uint8* , uint32 size); ///< append bytes from a given buffer, grows Buffer if necessary + bool put (const char8* , uint32 size); ///< append bytes from a given buffer, grows Buffer if necessary + bool put (const String&); ///< append String at end, grows Buffer if necessary + + void set (uint8 value); ///< fills complete Buffer with given value + + // strings ---------------- + bool appendString (const tchar* s); + bool appendString (tchar* s); + bool appendString (tchar c) { return put (c); } + + bool appendString8 (const char8* s); + bool appendString16 (const char16* s); + + bool appendString8 (char8* s) { return appendString8 ((const char8*)s); } + bool appendString8 (unsigned char* s) { return appendString8 ((const char8*)s); } + bool appendString8 (const unsigned char* s) { return appendString8 ((const char8*)s); } + + bool appendString8 (char8 c) { return put ((uint8)c); } + bool appendString8 (unsigned char c) { return put (c); } + bool appendString16 (char16 c) { return put (c); } + bool appendString16 (char16* s) { return appendString16 ((const char16*)s); } + + bool prependString (const tchar* s); + bool prependString (tchar* s); + bool prependString (tchar c); + + bool prependString8 (const char8* s); + bool prependString16 (const char16* s); + + bool prependString8 (char8 c); + bool prependString8 (unsigned char c) { return prependString8 ((char8)c); } + bool prependString8 (char8* s) { return prependString8 ((const char8*)s); } + bool prependString8 (unsigned char* s) { return prependString8((const char8*)s); } + bool prependString8 (const unsigned char* s) { return prependString8 ((const char8*)s); } + bool prependString16 (char16 c); + bool prependString16 (char16* s) { return prependString16 ((const char16*)s); } + + bool operator+= (const char* s) { return appendString8 (s); } + bool operator+= (char c) { return appendString8 (c); } + bool operator+= (const char16* s) { return appendString16 (s); } + bool operator+= (char16 c) { return appendString16 (c); } + + bool operator= (const char* s) { flush (); return appendString8 (s); } + bool operator= (const char16* s) { flush (); return appendString16 (s); } + bool operator= (char8 c) { flush (); return appendString8 (c); } + bool operator= (char16 c) { flush (); return appendString16 (c); } + + void endString () {put (tchar (0));} + void endString8 () {put (char8 (0));} + void endString16 () {put (char16 (0));} + + bool makeHexString (String& result); + bool fromHexString (const char8* string); + + // conversion + operator void* () const { return (void*)buffer; } ///< conversion + inline tchar* str () const {return (tchar*)buffer;} ///< conversion + inline char8* str8 () const {return (char8*)buffer;} ///< conversion + inline char16* str16 () const {return (char16*)buffer;} ///< conversion + inline int8* int8Ptr () const {return (int8*)buffer;} ///< conversion + inline uint8* uint8Ptr () const {return (uint8*)buffer; } ///< conversion + inline int16* int16Ptr () const {return (int16*)buffer; } ///< conversion + inline uint16* uint16Ptr () const {return (uint16*)buffer; } ///< conversion + inline int32* int32Ptr () const {return (int32*)buffer; } ///< conversion + inline uint32* uint32Ptr () const {return (uint32*)buffer; } ///< conversion + inline float* floatPtr () const {return (float*)buffer; } ///< conversion + inline double* doublePtr () const {return (double*)buffer; } ///< conversion + inline char16* wcharPtr () const {return (char16*)buffer;} ///< conversion + + int8* operator + (uint32 i); ///< \return the internal Buffer's address plus the given offset i, zero if offset is out of range + + int32 operator ! () { return buffer == 0; } + + enum swapSize + { + kSwap16 = 2, + kSwap32 = 4, + kSwap64 = 8 + }; + bool swap (int16 swapSize); ///< swap all bytes of this Buffer by the given swapSize + static bool swap (void* buffer, uint32 bufferSize, int16 swapSize); ///< utility, swap given number of bytes in given buffer by the given swapSize + + void take (Buffer& from); ///< takes another Buffer's memory, frees the current Buffer's memory + int8* pass (); ///< pass the current Buffer's memory + + /** Converts a Buffer's content to UTF-16 from a given multi-byte code page, Buffer must contain char8 of given encoding. + \param[in] sourceCodePage : the actual code page of the Buffer's content + \return true, if the conversion was successful, else false + */ + virtual bool toWideString (int32 sourceCodePage); // Buffer contains char8 of given encoding -> utf16 + + /** Converts a Buffer's content from UTF-16 to a given multi-byte code page, Buffer must contain UTF-16 encoded characters. + \param[in] destCodePage : the desired code page to convert the Buffer's content to + \return true, if the conversion was successful, else false + */ + virtual bool toMultibyteString (int32 destCodePage); // Buffer contains utf16 -> char8 of given encoding + +//------------------------------------------------------------------------ +protected: + static const uint32 defaultDelta = 0x1000; // 0x1000 + + int8* buffer; + uint32 memSize; + uint32 fillSize; + uint32 delta; +}; + +inline bool Buffer::put (void* p, uint32 count) { return put ((const void*)p , count ); } +inline bool Buffer::put (uint8 * p, uint32 count) { return put ((const void*)p , count ); } +inline bool Buffer::put (char8* p, uint32 count) { return put ((const void*)p , count ); } +inline bool Buffer::put (const uint8* p, uint32 count) { return put ((const void*)p , count ); } +inline bool Buffer::put (const char8* p, uint32 count) { return put ((const void*)p , count ); } + +//------------------------------------------------------------------------ +inline bool Buffer::appendString (const tchar* s) +{ +#ifdef UNICODE + return appendString16 (s); +#else + return appendString8 (s); +#endif +} + +//------------------------------------------------------------------------ +inline bool Buffer::appendString (tchar* s) +{ +#ifdef UNICODE + return appendString16 (s); +#else + return appendString8 (s); +#endif +} + +//------------------------------------------------------------------------ +inline bool Buffer::prependString (const tchar* s) +{ +#ifdef UNICODE + return prependString16 (s); +#else + return prependString8 (s); +#endif +} + +//------------------------------------------------------------------------ +inline bool Buffer::prependString (tchar* s) +{ +#ifdef UNICODE + return prependString16 (s); +#else + return prependString8 (s); +#endif +} + +//------------------------------------------------------------------------ +inline bool Buffer::prependString (tchar c) +{ +#ifdef UNICODE + return prependString16 (c); +#else + return prependString8 (c); +#endif +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.cpp new file mode 100644 index 0000000000..7828add9fa --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.cpp @@ -0,0 +1,314 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fdebug.cpp +// Created by : Steinberg, 1995 +// Description : There are 2 levels of debugging messages: +// DEVELOPMENT During development +// RELEASE Program is shipping. +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "base/source/fdebug.h" + +#if DEVELOPMENT + +#include +#include +#include + +#if SMTG_OS_WINDOWS +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0400 +#endif +#include +#include +#define vsnprintf _vsnprintf +#define snprintf _snprintf + +#elif SMTG_OS_MACOS +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool AmIBeingDebugged (void); + +#define THREAD_ALLOC_WATCH 0 // check allocations on specific threads + +#if THREAD_ALLOC_WATCH +mach_port_t watchThreadID = 0; +#endif + +#endif + +AssertionHandler gAssertionHandler = nullptr; +AssertionHandler gPreAssertionHook = nullptr; +DebugPrintLogger gDebugPrintLogger = nullptr; + +namespace boost { +// Define the boost assertion handler to redirect to our assertion handler, +// otherwise it just calls abort(). Note that we don't need to include any boost +// headers for this, it just provides the handler. +void assertion_failed (char const* expr, char const* function, char const* file, long line) +{ +#if DEVELOPMENT + char message[512]; + snprintf (message, 512, "%s at %s, %s:%ld", expr, function, file, line); + if (gAssertionHandler) + { + FDebugBreak (message); + } + else + { + assert (!(const char *)message); + } +#endif +} +} + +//-------------------------------------------------------------------------- +static const int kDebugPrintfBufferSize = 10000; +static bool neverDebugger = false; // so I can switch it off in the debugger... + +//-------------------------------------------------------------------------- +static void printDebugString (const char* string) +{ + if (!string) + return; + + if (gDebugPrintLogger) + { + gDebugPrintLogger (string); + } + else + { +#if SMTG_OS_MACOS + fprintf (stderr, "%s", string); +#elif SMTG_OS_WINDOWS + OutputDebugStringA (string); +#endif + } +} + +//-------------------------------------------------------------------------- +// printf style debugging output +//-------------------------------------------------------------------------- +void FDebugPrint (const char* format, ...) +{ + char string[kDebugPrintfBufferSize]; + va_list marker; + va_start (marker, format); + vsnprintf (string, kDebugPrintfBufferSize, format, marker); + + printDebugString (string); +} + +#if SMTG_OS_WINDOWS +#define AmIBeingDebugged IsDebuggerPresent +#endif + +#if SMTG_OS_LINUX +#include +#include +#include +//-------------------------------------------------------------------------- +static inline bool AmIBeingDebugged () +{ + // TODO: check if GDB or LLDB is attached + return true; +} +#endif + +//-------------------------------------------------------------------------- +// printf style debugging output +//-------------------------------------------------------------------------- +void FDebugBreak (const char* format, ...) +{ + char string[kDebugPrintfBufferSize]; + va_list marker; + va_start (marker, format); + vsnprintf (string, kDebugPrintfBufferSize, format, marker); + + printDebugString (string); + + // The Pre-assertion hook is always called, even if we're not running in the debugger, + // so that we can log asserts without displaying them + if (gPreAssertionHook) + { + gPreAssertionHook (string); + } + + if (neverDebugger) + return; + if (AmIBeingDebugged ()) + { + // do not crash if no debugger present + // If there is an assertion handler defined then let this override the UI + // and tell us whether we want to break into the debugger + bool breakIntoDebugger = true; + if (gAssertionHandler && gAssertionHandler (string) == false) + { + breakIntoDebugger = false; + } + + if (breakIntoDebugger) + { +#if SMTG_OS_WINDOWS + __debugbreak (); // intrinsic version of DebugBreak() +#elif __ppc64__ || __ppc__ || __arm__ + kill (getpid (), SIGINT); +#elif __i386__ || __x86_64__ + { + __asm__ volatile ("int3"); + } +#endif + } + } +} + +//-------------------------------------------------------------------------- +void FPrintLastError (const char* file, int line) +{ +#if SMTG_OS_WINDOWS + LPVOID lpMessageBuffer; + FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, + GetLastError (), MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&lpMessageBuffer, 0, NULL); + FDebugPrint ("%s(%d) : %s\n", file, line, lpMessageBuffer); + LocalFree (lpMessageBuffer); +#endif + +#if SMTG_OS_MACOS +#if !__MACH__ + extern int errno; +#endif + FDebugPrint ("%s(%d) : Errno %d\n", file, line, errno); +#endif +} + +#if SMTG_OS_MACOS + +//------------------------------------------------------------------------ +void* operator new (size_t size, int, const char* file, int line) +{ +#if THREAD_ALLOC_WATCH + mach_port_t threadID = mach_thread_self (); + if (watchThreadID == threadID) + { + FDebugPrint ("Watched Thread Allocation : %s (Line:%d)\n", file ? file : "Unknown", line); + } +#endif + try + { + return ::operator new (size); + } + catch (std::bad_alloc exception) + { + FDebugPrint ("bad_alloc exception : %s (Line:%d)", file ? file : "Unknown", line); + } + return (void*)-1; +} + +//------------------------------------------------------------------------ +void* operator new[] (size_t size, int, const char* file, int line) +{ +#if THREAD_ALLOC_WATCH + mach_port_t threadID = mach_thread_self (); + if (watchThreadID == threadID) + { + FDebugPrint ("Watched Thread Allocation : %s (Line:%d)\n", file ? file : "Unknown", line); + } +#endif + try + { + return ::operator new[] (size); + } + catch (std::bad_alloc exception) + { + FDebugPrint ("bad_alloc exception : %s (Line:%d)", file ? file : "Unknown", line); + } + return (void*)-1; +} + +//------------------------------------------------------------------------ +void operator delete (void* p, int, const char* file, int line) +{ + ::operator delete (p); +} + +//------------------------------------------------------------------------ +void operator delete[] (void* p, int, const char* file, int line) +{ + ::operator delete[] (p); +} + +//------------------------------------------------------------------------ +// from Technical Q&A QA1361 (http://developer.apple.com/qa/qa2004/qa1361.html) +//------------------------------------------------------------------------ +bool AmIBeingDebugged (void) +// Returns true if the current process is being debugged (either +// running under the debugger or has a debugger attached post facto). +{ + int mib[4]; + struct kinfo_proc info; + size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid (); + + // Call sysctl. + + size = sizeof (info); + sysctl (mib, sizeof (mib) / sizeof (*mib), &info, &size, NULL, 0); + + // We're being debugged if the P_TRACED flag is set. + return ((info.kp_proc.p_flag & P_TRACED) != 0); +} + +#endif // SMTG_OS_MACOS + +#endif // DEVELOPMENT diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.h new file mode 100644 index 0000000000..e61f0aacc9 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fdebug.h @@ -0,0 +1,233 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fdebug.h +// Created by : Steinberg, 1995 +// Description : There are 2 levels of debugging messages: +// DEVELOPMENT During development +// RELEASE Program is shipping. +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +/** @file base/source/fdebug.h + Debugging tools. + + There are 2 levels of debugging messages: + - DEVELOPMENT + - During development + - RELEASE + - Program is shipping. +*/ +//----------------------------------------------------------------------------- +#pragma once + +#include "pluginterfaces/base/ftypes.h" +#include + +#if SMTG_OS_MACOS +#include +#endif + +//----------------------------------------------------------------------------- +// development / release +//----------------------------------------------------------------------------- +#if !defined (DEVELOPMENT) && !defined (RELEASE) + #ifdef _DEBUG + #define DEVELOPMENT 1 + #elif defined (NDEBUG) + #define RELEASE 1 + #else + #error DEVELOPMENT, RELEASE, _DEBUG, or NDEBUG must be defined! + #endif +#endif + +//----------------------------------------------------------------------------- +#if SMTG_OS_WINDOWS + +/** Disable compiler warning: + * C4291: "No matching operator delete found; memory will not be freed if initialization throws an + * exception. A placement new is used for which there is no placement delete." */ +#if DEVELOPMENT && defined(_MSC_VER) +#pragma warning(disable : 4291) +#pragma warning(disable : 4985) +#endif + +#endif // SMTG_OS_WINDOWS + +#if DEVELOPMENT +//----------------------------------------------------------------------------- +/** If "f" is not true and a debugger is present, send an error string to the debugger for display + and cause a breakpoint exception to occur in the current process. SMTG_ASSERT is removed + completely in RELEASE configuration. So do not pass methods calls to this macro that are expected + to exist in the RELEASE build (for method calls that need to be present in a RELEASE build, use + the VERIFY macros instead)*/ +#define SMTG_ASSERT(f) \ + if (!(f)) \ + FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f); + +/** Send "comment" string to the debugger for display. */ +#define SMTG_WARNING(comment) FDebugPrint ("%s(%d) : %s\n", __FILE__, __LINE__, comment); + +/** Send the last error string to the debugger for display. */ +#define SMTG_PRINTSYSERROR FPrintLastError (__FILE__, __LINE__); + +/** If a debugger is present, send string "s" to the debugger for display and + cause a breakpoint exception to occur in the current process. */ +#define SMTG_DEBUGSTR(s) FDebugBreak (s); + +/** Use VERIFY for calling methods "f" having a bool result (expecting them to return 'true') + The call of "f" is not removed in RELEASE builds, only the result verification. eg: SMTG_VERIFY + (isValid ()) */ +#define SMTG_VERIFY(f) SMTG_ASSERT (f) + +/** Use VERIFY_IS for calling methods "f" and expect a certain result "r". + The call of "f" is not removed in RELEASE builds, only the result verification. eg: + SMTG_VERIFY_IS (callMethod (), kResultOK) */ +#define SMTG_VERIFY_IS(f, r) \ + if ((f) != (r)) \ + FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f); + +/** Use VERIFY_NOT for calling methods "f" and expect the result to be anything else but "r". + The call of "f" is not removed in RELEASE builds, only the result verification. eg: + SMTG_VERIFY_NOT (callMethod (), kResultError) */ +#define SMTG_VERIFY_NOT(f, r) \ + if ((f) == (r)) \ + FDebugBreak ("%s(%d) : Assert failed: %s\n", __FILE__, __LINE__, #f); + +/** @name Shortcut macros for sending strings to the debugger for display. + First parameter is always the format string (printf like). +*/ + +///@{ +#define DBPRT0(a) FDebugPrint (a); +#define DBPRT1(a, b) FDebugPrint (a, b); +#define DBPRT2(a, b, c) FDebugPrint (a, b, c); +#define DBPRT3(a, b, c, d) FDebugPrint (a, b, c, d); +#define DBPRT4(a, b, c, d, e) FDebugPrint (a, b, c, d, e); +#define DBPRT5(a, b, c, d, e, f) FDebugPrint (a, b, c, d, e, f); +///@} + +/** @name Helper functions for the above defined macros. + + You shouldn't use them directly (if you do so, don't forget "#if DEVELOPMENT")! + It is recommended to use the macros instead. +*/ +///@{ +void FDebugPrint (const char* format, ...); +void FDebugBreak (const char* format, ...); +void FPrintLastError (const char* file, int line); +///@} + +/** @name Provide a custom assertion handler and debug print handler, eg + so that we can provide an assert with a custom dialog, or redirect + the debug output to a file or stream. +*/ +///@{ +typedef bool (*AssertionHandler) (const char* message); +extern AssertionHandler gAssertionHandler; +extern AssertionHandler gPreAssertionHook; +typedef void (*DebugPrintLogger) (const char* message); +extern DebugPrintLogger gDebugPrintLogger; +///@} + +/** Definition of memory allocation macros: + Use "NEW" to allocate storage for individual objects. + Use "NEWVEC" to allocate storage for an array of objects. */ +#if SMTG_OS_MACOS +void* operator new (size_t, int, const char*, int); +void* operator new[] (size_t, int, const char*, int); +void operator delete (void* p, int, const char* file, int line); +void operator delete[] (void* p, int, const char* file, int line); +#ifndef NEW +#define NEW new (1, __FILE__, __LINE__) +#define NEWVEC new (1, __FILE__, __LINE__) +#endif + +#define DEBUG_NEW DEBUG_NEW_LEAKS + +#elif SMTG_OS_WINDOWS && defined(_MSC_VER) +#ifndef NEW +void* operator new (size_t, int, const char*, int); +#define NEW new (1, __FILE__, __LINE__) +#define NEWVEC new (1, __FILE__, __LINE__) +#endif + +#else +#ifndef NEW +#define NEW new +#define NEWVEC new +#endif +#endif + +#else +/** if DEVELOPMENT is not set, these macros will do nothing. */ +#define SMTG_ASSERT(f) +#define SMTG_WARNING(s) +#define SMTG_PRINTSYSERROR +#define SMTG_DEBUGSTR(s) +#define SMTG_VERIFY(f) f; +#define SMTG_VERIFY_IS(f, r) f; +#define SMTG_VERIFY_NOT(f, r) f; + +#define DBPRT0(a) +#define DBPRT1(a, b) +#define DBPRT2(a, b, c) +#define DBPRT3(a, b, c, d) +#define DBPRT4(a, b, c, d, e) +#define DBPRT5(a, b, c, d, e, f) + +#ifndef NEW +#define NEW new +#define NEWVEC new + +#endif +#endif + +#if SMTG_CPPUNIT_TESTING +#define SMTG_IS_TEST true +#else +#define SMTG_IS_TEST false +#endif + +#if !SMTG_RENAME_ASSERT +#if SMTG_OS_WINDOWS +#undef ASSERT +#endif + +#define ASSERT SMTG_ASSERT +#define WARNING SMTG_WARNING +#define DEBUGSTR SMTG_DEBUGSTR +#define VERIFY SMTG_VERIFY +#define VERIFY_IS SMTG_VERIFY_IS +#define VERIFY_NOT SMTG_VERIFY_NOT +#define PRINTSYSERROR SMTG_PRINTSYSERROR +#endif diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.cpp new file mode 100644 index 0000000000..7e83d3f9a7 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.cpp @@ -0,0 +1,184 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fobject.cpp +// Created by : Steinberg, 2008 +// Description : Basic Object implementing FUnknown +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "base/source/fobject.h" +#include "base/thread/include/flock.h" + +#include + +namespace Steinberg { + +IUpdateHandler* FObject::gUpdateHandler = 0; + +//------------------------------------------------------------------------ +const FUID FObject::iid; + +//------------------------------------------------------------------------ +struct FObjectIIDInitializer +{ + // the object iid is always generated so that different components + // only can cast to their own objects + // this initializer must be after the definition of FObject::iid, otherwise + // the default constructor of FUID will clear the generated iid + FObjectIIDInitializer () + { + const_cast (FObject::iid).generate (); + } +} gFObjectIidInitializer; + +//------------------------------------------------------------------------ +uint32 PLUGIN_API FObject::addRef () +{ + return FUnknownPrivate::atomicAdd (refCount, 1); +} + +//------------------------------------------------------------------------ +uint32 PLUGIN_API FObject::release () +{ + if (FUnknownPrivate::atomicAdd (refCount, -1) == 0) + { + refCount = -1000; + delete this; + return 0; + } + return refCount; +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API FObject::queryInterface (const TUID _iid, void** obj) +{ + QUERY_INTERFACE (_iid, obj, FUnknown::iid, FUnknown) + QUERY_INTERFACE (_iid, obj, IDependent::iid, IDependent) + QUERY_INTERFACE (_iid, obj, FObject::iid, FObject) + *obj = 0; + return kNoInterface; +} + +//------------------------------------------------------------------------ +void FObject::addDependent (IDependent* dep) +{ + if (gUpdateHandler) + gUpdateHandler->addDependent (unknownCast (), dep); +} + +//------------------------------------------------------------------------ +void FObject::removeDependent (IDependent* dep) +{ + if (gUpdateHandler) + gUpdateHandler->removeDependent (unknownCast (), dep); +} + +//------------------------------------------------------------------------ +void FObject::changed (int32 msg) +{ + if (gUpdateHandler) + gUpdateHandler->triggerUpdates (unknownCast (), msg); + else + updateDone (msg); +} + +//------------------------------------------------------------------------ +void FObject::deferUpdate (int32 msg) +{ + if (gUpdateHandler) + gUpdateHandler->deferUpdates (unknownCast (), msg); + else + updateDone (msg); +} + +//------------------------------------------------------------------------ +/** Automatic creation and destruction of singleton instances. */ +//------------------------------------------------------------------------ +namespace Singleton +{ + typedef std::vector ObjectVector; + ObjectVector* singletonInstances = 0; + bool singletonsTerminated = false; + Steinberg::Base::Thread::FLock* singletonsLock; + + bool isTerminated () {return singletonsTerminated;} + + void lockRegister () + { + if (!singletonsLock) // assume first call not from multiple threads + singletonsLock = NEW Steinberg::Base::Thread::FLock; + singletonsLock->lock (); + } + void unlockRegister () + { + singletonsLock->unlock (); + } + + void registerInstance (FObject** o) + { + SMTG_ASSERT (singletonsTerminated == false) + if (singletonsTerminated == false) + { + if (singletonInstances == 0) + singletonInstances = NEW std::vector; + singletonInstances->push_back (o); + } + } + + struct Deleter + { + ~Deleter () + { + singletonsTerminated = true; + if (singletonInstances) + { + for (ObjectVector::iterator it = singletonInstances->begin (), + end = singletonInstances->end (); + it != end; ++it) + { + FObject** obj = (*it); + (*obj)->release (); + *obj = 0; + obj = 0; + } + + delete singletonInstances; + singletonInstances = 0; + } + delete singletonsLock; + singletonsLock = 0; + } + } deleter; +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.h new file mode 100644 index 0000000000..67b0af12fe --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fobject.h @@ -0,0 +1,518 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fobject.h +// Created by : Steinberg, 2008 +// Description : Basic Object implementing FUnknown +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +//------------------------------------------------------------------------ +/** @file base/source/fobject.h + Basic Object implementing FUnknown. */ +//------------------------------------------------------------------------ +#pragma once + +#include "pluginterfaces/base/funknown.h" +#include "pluginterfaces/base/iupdatehandler.h" +//#include "base/source/basefwd.h" +#include "base/source/fdebug.h" // NEW + + +namespace Steinberg { + +//---------------------------------- + +typedef FIDString FClassID; + +//------------------------------------------------------------------------ +// Basic FObject - implements FUnknown + IDependent +//------------------------------------------------------------------------ +/** Implements FUnknown and IDependent. + +FObject is a polymorphic class that implements IDependent (of SKI module) +and therefore derived from FUnknown, which is the most abstract base class of all. + +All COM-like virtual methods of FUnknown such as queryInterface(), addRef(), release() +are implemented here. On top of that, dependency-related methods are implemented too. + +Pointer casting is done via the template methods FCast, either FObject to FObject or +FUnknown to FObject. + +FObject supports a new singleton concept, therefore these objects are deleted automatically upon program termination. + +- Runtime type information: An object can be queried at runtime, of what class +it is. To do this correctly, every class must override some methods. This +is simplified by using the OBJ_METHODS macros + + +@see + - FUnknown + - IDependent + - IUpdateHandler +*/ +//------------------------------------------------------------------------ +class FObject : public IDependent +{ +public: + //------------------------------------------------------------------------ + FObject () : refCount (1) {} ///< default constructor... + FObject (const FObject&) : refCount (1) {} ///< overloaded constructor... + virtual ~FObject () {} ///< destructor... + FObject& operator = (const FObject&) { return *this; } ///< overloads operator "=" as the reference assignment + + // OBJECT_METHODS + static inline FClassID getFClassID () {return "FObject";} ///< return Class ID as an ASCII string (statically) + virtual FClassID isA () const {return FObject::getFClassID ();} ///< a local alternative to getFClassID () + virtual bool isA (FClassID s) const {return isTypeOf (s, false);} ///< evaluates if the passed ID is of the FObject type + virtual bool isTypeOf (FClassID s, bool /*askBaseClass*/ = true) const {return classIDsEqual (s, FObject::getFClassID ());} + ///< evaluates if the passed ID is of the FObject type + int32 getRefCount () {return refCount;} ///< returns the current interface reference count + FUnknown* unknownCast () {return this;} ///< get FUnknown interface from object + + // FUnknown + virtual tresult PLUGIN_API queryInterface (const TUID _iid, void** obj) SMTG_OVERRIDE; ///< please refer to FUnknown::queryInterface () + virtual uint32 PLUGIN_API addRef () SMTG_OVERRIDE; ///< please refer to FUnknown::addref () + virtual uint32 PLUGIN_API release () SMTG_OVERRIDE; ///< please refer to FUnknown::release () + + // IDependent + virtual void PLUGIN_API update (FUnknown* /*changedUnknown*/, int32 /*message*/) SMTG_OVERRIDE {} + ///< empty virtual method that should be overridden by derived classes for data updates upon changes + // IDependency + virtual void addDependent (IDependent* dep); ///< adds dependency to the object + virtual void removeDependent (IDependent* dep); ///< removes dependency from the object + virtual void changed (int32 msg = kChanged); ///< Inform all dependents, that the object has changed. + virtual void deferUpdate (int32 msg = kChanged); ///< Similar to triggerUpdates, except only delivered in idle (usefull in collecting updates). + virtual void updateDone (int32 /* msg */) {} ///< empty virtual method that should be overridden by derived classes + virtual bool isEqualInstance (FUnknown* d) {return this == d;} + + static void setUpdateHandler (IUpdateHandler* handler) {gUpdateHandler = handler;} ///< set method for the local attribute + static IUpdateHandler* getUpdateHandler () {return gUpdateHandler;} ///< get method for the local attribute + + // static helper functions + static inline bool classIDsEqual (FClassID ci1, FClassID ci2); ///< compares (evaluates) 2 class IDs + static inline FObject* unknownToObject (FUnknown* unknown); ///< pointer conversion from FUnknown to FObject + + /** Special UID that is used to cast an FUnknown pointer to a FObject */ + static const FUID iid; + +//------------------------------------------------------------------------ +protected: + int32 refCount; ///< COM-model local reference count + + static IUpdateHandler* gUpdateHandler; +}; + + +//------------------------------------------------------------------------ +// conversion from FUnknown to FObject +//------------------------------------------------------------------------ +inline FObject* FObject::unknownToObject (FUnknown* unknown) +{ + FObject* object = 0; + if (unknown) + { + unknown->queryInterface (FObject::iid, (void**)&object); + if (object) + object->release (); // queryInterface has added ref + } + return object; +} + +//------------------------------------------------------------------------ +inline bool FObject::classIDsEqual (FClassID ci1, FClassID ci2) +{ + return (ci1 && ci2) ? (strcmp (ci1, ci2) == 0) : false; +} + +//----------------------------------------------------------------------- +/** FCast overload 1 - FObject to FObject */ +//----------------------------------------------------------------------- +template +inline C* FCast (const FObject* object) +{ + if (object && object->isTypeOf (C::getFClassID (), true)) + return (C*) object; + return 0; +} + +//----------------------------------------------------------------------- +/** FCast overload 2 - FUnknown to FObject */ +//----------------------------------------------------------------------- +template +inline C* FCast (FUnknown* unknown) +{ + FObject* object = FObject::unknownToObject (unknown); + return FCast (object); +} + +//----------------------------------------------------------------------- +/** FUCast - casting from FUnknown to Interface */ +//----------------------------------------------------------------------- +template +inline C* FUCast (FObject* object) +{ + return FUnknownPtr (object ? object->unknownCast () : 0); +} + +template +inline C* FUCast (FUnknown* object) +{ + return FUnknownPtr (object); +} + +//------------------------------------------------------------------------ +/** @name Convenience methods that call release or delete respectively + on a pointer if it is non-zero, and then set the pointer to zero. + Note: you should prefer using IPtr or OPtr instead of these methods + whenever possible. + Examples: + @code + ~Foo () + { + // instead of ... + if (somePointer) + { + somePointer->release (); + somePointer = 0; + } + // ... just being lazy I write + SafeRelease (somePointer) + } + @endcode +*/ +///@{ +//----------------------------------------------------------------------- +template +inline void SafeRelease (I *& ptr) +{ + if (ptr) + { + ptr->release (); + ptr = 0; + } +} + +//----------------------------------------------------------------------- +template +inline void SafeRelease (IPtr & ptr) +{ + ptr = 0; +} + + +//----------------------------------------------------------------------- +template +inline void SafeDelete (T *& ptr) +{ + if (ptr) + { + delete ptr; + ptr = 0; + } +} +///@} + +//----------------------------------------------------------------------- +template +inline void AssignShared (T*& dest, T* newPtr) +{ + if (dest == newPtr) + return; + + if (dest) + dest->release (); + dest = newPtr; + if (dest) + dest->addRef (); +} + +//----------------------------------------------------------------------- +template +inline void AssignSharedDependent (IDependent* _this, T*& dest, T* newPtr) +{ + if (dest == newPtr) + return; + + if (dest) + dest->removeDependent (_this); + AssignShared (dest, newPtr); + if (dest) + dest->addDependent (_this); +} + +//----------------------------------------------------------------------- +template +inline void AssignSharedDependent (IDependent* _this, IPtr& dest, T* newPtr) +{ + if (dest == newPtr) + return; + + if (dest) + dest->removeDependent (_this); + dest = newPtr; + if (dest) + dest->addDependent (_this); +} + +//----------------------------------------------------------------------- +template +inline void SafeReleaseDependent (IDependent* _this, T*& dest) +{ + if (dest) + dest->removeDependent (_this); + SafeRelease (dest); +} + +//----------------------------------------------------------------------- +template +inline void SafeReleaseDependent (IDependent* _this, IPtr& dest) +{ + if (dest) + dest->removeDependent (_this); + SafeRelease (dest); +} + + +//------------------------------------------------------------------------ +/** Automatic creation and destruction of singleton instances. */ +namespace Singleton { + /** registers an instance (type FObject) */ + void registerInstance (FObject** o); + + /** Returns true when singleton instances were already released. */ + bool isTerminated (); + + /** lock and unlock the singleton registration for multi-threading safety */ + void lockRegister (); + void unlockRegister (); +} + +//------------------------------------------------------------------------ +} // namespace Steinberg + +//----------------------------------------------------------------------- +#define SINGLETON(ClassName) \ + static ClassName* instance (bool create = true) \ + { \ + static Steinberg::FObject* inst = nullptr; \ + if (inst == nullptr && create && Steinberg::Singleton::isTerminated () == false) \ + { \ + Steinberg::Singleton::lockRegister (); \ + if (inst == nullptr) \ + { \ + inst = NEW ClassName; \ + Steinberg::Singleton::registerInstance (&inst); \ + } \ + Steinberg::Singleton::unlockRegister (); \ + } \ + return (ClassName*)inst; \ + } + +//----------------------------------------------------------------------- +#define OBJ_METHODS(className, baseClass) \ + static inline Steinberg::FClassID getFClassID () {return (#className);} \ + virtual Steinberg::FClassID isA () const SMTG_OVERRIDE {return className::getFClassID ();} \ + virtual bool isA (Steinberg::FClassID s) const SMTG_OVERRIDE {return isTypeOf (s, false);} \ + virtual bool isTypeOf (Steinberg::FClassID s, bool askBaseClass = true) const SMTG_OVERRIDE \ + { return (classIDsEqual (s, #className) ? true : (askBaseClass ? baseClass::isTypeOf (s, true) : false)); } + +//------------------------------------------------------------------------ +/** Delegate refcount functions to BaseClass. + BaseClase must implement ref counting. +*/ +//------------------------------------------------------------------------ +#define REFCOUNT_METHODS(BaseClass) \ +virtual Steinberg::uint32 PLUGIN_API addRef ()SMTG_OVERRIDE{ return BaseClass::addRef (); } \ +virtual Steinberg::uint32 PLUGIN_API release ()SMTG_OVERRIDE{ return BaseClass::release (); } + +//------------------------------------------------------------------------ +/** @name Macros to implement FUnknown::queryInterface (). + + Examples: + @code + class Foo : public FObject, public IFoo2, public IFoo3 + { + ... + DEFINE_INTERFACES + DEF_INTERFACE (IFoo2) + DEF_INTERFACE (IFoo3) + END_DEFINE_INTERFACES (FObject) + REFCOUNT_METHODS(FObject) + // Implement IFoo2 interface ... + // Implement IFoo3 interface ... + ... + }; + @endcode +*/ +///@{ +//------------------------------------------------------------------------ +/** Start defining interfaces. */ +//------------------------------------------------------------------------ +#define DEFINE_INTERFACES \ +Steinberg::tresult PLUGIN_API queryInterface (const Steinberg::TUID iid, void** obj) SMTG_OVERRIDE \ +{ + +//------------------------------------------------------------------------ +/** Add a interfaces. */ +//------------------------------------------------------------------------ +#define DEF_INTERFACE(InterfaceName) \ + QUERY_INTERFACE (iid, obj, InterfaceName::iid, InterfaceName) + +//------------------------------------------------------------------------ +/** End defining interfaces. */ +//------------------------------------------------------------------------ +#define END_DEFINE_INTERFACES(BaseClass) \ + return BaseClass::queryInterface (iid, obj); \ +} +///@} + +//------------------------------------------------------------------------ +/** @name Convenient macros to implement Steinberg::FUnknown::queryInterface (). + Examples: + @code + class Foo : public FObject, public IFoo2, public IFoo3 + { + ... + DEF_INTERFACES_2(IFoo2,IFoo3,FObject) + REFCOUNT_METHODS(FObject) + ... + }; + @endcode +*/ +///@{ +//------------------------------------------------------------------------ +#define DEF_INTERFACES_1(InterfaceName,BaseClass) \ +DEFINE_INTERFACES \ +DEF_INTERFACE (InterfaceName) \ +END_DEFINE_INTERFACES (BaseClass) + +//------------------------------------------------------------------------ +#define DEF_INTERFACES_2(InterfaceName1,InterfaceName2,BaseClass) \ +DEFINE_INTERFACES \ +DEF_INTERFACE (InterfaceName1) \ +DEF_INTERFACE (InterfaceName2) \ +END_DEFINE_INTERFACES (BaseClass) + +//------------------------------------------------------------------------ +#define DEF_INTERFACES_3(InterfaceName1,InterfaceName2,InterfaceName3,BaseClass) \ +DEFINE_INTERFACES \ +DEF_INTERFACE (InterfaceName1) \ +DEF_INTERFACE (InterfaceName2) \ +DEF_INTERFACE (InterfaceName3) \ +END_DEFINE_INTERFACES (BaseClass) + +//------------------------------------------------------------------------ +#define DEF_INTERFACES_4(InterfaceName1,InterfaceName2,InterfaceName3,InterfaceName4,BaseClass) \ + DEFINE_INTERFACES \ + DEF_INTERFACE (InterfaceName1) \ + DEF_INTERFACE (InterfaceName2) \ + DEF_INTERFACE (InterfaceName3) \ + DEF_INTERFACE (InterfaceName4) \ + END_DEFINE_INTERFACES (BaseClass) +///@} + +//------------------------------------------------------------------------ +/** @name Convenient macros to implement Steinberg::FUnknown methods. + Examples: + @code + class Foo : public FObject, public IFoo2, public IFoo3 + { + ... + FUNKNOWN_METHODS2(IFoo2,IFoo3,FObject) + ... + }; + @endcode +*/ +///@{ +#define FUNKNOWN_METHODS(InterfaceName,BaseClass) \ +DEF_INTERFACES_1(InterfaceName,BaseClass) \ +REFCOUNT_METHODS(BaseClass) + +#define FUNKNOWN_METHODS2(InterfaceName1,InterfaceName2,BaseClass) \ +DEF_INTERFACES_2(InterfaceName1,InterfaceName2,BaseClass) \ +REFCOUNT_METHODS(BaseClass) + +#define FUNKNOWN_METHODS3(InterfaceName1,InterfaceName2,InterfaceName3,BaseClass) \ +DEF_INTERFACES_3(InterfaceName1,InterfaceName2,InterfaceName3,BaseClass) \ +REFCOUNT_METHODS(BaseClass) + +#define FUNKNOWN_METHODS4(InterfaceName1,InterfaceName2,InterfaceName3,InterfaceName4,BaseClass) \ +DEF_INTERFACES_4(InterfaceName1,InterfaceName2,InterfaceName3,InterfaceName4,BaseClass) \ +REFCOUNT_METHODS(BaseClass) +///@} + + +//------------------------------------------------------------------------ +//------------------------------------------------------------------------ +#if COM_COMPATIBLE +//------------------------------------------------------------------------ +/** @name Macros to implement IUnknown interfaces with FObject. + Examples: + @code + class MyEnumFormat : public FObject, IEnumFORMATETC + { + ... + COM_UNKNOWN_METHODS (IEnumFORMATETC, IUnknown) + ... + }; + @endcode +*/ +///@{ +//------------------------------------------------------------------------ +#define IUNKNOWN_REFCOUNT_METHODS(BaseClass) \ +STDMETHOD_ (ULONG, AddRef) (void) {return BaseClass::addRef ();} \ +STDMETHOD_ (ULONG, Release) (void) {return BaseClass::release ();} + +//------------------------------------------------------------------------ +#define COM_QUERY_INTERFACE(iid, obj, InterfaceName) \ +if (riid == __uuidof(InterfaceName)) \ +{ \ + addRef (); \ + *obj = (InterfaceName*)this; \ + return kResultOk; \ +} + +//------------------------------------------------------------------------ +#define COM_OBJECT_QUERY_INTERFACE(InterfaceName,BaseClass) \ +STDMETHOD (QueryInterface) (REFIID riid, void** object) \ +{ \ + COM_QUERY_INTERFACE (riid, object, InterfaceName) \ + return BaseClass::queryInterface ((FIDString)&riid, object); \ +} + +//------------------------------------------------------------------------ +#define COM_UNKNOWN_METHODS(InterfaceName,BaseClass) \ +COM_OBJECT_QUERY_INTERFACE(InterfaceName,BaseClass) \ +IUNKNOWN_REFCOUNT_METHODS(BaseClass) +///@} + +#endif // COM_COMPATIBLE diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.cpp new file mode 100644 index 0000000000..bb87dc66b4 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.cpp @@ -0,0 +1,726 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fstreamer.cpp +// Created by : Steinberg, 15.12.2005 +// Description : Extract of typed stream i/o methods from FStream +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "fstreamer.h" + +#include "base/source/fstring.h" +#include "base/source/fbuffer.h" +#include "pluginterfaces/base/ibstream.h" + +#ifndef UNICODE +#include "pluginterfaces/base/futils.h" +#endif + +namespace Steinberg { + +//------------------------------------------------------------------------ +// IBStreamer +//------------------------------------------------------------------------ +IBStreamer::IBStreamer (IBStream* stream, int16 _byteOrder) +: FStreamer (_byteOrder) +, stream (stream) +{} + +//------------------------------------------------------------------------ +TSize IBStreamer::readRaw (void* buffer, TSize size) +{ + int32 numBytesRead = 0; + stream->read (buffer, (int32)size, &numBytesRead); + return numBytesRead; +} + +//------------------------------------------------------------------------ +TSize IBStreamer::writeRaw (const void* buffer, TSize size) +{ + int32 numBytesWritten = 0; + stream->write ((void*)buffer, (int32)size, &numBytesWritten); + return numBytesWritten; +} + +//------------------------------------------------------------------------ +int64 IBStreamer::seek (int64 pos, FSeekMode mode) +{ + int64 result = -1; + stream->seek (pos, mode, &result); + return result; +} + +//------------------------------------------------------------------------ +int64 IBStreamer::tell () +{ + int64 pos = 0; + stream->tell (&pos); + return pos; +} + +//------------------------------------------------------------------------ +// FStreamSizeHolder Implementation +//------------------------------------------------------------------------ +FStreamSizeHolder::FStreamSizeHolder (FStreamer &s) +: stream (s), sizePos (-1) +{} + +//------------------------------------------------------------------------ +void FStreamSizeHolder::beginWrite () +{ + sizePos = stream.tell (); + stream.writeInt32 (0L); +} + +//------------------------------------------------------------------------ +int32 FStreamSizeHolder::endWrite () +{ + if (sizePos < 0) + return 0; + + int64 currentPos = stream.tell (); + + stream.seek (sizePos, kSeekSet); + int32 size = int32 (currentPos - sizePos - sizeof (int32)); + stream.writeInt32 (size); + + stream.seek (currentPos, kSeekSet); + return size; +} + +//------------------------------------------------------------------------ +int32 FStreamSizeHolder::beginRead () +{ + sizePos = stream.tell (); + int32 size = 0; + stream.readInt32 (size); + sizePos += size + sizeof (int32); + return size; +} + +//------------------------------------------------------------------------ +void FStreamSizeHolder::endRead () +{ + if (sizePos >= 0) + stream.seek (sizePos, kSeekSet); +} + +//------------------------------------------------------------------------ +// FStreamer +//------------------------------------------------------------------------ +FStreamer::FStreamer (int16 _byteOrder) +: byteOrder (_byteOrder) +{} + +// int8 / char ----------------------------------------------------------- +//------------------------------------------------------------------------ +bool FStreamer::writeChar8 (char8 c) +{ + return writeRaw ((void*)&c, sizeof (char8)) == sizeof (char8); +} + +//------------------------------------------------------------------------ +bool FStreamer::readChar8 (char8& c) +{ + return readRaw ((void*)&c, sizeof (char8)) == sizeof (char8); +} + +//------------------------------------------------------------------------ +bool FStreamer::writeUChar8 (unsigned char c) +{ + return writeRaw ((void*)&c, sizeof (unsigned char)) == sizeof (unsigned char); +} + +//------------------------------------------------------------------------ +bool FStreamer::readUChar8 (unsigned char& c) +{ + return readRaw ((void*)&c, sizeof (unsigned char)) == sizeof (unsigned char); +} + +//------------------------------------------------------------------------ +bool FStreamer::writeChar16 (char16 c) +{ + if (BYTEORDER != byteOrder) + SWAP_16 (c); + return writeRaw ((void*)&c, sizeof (char16)) == sizeof (char16); +} + +//------------------------------------------------------------------------ +bool FStreamer::readChar16 (char16& c) +{ + if (readRaw ((void*)&c, sizeof (char16)) == sizeof (char16)) + { + if (BYTEORDER != byteOrder) + SWAP_16 (c); + return true; + } + c = 0; + return false; +} + +// int16 ----------------------------------------------------------------- +//------------------------------------------------------------------------ +bool FStreamer::writeInt16 (int16 i) +{ + if (BYTEORDER != byteOrder) + SWAP_16 (i); + return writeRaw ((void*)&i, sizeof (int16)) == sizeof (int16); +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt16 (int16& i) +{ + if (readRaw ((void*)&i, sizeof (int16)) == sizeof (int16)) + { + if (BYTEORDER != byteOrder) + SWAP_16 (i); + return true; + } + i = 0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt16Array (const int16* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeInt16 (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt16Array (int16* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readInt16 (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt16u (uint16 i) +{ + if (BYTEORDER != byteOrder) + SWAP_16 (i); + return writeRaw ((void*)&i, sizeof (uint16)) == sizeof (uint16); +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt16u (uint16& i) +{ + if (readRaw ((void*)&i, sizeof (uint16)) == sizeof (uint16)) + { + if (BYTEORDER != byteOrder) + SWAP_16 (i); + return true; + } + i = 0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt16uArray (const uint16* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeInt16u (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt16uArray (uint16* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readInt16u (array[i])) + return false; + } + return true; +} + +// int32 ----------------------------------------------------------------- +//------------------------------------------------------------------------ +bool FStreamer::writeInt32 (int32 i) +{ + if (BYTEORDER != byteOrder) + SWAP_32 (i); + return writeRaw ((void*)&i, sizeof (int32)) == sizeof (int32); +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt32 (int32& i) +{ + if (readRaw ((void*)&i, sizeof (int32)) == sizeof (int32)) + { + if (BYTEORDER != byteOrder) + SWAP_32 (i); + return true; + } + i = 0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt32Array (const int32* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeInt32 (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt32Array (int32* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readInt32 (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt32u (uint32 i) +{ + if (BYTEORDER != byteOrder) + SWAP_32 (i); + return writeRaw ((void*)&i, sizeof (uint32)) == sizeof (uint32); +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt32u (uint32& i) +{ + if (readRaw ((void*)&i, sizeof (uint32)) == sizeof (uint32)) + { + if (BYTEORDER != byteOrder) + SWAP_32 (i); + return true; + } + i = 0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt32uArray (const uint32* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeInt32u (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt32uArray (uint32* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readInt32u (array[i])) + return false; + } + return true; +} + +// int64 ----------------------------------------------------------------- +//------------------------------------------------------------------------ +bool FStreamer::writeInt64 (int64 i) +{ + if (BYTEORDER != byteOrder) + SWAP_64 (i); + return writeRaw ((void*)&i, sizeof (int64)) == sizeof (int64); +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt64 (int64& i) +{ + if (readRaw ((void*)&i, sizeof (int64)) == sizeof (int64)) + { + if (BYTEORDER != byteOrder) + SWAP_64 (i); + return true; + } + i = 0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt64Array (const int64* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeInt64 (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt64Array (int64* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readInt64 (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt64u (uint64 i) +{ + if (BYTEORDER != byteOrder) + SWAP_64 (i); + return writeRaw ((void*)&i, sizeof (uint64)) == sizeof (uint64); +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt64u (uint64& i) +{ + if (readRaw ((void*)&i, sizeof (uint64)) == sizeof (uint64)) + { + if (BYTEORDER != byteOrder) + SWAP_64 (i); + return true; + } + i = 0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeInt64uArray (const uint64* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeInt64u (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readInt64uArray (uint64* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readInt64u (array[i])) + return false; + } + return true; +} + +// float / double -------------------------------------------------------- +//------------------------------------------------------------------------ +bool FStreamer::writeFloat (float f) +{ + if (BYTEORDER != byteOrder) + SWAP_32 (f); + return writeRaw ((void*)&f, sizeof (float)) == sizeof (float); +} + +//------------------------------------------------------------------------ +bool FStreamer::readFloat (float& f) +{ + if (readRaw ((void*)&f, sizeof (float)) == sizeof (float)) + { + if (BYTEORDER != byteOrder) + SWAP_32 (f); + return true; + } + f = 0.f; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeFloatArray (const float* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeFloat (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readFloatArray (float* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readFloat (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeDouble (double d) +{ + if (BYTEORDER != byteOrder) + SWAP_64 (d); + return writeRaw ((void*)&d, sizeof (double)) == sizeof (double); +} + +//------------------------------------------------------------------------ +bool FStreamer::readDouble (double& d) +{ + if (readRaw ((void*)&d, sizeof (double)) == sizeof (double)) + { + if (BYTEORDER != byteOrder) + SWAP_64 (d); + return true; + } + d = 0.0; + return false; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeDoubleArray (const double* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!writeDouble (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readDoubleArray (double* array, int32 count) +{ + for (int32 i = 0; i < count; i++) + { + if (!readDouble (array[i])) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::readBool (bool& b) +{ + int16 v = 0; + bool res = readInt16 (v); + b = (v != 0); + return res; +} + +//------------------------------------------------------------------------ +bool FStreamer::writeBool (bool b) +{ + return writeInt16 ((int16)b); +} + +//------------------------------------------------------------------------ +TSize FStreamer::writeString8 (const char8* ptr, bool terminate) +{ + TSize size = strlen (ptr); + if (terminate) // write \0 + size++; + + return writeRaw ((void*)ptr, size); +} + +//------------------------------------------------------------------------ +TSize FStreamer::readString8 (char8* ptr, TSize size) +{ + TSize i = 0; + char8 c = 0; + while (i < size) + { + if (readRaw ((void*)&c, sizeof (char)) != sizeof (char)) + break; + ptr[i] = c; + i++; + if (c == '\n' || c == '\0') + break; + } + if (c == '\n' && ptr[i - 2] == '\r') + ptr[i - 2] = 0; + if (i < size) + ptr[i] = 0; + else + ptr[size - 1] = 0; + + return strlen (ptr); +} + +//------------------------------------------------------------------------ +bool FStreamer::writeStringUtf8 (const tchar* ptr) +{ + bool isUtf8 = false; + + String str (ptr); + if (str.isAsciiString () == false) + { + str.toMultiByte (kCP_Utf8); + isUtf8 = true; + } + else + { + str.toMultiByte (); + } + + if (isUtf8) + if (writeRaw (kBomUtf8, kBomUtf8Length) != kBomUtf8Length) + return false; + + TSize size = str.length () + 1; + if (writeRaw (str.text8 (), size) != size) + return false; + + return true; +} + +//------------------------------------------------------------------------ +int32 FStreamer::readStringUtf8 (tchar* ptr, int32 nChars) +{ + char8 c = 0; + + ptr [0] = 0; + + Buffer tmp; + tmp.setDelta (1024); + + while (true) + { + if (readRaw ((void*)&c, sizeof (char)) != sizeof (char)) + break; + tmp.put (c); + if (c == '\0') + break; + } + + char8* source = tmp.int8Ptr (); + uint32 codePage = kCP_Default; // for legacy take default page if no utf8 bom is present... + if (tmp.getFillSize () > 2) + { + if (memcmp (source, kBomUtf8, kBomUtf8Length) == 0) + { + codePage = kCP_Utf8; + source += 3; + } + } + + if (tmp.getFillSize () > 1) + { +#ifdef UNICODE + ConstString::multiByteToWideString (ptr, source, nChars, codePage); +#else + if (codePage == kCP_Utf8) + { + Buffer wideBuffer (tmp.getFillSize () * 3); + ConstString::multiByteToWideString (wideBuffer.wcharPtr (), source, wideBuffer.getSize () / 2, kCP_Utf8); + ConstString::wideStringToMultiByte (ptr, wideBuffer.wcharPtr (), nChars); + } + else + { + memcpy (ptr, source, Min (nChars, tmp.getFillSize ())); + } +#endif + } + + ptr[nChars - 1] = 0; + return ConstString (ptr).length (); +} + +//------------------------------------------------------------------------ +bool FStreamer::writeStr8 (const char8* s) +{ + int32 length = (s) ? (int32) strlen (s) + 1 : 0; + if (!writeInt32 (length)) + return false; + + if (length > 0) + return writeRaw (s, sizeof (char8) * length) == static_cast(sizeof (char8) * length); + + return true; +} + +//------------------------------------------------------------------------ +int32 FStreamer::getStr8Size (const char8* s) +{ + return sizeof (int32) + (int32)strlen (s) + 1; +} + +//------------------------------------------------------------------------ +char8* FStreamer::readStr8 () +{ + int32 length; + if (!readInt32 (length)) + return 0; + + // check corruption + if (length > 262144) + return 0; + + char8* s = (length > 0) ? NEWVEC char8[length] : 0; + if (s) + readRaw (s, length * sizeof (char8)); + return s; +} + +//------------------------------------------------------------------------ +bool FStreamer::skip (uint32 bytes) +{ + int8 tmp; + while (bytes-- > 0) + { + if (readInt8 (tmp) == false) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +bool FStreamer::pad (uint32 bytes) +{ + while (bytes-- > 0) + { + if (writeInt8 (0) == false) + return false; + } + return true; +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.h new file mode 100644 index 0000000000..1c4d1033b4 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstreamer.h @@ -0,0 +1,242 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fstreamer.h +// Created by : Steinberg, 12/2005 +// Description : Extract of typed stream i/o methods from FStream +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/funknown.h" + +namespace Steinberg { + +//------------------------------------------------------------------------ +enum FSeekMode +{ + kSeekSet, + kSeekCurrent, + kSeekEnd +}; + +//------------------------------------------------------------------------ +// FStreamer +//------------------------------------------------------------------------ +/** Byteorder-aware base class for typed stream i/o. */ +//------------------------------------------------------------------------ +class FStreamer +{ +public: +//------------------------------------------------------------------------ + FStreamer (int16 byteOrder = BYTEORDER); + virtual ~FStreamer () {} + + /** @name Implementing class must override. */ + ///@{ + virtual TSize readRaw (void*, TSize) = 0; ///< Read one buffer of size. + virtual TSize writeRaw (const void*, TSize) = 0; ///< Write one buffer of size. + virtual int64 seek (int64, FSeekMode) = 0; ///< Set file position for stream. + virtual int64 tell () = 0; ///< Return current file position. + ///@} + + /** @name Streams are byteOrder aware. */ + ///@{ + inline void setByteOrder (int32 e) { byteOrder = (int16)e; } + inline int32 getByteOrder () { return byteOrder; } + ///@} + + /** @name read and write int8 and char. */ + ///@{ + bool writeChar8 (char8); + bool readChar8 (char8&); + bool writeUChar8 (unsigned char); + bool readUChar8 (unsigned char&); + bool writeChar16 (char16 c); + bool readChar16 (char16& c); + + bool writeInt8 (int8 c){return writeChar8 (c);} + bool readInt8 (int8& c){return readChar8 (c);} + bool writeInt8u (uint8 c){return writeUChar8 (c);} + bool readInt8u (uint8& c){return readUChar8 (c);} + ///@} + + /** @name read and write int16. */ + ///@{ + bool writeInt16 (int16); + bool readInt16 (int16&); + bool writeInt16Array (const int16* array, int32 count); + bool readInt16Array (int16* array, int32 count); + bool writeInt16u (uint16); + bool readInt16u (uint16&); + bool writeInt16uArray (const uint16* array, int32 count); + bool readInt16uArray (uint16* array, int32 count); + ///@} + + /** @name read and write int32. */ + ///@{ + bool writeInt32 (int32); + bool readInt32 (int32&); + bool writeInt32Array (const int32* array, int32 count); + bool readInt32Array (int32* array, int32 count); + bool writeInt32u (uint32); + bool readInt32u (uint32&); + bool writeInt32uArray (const uint32* array, int32 count); + bool readInt32uArray (uint32* array, int32 count); + ///@} + + /** @name read and write int64. */ + ///@{ + bool writeInt64 (int64); + bool readInt64 (int64&); + bool writeInt64Array (const int64* array, int32 count); + bool readInt64Array (int64* array, int32 count); + bool writeInt64u (uint64); + bool readInt64u (uint64&); + bool writeInt64uArray (const uint64* array, int32 count); + bool readInt64uArray (uint64* array, int32 count); + ///@} + + /** @name read and write float and float array. */ + ///@{ + bool writeFloat (float); + bool readFloat (float&); + bool writeFloatArray (const float* array, int32 count); + bool readFloatArray (float* array, int32 count); + ///@} + + /** @name read and write double and double array. */ + ///@{ + bool writeDouble (double); + bool readDouble (double&); + bool writeDoubleArray (const double* array, int32 count); + bool readDoubleArray (double* array, int32 count); + ///@} + + /** @name read and write Boolean. */ + ///@{ + bool writeBool (bool); ///< Write one boolean + bool readBool (bool&); ///< Read one bool. + ///@} + + /** @name read and write Strings. */ + ///@{ + TSize writeString8 (const char8* ptr, bool terminate = false); ///< a direct output function writing only one string (ascii 8bit) + TSize readString8 (char8* ptr, TSize size); ///< a direct input function reading only one string (ascii) (ended by a \n or \0 or eof) + + bool writeStr8 (const char8* ptr); ///< write a string length (strlen) and string itself + char8* readStr8 (); ///< read a string length and string text (The return string must be deleted when use is finished) + + static int32 getStr8Size (const char8* ptr); ///< returns the size of a saved string + + bool writeStringUtf8 (const tchar* ptr); ///< always terminated, converts to utf8 if non ascii characters are in string + int32 readStringUtf8 (tchar* ptr, int32 maxSize); ///< read a UTF8 string + ///@} + + bool skip (uint32 bytes); + bool pad (uint32 bytes); + + +//------------------------------------------------------------------------ +protected: + int16 byteOrder; +}; + + +//------------------------------------------------------------------------ +/** FStreamSizeHolder Declaration + remembers size of stream chunk for backward compatibility. + + Example: + @code + externalize (a) + { + FStreamSizeHolder sizeHolder; + sizeHolder.beginWrite (); // sets start mark, writes dummy size + a << .... + sizeHolder.endWrite (); // jumps to start mark, updates size, jumps back here + } + + internalize (a) + { + FStreamSizeHolder sizeHolder; + sizeHolder.beginRead (); // reads size, mark + a >> .... + sizeHolder.endRead (); // jumps forward if new version has larger size + } + @endcode +*/ +//------------------------------------------------------------------------ +class FStreamSizeHolder +{ +public: + FStreamSizeHolder (FStreamer &s); + + void beginWrite (); ///< remembers position and writes 0 + int32 endWrite (); ///< writes and returns size (since the start marker) + int32 beginRead (); ///< returns size + void endRead (); ///< jump to end of chunk + +protected: + FStreamer &stream; + int64 sizePos; +}; + +class IBStream; + +//------------------------------------------------------------------------ +// IBStreamer +//------------------------------------------------------------------------ +/** Wrapper class for typed reading/writing from or to IBStream. + Can be used framework-independent in Plug-ins. */ +//------------------------------------------------------------------------ +class IBStreamer: public FStreamer +{ +public: +//------------------------------------------------------------------------ + /** Constructor for a given IBSTream and a byteOrder. */ + IBStreamer (IBStream* stream, int16 byteOrder = BYTEORDER); + + IBStream* getStream () { return stream; } ///< Returns the associated IBStream. + + // FStreamer overrides: + TSize readRaw (void*, TSize) SMTG_OVERRIDE; ///< Read one buffer of size. + TSize writeRaw (const void*, TSize) SMTG_OVERRIDE; ///< Write one buffer of size. + int64 seek (int64, FSeekMode) SMTG_OVERRIDE; ///< Set file position for stream. + int64 tell () SMTG_OVERRIDE; ///< Return current file position. +//------------------------------------------------------------------------ +protected: + IBStream* stream; +}; + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.cpp new file mode 100644 index 0000000000..bd3a360b6f --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.cpp @@ -0,0 +1,3996 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fstring.cpp +// Created by : Steinberg, 2008 +// Description : String class +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "base/source/fstring.h" +#include "base/source/fdebug.h" +#include "pluginterfaces/base/futils.h" +#include "pluginterfaces/base/fvariant.h" + +#include +#include +#include +#include +#include + +#if SMTG_OS_WINDOWS +#include +#pragma warning (disable : 4244) +#pragma warning (disable : 4267) +#pragma warning (disable : 4996) + +#if DEVELOPMENT +#include + +#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__) +#define realloc(p,s) _realloc_dbg(p,s, _NORMAL_BLOCK, __FILE__, __LINE__) +#define free(p) _free_dbg(p, _NORMAL_BLOCK) + +#endif + +#endif + +#ifndef kPrintfBufferSize +#define kPrintfBufferSize 4096 +#endif + +#if SMTG_OS_MACOS +#include +#include +#include +#include + +#if defined (__GNUC__) && (__GNUC__ >= 4) && !__LP64__ +// on 32 bit Mac OS X we can safely ignore the format warnings as sizeof(int) == sizeof(long) +#pragma GCC diagnostic ignored "-Wformat" +#endif + +#define SMTG_ENABLE_DEBUG_CFALLOCATOR 0 +#define SMTG_DEBUG_CFALLOCATOR (DEVELOPMENT && SMTG_ENABLE_DEBUG_CFALLOCATOR) + +#if SMTG_DEBUG_CFALLOCATOR +#include +#include +#endif + +namespace Steinberg { +#if SMTG_DEBUG_CFALLOCATOR +static CFAllocatorRef kCFAllocator = NULL; + +struct CFStringDebugAllocator : CFAllocatorContext +{ + CFStringDebugAllocator () + { + version = 0; + info = this; + retain = nullptr; + release = nullptr; + copyDescription = nullptr; + allocate = allocateCallBack; + reallocate = reallocateCallBack; + deallocate = deallocateCallBack; + preferredSize = preferredSizeCallBack; + + numAllocations = allocationSize = numDeallocations = 0; + cfAllocator = CFAllocatorCreate (kCFAllocatorUseContext, this); + + Dl_info info; + if (dladdr ((const void*)CFStringDebugAllocator::allocateCallBack, &info)) + { + moduleName = info.dli_fname; + } + kCFAllocator = cfAllocator; + } + + ~CFStringDebugAllocator () + { + kCFAllocator = kCFAllocatorDefault; + CFRelease (cfAllocator); + FDebugPrint ("CFStringDebugAllocator (%s):\n", moduleName.text8 ()); + FDebugPrint ("\tNumber of allocations : %u\n", numAllocations); + FDebugPrint ("\tNumber of deallocations: %u\n", numDeallocations); + FDebugPrint ("\tAllocated Bytes : %u\n", allocationSize); + } + + String moduleName; + CFAllocatorRef cfAllocator; + volatile int64_t numAllocations; + volatile int64_t numDeallocations; + volatile int64_t allocationSize; + + void* doAllocate (CFIndex allocSize, CFOptionFlags hint) + { + void* ptr = CFAllocatorAllocate (kCFAllocatorDefault, allocSize, hint); + OSAtomicIncrement64 (&numAllocations); + OSAtomicAdd64 (allocSize, &allocationSize); + return ptr; + } + void* doReallocate (void* ptr, CFIndex newsize, CFOptionFlags hint) + { + void* newPtr = CFAllocatorReallocate (kCFAllocatorDefault, ptr, newsize, hint); + return newPtr; + } + void doDeallocate (void* ptr) + { + CFAllocatorDeallocate (kCFAllocatorDefault, ptr); + OSAtomicIncrement64 (&numDeallocations); + } + CFIndex getPreferredSize (CFIndex size, CFOptionFlags hint) + { + return CFAllocatorGetPreferredSizeForSize (kCFAllocatorDefault, size, hint); + } + + static void* allocateCallBack (CFIndex allocSize, CFOptionFlags hint, void* info) + { + return static_cast (info)->doAllocate (allocSize, hint); + } + static void* reallocateCallBack (void* ptr, CFIndex newsize, CFOptionFlags hint, void* info) + { + return static_cast (info)->doReallocate (ptr, newsize, hint); + } + + static void deallocateCallBack (void* ptr, void* info) + { + static_cast (info)->doDeallocate (ptr); + } + static CFIndex preferredSizeCallBack (CFIndex size, CFOptionFlags hint, void* info) + { + return static_cast (info)->getPreferredSize (size, hint); + } +}; +static CFStringDebugAllocator gDebugAllocator; +#else + +static const CFAllocatorRef kCFAllocator = ::kCFAllocatorDefault; +#endif +} + +//----------------------------------------------------------------------------- +static void* toCFStringRef (const Steinberg::char8* source, Steinberg::uint32 encoding) +{ + if (encoding == 0xFFFF) + encoding = kCFStringEncodingASCII; + if (source) + return (void*)CFStringCreateWithCString (Steinberg::kCFAllocator, source, encoding); + else + return (void*)CFStringCreateWithCString (Steinberg::kCFAllocator, "", encoding); +} + +//----------------------------------------------------------------------------- +static bool fromCFStringRef (Steinberg::char8* dest, Steinberg::int32 destSize, const void* cfStr, Steinberg::uint32 encoding) +{ + CFIndex usedBytes; + CFRange range = {0, CFStringGetLength ((CFStringRef)cfStr)}; + bool result = CFStringGetBytes ((CFStringRef)cfStr, range, encoding, '?', false, (UInt8*)dest, destSize, &usedBytes); + dest[usedBytes] = 0; + return result; +} +#endif // SMTG_OS_MACOS + +#if SMTG_OS_WINDOWS +#define stricmp16 wcsicmp +#define strnicmp16 wcsnicmp +#define strrchr16 wcsrchr +#define sprintf16 swprintf +#define snprintf16 snwprintf +#define vsnprintf16 vsnwprintf +#define vsprintf16 wvsprintf +#define vfprintf16 vfwprintf +#define sscanf16 swscanf +#define toupper16 towupper +#define tolower16 towlower +#define isupper16 iswupper +#define islower16 iswlower +#define isspace16 iswspace +#define isalpha16 iswalpha +#define isdigit16 iswdigit +#define isalnum16 iswalnum + +#define stricmp _stricmp +#define strnicmp _strnicmp +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#define snwprintf _snwprintf +#define vsnwprintf _vsnwprintf + +#define wtoi _wtoi +#define wtol _wtol +#define wtof _wtof + +#elif SMTG_OS_LINUX +#include +#include +#include +#include +#include +#include +#include + +using ConverterFacet = std::codecvt_utf8_utf16; +using Converter = std::wstring_convert; + +//------------------------------------------------------------------------ +static ConverterFacet& converterFacet () +{ + static ConverterFacet gFacet; + return gFacet; +} + +//------------------------------------------------------------------------ +static Converter& converter () +{ + static Converter gConverter; + return gConverter; +} + +//----------------------------------------------------------------------------- +static inline int stricasecmp (const Steinberg::char8* s1, const Steinberg::char8* s2) +{ + return ::strcasecmp (s1, s2); +} + +//----------------------------------------------------------------------------- +static inline int strnicasecmp (const Steinberg::char8* s1, const Steinberg::char8* s2, size_t n) +{ + return ::strncasecmp (s1, s2, n); +} + +//----------------------------------------------------------------------------- +static inline int stricmp16 (const Steinberg::char16* s1, const Steinberg::char16* s2) +{ + auto str1 = converter ().to_bytes (s1); + auto str2 = converter ().to_bytes (s2); + return stricasecmp (str1.data (), str2.data ()); +} + +//----------------------------------------------------------------------------- +static inline int strnicmp16 (const Steinberg::char16* s1, const Steinberg::char16* s2, int n) +{ + auto str1 = converter ().to_bytes (s1); + auto str2 = converter ().to_bytes (s2); + return strnicasecmp (str1.data (), str2.data (), n); +} + +//----------------------------------------------------------------------------- +static inline int sprintf16 (Steinberg::char16* wcs, const Steinberg::char16* format, ...) +{ +#warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + return 0; +} + +//----------------------------------------------------------------------------- +static inline int vsnwprintf (Steinberg::char16* wcs, size_t maxlen, + const Steinberg::char16* format, va_list args) +{ + Steinberg::char8 str8[kPrintfBufferSize]; + auto format_utf8 = converter ().to_bytes(format); + auto len = vsnprintf (str8, kPrintfBufferSize, format_utf8.data (), args); + + auto tmp_str = converter ().from_bytes (str8, str8 + len); + auto target_len = std::min (tmp_str.size (), maxlen - 1); + tmp_str.copy (wcs, target_len); + wcs[target_len] = '\0'; + + return tmp_str.size (); +} + +//----------------------------------------------------------------------------- +static inline Steinberg::char16* strrchr16 (const Steinberg::char16* str, Steinberg::char16 c) +{ +#warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + return nullptr; +} + +#elif SMTG_OS_MACOS +#define tstrtoi64 strtoll +#define stricmp strcasecmp +#define strnicmp strncasecmp + +//----------------------------------------------------------------------------- +static inline Steinberg::int32 strnicmp16 (const Steinberg::char16* str1, const Steinberg::char16* str2, size_t size) +{ + if (size == 0) + return 0; + + CFIndex str1Len = Steinberg::strlen16 (str1); + CFIndex str2Len = Steinberg::strlen16 (str2); + if (size < str2Len) // range is not applied to second string + str2Len = size; + CFStringRef cfStr1 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str1, str1Len, kCFAllocatorNull); + CFStringRef cfStr2 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str2, str2Len, kCFAllocatorNull); + CFComparisonResult result = CFStringCompareWithOptions (cfStr1, cfStr2, CFRangeMake (0, size), kCFCompareCaseInsensitive); + CFRelease (cfStr1); + CFRelease (cfStr2); + switch (result) + { + case kCFCompareEqualTo: return 0; + case kCFCompareLessThan: return -1; + case kCFCompareGreaterThan: + default: return 1; + }; +} + +//----------------------------------------------------------------------------- +static inline Steinberg::int32 stricmp16 (const Steinberg::char16* str1, CFIndex str1Len, const Steinberg::char16* str2, CFIndex str2Len) +{ + CFStringRef cfStr1 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str1, str1Len, kCFAllocatorNull); + CFStringRef cfStr2 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str2, str2Len, kCFAllocatorNull); + CFComparisonResult result = CFStringCompare (cfStr1, cfStr2, kCFCompareCaseInsensitive); + CFRelease (cfStr1); + CFRelease (cfStr2); + switch (result) + { + case kCFCompareEqualTo: return 0; + case kCFCompareLessThan: return -1; + case kCFCompareGreaterThan: + default: return 1; + }; +} + +//----------------------------------------------------------------------------- +static inline Steinberg::int32 stricmp16 (const Steinberg::ConstString& str1, const Steinberg::ConstString& str2) +{ + return stricmp16 (str1.text16 (), str1.length (), str2.text16 (), str2.length ()); +} + +//----------------------------------------------------------------------------- +static inline Steinberg::int32 stricmp16 (const Steinberg::char16* str1, const Steinberg::char16* str2) +{ + CFIndex str1Len = Steinberg::strlen16 (str1); + CFIndex str2Len = Steinberg::strlen16 (str2); + return stricmp16 (str1, str1Len, str2, str2Len); +} + +//----------------------------------------------------------------------------- +static inline Steinberg::char16* strrchr16 (const Steinberg::char16* str, Steinberg::char16 c) +{ + Steinberg::int32 len = Steinberg::ConstString (str).length (); + while (len > 0) + { + if (str[len] == c) + return const_cast(str + len); + len--; + } + return 0; +} + +//----------------------------------------------------------------------------- +static inline Steinberg::int32 vsnwprintf (Steinberg::char16* str, Steinberg::int32 size, const Steinberg::char16* format, va_list ap) +{ + // wrapped using CoreFoundation's CFString + CFMutableStringRef formatString = (CFMutableStringRef)Steinberg::ConstString (format).toCFStringRef (0xFFFF, true); + CFStringFindAndReplace (formatString, CFSTR("%s"), CFSTR("%S"), CFRangeMake (0, CFStringGetLength (formatString)), 0); + CFStringRef resultString = CFStringCreateWithFormatAndArguments (Steinberg::kCFAllocator, 0, formatString, ap); + CFRelease (formatString); + if (resultString) + { + Steinberg::String res; + res.fromCFStringRef (resultString); + res.copyTo16 (str, 0, size); + CFRelease (resultString); + return 0; + } + return 1; +} + +//----------------------------------------------------------------------------- +static inline Steinberg::int32 sprintf16 (Steinberg::char16* str, const Steinberg::char16* format, ...) +{ + va_list marker; + va_start (marker, format); + return vsnwprintf (str, -1, format, marker); +} + +#endif + +/* +UTF-8 EF BB BF +UTF-16 Big Endian FE FF +UTF-16 Little Endian FF FE +UTF-32 Big Endian 00 00 FE FF +UTF-32 Little Endian FF FE 00 00 +*/ + +namespace Steinberg { + +//----------------------------------------------------------------------------- +static inline bool isCaseSensitive (ConstString::CompareMode mode) +{ + return mode == ConstString::kCaseSensitive; +} + +//----------------------------------------------------------------------------- +// ConstString +//----------------------------------------------------------------------------- +ConstString::ConstString (const char8* str, int32 length) +: buffer8 ((char8*)str) +, len (length < 0 ? (str ? static_cast (strlen (str)) : 0) : length) +, isWide (0) +{ +} + +//----------------------------------------------------------------------------- +ConstString::ConstString (const char16* str, int32 length) +: buffer16 ((char16*)str) +, len (length < 0 ? (str ? strlen16 (str) : 0) : length) +, isWide (1) +{ +} + +//----------------------------------------------------------------------------- +ConstString::ConstString (const ConstString& str, int32 offset, int32 length) +: buffer (str.buffer) +, len (length < 0 ? (str.len - (offset > 0 ? offset : 0)) : length) +, isWide (str.isWide) +{ + if (offset > 0) + { + if (isWide) + buffer16 += offset; + else + buffer8 += offset; + } +} + +//----------------------------------------------------------------------------- +ConstString::ConstString (const FVariant& var) +: buffer (0) +, len (0) +, isWide (0) +{ + switch (var.getType ()) + { + case FVariant::kString8: + buffer8 = (char8*)var.getString8 (); + len = buffer8 ? strlen8 (buffer8) : 0; + isWide = false; + break; + + case FVariant::kString16: + buffer16 = (char16*)var.getString16 (); + len = buffer16 ? strlen16 (buffer16) : 0; + isWide = true; + break; + } +} + +//----------------------------------------------------------------------------- +ConstString::ConstString () +: buffer (0) +, len (0) +, isWide (0) +{ +} + +//----------------------------------------------------------------------------- +bool ConstString::testChar8 (uint32 index, char8 c) const +{ + if (index >= len) + return c == 0; + if (isWide) + { + // make c wide + char8 src[] = {c, 0}; + char16 dest[2] = {0}; + if (multiByteToWideString (dest, src, 2) > 0) + return buffer16[index] == dest[0]; + return false; + } + return buffer8[index] == c; +} + +//----------------------------------------------------------------------------- +bool ConstString::testChar16 (uint32 index, char16 c) const +{ + if (index >= len) + return c == 0; + if (!isWide) + { + // make c ansi + char16 src[] = {c, 0}; + char8 dest[8] = {0}; + if (wideStringToMultiByte (dest, src, 2) > 0 && dest[1] == 0) + return buffer8[index] == dest[0]; + return false; + } + return buffer16[index] == c; +} + +//----------------------------------------------------------------------------- +bool ConstString::extract (String& result, uint32 idx, int32 n) const +{ + if (len == 0|| idx >= len) + return false; + + if ((idx + n > len) || n < 0) + n = len - idx; + + if (isWide) + result.assign (buffer16 + idx, n); + else + result.assign (buffer8 + idx, n); + + return true; +} + +//----------------------------------------------------------------------------- +int32 ConstString::copyTo8 (char8* str, uint32 idx, int32 n) const +{ + if (!str) + return 0; + + if (isWide) + { + String tmp (text16 ()); + if (tmp.toMultiByte () == false) + return 0; + return tmp.copyTo8 (str, idx, n); + } + + if (isEmpty () || idx >= len || !buffer8) + { + str[0] = 0; + return 0; + } + + if ((idx + n > len) || n < 0) + n = len - idx; + + memcpy (str, &(buffer8[idx]), n * sizeof (char8)); + str[n] = 0; + return n; +} + +//----------------------------------------------------------------------------- +int32 ConstString::copyTo16 (char16* str, uint32 idx, int32 n) const +{ + if (!str) + return 0; + + if (!isWide) + { + String tmp (text8 ()); + if (tmp.toWideString () == false) + return 0; + return tmp.copyTo16 (str, idx, n); + } + + if (isEmpty () || idx >= len || !buffer16) + { + str[0] = 0; + return 0; + } + + if ((idx + n > len) || n < 0) + n = len - idx; + + memcpy (str, &(buffer16[idx]), n * sizeof (char16)); + str[n] = 0; + return n; +} + +//----------------------------------------------------------------------------- +int32 ConstString::copyTo (tchar* str, uint32 idx, int32 n) const +{ +#ifdef UNICODE + return copyTo16 (str, idx, n); +#else + return copyTo8 (str, idx, n); +#endif +} + +//----------------------------------------------------------------------------- +void ConstString::copyTo (IStringResult* result) const +{ + if (isWideString () == false) + { + result->setText (text8 ()); + } + else + { + FUnknownPtr iStr (result); + if (iStr) + { + iStr->setText16 (text16 ()); + } + else + { + String tmp (*this); + tmp.toMultiByte (); + result->setText (tmp.text8 ()); + } + } +} + +//----------------------------------------------------------------------------- +void ConstString::copyTo (IString& string) const +{ + if (isWideString ()) + string.setText16 (text16 ()); + else + string.setText8 (text8 ()); +} + + + +//----------------------------------------------------------------------------- +int32 ConstString::compare (const ConstString& str, int32 n, CompareMode mode) const +{ + if (n == 0) + return 0; + + if (str.isEmpty ()) + { + if (isEmpty ()) + return 0; + return 1; + } + else if (isEmpty ()) + return -1; + + if (!isWide && !str.isWide) + { + if (n < 0) + { + if (isCaseSensitive (mode)) + return strcmp (*this, str); + else + return stricmp (*this, str); + } + else + { + if (isCaseSensitive (mode)) + return strncmp (*this, str, n); + else + return strnicmp (*this, str, n); + } + } + else if (isWide && str.isWide) + { + if (n < 0) + { + if (isCaseSensitive (mode)) + return strcmp16 (*this, str); + else + return stricmp16 (*this, str); + } + else + { + if (isCaseSensitive (mode)) + return strncmp16 (*this, str, n); + else + return strnicmp16 (*this, str, n); + } + } + return compareAt (0, str, n, mode); +} + +//----------------------------------------------------------------------------- +int32 ConstString::compare (const ConstString& str, CompareMode mode) const +{ + return compare (str, -1, mode); +} + +//----------------------------------------------------------------------------- +int32 ConstString::compareAt (uint32 index, const ConstString& str, int32 n, CompareMode mode) const +{ + if (n == 0) + return 0; + + if (str.isEmpty ()) + { + if (isEmpty ()) + return 0; + return 1; + } + else if (isEmpty ()) + return -1; + + if (!isWide && !str.isWide) + { + char8* toCompare = buffer8; + if (index > 0) + { + if (index >= len) + { + if (str.isEmpty ()) + return 0; + return -1; + } + toCompare += index; + } + + if (n < 0) + { + if (isCaseSensitive (mode)) + return strcmp (toCompare, str); + else + return stricmp (toCompare, str); + } + else + { + if (isCaseSensitive (mode)) + return strncmp (toCompare, str, n); + else + return strnicmp (toCompare, str, n); + } + } + else if (isWide && str.isWide) + { + char16* toCompare = buffer16; + if (index > 0) + { + if (index >= len) + { + if (str.isEmpty ()) + return 0; + return -1; + } + toCompare += index; + } + + if (n < 0) + { + if (isCaseSensitive (mode)) + return strcmp16 (toCompare, str.text16 ()); + else + return stricmp16 (toCompare, str.text16 ()); + } + else + { + if (isCaseSensitive (mode)) + return strncmp16 (toCompare, str.text16 (), n); + else + return strnicmp16 (toCompare, str.text16 (), n); + } + } + else + { + if (isWide) + { + String tmp (str.text8 ()); + if (tmp.toWideString () == false) + return -1; + return compareAt (index, tmp, n, mode); + } + else + { + String tmp (text8 ()); + if (tmp.toWideString () == false) + return 1; + return tmp.compareAt (index, str, n, mode); + } + } +} + +//------------------------------------------------------------------------ +Steinberg::int32 ConstString::naturalCompare (const ConstString& str, CompareMode mode /*= kCaseSensitive*/) const +{ + if (str.isEmpty ()) + { + if (isEmpty ()) + return 0; + return 1; + } + else if (isEmpty ()) + return -1; + + if (!isWide && !str.isWide) + return strnatcmp8 (buffer8, str.text8 (), isCaseSensitive (mode)); + else if (isWide && str.isWide) + return strnatcmp16 (buffer16, str.text16 (), isCaseSensitive (mode)); + else + { + if (isWide) + { + String tmp (str.text8 ()); + tmp.toWideString (); + return strnatcmp16 (buffer16, tmp.text16 (), isCaseSensitive (mode)); + } + else + { + String tmp (text8 ()); + tmp.toWideString (); + return strnatcmp16 (tmp.text16 (), str.text16 (), isCaseSensitive (mode)); + } + } +} + +//----------------------------------------------------------------------------- +bool ConstString::startsWith (const ConstString& str, CompareMode mode /*= kCaseSensitive*/) const +{ + if (str.isEmpty ()) + { + return isEmpty (); + } + else if (isEmpty ()) + { + return false; + } + if (length () < str.length ()) + { + return false; + } + if (!isWide && !str.isWide) + { + if (isCaseSensitive (mode)) + return strncmp (buffer8, str.buffer8, str.length ()) == 0; + return strnicmp (buffer8, str.buffer8, str.length ()) == 0; + } + else if (isWide && str.isWide) + { + if (isCaseSensitive (mode)) + return strncmp16 (buffer16, str.buffer16, str.length ()) == 0; + return strnicmp16 (buffer16, str.buffer16, str.length ()) == 0; + } + else if (isWide) + { + String tmp (str.text8 ()); + tmp.toWideString (); + if (tmp.length () > length ()) + return false; + if (isCaseSensitive (mode)) + return strncmp16 (buffer16, tmp.buffer16, tmp.length ()) == 0; + return strnicmp16 (buffer16, tmp.buffer16, tmp.length ()) == 0; + } + else + { + String tmp (text8 ()); + tmp.toWideString (); + if (str.length () > tmp.length ()) + return false; + if (isCaseSensitive (mode)) + return strncmp16 (tmp.buffer16, str.buffer16, str.length ()) == 0; + return strnicmp16 (tmp.buffer16, str.buffer16, str.length ()) == 0; + } +} + +//----------------------------------------------------------------------------- +bool ConstString::endsWith (const ConstString& str, CompareMode mode /*= kCaseSensitive*/) const +{ + if (str.isEmpty ()) + { + return isEmpty (); + } + else if (isEmpty ()) + { + return false; + } + if (length () < str.length ()) + { + return false; + } + if (!isWide && !str.isWide) + { + if (isCaseSensitive (mode)) + return strncmp (buffer8 + (length () - str.length ()), str.buffer8, str.length ()) == 0; + return strnicmp (buffer8 + (length () - str.length ()), str.buffer8, str.length ()) == 0; + } + else if (isWide && str.isWide) + { + if (isCaseSensitive (mode)) + return strncmp16 (buffer16 + (length () - str.length ()), str.buffer16, str.length ()) == 0; + return strnicmp16 (buffer16 + (length () - str.length ()), str.buffer16, str.length ()) == 0; + } + else if (isWide) + { + String tmp (str.text8 ()); + tmp.toWideString (); + if (tmp.length () > length ()) + return false; + if (isCaseSensitive (mode)) + return strncmp16 (buffer16 + (length () - tmp.length ()), tmp.buffer16, tmp.length ()) == 0; + return strnicmp16 (buffer16 + (length () - tmp.length ()), tmp.buffer16, tmp.length ()) == 0; + } + else + { + String tmp (text8 ()); + tmp.toWideString (); + if (str.length () > tmp.length ()) + return false; + if (isCaseSensitive (mode)) + return strncmp16 (tmp.buffer16 + (tmp.length () - str.length ()), str.buffer16, str.length ()) == 0; + return strnicmp16 (tmp.buffer16 + (tmp.length () - str.length ()), str.buffer16, str.length ()) == 0; + } +} + +//----------------------------------------------------------------------------- +bool ConstString::contains (const ConstString& str, CompareMode m) const +{ + return findFirst (str, -1, m) != -1; +} + +//----------------------------------------------------------------------------- +int32 ConstString::findNext (int32 startIndex, const ConstString& str, int32 n, CompareMode mode, int32 endIndex) const +{ + uint32 endLength = len; + if (endIndex > -1 && (uint32)endIndex < len) + endLength = endIndex + 1; + + if (isWide && str.isWide) + { + if (startIndex < 0) + startIndex = 0; + + uint32 stringLength = str.length (); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (n > 0) + { + uint32 i = 0; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i < endLength; i++) + if (strncmp16 (buffer16 + i, str, n) == 0) + return i; + } + else + { + for (i = startIndex; i < endLength; i++) + if (strnicmp16 (buffer16 + i, str, n) == 0) + return i; + } + } + return -1; + } + else if (!isWide && !str.isWide) + { + uint32 stringLength = str.length (); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (startIndex < 0) + startIndex = 0; + + if (n > 0) + { + uint32 i = 0; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i < endLength; i++) + if (strncmp (buffer8 + i, str, n) == 0) + return i; + } + else + { + for (i = startIndex; i < endLength; i++) + if (strnicmp (buffer8 + i, str, n) == 0) + return i; + } + } + return -1; + } + String tmp; + if (isWide) + { + tmp = str.text8 (); + tmp.toWideString (); + return findNext (startIndex, tmp, n , mode, endIndex); + } + tmp = text8 (); + tmp.toWideString (); + return tmp.findNext (startIndex, str, n, mode, endIndex); +} + +//------------------------------------------------------------------------------------------------ +int32 ConstString::findNext (int32 startIndex, char8 c, CompareMode mode, int32 endIndex) const +{ + uint32 endLength = len; + if (endIndex > -1 && (uint32)endIndex < len) + endLength = endIndex + 1; + + if (isWide) + { + char8 src[] = {c, 0}; + char16 dest[8] = {0}; + if (multiByteToWideString (dest, src, 2) > 0) + return findNext (startIndex, dest[0], mode, endIndex); + return -1; + } + + if (startIndex < 0) + startIndex = 0; + uint32 i; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i < endLength; i++) + { + if (buffer8[i] == c) + return i; + } + } + else + { + c = toLower (c); + for (i = startIndex; i < endLength; i++) + { + if (toLower (buffer8[i]) == c) + return i; + } + } + return -1; +} + +//----------------------------------------------------------------------------- +int32 ConstString::findNext (int32 startIndex, char16 c, CompareMode mode, int32 endIndex) const +{ + uint32 endLength = len; + if (endIndex > -1 && (uint32)endIndex < len) + endLength = endIndex + 1; + + if (!isWide) + { + char16 src[] = {c, 0}; + char8 dest[8] = {0}; + if (wideStringToMultiByte (dest, src, 2) > 0 && dest[1] == 0) + return findNext (startIndex, dest[0], mode, endIndex); + + return -1; + } + + uint32 i; + if (startIndex < 0) + startIndex = 0; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i < endLength; i++) + { + if (buffer16[i] == c) + return i; + } + } + else + { + c = toLower (c); + for (i = startIndex; i < endLength; i++) + { + if (toLower (buffer16[i]) == c) + return i; + } + } + return -1; +} + +//----------------------------------------------------------------------------- +int32 ConstString::findPrev (int32 startIndex, char8 c, CompareMode mode) const +{ + if (len == 0) + return -1; + + if (isWide) + { + char8 src[] = {c, 0}; + char16 dest[8] = {0}; + if (multiByteToWideString (dest, src, 2) > 0) + return findPrev (startIndex, dest[0], mode); + return -1; + } + + if (startIndex < 0 || startIndex > (int32)len) + startIndex = len; + + int32 i; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i >= 0; i--) + { + if (buffer8[i] == c) + return i; + } + } + else + { + c = toLower (c); + for (i = startIndex; i >= 0; i--) + { + if (toLower (buffer8[i]) == c) + return i; + } + } + return -1; +} + +//----------------------------------------------------------------------------- +int32 ConstString::findPrev (int32 startIndex, char16 c, CompareMode mode) const +{ + if (len == 0) + return -1; + + if (!isWide) + { + char16 src[] = {c, 0}; + char8 dest[8] = {0}; + if (wideStringToMultiByte (dest, src, 2) > 0 && dest[1] == 0) + return findPrev (startIndex, dest[0], mode); + + return -1; + } + + if (startIndex < 0 || startIndex > (int32)len) + startIndex = len; + + int32 i; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i >= 0; i--) + { + if (buffer16[i] == c) + return i; + } + } + else + { + c = toLower (c); + for (i = startIndex; i >= 0; i--) + { + if (toLower (buffer16[i]) == c) + return i; + } + } + return -1; +} + +//----------------------------------------------------------------------------- +int32 ConstString::findPrev (int32 startIndex, const ConstString& str, int32 n, CompareMode mode) const +{ + if (isWide && str.isWide) + { + uint32 stringLength = str.length (); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (startIndex < 0 || startIndex >= (int32)len) + startIndex = len - 1; + + if (n > 0) + { + int32 i = 0; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i >= 0; i--) + if (strncmp16 (buffer16 + i, str, n) == 0) + return i; + } + else + { + for (i = startIndex; i >= 0; i--) + if (strnicmp16 (buffer16 + i, str, n) == 0) + return i; + } + } + return -1; + } + else if (!isWide && !str.isWide) + { + uint32 stringLength = str.length (); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (startIndex < 0 || startIndex >= (int32)len) + startIndex = len - 1; + + if (n > 0) + { + int32 i = 0; + + if (isCaseSensitive (mode)) + { + for (i = startIndex; i >= 0; i--) + if (strncmp (buffer8 + i, str, n) == 0) + return i; + } + else + { + for (i = startIndex; i >= 0; i--) + if (strnicmp (buffer8 + i, str, n) == 0) + return i; + } + } + return -1; + } + if (isWide) + { + String tmp (str.text8 ()); + tmp.toWideString (); + return findPrev (startIndex, tmp, n, mode); + } + String tmp (text8 ()); + tmp.toWideString (); + return tmp.findPrev (startIndex, str, n, mode); +} + +//----------------------------------------------------------------------------- +int32 ConstString::countOccurences (char8 c, uint32 startIndex, CompareMode mode) const +{ + if (isWide) + { + char8 src[] = {c, 0}; + char16 dest[8] = {0}; + if (multiByteToWideString (dest, src, 2) > 0) + return countOccurences (dest[0], startIndex, mode); + return -1; + } + + int32 result = 0; + int32 next = startIndex; + while (true) + { + next = findNext (next, c, mode); + if (next >= 0) + { + next++; + result++; + } + else + break; + } + return result; +} + +//----------------------------------------------------------------------------- +int32 ConstString::countOccurences (char16 c, uint32 startIndex, CompareMode mode) const +{ + if (!isWide) + { + char16 src[] = {c, 0}; + char8 dest[8] = {0}; + if (wideStringToMultiByte (dest, src, 2) > 0 && dest[1] == 0) + return countOccurences (dest[0], startIndex, mode); + + return -1; + } + int32 result = 0; + int32 next = startIndex; + while (true) + { + next = findNext (next, c, mode); + if (next >= 0) + { + next++; + result++; + } + else + break; + } + return result; +} + +//----------------------------------------------------------------------------- +int32 ConstString::getFirstDifferent (const ConstString& str, CompareMode mode) const +{ + if (str.isWide != isWide) + { + if (isWide) + { + String tmp (str.text8 ()); + if (tmp.toWideString () == false) + return -1; + return getFirstDifferent (tmp, mode); + } + else + { + String tmp (text8 ()); + if (tmp.toWideString () == false) + return -1; + return tmp.getFirstDifferent (str, mode); + } + } + + uint32 len1 = len; + uint32 len2 = str.len; + uint32 i; + + if (isWide) + { + if (isCaseSensitive (mode)) + { + for (i = 0; i <= len1 && i <= len2; i++) + { + if (buffer16[i] != str.buffer16[i]) + return i; + } + } + else + { + for (i = 0; i <= len1 && i <= len2; i++) + { + if (toLower (buffer16[i]) != toLower (str.buffer16[i])) + return i; + } + } + } + else + { + if (isCaseSensitive (mode)) + { + for (i = 0; i <= len1 && i <= len2; i++) + { + if (buffer8[i] != str.buffer8[i]) + return i; + } + } + else + { + for (i = 0; i <= len1 && i <= len2; i++) + { + if (toLower (buffer8[i]) != toLower (str.buffer8[i])) + return i; + } + } + } + return -1; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanInt64 (int64& value, uint32 offset, bool scanToEnd) const +{ + if (isEmpty () || offset >= len) + return false; + + if (isWide) + return scanInt64_16 (buffer16 + offset, value, scanToEnd); + else + return scanInt64_8 (buffer8 + offset, value, scanToEnd); +} + +//----------------------------------------------------------------------------- +bool ConstString::scanUInt64 (uint64& value, uint32 offset, bool scanToEnd) const +{ + if (isEmpty () || offset >= len) + return false; + + if (isWide) + return scanUInt64_16 (buffer16 + offset, value, scanToEnd); + else + return scanUInt64_8 (buffer8 + offset, value, scanToEnd); +} + +//----------------------------------------------------------------------------- +bool ConstString::scanHex (uint8& value, uint32 offset, bool scanToEnd) const +{ + if (isEmpty () || offset >= len) + return false; + + if (isWide) + return scanHex_16 (buffer16 + offset, value, scanToEnd); + else + return scanHex_8 (buffer8 + offset, value, scanToEnd); +} + +//----------------------------------------------------------------------------- +bool ConstString::scanInt32 (int32& value, uint32 offset, bool scanToEnd) const +{ + if (isEmpty () || offset >= len) + return false; + + if (isWide) + return scanInt32_16 (buffer16 + offset, value, scanToEnd); + else + return scanInt32_8 (buffer8 + offset, value, scanToEnd); +} + +//----------------------------------------------------------------------------- +bool ConstString::scanUInt32 (uint32& value, uint32 offset, bool scanToEnd) const +{ + if (isEmpty () || offset >= len) + return false; + + if (isWide) + return scanUInt32_16 (buffer16 + offset, value, scanToEnd); + else + return scanUInt32_8 (buffer8 + offset, value, scanToEnd); +} + +//----------------------------------------------------------------------------- +bool ConstString::scanInt64_8 (const char8* text, int64& value, bool scanToEnd) +{ + while (text && text[0]) + { + if (sscanf (text, "%" FORMAT_INT64A, &value) == 1) + return true; + else if (scanToEnd == false) + return false; + text++; + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanInt64_16 (const char16* text, int64& value, bool scanToEnd) +{ + if (text && text[0]) + { + String str (text); + str.toMultiByte (kCP_Default); + return scanInt64_8 (str, value, scanToEnd); + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanUInt64_8 (const char8* text, uint64& value, bool scanToEnd) +{ + while (text && text[0]) + { + if (sscanf (text, "%" FORMAT_UINT64A, &value) == 1) + return true; + else if (scanToEnd == false) + return false; + text++; + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanUInt64_16 (const char16* text, uint64& value, bool scanToEnd) +{ + if (text && text[0]) + { + String str (text); + str.toMultiByte (kCP_Default); + return scanUInt64_8 (str, value, scanToEnd); + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanInt64 (const tchar* text, int64& value, bool scanToEnd) +{ +#ifdef UNICODE + return scanInt64_16 (text, value,scanToEnd); +#else + return scanInt64_8 (text, value, scanToEnd); +#endif +} + +//----------------------------------------------------------------------------- +bool ConstString::scanUInt64 (const tchar* text, uint64& value, bool scanToEnd) +{ +#ifdef UNICODE + return scanUInt64_16 (text, value, scanToEnd); +#else + return scanUInt64_8 (text, value, scanToEnd); +#endif +} + +//----------------------------------------------------------------------------- +bool ConstString::scanHex_8 (const char8* text, uint8& value, bool scanToEnd) +{ + while (text && text[0]) + { + unsigned int v; // scanf expects an unsigned int for %x + if (sscanf (text, "%x", &v) == 1) + { + value = (uint8)v; + return true; + } + else if (scanToEnd == false) + return false; + text++; + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanHex_16 (const char16* text, uint8& value, bool scanToEnd) +{ + if (text && text[0]) + { + String str (text); + str.toMultiByte (kCP_Default); // scanf uses default codepage + return scanHex_8 (str, value, scanToEnd); + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::scanHex (const tchar* text, uint8& value, bool scanToEnd) +{ +#ifdef UNICODE + return scanHex_16 (text, value, scanToEnd); +#else + return scanHex_8 (text, value, scanToEnd); +#endif +} + +//----------------------------------------------------------------------------- +bool ConstString::scanFloat (double& value, uint32 offset, bool scanToEnd) const +{ + if (isEmpty () || offset >= len) + return false; + + String str (*this); + int32 pos = -1; + if (isWide) + { + if ((pos = str.findNext (offset, STR(','))) >= 0 && ((uint32)pos) >= offset) + str.setChar (pos, STR('.')); + + str.toMultiByte (kCP_Default); // scanf uses default codepage + } + else + { + if ((pos = str.findNext (offset, ',')) >= 0 && ((uint32)pos) >= offset) + str.setChar (pos, '.'); + } + + const char8* txt = str.text8 () + offset; + while (txt && txt[0]) + { + if (sscanf (txt, "%lf", &value) == 1) + return true; + else if (scanToEnd == false) + return false; + txt++; + } + return false; +} + +//----------------------------------------------------------------------------- +char16 ConstString::toLower (char16 c) +{ + #if SMTG_OS_WINDOWS + WCHAR temp[2] = {c, 0}; + ::CharLowerW (temp); + return temp[0]; + #elif SMTG_OS_MACOS + // only convert characters which in lowercase are also single characters + UniChar characters [2] = {0}; + characters[0] = c; + CFMutableStringRef str = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, characters, 1, 2, kCFAllocatorNull); + if (str) + { + CFStringLowercase (str, NULL); + CFRelease (str); + if (characters[1] == 0) + return characters[0]; + } + return c; + #elif SMTG_OS_LINUX + #warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + return c; + #else + return towlower (c); + #endif +} + +//----------------------------------------------------------------------------- +char16 ConstString::toUpper (char16 c) +{ + #if SMTG_OS_WINDOWS + WCHAR temp[2] = {c, 0}; + ::CharUpperW (temp); + return temp[0]; + #elif SMTG_OS_MACOS + // only convert characters which in uppercase are also single characters (don't translate a sharp-s which would result in SS) + UniChar characters [2] = {0}; + characters[0] = c; + CFMutableStringRef str = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, characters, 1, 2, kCFAllocatorNull); + if (str) + { + CFStringUppercase (str, NULL); + CFRelease (str); + if (characters[1] == 0) + return characters[0]; + } + return c; + #elif SMTG_OS_LINUX + #warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + return c; + #else + return towupper (c); + #endif +} + +//----------------------------------------------------------------------------- +char8 ConstString::toLower (char8 c) +{ + if ((c >= 'A') && (c <= 'Z')) + return c + ('a' - 'A'); + #if SMTG_OS_WINDOWS + CHAR temp[2] = {c, 0}; + ::CharLowerA (temp); + return temp[0]; + #else + return tolower (c); + #endif +} + +//----------------------------------------------------------------------------- +char8 ConstString::toUpper (char8 c) +{ + if ((c >= 'a') && (c <= 'z')) + return c - ('a' - 'A'); + #if SMTG_OS_WINDOWS + CHAR temp[2] = {c, 0}; + ::CharUpperA (temp); + return temp[0]; + #else + return toupper (c); + #endif +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharSpace (const char8 character) +{ + return isspace (character) != 0; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharSpace (const char16 character) +{ + switch (character) + { + case 0x0020: + case 0x00A0: + case 0x2002: + case 0x2003: + case 0x2004: + case 0x2005: + case 0x2006: + case 0x2007: + case 0x2008: + case 0x2009: + case 0x200A: + case 0x200B: + case 0x202F: + case 0x205F: + case 0x3000: + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharAlpha (const char8 character) +{ + return isalpha (character) != 0; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharAlpha (const char16 character) +{ + return iswalpha (character) != 0; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharAlphaNum (const char8 character) +{ + return isalnum (character) != 0; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharAlphaNum (const char16 character) +{ + return iswalnum (character) != 0; // this may not work on macOSX when another locale is set inside the c-lib +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharDigit (const char8 character) +{ + return isdigit (character) != 0; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharDigit (const char16 character) +{ + return iswdigit (character) != 0; // this may not work on macOSX when another locale is set inside the c-lib +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharAscii (char8 character) +{ + return character >= 0; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharAscii (char16 character) +{ + return character < 128; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharUpper (char8 character) +{ + return toUpper (character) == character; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharUpper (char16 character) +{ + return toUpper (character) == character; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharLower (char8 character) +{ + return toLower (character) == character; +} + +//----------------------------------------------------------------------------- +bool ConstString::isCharLower (char16 character) +{ + return toLower (character) == character; +} + +//----------------------------------------------------------------------------- +bool ConstString::isDigit (uint32 index) const +{ + if (isEmpty () || index >= len) + return false; + + if (isWide) + return ConstString::isCharDigit (buffer16[index]); + else + return ConstString::isCharDigit (buffer8[index]); +} + +//----------------------------------------------------------------------------- +int32 ConstString::getTrailingNumberIndex (uint32 width) const +{ + if (isEmpty ()) + return -1; + + int32 endIndex = len - 1; + int32 i = endIndex; + while (isDigit ((uint32) i) && i >= 0) + i--; + + // now either all are digits or i is on the first non digit + if (i < endIndex) + { + if (width > 0 && (endIndex - i != static_cast (width))) + return -1; + + return i + 1; + } + + return -1; +} + +//----------------------------------------------------------------------------- +int64 ConstString::getTrailingNumber (int64 fallback) const +{ + int32 index = getTrailingNumberIndex (); + + int64 number = 0; + + if (index >= 0) + if (scanInt64 (number, index)) + return number; + + return fallback; +} + + + +//----------------------------------------------------------------------------- +void ConstString::toVariant (FVariant& var) const +{ + if (isWide) + { + var.setString16 (buffer16); + } + else + { + var.setString8 (buffer8); + } +} + +//----------------------------------------------------------------------------- +bool ConstString::isAsciiString () const +{ + uint32 i; + if (isWide) + { + for (i = 0; i < len; i++) + if (ConstString::isCharAscii (buffer16 [i]) == false) + return false; + } + else + { + for (i = 0; i < len; i++) + if (ConstString::isCharAscii (buffer8 [i]) == false) + return false; + } + return true; +} + + +#if SMTG_OS_MACOS +uint32 kDefaultSystemEncoding = kCFStringEncodingMacRoman; +//----------------------------------------------------------------------------- +static CFStringEncoding MBCodePageToCFStringEncoding (uint32 codePage) +{ + switch (codePage) + { + case kCP_ANSI: return kDefaultSystemEncoding; // MacRoman or JIS + case kCP_MAC_ROMAN: return kCFStringEncodingMacRoman; + case kCP_ANSI_WEL: return kCFStringEncodingWindowsLatin1; + case kCP_MAC_CEE: return kCFStringEncodingMacCentralEurRoman; + case kCP_Utf8: return kCFStringEncodingUTF8; + case kCP_ShiftJIS: return kCFStringEncodingShiftJIS_X0213_00; + case kCP_US_ASCII: return kCFStringEncodingASCII; + } + return kCFStringEncodingASCII; +} +#endif + +//----------------------------------------------------------------------------- +int32 ConstString::multiByteToWideString (char16* dest, const char8* source, int32 charCount, uint32 sourceCodePage) +{ + if (source == 0 || source[0] == 0) + { + if (dest && charCount > 0) + { + dest[0] = 0; + } + return 0; + } + int32 result = 0; +#if SMTG_OS_WINDOWS + result = MultiByteToWideChar (sourceCodePage, MB_ERR_INVALID_CHARS, source, -1, dest, charCount); +#endif + +#if SMTG_OS_MACOS + CFStringRef cfStr = + (CFStringRef)::toCFStringRef (source, MBCodePageToCFStringEncoding (sourceCodePage)); + if (cfStr) + { + CFRange range = {0, CFStringGetLength (cfStr)}; + CFIndex usedBytes; + if (CFStringGetBytes (cfStr, range, kCFStringEncodingUnicode, ' ', false, (UInt8*)dest, + charCount * 2, &usedBytes) > 0) + { + result = static_cast (usedBytes / 2 + 1); + if (dest) + dest[usedBytes / 2] = 0; + } + + CFRelease (cfStr); + } +#endif + +#if SMTG_OS_LINUX + if (sourceCodePage == kCP_ANSI || sourceCodePage == kCP_Utf8) + { + if (dest == nullptr) + { + auto state = std::mbstate_t (); + auto maxChars = charCount ? charCount : std::numeric_limits::max () - 1; + result = converterFacet ().length (state, source, source + strlen (source), maxChars); + } + else + { + auto utf16Str = converter ().from_bytes (source); + if (!utf16Str.empty ()) + { + result = std::min (charCount, utf16Str.size ()); + memcpy (dest, utf16Str.data (), result * sizeof (char16)); + dest[result] = 0; + } + } + } + else + { +#warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + } + +#endif + + SMTG_ASSERT (result > 0) + return result; +} + +//----------------------------------------------------------------------------- +int32 ConstString::wideStringToMultiByte (char8* dest, const char16* wideString, int32 charCount, uint32 destCodePage) +{ +#if SMTG_OS_WINDOWS + return WideCharToMultiByte (destCodePage, 0, wideString, -1, dest, charCount, 0, 0); + +#elif SMTG_OS_MACOS + int32 result = 0; + if (wideString != 0) + { + if (dest) + { + CFStringRef cfStr = CFStringCreateWithCharactersNoCopy (kCFAllocator, (const UniChar*)wideString, strlen16 (wideString), kCFAllocatorNull); + if (cfStr) + { + if (fromCFStringRef (dest, charCount, cfStr, MBCodePageToCFStringEncoding (destCodePage))) + result = static_cast (strlen (dest) + 1); + CFRelease (cfStr); + } + } + else + { + return static_cast (CFStringGetMaximumSizeForEncoding (strlen16 (wideString), MBCodePageToCFStringEncoding (destCodePage))); + } + } + return result; + +#elif SMTG_OS_LINUX + int32 result = 0; + if (destCodePage == kCP_Utf8) + { + if (dest == nullptr) + { + auto maxChars = charCount ? charCount : tstrlen (wideString); + result = converterFacet ().max_length () * maxChars; + } + else + { + auto utf8Str = converter ().to_bytes (wideString); + if (!utf8Str.empty ()) + { + result = std::min (charCount, utf8Str.size ()); + memcpy (dest, utf8Str.data (), result * sizeof (char8)); + dest[result] = 0; + } + } + } + else if (destCodePage == kCP_ANSI) + { + if (dest == nullptr) + { + result = strlen16 (wideString) + 1; + } + else + { + int32 i = 0; + for (; i < charCount; ++i) + { + if (wideString[i] == 0) + break; + if (wideString[i] <= 0x007F) + dest[i] = wideString[i]; + else + dest[i] = '_'; + } + dest[i] = 0; + result = i; + } + } + else + { +#warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + } + return result; + +#else +#warning DEPRECATED No Linux implementation + assert(false && "DEPRECATED No Linux implementation"); + return 0; +#endif + +} + +//----------------------------------------------------------------------------- +bool ConstString::isNormalized (UnicodeNormalization n) +{ + if (isWide == false) + return false; + +#if SMTG_OS_WINDOWS +#ifdef UNICODE + if (n != kUnicodeNormC) + return false; + uint32 normCharCount = static_cast (FoldString (MAP_PRECOMPOSED, buffer16, len, 0, 0)); + return (normCharCount == len); +#else + return false; +#endif + +#elif SMTG_OS_MACOS + if (n != kUnicodeNormC) + return false; + + CFStringRef cfStr = (CFStringRef)toCFStringRef (); + CFIndex charCount = CFStringGetLength (cfStr); + CFRelease (cfStr); + return (charCount == len); +#else + return false; +#endif +} + +//----------------------------------------------------------------------------- +// String +//----------------------------------------------------------------------------- +String::String () +{ + isWide = kWideStringDefault ? 1 : 0; +} + +//----------------------------------------------------------------------------- +String::String (const char8* str, MBCodePage codePage, int32 n, bool isTerminated) +{ + isWide = 0; + if (str) + { + assign (str, n, isTerminated); + toWideString (codePage); + } +} + +//----------------------------------------------------------------------------- +String::String (const char8* str, int32 n, bool isTerminated) +{ + if (str) + assign (str, n, isTerminated); +} + +//----------------------------------------------------------------------------- +String::String (const char16* str, int32 n, bool isTerminated) +{ + isWide = 1; + if (str) + assign (str, n, isTerminated); +} + +//----------------------------------------------------------------------------- +String::String (const String& str, int32 n) +{ + isWide = str.isWideString (); + if (!str.isEmpty ()) + assign (str, n); +} + +//----------------------------------------------------------------------------- +String::String (const ConstString& str, int32 n) +{ + isWide = str.isWideString (); + if (!str.isEmpty ()) + assign (str, n); +} + +//----------------------------------------------------------------------------- +String::String (const FVariant& var) +{ + isWide = kWideStringDefault ? 1 : 0; + fromVariant (var); +} + +//----------------------------------------------------------------------------- +String::String (IString* str) +{ + isWide = str->isWideString (); + if (isWide) + assign (str->getText16 ()); + else + assign (str->getText8 ()); +} + +//----------------------------------------------------------------------------- +String::~String () +{ + if (buffer) + resize (0, false); +} + +#if SMTG_CPP11_STDLIBSUPPORT +//----------------------------------------------------------------------------- +String::String (String&& str) +{ + *this = std::move (str); +} + +//----------------------------------------------------------------------------- +String& String::operator= (String&& str) +{ + SMTG_ASSERT (buffer == 0 || buffer != str.buffer); + tryFreeBuffer (); + + isWide = str.isWide; + buffer = str.buffer; + len = str.len; + str.buffer = nullptr; + str.len = 0; + return *this; +} +#endif + +//----------------------------------------------------------------------------- +void String::updateLength () +{ + if (isWide) + len = strlen16 (text16 ()); + else + len = strlen8 (text8 ()); +} + +//----------------------------------------------------------------------------- +bool String::toWideString (uint32 sourceCodePage) +{ + if (!isWide) + { + if (buffer8 && len > 0) + { + int32 bytesNeeded = multiByteToWideString (0, buffer8, 0, sourceCodePage) * sizeof (char16); + if (bytesNeeded) + { + bytesNeeded += sizeof (char16); + char16* newStr = (char16*) malloc (bytesNeeded); + if (multiByteToWideString (newStr, buffer8, len + 1, sourceCodePage) <= 0) + { + free (newStr); + return false; + } + free (buffer8); + buffer16 = newStr; + isWide = true; + updateLength (); + } + else + { + return false; + } + } + isWide = true; + } + return true; +} + +#define SMTG_STRING_CHECK_CONVERSION 1 +#define SMTG_STRING_CHECK_CONVERSION_NO_BREAK 1 + +#if SMTG_STRING_CHECK_CONVERSION_NO_BREAK + #define SMTG_STRING_CHECK_MSG FDebugPrint +#else + #define SMTG_STRING_CHECK_MSG FDebugBreak +#endif +//----------------------------------------------------------------------------- +bool String::checkToMultiByte (uint32 destCodePage) const +{ + if (!isWide || isEmpty ()) + return true; + +#if DEVELOPMENT && SMTG_STRING_CHECK_CONVERSION + int debugLen = length (); + int debugNonASCII = 0; + for (int32 i = 0; i < length (); i++) + { + if (buffer16[i] > 127) + ++debugNonASCII; + } + + String* backUp = nullptr; + if (debugNonASCII > 0) + backUp = NEW String (*this); +#endif + + // this should be avoided, since it can lead to information loss + bool result = const_cast (*this).toMultiByte (destCodePage); + +#if DEVELOPMENT && SMTG_STRING_CHECK_CONVERSION + if (backUp) + { + String temp (*this); + temp.toWideString (destCodePage); + + if (temp != *backUp) + { + backUp->toMultiByte (kCP_Utf8); + SMTG_STRING_CHECK_MSG ("Indirect string conversion information loss ! %d/%d non ASCII chars: \"%s\" -> \"%s\"\n", debugNonASCII, debugLen, backUp->buffer8, buffer8); + } + else + SMTG_STRING_CHECK_MSG ("Indirect string potential conversion information loss ! %d/%d non ASCII chars result: \"%s\"\n", debugNonASCII, debugLen, buffer8); + + delete backUp; + } +#endif + + return result; +} + +//----------------------------------------------------------------------------- +bool String::toMultiByte (uint32 destCodePage) +{ + if (isWide) + { + if (buffer16 && len > 0) + { + int32 numChars = wideStringToMultiByte (0, buffer16, 0, destCodePage) + sizeof (char8); + char8* newStr = (char8*) malloc (numChars * sizeof (char8)); + if (wideStringToMultiByte (newStr, buffer16, numChars, destCodePage) <= 0) + { + free (newStr); + return false; + } + free (buffer16); + buffer8 = newStr; + isWide = false; + updateLength (); + } + isWide = false; + } + else if (destCodePage != kCP_Default) + { + if (toWideString () == false) + return false; + return toMultiByte (destCodePage); + } + return true; +} + +//----------------------------------------------------------------------------- +void String::fromUTF8 (const char8* utf8String) +{ + assign (utf8String); + toWideString (kCP_Utf8); +} + +//----------------------------------------------------------------------------- +bool String::normalize (UnicodeNormalization n) +{ + if (isWide == false) + return false; + + if (buffer16 == 0) + return true; + +#if SMTG_OS_WINDOWS +#ifdef UNICODE + if (n != kUnicodeNormC) + return false; + + uint32 normCharCount = static_cast (FoldString (MAP_PRECOMPOSED, buffer16, len, 0, 0)); + if (normCharCount == len) + return true; + + char16* newString = (char16*)malloc ((normCharCount + 1) * sizeof (char16)); + uint32 converterCount = static_cast (FoldString (MAP_PRECOMPOSED, buffer16, len, newString, normCharCount + 1)); + if (converterCount != normCharCount) + { + free (newString); + return false; + } + newString [converterCount] = 0; + free (buffer16); + buffer16 = newString; + updateLength (); + return true; +#else + return false; +#endif + +#elif SMTG_OS_MACOS + CFMutableStringRef origStr = (CFMutableStringRef)toCFStringRef (0xFFFF, true); + if (origStr) + { + CFStringNormalizationForm normForm = kCFStringNormalizationFormD; + switch (n) + { + case kUnicodeNormC: normForm = kCFStringNormalizationFormC; break; + case kUnicodeNormD: normForm = kCFStringNormalizationFormD; break; + case kUnicodeNormKC: normForm = kCFStringNormalizationFormKC; break; + case kUnicodeNormKD: normForm = kCFStringNormalizationFormKD; break; + } + CFStringNormalize (origStr, normForm); + bool result = fromCFStringRef (origStr); + CFRelease (origStr); + return result; + } + return false; +#else + return false; +#endif +} + +//----------------------------------------------------------------------------- +void String::tryFreeBuffer () +{ + if (buffer) + { + free (buffer); + buffer = 0; + } +} + +//----------------------------------------------------------------------------- +bool String::resize (uint32 newLength, bool wide, bool fill) +{ + if (newLength == 0) + { + tryFreeBuffer (); + len = 0; + isWide = wide ? 1 : 0; + } + else + { + size_t newCharSize = wide ? sizeof (char16) : sizeof (char8); + size_t oldCharSize = (isWide != 0) ? sizeof (char16) : sizeof (char8); + + size_t newBufferSize = (newLength + 1) * newCharSize; + size_t oldBufferSize = (len + 1) * oldCharSize; + + isWide = wide ? 1 : 0; + + if (buffer) + { + if (newBufferSize != oldBufferSize) + { + void* newstr = realloc (buffer, newBufferSize); + if (newstr == 0) + return false; + buffer = newstr; + if (isWide) + buffer16[newLength] = 0; + else + buffer8[newLength] = 0; + } + else if (wide && newCharSize != oldCharSize) + buffer16[newLength] = 0; + } + else + { + void* newstr = malloc (newBufferSize); + if (newstr == 0) + return false; + buffer = newstr; + if (isWide) + { + buffer16[0] = 0; + buffer16[newLength] = 0; + } + else + { + buffer8[0] = 0; + buffer8[newLength] = 0; + } + } + + if (fill && len < newLength && buffer) + { + if (isWide) + { + char16 c = ' '; + for (uint32 i = len; i < newLength; i++) + buffer16 [i] = c; + } + else + { + memset (buffer8 + len, ' ', newLength - len); + } + } + } + return true; +} + +//----------------------------------------------------------------------------- +bool String::setChar8 (uint32 index, char8 c) +{ + if (index == len && c == 0) + return true; + + if (index >= len) + { + if (c == 0) + { + if (resize (index, isWide, true) == false) + return false; + len = index; + return true; + } + else + { + if (resize (index + 1, isWide, true) == false) + return false; + len = index + 1; + } + } + + if (index < len && buffer) + { + if (isWide) + { + if (c == 0) + buffer16[index] = 0; + else + { + char8 src[] = {c, 0}; + char16 dest[8] = {0}; + if (multiByteToWideString (dest, src, 2) > 0) + buffer16[index] = dest[0]; + } + SMTG_ASSERT (buffer16[len] == 0) + } + else + { + buffer8[index] = c; + SMTG_ASSERT (buffer8[len] == 0) + } + + if (c == 0) + updateLength (); + + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +bool String::setChar16 (uint32 index, char16 c) +{ + if (index == len && c == 0) + return true; + + if (index >= len) + { + if (c == 0) + { + if (resize (index, isWide, true) == false) + return false; + len = index; + return true; + } + else + { + if (resize (index + 1, isWide, true) == false) + return false; + len = index + 1; + } + } + + if (index < len && buffer) + { + if (isWide) + { + buffer16[index] = c; + SMTG_ASSERT (buffer16[len] == 0) + } + else + { + SMTG_ASSERT (buffer8[len] == 0) + char16 src[] = {c, 0}; + char8 dest[8] = {0}; + if (wideStringToMultiByte (dest, src, 2) > 0 && dest[1] == 0) + buffer8[index] = dest[0]; + else + return false; + } + + if (c == 0) + updateLength (); + + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +String& String::assign (const ConstString& str, int32 n) +{ + if (str.isWideString ()) + return assign (str.text16 (), n < 0 ? str.length () : n); + else + return assign (str.text8 (), n < 0 ? str.length () : n); +} + +//----------------------------------------------------------------------------- +String& String::assign (const char8* str, int32 n, bool isTerminated) +{ + if (str == buffer8) + return *this; + + if (isTerminated) + { + uint32 stringLength = (uint32)((str) ? strlen (str) : 0); + n = n < 0 ? stringLength : Min (n, stringLength); + } + else if (n < 0) + return *this; + + if (resize (n, false)) + { + if (buffer8 && n > 0) + { + memcpy (buffer8, str, n * sizeof (char8)); + SMTG_ASSERT (buffer8[n] == 0) + } + isWide = 0; + len = n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::assign (const char16* str, int32 n, bool isTerminated) +{ + if (str == buffer16) + return *this; + + if (isTerminated) + { + uint32 stringLength = (uint32)((str) ? strlen16 (str) : 0); + n = n < 0 ? stringLength : Min (n, stringLength); + } + else if (n < 0) + return *this; + + if (resize (n, true)) + { + if (buffer16 && n > 0) + { + memcpy (buffer16, str, n * sizeof (char16)); + SMTG_ASSERT (buffer16[n] == 0) + } + isWide = 1; + len = n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::assign (char8 c, int32 n) +{ + if (resize (n, false)) + { + if (buffer8 && n > 0) + { + memset (buffer8, c, n * sizeof (char8)); + SMTG_ASSERT (buffer8[n] == 0) + } + isWide = 0; + len = n; + } + return *this; + +} + +//----------------------------------------------------------------------------- +String& String::assign (char16 c, int32 n) +{ + if (resize (n, true)) + { + if (buffer && n > 0) + { + for (int32 i = 0; i < n; i++) + buffer16[i] = c; + SMTG_ASSERT (buffer16[n] == 0) + } + isWide = 1; + len = n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::append (const ConstString& str, int32 n) +{ + if (str.isWideString ()) + return append (str.text16 (), n); + else + return append (str.text8 (), n); +} + +//----------------------------------------------------------------------------- +String& String::append (const char8* str, int32 n) +{ + if (str == buffer8) + return *this; + + if (len == 0) + return assign (str, n); + + if (isWide) + { + String tmp (str); + if (tmp.toWideString () == false) + return *this; + + return append (tmp.buffer16, n); + } + + uint32 stringLength = (uint32)((str) ? strlen (str) : 0); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (n > 0) + { + int32 newlen = n + len; + if (!resize (newlen, false)) + return *this; + + if (buffer) + { + memcpy (buffer8 + len, str, n * sizeof (char8)); + SMTG_ASSERT (buffer8[newlen] == 0) + } + + len += n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::append (const char16* str, int32 n) +{ + if (str == buffer16) + return *this; + + if (len == 0) + return assign (str, n); + + if (!isWide) + { + if (toWideString () == false) + return *this; + } + + uint32 stringLength = (uint32)((str) ? strlen16 (str) : 0); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (n > 0) + { + int32 newlen = n + len; + if (!resize (newlen, true)) + return *this; + + if (buffer16) + { + memcpy (buffer16 + len, str, n * sizeof (char16)); + SMTG_ASSERT (buffer16[newlen] == 0) + } + + len += n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::append (const char8 c, int32 n) +{ + char8 str[] = {c, 0}; + if (n == 1) + { + return append (str, 1); + } + else if (n > 1) + { + if (isWide) + { + String tmp (str); + if (tmp.toWideString () == false) + return *this; + + return append (tmp.buffer16[0], n); + } + + int32 newlen = n + len; + if (!resize (newlen, false)) + return *this; + + if (buffer) + { + memset (buffer8 + len, c, n * sizeof (char8)); + SMTG_ASSERT (buffer8[newlen] == 0) + } + + len += n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::append (const char16 c, int32 n) +{ + if (n == 1) + { + char16 str[] = {c, 0}; + return append (str, 1); + } + else if (n > 1) + { + if (!isWide) + { + if (toWideString () == false) + return *this; + } + + int32 newlen = n + len; + if (!resize (newlen, true)) + return *this; + + if (buffer16) + { + for (int32 i = len; i < newlen; i++) + buffer16[i] = c; + SMTG_ASSERT (buffer16[newlen] == 0) + } + + len += n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::insertAt (uint32 idx, const ConstString& str, int32 n) +{ + if (str.isWideString ()) + return insertAt (idx, str.text16 (), n); + else + return insertAt (idx, str.text8 (), n); +} + +//----------------------------------------------------------------------------- +String& String::insertAt (uint32 idx, const char8* str, int32 n) +{ + if (idx > len) + return *this; + + if (isWide) + { + String tmp (str); + if (tmp.toWideString () == false) + return *this; + return insertAt (idx, tmp.buffer16, n); + } + + uint32 stringLength = (uint32)((str) ? strlen (str) : 0); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (n > 0) + { + int32 newlen = len + n; + if (!resize (newlen, false)) + return *this; + + if (buffer) + { + if (idx < len) + memmove (buffer8 + idx + n, buffer8 + idx, (len - idx) * sizeof (char8)); + memcpy (buffer8 + idx, str, n * sizeof (char8)); + SMTG_ASSERT (buffer8[newlen] == 0) + } + + len += n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::insertAt (uint32 idx, const char16* str, int32 n) +{ + if (idx > len) + return *this; + + if (!isWide) + { + if (toWideString () == false) + return *this; + } + + uint32 stringLength = (uint32)((str) ? strlen16 (str) : 0); + n = n < 0 ? stringLength : Min (n, stringLength); + + if (n > 0) + { + int32 newlen = len + n; + if (!resize (newlen, true)) + return *this; + + if (buffer) + { + if (idx < len) + memmove (buffer16 + idx + n, buffer16 + idx, (len - idx) * sizeof (char16)); + memcpy (buffer16 + idx, str, n * sizeof (char16)); + SMTG_ASSERT (buffer16[newlen] == 0) + } + + len += n; + } + return *this; +} + +//----------------------------------------------------------------------------- +String& String::replace (uint32 idx, int32 n1, const ConstString& str, int32 n2) +{ + if (str.isWideString ()) + return replace (idx, n1, str.text16 (), n2); + else + return replace (idx, n1, str.text8 (), n2); +} + +// "replace" replaces n1 number of characters at the specified index with +// n2 characters from the specified string. +//----------------------------------------------------------------------------- +String& String::replace (uint32 idx, int32 n1, const char8* str, int32 n2) +{ + if (idx > len || str == 0) + return *this; + + if (isWide) + { + String tmp (str); + if (tmp.toWideString () == false) + return *this; + if (tmp.length () == 0 || n2 == 0) + return remove (idx, n1); + return replace (idx, n1, tmp.buffer16, n2); + } + + if (n1 < 0 || idx + n1 > len) + n1 = len - idx; + if (n1 == 0) + return *this; + + uint32 stringLength = (uint32)((str) ? strlen (str) : 0); + n2 = n2 < 0 ? stringLength : Min (n2, stringLength); + + uint32 newlen = len - n1 + n2; + if (newlen > len) + if (!resize (newlen, false)) + return *this; + + if (buffer) + { + memmove (buffer8 + idx + n2, buffer8 + idx + n1, (len - (idx + n1)) * sizeof (char8)); + memcpy (buffer8 + idx, str, n2 * sizeof (char8)); + buffer8[newlen] = 0; // cannot be removed because resize is not called called in all cases (newlen > len) + } + + len = newlen; + + return *this; +} + +//----------------------------------------------------------------------------- +String& String::replace (uint32 idx, int32 n1, const char16* str, int32 n2) +{ + if (idx > len || str == 0) + return *this; + + if (!isWide) + { + if (toWideString () == false) + return *this; + } + + if (n1 < 0 || idx + n1 > len) + n1 = len - idx; + if (n1 == 0) + return *this; + + uint32 stringLength = (uint32)((str) ? strlen16 (str) : 0); + n2 = n2 < 0 ? stringLength : Min (n2, stringLength); + + uint32 newlen = len - n1 + n2; + if (newlen > len) + if (!resize (newlen, true)) + return *this; + + if (buffer) + { + memmove (buffer16 + idx + n2, buffer16 + idx + n1, (len - (idx + n1)) * sizeof (char16)); + memcpy (buffer16 + idx, str, n2 * sizeof (char16)); + buffer16[newlen] = 0; // cannot be removed because resize is not called called in all cases (newlen > len) + } + + len = newlen; + + return *this; +} + +//----------------------------------------------------------------------------- +int32 String::replace (const char8* toReplace, const char8* toReplaceWith, bool all, CompareMode m) +{ + if (toReplace == 0 || toReplaceWith == 0) + return 0; + + int32 result = 0; + + int32 idx = findFirst (toReplace, -1, m); + if (idx > -1) + { + int32 toReplaceLen = static_cast (strlen (toReplace)); + int32 toReplaceWithLen = static_cast (strlen (toReplaceWith)); + while (idx > -1) + { + replace (idx, toReplaceLen, toReplaceWith, toReplaceWithLen); + result++; + + if (all) + idx = findNext (idx + toReplaceWithLen , toReplace, -1, m); + else + break; + } + } + + return result; +} + +//----------------------------------------------------------------------------- +int32 String::replace (const char16* toReplace, const char16* toReplaceWith, bool all, CompareMode m) +{ + if (toReplace == 0 || toReplaceWith == 0) + return 0; + + int32 result = 0; + + int32 idx = findFirst (toReplace, -1, m); + if (idx > -1) + { + int32 toReplaceLen = strlen16 (toReplace); + int32 toReplaceWithLen = strlen16 (toReplaceWith); + while (idx > -1) + { + replace (idx, toReplaceLen, toReplaceWith, toReplaceWithLen); + result++; + + if (all) + idx = findNext (idx + toReplaceWithLen, toReplace, -1, m); + else + break; + } + } + return result; +} + +//----------------------------------------------------------------------------- +template +static bool performReplace (T* str, const T* toReplace, T toReplaceBy) +{ + bool anyReplace = false; + T* p = str; + while (*p) + { + const T* rep = toReplace; + while (*rep) + { + if (*p == *rep) + { + *p = toReplaceBy; + anyReplace = true; + break; + } + rep++; + } + p++; + } + return anyReplace; +} + +//----------------------------------------------------------------------------- +bool String::replaceChars8 (const char8* toReplace, char8 toReplaceBy) +{ + if (isEmpty ()) + return false; + + if (isWide) + { + String toReplaceW (toReplace); + if (toReplaceW.toWideString () == false) + return false; + + char8 src[] = {toReplaceBy, 0}; + char16 dest[2] = {0}; + if (multiByteToWideString (dest, src, 2) > 0) + { + return replaceChars16 (toReplaceW.text16 (), dest[0]); + } + return false; + } + + if (toReplaceBy == 0) + toReplaceBy = ' '; + + return performReplace (buffer8, toReplace, toReplaceBy); +} + +//----------------------------------------------------------------------------- +bool String::replaceChars16 (const char16* toReplace, char16 toReplaceBy) +{ + if (isEmpty ()) + return false; + + if (!isWide) + { + String toReplaceA (toReplace); + if (toReplaceA.toMultiByte () == false) + return false; + + if (toReplaceA.length () > 1) + { + SMTG_WARNING("cannot replace non ASCII chars on non Wide String") + return false; + } + + char16 src[] = {toReplaceBy, 0}; + char8 dest[8] = {0}; + if (wideStringToMultiByte (dest, src, 2) > 0 && dest[1] == 0) + return replaceChars8 (toReplaceA.text8 (), dest[0]); + + return false; + } + + if (toReplaceBy == 0) + toReplaceBy = STR16 (' '); + + return performReplace (buffer16, toReplace, toReplaceBy); +} + +// "remove" removes the specified number of characters from the string +// starting at the specified index. +//----------------------------------------------------------------------------- +String& String::remove (uint32 idx, int32 n) +{ + if (isEmpty () || idx >= len || n == 0) + return *this; + + if ((idx + n > len) || n < 0) + n = len - idx; + else + { + int32 toMove = len - idx - n; + if (buffer) + { + if (isWide) + memmove (buffer16 + idx, buffer16 + idx + n, toMove * sizeof (char16)); + else + memmove (buffer8 + idx, buffer8 + idx + n, toMove * sizeof (char8)); + } + } + + resize (len - n, isWide); + updateLength (); + + return *this; +} + +//----------------------------------------------------------------------------- +bool String::removeSubString (const ConstString& subString, bool allOccurences) +{ + bool removed = false; + while (!removed || allOccurences) + { + int32 idx = findFirst (subString); + if (idx < 0) + break; + remove (idx, subString.length ()); + removed = true; + } + return removed; +} + +//----------------------------------------------------------------------------- +template +static uint32 performTrim (T* str, uint32 length, F func, bool funcResult) +{ + uint32 toRemoveAtHead = 0; + uint32 toRemoveAtTail = 0; + + T* p = str; + + while ((*p) && ((func (*p) != 0) == funcResult)) + p++; + + toRemoveAtHead = static_cast (p - str); + + if (toRemoveAtHead < length) + { + p = str + length - 1; + + while (((func (*p) != 0) == funcResult) && (p > str)) + { + p--; + toRemoveAtTail++; + } + } + + uint32 newLength = length - (toRemoveAtHead + toRemoveAtTail); + if (newLength != length) + { + if (toRemoveAtHead) + memmove (str, str + toRemoveAtHead, newLength * sizeof (T)); + } + return newLength; +} + +// "trim" trims the leading and trailing unwanted characters from the string. +//----------------------------------------------------------------------------- +bool String::trim (String::CharGroup group) +{ + if (isEmpty ()) + return false; + + uint32 newLength; + + switch (group) + { + case kSpace: + if (isWide) + newLength = performTrim (buffer16, len, iswspace, true); + else + newLength = performTrim (buffer8, len, isspace, true); + break; + + case kNotAlphaNum: + if (isWide) + newLength = performTrim (buffer16, len, iswalnum, false); + else + newLength = performTrim (buffer8, len, isalnum, false); + break; + + case kNotAlpha: + if (isWide) + newLength = performTrim (buffer16, len, iswalpha, false); + else + newLength = performTrim (buffer8, len, isalpha, false); + break; + + default: // Undefined enum value + return false; + } + + if (newLength != len) + { + resize (newLength, isWide); + len = newLength; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +template +static uint32 performRemove (T* str, uint32 length, F func, bool funcResult) +{ + T* p = str; + + while (*p) + { + if ((func (*p) != 0) == funcResult) + { + size_t toMove = length - (p - str); + memmove (p, p + 1, toMove * sizeof (T)); + length--; + } + else + p++; + } + return length; +} +//----------------------------------------------------------------------------- +void String::removeChars (CharGroup group) +{ + if (isEmpty ()) + return; + + uint32 newLength; + + switch (group) + { + case kSpace: + if (isWide) + newLength = performRemove (buffer16, len, iswspace, true); + else + newLength = performRemove (buffer8, len, isspace, true); + break; + + case kNotAlphaNum: + if (isWide) + newLength = performRemove (buffer16, len, iswalnum, false); + else + newLength = performRemove (buffer8, len, isalnum, false); + break; + + case kNotAlpha: + if (isWide) + newLength = performRemove (buffer16, len, iswalpha, false); + else + newLength = performRemove (buffer8, len, isalpha, false); + break; + + default: // Undefined enum value + return; + } + + if (newLength != len) + { + resize (newLength, isWide); + len = newLength; + } +} + +//----------------------------------------------------------------------------- +template +static uint32 performRemoveChars (T* str, uint32 length, const T* toRemove) +{ + T* p = str; + + while (*p) + { + bool found = false; + const T* rem = toRemove; + while (*rem) + { + if (*p == *rem) + { + found = true; + break; + } + rem++; + } + + if (found) + { + size_t toMove = length - (p - str); + memmove (p, p + 1, toMove * sizeof (T)); + length--; + } + else + p++; + } + return length; +} + +//----------------------------------------------------------------------------- +bool String::removeChars8 (const char8* toRemove) +{ + if (isEmpty () || toRemove == 0) + return true; + + if (isWide) + { + String wStr (toRemove); + if (wStr.toWideString () == false) + return false; + return removeChars16 (wStr.text16 ()); + } + + uint32 newLength = performRemoveChars (buffer8, len, toRemove); + + if (newLength != len) + { + resize (newLength, false); + len = newLength; + } + return true; +} + +//----------------------------------------------------------------------------- +bool String::removeChars16 (const char16* toRemove) +{ + if (isEmpty () || toRemove == 0) + return true; + + if (!isWide) + { + String str8 (toRemove); + if (str8.toMultiByte () == false) + return false; + return removeChars8 (str8.text8 ()); + } + + uint32 newLength = performRemoveChars (buffer16, len, toRemove); + + if (newLength != len) + { + resize (newLength, true); + len = newLength; + } + return true; +} + +//----------------------------------------------------------------------------- +String& String::printf (const char8* format, ...) +{ + char8 string[kPrintfBufferSize]; + + va_list marker; + va_start (marker, format); + + vsnprintf (string, kPrintfBufferSize-1, format, marker); + return assign (string); +} + + +//----------------------------------------------------------------------------- +String& String::printf (const char16* format, ...) +{ + char16 string[kPrintfBufferSize]; + + va_list marker; + va_start (marker, format); + + vsnwprintf (string, kPrintfBufferSize-1, format, marker); + return assign (string); +} + +//----------------------------------------------------------------------------- +String& String::vprintf (const char8* format, va_list args) +{ + char8 string[kPrintfBufferSize]; + + vsnprintf (string, kPrintfBufferSize-1, format, args); + return assign (string); +} + +//----------------------------------------------------------------------------- +String& String::vprintf (const char16* format, va_list args) +{ + char16 string[kPrintfBufferSize]; + + vsnwprintf (string, kPrintfBufferSize-1, format, args); + return assign (string); +} + +//----------------------------------------------------------------------------- +String& String::printInt64 (int64 value) +{ + if (isWide) + { + #if SMTG_CPP11 + return String::printf (STR("%") STR(FORMAT_INT64A), value); + #else + return String::printf (STR("%" FORMAT_INT64A), value); + #endif + } + else + return String::printf ("%" FORMAT_INT64A, value); +} + +//----------------------------------------------------------------------------- +String& String::printFloat (double value) +{ + if (isWide) + { + char16 string[kPrintfBufferSize]; + sprintf16 (string, STR16 ("%lf"), value); + + char16* pointPtr = strrchr16 (string, STR ('.')); + if (pointPtr) + { + pointPtr++; // keep 1st digit after point + int32 index = strlen16 (string) - 1; + char16 zero = STR16 ('0'); + while (pointPtr < (string + index)) + { + if (string[index] == zero) + { + string[index] = 0; + index--; + } + else + break; + } + } + return assign (string); + } + else + { + char8 string[kPrintfBufferSize]; + sprintf (string, "%lf", value); + + char8* pointPtr = strrchr (string, '.'); + if (pointPtr) + { + pointPtr++; // keep 1st digit after point + int32 index = (int32) (strlen (string) - 1); + while (pointPtr < (string + index)) + { + if (string[index] == '0') + { + string[index] = 0; + index--; + } + else + break; + } + } + return assign (string); + } +} + +//----------------------------------------------------------------------------- +bool String::incrementTrailingNumber (uint32 width, tchar separator, uint32 minNumber, bool applyOnlyFormat) +{ + if (width > 32) + return false; + + int64 number = 1; + int32 index = getTrailingNumberIndex (); + if (index >= 0) + { + if (scanInt64 (number, index)) + if (!applyOnlyFormat) + number++; + + if (separator != 0 && index > 0 && testChar (index - 1, separator) == true) + index--; + + remove (index); + } + + if (number < minNumber) + number = minNumber; + + if (isWide) + { + char16 format[64]; + char16 trail[128]; + if (separator && isEmpty () == false) + { + sprintf16 (format, STR16 ("%%c%%0%uu"), width); + sprintf16 (trail, format, separator, (uint32) number); + } + else + { + sprintf16 (format, STR16 ("%%0%uu"), width); + sprintf16 (trail, format, (uint32) number); + } + append (trail); + } + else + { + char format[64]; + char trail[128]; + if (separator && isEmpty () == false) + { + sprintf (format, "%%c%%0%uu", width); + sprintf (trail, format, separator, (uint32) number); + } + else + { + sprintf (format, "%%0%uu", width); + sprintf (trail, format, (uint32) number); + } + append (trail); + } + + return true; +} + +//----------------------------------------------------------------------------- +void String::toLower (uint32 index) +{ + if (buffer && index < len) + { + if (isWide) + buffer16[index] = ConstString::toLower (buffer16[index]); + else + buffer8[index] = ConstString::toLower (buffer8[index]); + } +} + +//----------------------------------------------------------------------------- +void String::toLower () +{ + int32 i = len; + if (buffer && i > 0) + { + if (isWide) + { +#if SMTG_OS_MACOS + CFMutableStringRef cfStr = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, (UniChar*)buffer16, len, len+1, kCFAllocatorNull); + CFStringLowercase (cfStr, NULL); + CFRelease (cfStr); +#else + char16* c = buffer16; + while (i--) + { + *c = ConstString::toLower (*c); + c++; + } +#endif + } + else + { + char8* c = buffer8; + while (i--) + { + *c = ConstString::toLower (*c); + c++; + } + } + } +} + +//----------------------------------------------------------------------------- +void String::toUpper (uint32 index) +{ + if (buffer && index < len) + { + if (isWide) + buffer16[index] = ConstString::toUpper (buffer16[index]); + else + buffer8[index] = ConstString::toUpper (buffer8[index]); + } +} + +//----------------------------------------------------------------------------- +void String::toUpper () +{ + int32 i = len; + if (buffer && i > 0) + { + if (isWide) + { +#if SMTG_OS_MACOS + CFMutableStringRef cfStr = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, (UniChar*)buffer16, len, len+1, kCFAllocatorNull); + CFStringUppercase (cfStr, NULL); + CFRelease (cfStr); +#else + char16* c = buffer16; + while (i--) + { + *c = ConstString::toUpper (*c); + c++; + } +#endif + } + else + { + char8* c = buffer8; + while (i--) + { + *c = ConstString::toUpper (*c); + c++; + } + } + } +} + +//----------------------------------------------------------------------------- +bool String::fromVariant (const FVariant& var) +{ + switch (var.getType ()) + { + case FVariant::kString8: + assign (var.getString8 ()); + return true; + + case FVariant::kString16: + assign (var.getString16 ()); + return true; + + case FVariant::kFloat: + printFloat (var.getFloat ()); + return true; + + case FVariant::kInteger: + printInt64 (var.getInt ()); + return true; + + default: + remove (); + } + return false; +} + +//----------------------------------------------------------------------------- +void String::toVariant (FVariant& var) const +{ + if (isWide) + { + var.setString16 (text16 ()); + } + else + { + var.setString8 (text8 ()); + } +} + +//----------------------------------------------------------------------------- +bool String::fromAttributes (IAttributes* a, IAttrID attrID) +{ + FVariant variant; + if (a->get (attrID, variant) == kResultTrue) + return fromVariant (variant); + return false; +} + +//----------------------------------------------------------------------------- +bool String::toAttributes (IAttributes* a, IAttrID attrID) +{ + FVariant variant; + toVariant (variant); + if (a->set (attrID, variant) == kResultTrue) + return true; + return false; +} + +// "swapContent" swaps ownership of the strings pointed to +//----------------------------------------------------------------------------- +void String::swapContent (String& s) +{ + void* tmp = s.buffer; + uint32 tmpLen = s.len; + bool tmpWide = s.isWide; + s.buffer = buffer; + s.len = len; + s.isWide = isWide; + buffer = tmp; + len = tmpLen; + isWide = tmpWide; +} + +//----------------------------------------------------------------------------- +void String::take (String& other) +{ + resize (0, other.isWide); + buffer = other.buffer; + len = other.len; + + other.buffer = 0; + other.len = 0; +} + +//----------------------------------------------------------------------------- +void String::take (void* b, bool wide) +{ + resize (0, wide); + buffer = b; + isWide = wide; + updateLength (); +} + +//----------------------------------------------------------------------------- +void* String::pass () +{ + void* res = buffer; + len = 0; + buffer = 0; + return res; +} + +//----------------------------------------------------------------------------- +void String::passToVariant (FVariant& var) +{ + void* passed = pass (); + + if (isWide) + { + if (passed) + { + var.setString16 ((const char16*)passed); + var.setOwner (true); + } + else + var.setString16 (kEmptyString16); + } + else + { + if (passed) + { + var.setString8 ((const char8*)passed); + var.setOwner (true); + } + else + var.setString8 (kEmptyString8); + } +} + + +//----------------------------------------------------------------------------- +unsigned char* String::toPascalString (unsigned char* buf) +{ + if (buffer) + { + if (isWide) + { + String tmp (*this); + tmp.toMultiByte (); + return tmp.toPascalString (buf); + } + + int32 length = len; + if (length > 255) + length = 255; + buf[0] = (uint8)length; + while (length >= 0) + { + buf[length + 1] = buffer8[length]; + length--; + } + return buf; + } + else + { + *buf = 0; + return buf; + } +} + +//----------------------------------------------------------------------------- +const String& String::fromPascalString (const unsigned char* buf) +{ + resize (0, false); + isWide = 0; + int32 length = buf[0]; + resize (length + 1, false); + buffer8[length] = 0; // cannot be removed, because we only do the 0-termination for multibyte buffer8 + while (--length >= 0) + buffer8[length] = buf[length + 1]; + len = buf[0]; + return *this; +} + +#if SMTG_OS_MACOS + +//----------------------------------------------------------------------------- +bool String::fromCFStringRef (const void* cfStr, uint32 encoding) +{ + if (cfStr == 0) + return false; + + CFStringRef strRef = (CFStringRef)cfStr; + if (isWide) + { + CFRange range = { 0, CFStringGetLength (strRef)}; + CFIndex usedBytes; + if (resize (static_cast (range.length + 1), true)) + { + if (encoding == 0xFFFF) + encoding = kCFStringEncodingUnicode; + if (CFStringGetBytes (strRef, range, encoding, ' ', false, (UInt8*)buffer16, range.length * 2, &usedBytes) > 0) + { + buffer16[usedBytes/2] = 0; + this->len = strlen16 (buffer16); + return true; + } + } + } + else + { + if (cfStr == 0) + return false; + if (encoding == 0xFFFF) + encoding = kCFStringEncodingASCII; + int32 len = static_cast (CFStringGetLength (strRef) * 2); + if (resize (++len, false)) + { + if (CFStringGetCString (strRef, buffer8, len, encoding)) + { + this->len = static_cast (strlen (buffer8)); + return true; + } + } + } + + return false; +} + +//----------------------------------------------------------------------------- +void* ConstString::toCFStringRef (uint32 encoding, bool mutableCFString) const +{ + if (mutableCFString) + { + CFMutableStringRef str = CFStringCreateMutable (kCFAllocator, 0); + if (isWide) + { + CFStringAppendCharacters (str, (const UniChar *)buffer16, len); + return str; + } + else + { + if (encoding == 0xFFFF) + encoding = kCFStringEncodingASCII; + CFStringAppendCString (str, buffer8, encoding); + return str; + } + } + else + { + if (isWide) + { + if (encoding == 0xFFFF) + encoding = kCFStringEncodingUnicode; + return (void*)CFStringCreateWithBytes (kCFAllocator, (const unsigned char*)buffer16, len * 2, encoding, false); + } + else + { + if (encoding == 0xFFFF) + encoding = kCFStringEncodingASCII; + if (buffer8) + return (void*)CFStringCreateWithCString (kCFAllocator, buffer8, encoding); + else + return (void*)CFStringCreateWithCString (kCFAllocator, "", encoding); + } + } + return 0; +} + +#endif + +//----------------------------------------------------------------------------- +uint32 hashString8 (const char8* s, uint32 m) +{ + uint32 h = 0; + if (s) + { + for (h = 0; *s != '\0'; s++) + h = (64 * h + *s) % m; + } + return h; +} + +//----------------------------------------------------------------------------- +uint32 hashString16 (const char16* s, uint32 m) +{ + uint32 h = 0; + if (s) + { + for (h = 0; *s != 0; s++) + h = (64 * h + *s) % m; + } + return h; +} + +//------------------------------------------------------------------------ +template int32 tstrnatcmp (const T* s1, const T* s2, bool caseSensitive = true) +{ + if (s1 == 0 && s2 == 0) + return 0; + else if (s1 == 0) + return -1; + else if (s2 == 0) + return 1; + + while (*s1 && *s2) + { + if (ConstString::isCharDigit (*s1) && ConstString::isCharDigit (*s2)) + { + int32 s1LeadingZeros = 0; + while (*s1 == '0') + { + s1++; // skip leading zeros + s1LeadingZeros++; + } + int32 s2LeadingZeros = 0; + while (*s2 == '0') + { + s2++; // skip leading zeros + s2LeadingZeros++; + } + + int32 countS1Digits = 0; + while (*(s1 + countS1Digits) && ConstString::isCharDigit (*(s1 + countS1Digits))) + countS1Digits++; + int32 countS2Digits = 0; + while (*(s2 + countS2Digits) && ConstString::isCharDigit (*(s2 + countS2Digits))) + countS2Digits++; + + if (countS1Digits != countS2Digits) + return countS1Digits - countS2Digits; // one number is longer than the other + + for (int32 i = 0; i < countS1Digits; i++) + { + // countS1Digits == countS2Digits + if (*s1 != *s2) + return (int32)(*s1 - *s2); // the digits differ + s1++; + s2++; + } + + if (s1LeadingZeros != s2LeadingZeros) + return s1LeadingZeros - s2LeadingZeros; // differentiate by the number of leading zeros + } + else + { + if (caseSensitive == false) + { + T srcToUpper = toupper (*s1); + T dstToUpper = toupper (*s2); + if (srcToUpper != dstToUpper) + return (int32)(srcToUpper - dstToUpper); + } + else if (*s1 != *s2) + return (int32)(*s1 - *s2); + + s1++; + s2++; + } + } + + if (*s1 == 0 && *s2 == 0) + return 0; + else if (*s1 == 0) + return -1; + else if (*s2 == 0) + return 1; + else + return (int32)(*s1 - *s2); +} + +//------------------------------------------------------------------------ +int32 strnatcmp8 (const char8* s1, const char8* s2, bool caseSensitive /*= true*/) +{ + return tstrnatcmp (s1, s2, caseSensitive); +} + +//------------------------------------------------------------------------ +int32 strnatcmp16 (const char16* s1, const char16* s2, bool caseSensitive /*= true*/) +{ + return tstrnatcmp (s1, s2, caseSensitive); +} + +//----------------------------------------------------------------------------- +// StringObject Implementation +//----------------------------------------------------------------------------- +void PLUGIN_API StringObject::setText (const char8* text) +{ + assign (text); +} + +//----------------------------------------------------------------------------- +void PLUGIN_API StringObject::setText8 (const char8* text) +{ + assign (text); +} + +//----------------------------------------------------------------------------- +void PLUGIN_API StringObject::setText16 (const char16* text) +{ + assign (text); +} + +//----------------------------------------------------------------------------- +const char8* PLUGIN_API StringObject::getText8 () +{ + return text8 (); +} + +//----------------------------------------------------------------------------- +const char16* PLUGIN_API StringObject::getText16 () +{ + return text16 (); +} + +//----------------------------------------------------------------------------- +void PLUGIN_API StringObject::take (void* s, bool _isWide) +{ + String::take (s, _isWide); +} + +//----------------------------------------------------------------------------- +bool PLUGIN_API StringObject::isWideString () const +{ + return String::isWideString (); +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.h new file mode 100644 index 0000000000..12cc3de47f --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/fstring.h @@ -0,0 +1,747 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/fstring.h +// Created by : Steinberg, 2008 +// Description : String class +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/ftypes.h" +#include "pluginterfaces/base/fstrdefs.h" +#include "pluginterfaces/base/istringresult.h" +#include "pluginterfaces/base/ipersistent.h" + +#include "base/source/fobject.h" + +#include + +namespace Steinberg { + +class FVariant; +class String; + +#ifdef UNICODE +static const bool kWideStringDefault = true; +#else +static const bool kWideStringDefault = false; +#endif + +static const uint16 kBomUtf16 = 0xFEFF; ///< UTF16 Byte Order Mark +static const char8* const kBomUtf8 = "\xEF\xBB\xBF"; ///< UTF8 Byte Order Mark +static const int32 kBomUtf8Length = 3; + + +enum MBCodePage +{ + kCP_ANSI = 0, ///< Default ANSI codepage. + kCP_MAC_ROMAN = 2, ///< Default Mac codepage. + + kCP_ANSI_WEL = 1252, ///< West European Latin Encoding. + kCP_MAC_CEE = 10029, ///< Mac Central European Encoding. + kCP_Utf8 = 65001, ///< UTF8 Encoding. + kCP_ShiftJIS = 932, ///< Shifted Japan Industrial Standard Encoding. + kCP_US_ASCII = 20127, ///< US-ASCII (7-bit). + + kCP_Default = kCP_ANSI ///< Default ANSI codepage. +}; + +enum UnicodeNormalization +{ + kUnicodeNormC, ///< Unicode normalization Form C, canonical composition. + kUnicodeNormD, ///< Unicode normalization Form D, canonical decomposition. + kUnicodeNormKC, ///< Unicode normalization form KC, compatibility composition. + kUnicodeNormKD ///< Unicode normalization form KD, compatibility decomposition. +}; + +//------------------------------------------------------------------------ +// Helper functions to create hash codes from string data. +//------------------------------------------------------------------------ +extern uint32 hashString8 (const char8* s, uint32 m); +extern uint32 hashString16 (const char16* s, uint32 m); +inline uint32 hashString (const tchar* s, uint32 m) +{ +#ifdef UNICODE + return hashString16 (s, m); +#else + return hashString8 (s, m); +#endif +} + + +//----------------------------------------------------------------------------- +/** Invariant String. +@ingroup adt + +A base class which provides methods to work with its +member string. Neither of the operations allows modifying the member string and +that is why all operation are declared as const. + +There are operations for access, comparison, find, numbers and conversion. + +Almost all operations exist in three versions for char8, char16 and the +polymorphic type tchar. The type tchar can either be char8 or char16 depending +on whether UNICODE is activated or not.*/ +//----------------------------------------------------------------------------- +class ConstString +{ +public: +//----------------------------------------------------------------------------- + ConstString (const char8* str, int32 length = -1); ///< Assign from string of type char8 (length=-1: all) + ConstString (const char16* str, int32 length = -1); ///< Assign from string of type char16 (length=-1: all) + ConstString (const ConstString& str, int32 offset = 0, int32 length = -1); ///< Copy constructor (length=-1: all). + ConstString (const FVariant& var); ///< Assign a string from FVariant + ConstString (); + virtual ~ConstString () {} ///< Destructor. + + // access ----------------------------------------------------------------- + virtual int32 length () const {return static_cast (len);} ///< Return length of string + inline bool isEmpty () const {return buffer == 0 || len == 0;} ///< Return true if string is empty + + operator const char8* () const {return text8 ();} ///< Returns pointer to string of type char8 (no modification allowed) + operator const char16* () const {return text16 ();} ///< Returns pointer to string of type char16(no modification allowed) + inline tchar operator[] (short idx) const {return getChar (static_cast (idx));} ///< Returns character at 'idx' + inline tchar operator[] (long idx) const {return getChar (static_cast (idx));} + inline tchar operator[] (int idx) const {return getChar (static_cast (idx));} + inline tchar operator[] (unsigned short idx) const {return getChar (idx);} + inline tchar operator[] (unsigned long idx) const {return getChar (static_cast (idx));} + inline tchar operator[] (unsigned int idx) const {return getChar (idx);} + + inline virtual const char8* text8 () const; ///< Returns pointer to string of type char8 + inline virtual const char16* text16 () const; ///< Returns pointer to string of type char16 + inline virtual const tchar* text () const; ///< Returns pointer to string of type tchar + inline virtual const void* ptr () const {return buffer;} ///< Returns pointer to string of type void + + inline virtual char8 getChar8 (uint32 index) const; ///< Returns character of type char16 at 'index' + inline virtual char16 getChar16 (uint32 index) const; ///< Returns character of type char8 at 'index' + inline tchar getChar (uint32 index) const; ///< Returns character of type tchar at 'index' + inline tchar getCharAt (uint32 index) const; ///< Returns character of type tchar at 'index', no conversion! + + bool testChar8 (uint32 index, char8 c) const; ///< Returns true if character is equal at position 'index' + bool testChar16 (uint32 index, char16 c) const; + inline bool testChar (uint32 index, char8 c) const {return testChar8 (index, c);} + inline bool testChar (uint32 index, char16 c) const {return testChar16 (index, c);} + + bool extract (String& result, uint32 idx, int32 n = -1) const; ///< Get n characters long substring starting at index (n=-1: until end) + int32 copyTo8 (char8* str, uint32 idx = 0, int32 n = -1) const; + int32 copyTo16 (char16* str, uint32 idx = 0, int32 n = -1) const; + int32 copyTo (tchar* str, uint32 idx = 0, int32 n = -1) const; + void copyTo (IStringResult* result) const; ///< Copies whole member string + void copyTo (IString& string) const; ///< Copies whole member string + + inline uint32 hash (uint32 tsize) const + { + return isWide ? hashString16 (buffer16, tsize) : hashString8 (buffer8, tsize) ; + } + //------------------------------------------------------------------------- + + // compare ---------------------------------------------------------------- + enum CompareMode + { + kCaseSensitive, ///< Comparison is done with regard to character's case + kCaseInsensitive ///< Comparison is done without regard to character's case + }; + + int32 compareAt (uint32 index, const ConstString& str, int32 n = -1, CompareMode m = kCaseSensitive) const; ///< Compare n characters of str with n characters of this starting at index (return: see above) + int32 compare (const ConstString& str, int32 n, CompareMode m = kCaseSensitive) const; ///< Compare n characters of str with n characters of this (return: see above) + int32 compare (const ConstString& str, CompareMode m = kCaseSensitive) const; ///< Compare all characters of str with this (return: see above) + + int32 naturalCompare (const ConstString& str, CompareMode mode = kCaseSensitive) const; + + bool startsWith (const ConstString& str, CompareMode m = kCaseSensitive) const; ///< Check if this starts with str + bool endsWith (const ConstString& str, CompareMode m = kCaseSensitive) const; ///< Check if this ends with str + bool contains (const ConstString& str, CompareMode m = kCaseSensitive) const; ///< Check if this contains str + + // static methods + static bool isCharSpace (char8 character); ///< Returns true if character is a space + static bool isCharSpace (char16 character); ///< @copydoc isCharSpace(const char8) + static bool isCharAlpha (char8 character); ///< Returns true if character is an alphabetic character + static bool isCharAlpha (char16 character); ///< @copydoc isCharAlpha(const char8) + static bool isCharAlphaNum (char8 character); ///< Returns true if character is an alphanumeric character + static bool isCharAlphaNum (char16 character); ///< @copydoc isCharAlphaNum(const char8) + static bool isCharDigit (char8 character); ///< Returns true if character is a number + static bool isCharDigit (char16 character); ///< @copydoc isCharDigit(const char8) + static bool isCharAscii (char8 character); ///< Returns true if character is in ASCII range + static bool isCharAscii (char16 character); ///< Returns true if character is in ASCII range + static bool isCharUpper (char8 character); + static bool isCharUpper (char16 character); + static bool isCharLower (char8 character); + static bool isCharLower (char16 character); + //------------------------------------------------------------------------- + + /** @name Find first occurrence of n characters of str in this (n=-1: all) ending at endIndex (endIndex = -1: all)*/ + ///@{ + inline int32 findFirst (const ConstString& str, int32 n = -1, CompareMode m = kCaseSensitive, int32 endIndex = -1) const {return findNext (0, str, n, m, endIndex);} + inline int32 findFirst (char8 c, CompareMode m = kCaseSensitive, int32 endIndex = -1) const {return findNext (0, c, m, endIndex);} + inline int32 findFirst (char16 c, CompareMode m = kCaseSensitive, int32 endIndex = -1) const {return findNext (0, c, m, endIndex);} + ///@} + /** @name Find next occurrence of n characters of str starting at startIndex in this (n=-1: all) ending at endIndex (endIndex = -1: all)*/ + ///@{ + int32 findNext (int32 startIndex, const ConstString& str, int32 n = -1, CompareMode = kCaseSensitive, int32 endIndex = -1) const; + int32 findNext (int32 startIndex, char8 c, CompareMode = kCaseSensitive, int32 endIndex = -1) const; + int32 findNext (int32 startIndex, char16 c, CompareMode = kCaseSensitive, int32 endIndex = -1) const; + ///@} + /** @name Find previous occurrence of n characters of str starting at startIndex in this (n=-1: all) */ + ///@{ + int32 findPrev (int32 startIndex, const ConstString& str, int32 n = -1, CompareMode = kCaseSensitive) const; + int32 findPrev (int32 startIndex, char8 c, CompareMode = kCaseSensitive) const; + int32 findPrev (int32 startIndex, char16 c, CompareMode = kCaseSensitive) const; + ///@} + + inline int32 findLast (const ConstString& str, int32 n = -1, CompareMode m = kCaseSensitive) const {return findPrev (-1, str, n, m);} ///< Find last occurrence of n characters of str in this (n=-1: all) + inline int32 findLast (char8 c, CompareMode m = kCaseSensitive) const {return findPrev (-1, c, m);} + inline int32 findLast (char16 c, CompareMode m = kCaseSensitive) const {return findPrev (-1, c, m);} + + int32 countOccurences (char8 c, uint32 startIndex, CompareMode = kCaseSensitive) const; ///< Counts occurences of c within this starting at index + int32 countOccurences (char16 c, uint32 startIndex, CompareMode = kCaseSensitive) const; + int32 getFirstDifferent (const ConstString& str, CompareMode = kCaseSensitive) const; ///< Returns position of first different character + //------------------------------------------------------------------------- + + // numbers ---------------------------------------------------------------- + bool isDigit (uint32 index) const; ///< Returns true if character at position is a digit + bool scanFloat (double& value, uint32 offset = 0, bool scanToEnd = true) const; ///< Converts string to double value starting at offset + bool scanInt64 (int64& value, uint32 offset = 0, bool scanToEnd = true) const; ///< Converts string to int64 value starting at offset + bool scanUInt64 (uint64& value, uint32 offset = 0, bool scanToEnd = true) const; ///< Converts string to uint64 value starting at offset + bool scanInt32 (int32& value, uint32 offset = 0, bool scanToEnd = true) const; ///< Converts string to int32 value starting at offset + bool scanUInt32 (uint32& value, uint32 offset = 0, bool scanToEnd = true) const; ///< Converts string to uint32 value starting at offset + bool scanHex (uint8& value, uint32 offset = 0, bool scanToEnd = true) const; ///< Converts string to hex/uint8 value starting at offset + + int32 getTrailingNumberIndex (uint32 width = 0) const; ///< Returns start index of trailing number + int64 getTrailingNumber (int64 fallback = 0) const; ///< Returns result of scanInt64 or the fallback + int64 getNumber () const; ///< Returns result of scanInt64 + + // static methods + static bool scanInt64_8 (const char8* text, int64& value, bool scanToEnd = true); ///< Converts string of type char8 to int64 value + static bool scanInt64_16 (const char16* text, int64& value, bool scanToEnd = true); ///< Converts string of type char16 to int64 value + static bool scanInt64 (const tchar* text, int64& value, bool scanToEnd = true); ///< Converts string of type tchar to int64 value + + static bool scanUInt64_8 (const char8* text, uint64& value, bool scanToEnd = true); ///< Converts string of type char8 to uint64 value + static bool scanUInt64_16 (const char16* text, uint64& value, bool scanToEnd = true); ///< Converts string of type char16 to uint64 value + static bool scanUInt64 (const tchar* text, uint64& value, bool scanToEnd = true); ///< Converts string of type tchar to uint64 value + + static bool scanInt32_8 (const char8* text, int32& value, bool scanToEnd = true); ///< Converts string of type char8 to int32 value + static bool scanInt32_16 (const char16* text, int32& value, bool scanToEnd = true); ///< Converts string of type char16 to int32 value + static bool scanInt32 (const tchar* text, int32& value, bool scanToEnd = true); ///< Converts string of type tchar to int32 value + + static bool scanUInt32_8 (const char8* text, uint32& value, bool scanToEnd = true); ///< Converts string of type char8 to int32 value + static bool scanUInt32_16 (const char16* text, uint32& value, bool scanToEnd = true); ///< Converts string of type char16 to int32 value + static bool scanUInt32 (const tchar* text, uint32& value, bool scanToEnd = true); ///< Converts string of type tchar to int32 value + + static bool scanHex_8 (const char8* text, uint8& value, bool scanToEnd = true); ///< Converts string of type char8 to hex/unit8 value + static bool scanHex_16 (const char16* text, uint8& value, bool scanToEnd = true); ///< Converts string of type char16 to hex/unit8 value + static bool scanHex (const tchar* text, uint8& value, bool scanToEnd = true); ///< Converts string of type tchar to hex/unit8 value + //------------------------------------------------------------------------- + + // conversion ------------------------------------------------------------- + void toVariant (FVariant& var) const; + + static char8 toLower (char8 c); ///< Converts to lower case + static char8 toUpper (char8 c); ///< Converts to upper case + static char16 toLower (char16 c); + static char16 toUpper (char16 c); + + static int32 multiByteToWideString (char16* dest, const char8* source, int32 wcharCount, uint32 sourceCodePage = kCP_Default); ///< If dest is zero, this returns the maximum number of bytes needed to convert source + static int32 wideStringToMultiByte (char8* dest, const char16* source, int32 char8Count, uint32 destCodePage = kCP_Default); ///< If dest is zero, this returns the maximum number of bytes needed to convert source + + bool isWideString () const {return isWide != 0;} ///< Returns true if string is wide + bool isAsciiString () const; ///< Checks if all characters in string are in ascii range + + bool isNormalized (UnicodeNormalization = kUnicodeNormC); ///< On PC only kUnicodeNormC is working + +#if SMTG_OS_MACOS + virtual void* toCFStringRef (uint32 encoding = 0xFFFF, bool mutableCFString = false) const; ///< CFString conversion +#endif +//------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +protected: + + union + { + void* buffer; + char8* buffer8; + char16* buffer16; + }; + uint32 len : 30; + uint32 isWide : 1; +}; + +//----------------------------------------------------------------------------- +/** String. +@ingroup adt + +Extends class ConstString by operations which allow modifications. + +\see ConstString */ +//----------------------------------------------------------------------------- +class String : public ConstString +{ +public: +//----------------------------------------------------------------------------- + String (); + String (const char8* str, MBCodePage codepage, int32 n = -1, bool isTerminated = true); ///< assign n characters of str and convert to wide string by using the specified codepage + String (const char8* str, int32 n = -1, bool isTerminated = true); ///< assign n characters of str (-1: all) + String (const char16* str, int32 n = -1, bool isTerminated = true); ///< assign n characters of str (-1: all) + String (const String& str, int32 n = -1); ///< assign n characters of str (-1: all) + String (const ConstString& str, int32 n = -1); ///< assign n characters of str (-1: all) + String (const FVariant& var); ///< assign from FVariant + String (IString* str); ///< assign from IString + ~String (); + +#if SMTG_CPP11_STDLIBSUPPORT + String (String&& str); + String& operator= (String&& str); +#endif + + // access------------------------------------------------------------------ + void updateLength (); ///< Call this when the string is truncated outside (not recommended though) + virtual const char8* text8 () const SMTG_OVERRIDE; + virtual const char16* text16 () const SMTG_OVERRIDE; + virtual char8 getChar8 (uint32 index) const SMTG_OVERRIDE; + virtual char16 getChar16 (uint32 index) const SMTG_OVERRIDE; + + bool setChar8 (uint32 index, char8 c); + bool setChar16 (uint32 index, char16 c); + inline bool setChar (uint32 index, char8 c) {return setChar8 (index, c);} + inline bool setChar (uint32 index, char16 c) {return setChar16 (index, c);} + //------------------------------------------------------------------------- + + // assignment-------------------------------------------------------------- + String& operator= (const char8* str) {return assign (str);} ///< Assign from a string of type char8 + String& operator= (const char16* str) {return assign (str);} + String& operator= (const ConstString& str) {return assign (str);} + String& operator= (const String& str) {return assign (str);} + String& operator= (char8 c) {return assign (c);} + String& operator= (char16 c) {return assign (c);} + + String& assign (const ConstString& str, int32 n = -1); ///< Assign n characters of str (-1: all) + String& assign (const char8* str, int32 n = -1, bool isTerminated = true); ///< Assign n characters of str (-1: all) + String& assign (const char16* str, int32 n = -1, bool isTerminated = true); ///< Assign n characters of str (-1: all) + String& assign (char8 c, int32 n = 1); + String& assign (char16 c, int32 n = 1); + //------------------------------------------------------------------------- + + // concat------------------------------------------------------------------ + String& append (const ConstString& str, int32 n = -1); ///< Append n characters of str to this (n=-1: all) + String& append (const char8* str, int32 n = -1); ///< Append n characters of str to this (n=-1: all) + String& append (const char16* str, int32 n = -1); ///< Append n characters of str to this (n=-1: all) + String& append (const char8 c, int32 n = 1); ///< Append char c n times + String& append (const char16 c, int32 n = 1); ///< Append char c n times + + String& insertAt (uint32 idx, const ConstString& str, int32 n = -1); ///< Insert n characters of str at position idx (n=-1: all) + String& insertAt (uint32 idx, const char8* str, int32 n = -1); ///< Insert n characters of str at position idx (n=-1: all) + String& insertAt (uint32 idx, const char16* str, int32 n = -1); ///< Insert n characters of str at position idx (n=-1: all) + String& insertAt (uint32 idx, char8 c) {char8 str[] = {c, 0}; return insertAt (idx, str, 1);} + String& insertAt (uint32 idx, char16 c) {char16 str[] = {c, 0}; return insertAt (idx, str, 1);} + + String& operator+= (const String& str) {return append (str);} + String& operator+= (const ConstString& str) {return append (str);} + String& operator+= (const char8* str) {return append (str);} + String& operator+= (const char16* str) {return append (str);} + String& operator+= (const char8 c) {return append (c);} + String& operator+= (const char16 c) {return append (c);} + //------------------------------------------------------------------------- + + // replace----------------------------------------------------------------- + String& replace (uint32 idx, int32 n1, const ConstString& str, int32 n2 = -1); ///< Replace n1 characters of this (starting at idx) with n2 characters of str (n1,n2=-1: until end) + String& replace (uint32 idx, int32 n1, const char8* str, int32 n2 = -1); ///< Replace n1 characters of this (starting at idx) with n2 characters of str (n1,n2=-1: until end) + String& replace (uint32 idx, int32 n1, const char16* str, int32 n2 = -1); ///< Replace n1 characters of this (starting at idx) with n2 characters of str (n1,n2=-1: until end) + + int32 replace (const char8* toReplace, const char8* toReplaceWith, bool all = false, CompareMode m = kCaseSensitive); ///< Replace find string with replace string - returns number of replacements + int32 replace (const char16* toReplace, const char16* toReplaceWith, bool all = false, CompareMode m = kCaseSensitive); ///< Replace find string with replace string - returns number of replacements + + bool replaceChars8 (const char8* toReplace, char8 toReplaceBy); ///< Returns true when any replacement was done + bool replaceChars16 (const char16* toReplace, char16 toReplaceBy); + inline bool replaceChars8 (char8 toReplace, char8 toReplaceBy) {char8 str[] = {toReplace, 0}; return replaceChars8 (str, toReplaceBy);} + inline bool replaceChars16 (char16 toReplace, char16 toReplaceBy) {char16 str[] = {toReplace, 0}; return replaceChars16 (str, toReplaceBy);} + inline bool replaceChars (char8 toReplace, char8 toReplaceBy) {return replaceChars8 (toReplace, toReplaceBy);} + inline bool replaceChars (char16 toReplace, char16 toReplaceBy) {return replaceChars16 (toReplace, toReplaceBy);} + inline bool replaceChars (const char8* toReplace, char8 toReplaceBy) {return replaceChars8 (toReplace, toReplaceBy);} + inline bool replaceChars (const char16* toReplace, char16 toReplaceBy) {return replaceChars16 (toReplace, toReplaceBy);} + //------------------------------------------------------------------------- + + // remove------------------------------------------------------------------ + String& remove (uint32 index = 0, int32 n = -1); ///< Remove n characters from string starting at index (n=-1: until end) + enum CharGroup {kSpace, kNotAlphaNum, kNotAlpha}; + bool trim (CharGroup mode = kSpace); ///< Trim lead/trail. + void removeChars (CharGroup mode = kSpace); ///< Removes all of group. + bool removeChars8 (const char8* which); ///< Remove all occurrences of each char in 'which' + bool removeChars16 (const char16* which); ///< Remove all occurrences of each char in 'which' + inline bool removeChars8 (const char8 which) {char8 str[] = {which, 0}; return removeChars8 (str); } + inline bool removeChars16 (const char16 which) {char16 str[] = {which, 0}; return removeChars16 (str); } + inline bool removeChars (const char8* which) {return removeChars8 (which);} + inline bool removeChars (const char16* which) {return removeChars16 (which);} + inline bool removeChars (const char8 which) {return removeChars8 (which);} + inline bool removeChars (const char16 which) {return removeChars16 (which);} + bool removeSubString (const ConstString& subString, bool allOccurences = true); + //------------------------------------------------------------------------- + + // print------------------------------------------------------------------- + String& printf (const char8* format, ...); ///< Print formatted data into string + String& printf (const char16* format, ...); ///< Print formatted data into string + String& vprintf (const char8* format, va_list args); + String& vprintf (const char16* format, va_list args); + //------------------------------------------------------------------------- + + // numbers----------------------------------------------------------------- + String& printInt64 (int64 value); + String& printFloat (double value); + /** Increment the trailing number if present else start with minNumber, width specifies the string width format (width 2 for number 3 is 03), + applyOnlyFormat set to true will only format the string to the given width without incrementing the founded trailing number */ + bool incrementTrailingNumber (uint32 width = 2, tchar separator = STR (' '), uint32 minNumber = 1, bool applyOnlyFormat = false); + //------------------------------------------------------------------------- + + // conversion-------------------------------------------------------------- + bool fromVariant (const FVariant& var); ///< Assigns string from FVariant + void toVariant (FVariant& var) const; + bool fromAttributes (IAttributes* a, IAttrID attrID); ///< Assigns string from FAttributes + bool toAttributes (IAttributes* a, IAttrID attrID); + + void swapContent (String& s); ///< Swaps ownership of the strings pointed to + void take (String& str); ///< Take ownership of the string of 'str' + void take (void* _buffer, bool wide); ///< Take ownership of buffer + void* pass (); + void passToVariant (FVariant& var); ///< Pass ownership of buffer to Variant - sets Variant ownership + + void toLower (uint32 index); ///< Lower case the character. + void toLower (); ///< Lower case the string. + void toUpper (uint32 index); ///< Upper case the character. + void toUpper (); ///< Upper case the string. + + unsigned char* toPascalString (unsigned char* buf); ///< Pascal string conversion + const String& fromPascalString (const unsigned char* buf); ///< Pascal string conversion + + bool toWideString (uint32 sourceCodePage = kCP_Default); ///< Converts to wide string according to sourceCodePage + bool toMultiByte (uint32 destCodePage = kCP_Default); + + void fromUTF8 (const char8* utf8String); ///< Assigns from UTF8 string + bool normalize (UnicodeNormalization = kUnicodeNormC); ///< On PC only kUnicodeNormC is working + +#if SMTG_OS_MACOS + virtual bool fromCFStringRef (const void*, uint32 encoding = 0xFFFF); ///< CFString conversion +#endif + //------------------------------------------------------------------------- + + //----------------------------------------------------------------------------- +protected: + bool resize (uint32 newSize, bool wide, bool fill = false); + +private: + void tryFreeBuffer (); + bool checkToMultiByte (uint32 destCodePage = kCP_Default) const; // to remove debug code from inline - const_cast inside!!! +}; + +// String concatenation functions. +inline String operator+ (const ConstString& s1, const ConstString& s2) {return String (s1).append (s2);} +inline String operator+ (const ConstString& s1, const char8* s2) {return String (s1).append (s2);} +inline String operator+ (const ConstString& s1, const char16* s2) {return String (s1).append (s2);} +inline String operator+ (const char8* s1, const ConstString& s2) {return String (s1).append (s2);} +inline String operator+ (const char16* s1, const ConstString& s2) {return String (s1).append (s2);} +inline String operator+ (const ConstString& s1, const String& s2) {return String (s1).append (s2);} +inline String operator+ (const String& s1, const ConstString& s2) {return String (s1).append (s2);} +inline String operator+ (const String& s1, const String& s2) {return String (s1).append (s2);} +inline String operator+ (const String& s1, const char8* s2) {return String (s1).append (s2);} +inline String operator+ (const String& s1, const char16* s2) {return String (s1).append (s2);} +inline String operator+ (const char8* s1, const String& s2) {return String (s1).append (s2);} +inline String operator+ (const char16* s1, const String& s2) {return String (s1).append (s2);} + +//----------------------------------------------------------------------------- +// ConstString +//----------------------------------------------------------------------------- +inline const tchar* ConstString::text () const +{ +#ifdef UNICODE + return text16 (); +#else + return text8 (); +#endif +} + +//----------------------------------------------------------------------------- +inline const char8* ConstString::text8 () const +{ + return (!isWide && buffer8) ? buffer8: kEmptyString8; +} + +//----------------------------------------------------------------------------- +inline const char16* ConstString::text16 () const +{ + return (isWide && buffer16) ? buffer16 : kEmptyString16; +} + +//----------------------------------------------------------------------------- +inline char8 ConstString::getChar8 (uint32 index) const +{ + if (index < len && buffer8 && !isWide) + return buffer8[index]; + return 0; +} + +//----------------------------------------------------------------------------- +inline char16 ConstString::getChar16 (uint32 index) const +{ + if (index < len && buffer16 && isWide) + return buffer16[index]; + return 0; +} + +//----------------------------------------------------------------------------- +inline tchar ConstString::getChar (uint32 index) const +{ +#ifdef UNICODE + return getChar16 (index); +#else + return getChar8 (index); +#endif +} + +//----------------------------------------------------------------------------- +inline tchar ConstString::getCharAt (uint32 index) const +{ +#ifdef UNICODE + if (isWide) + return getChar16 (index); +#endif + + return static_cast (getChar8 (index)); +} + +//----------------------------------------------------------------------------- +inline int64 ConstString::getNumber () const +{ + int64 tmp = 0; + scanInt64 (tmp); + return tmp; +} + +//----------------------------------------------------------------------------- +inline bool ConstString::scanInt32_8 (const char8* text, int32& value, bool scanToEnd) +{ + int64 tmp; + if (scanInt64_8 (text, tmp, scanToEnd)) + { + value = (int32)tmp; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +inline bool ConstString::scanInt32_16 (const char16* text, int32& value, bool scanToEnd) +{ + int64 tmp; + if (scanInt64_16 (text, tmp, scanToEnd)) + { + value = (int32)tmp; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +inline bool ConstString::scanInt32 (const tchar* text, int32& value, bool scanToEnd) +{ + int64 tmp; + if (scanInt64 (text, tmp, scanToEnd)) + { + value = (int32)tmp; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +inline bool ConstString::scanUInt32_8 (const char8* text, uint32& value, bool scanToEnd) +{ + uint64 tmp; + if (scanUInt64_8 (text, tmp, scanToEnd)) + { + value = (uint32)tmp; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +inline bool ConstString::scanUInt32_16 (const char16* text, uint32& value, bool scanToEnd) +{ + uint64 tmp; + if (scanUInt64_16 (text, tmp, scanToEnd)) + { + value = (uint32)tmp; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +inline bool ConstString::scanUInt32 (const tchar* text, uint32& value, bool scanToEnd) +{ + uint64 tmp; + if (scanUInt64 (text, tmp, scanToEnd)) + { + value = (uint32)tmp; + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +inline const char8* String::text8 () const +{ + if (isWide && !isEmpty ()) + checkToMultiByte (); // this should be avoided, since it can lead to information loss + + return ConstString::text8 (); +} + +//----------------------------------------------------------------------------- +inline const char16* String::text16 () const +{ + if (!isWide && !isEmpty ()) + { + const_cast (*this).toWideString (); + } + return ConstString::text16 (); +} + +//----------------------------------------------------------------------------- +inline char8 String::getChar8 (uint32 index) const +{ + if (isWide && !isEmpty ()) + checkToMultiByte (); // this should be avoided, since it can lead to information loss + + return ConstString::getChar8 (index); +} + +//----------------------------------------------------------------------------- +inline char16 String::getChar16 (uint32 index) const +{ + if (!isWide && !isEmpty ()) + { + const_cast (*this).toWideString (); + } + return ConstString::getChar16 (index); +} + +//----------------------------------------------------------------------------- + + +inline bool operator< (const ConstString& s1, const ConstString& s2) {return (s1.compare (s2) < 0) ? true : false;} +inline bool operator<= (const ConstString& s1, const ConstString& s2) {return (s1.compare (s2) <= 0) ? true : false;} +inline bool operator> (const ConstString& s1, const ConstString& s2) {return (s1.compare (s2) > 0) ? true : false;} +inline bool operator>= (const ConstString& s1, const ConstString& s2) {return (s1.compare (s2) >= 0) ? true : false;} +inline bool operator== (const ConstString& s1, const ConstString& s2) {return (s1.compare (s2) == 0) ? true : false;} +inline bool operator!= (const ConstString& s1, const ConstString& s2) {return (s1.compare (s2) != 0) ? true : false;} + +inline bool operator< (const ConstString& s1, const char8* s2) {return (s1.compare (s2) < 0) ? true : false;} +inline bool operator<= (const ConstString& s1, const char8* s2) {return (s1.compare (s2) <= 0) ? true : false;} +inline bool operator> (const ConstString& s1, const char8* s2) {return (s1.compare (s2) > 0) ? true : false;} +inline bool operator>= (const ConstString& s1, const char8* s2) {return (s1.compare (s2) >= 0) ? true : false;} +inline bool operator== (const ConstString& s1, const char8* s2) {return (s1.compare (s2) == 0) ? true : false;} +inline bool operator!= (const ConstString& s1, const char8* s2) {return (s1.compare (s2) != 0) ? true : false;} +inline bool operator< (const char8* s1, const ConstString& s2) {return (s2.compare (s1) > 0) ? true : false;} +inline bool operator<= (const char8* s1, const ConstString& s2) {return (s2.compare (s1) >= 0) ? true : false;} +inline bool operator> (const char8* s1, const ConstString& s2) {return (s2.compare (s1) < 0) ? true : false;} +inline bool operator>= (const char8* s1, const ConstString& s2) {return (s2.compare (s1) <= 0) ? true : false;} +inline bool operator== (const char8* s1, const ConstString& s2) {return (s2.compare (s1) == 0) ? true : false;} +inline bool operator!= (const char8* s1, const ConstString& s2) {return (s2.compare (s1) != 0) ? true : false;} + +inline bool operator< (const ConstString& s1, const char16* s2) {return (s1.compare (s2) < 0) ? true : false;} +inline bool operator<= (const ConstString& s1, const char16* s2) {return (s1.compare (s2) <= 0) ? true : false;} +inline bool operator> (const ConstString& s1, const char16* s2) {return (s1.compare (s2) > 0) ? true : false;} +inline bool operator>= (const ConstString& s1, const char16* s2) {return (s1.compare (s2) >= 0) ? true : false;} +inline bool operator== (const ConstString& s1, const char16* s2) {return (s1.compare (s2) == 0) ? true : false;} +inline bool operator!= (const ConstString& s1, const char16* s2) {return (s1.compare (s2) != 0) ? true : false;} +inline bool operator< (const char16* s1, const ConstString& s2) {return (s2.compare (s1) > 0) ? true : false;} +inline bool operator<= (const char16* s1, const ConstString& s2) {return (s2.compare (s1) >= 0) ? true : false;} +inline bool operator> (const char16* s1, const ConstString& s2) {return (s2.compare (s1) < 0) ? true : false;} +inline bool operator>= (const char16* s1, const ConstString& s2) {return (s2.compare (s1) <= 0) ? true : false;} +inline bool operator== (const char16* s1, const ConstString& s2) {return (s2.compare (s1) == 0) ? true : false;} +inline bool operator!= (const char16* s1, const ConstString& s2) {return (s2.compare (s1) != 0) ? true : false;} + +// The following functions will only work with European Numbers! +// (e.g. Arabic, Tibetan, and Khmer digits are not supported) +extern int32 strnatcmp8 (const char8* s1, const char8* s2, bool caseSensitive = true); +extern int32 strnatcmp16 (const char16* s1, const char16* s2, bool caseSensitive = true); +inline int32 strnatcmp (const tchar* s1, const tchar* s2, bool caseSensitive = true) +{ +#ifdef UNICODE + return strnatcmp16 (s1, s2, caseSensitive); +#else + return strnatcmp8 (s1, s2, caseSensitive); +#endif +} + +//----------------------------------------------------------------------------- +/** StringObject implements IStringResult and IString methods. + It can therefore be exchanged with other Steinberg objects using one or both of these +interfaces. + +\see String, ConstString +*/ +//----------------------------------------------------------------------------- +class StringObject : public FObject, public String, public IStringResult, public IString +{ +public: +//----------------------------------------------------------------------------- + StringObject () {} + StringObject (const char16* str, int32 n = -1, bool isTerminated = true) : String (str, n, isTerminated) {} + StringObject (const char8* str, int32 n = -1, bool isTerminated = true) : String (str, n, isTerminated) {} + StringObject (const StringObject& str, int32 n = -1) : String (str, n) {} + StringObject (const String& str, int32 n = -1) : String (str, n) {} + StringObject (const FVariant& var) : String (var) {} + + using String::operator=; + + // IStringResult ---------------------------------------------------------- + virtual void PLUGIN_API setText (const char8* text) SMTG_OVERRIDE; + //------------------------------------------------------------------------- + + // IString----------------------------------------------------------------- + virtual void PLUGIN_API setText8 (const char8* text) SMTG_OVERRIDE; + virtual void PLUGIN_API setText16 (const char16* text) SMTG_OVERRIDE; + + virtual const char8* PLUGIN_API getText8 () SMTG_OVERRIDE; + virtual const char16* PLUGIN_API getText16 () SMTG_OVERRIDE; + + virtual void PLUGIN_API take (void* s, bool _isWide) SMTG_OVERRIDE; + virtual bool PLUGIN_API isWideString () const SMTG_OVERRIDE; + //------------------------------------------------------------------------- + + OBJ_METHODS (StringObject, FObject) + FUNKNOWN_METHODS2 (IStringResult, IString, FObject) +}; + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.cpp new file mode 100644 index 0000000000..5d3745b664 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.cpp @@ -0,0 +1,721 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/updatehandler.cpp +// Created by : Steinberg, 2008 +// Description : +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#include "base/source/updatehandler.h" +#include "base/source/classfactoryhelpers.h" +#include "base/source/fstring.h" + +#if SMTG_CPP11_STDLIBSUPPORT +#include +#else +#include +#endif +#include +#include +#include + +#define NON_EXISTING_DEPENDENCY_CHECK 0 // not yet +#define CLASS_NAME_TRACKED DEVELOPMENT + +using Steinberg::Base::Thread::FGuard; + +namespace Steinberg { + +DEF_CLASS_IID (IUpdateManager) +bool UpdateHandler::lockUpdates = false; + +namespace Update { +const uint32 kHashSize = (1 << 8); // must be power of 2 (16 bytes * 256 == 4096) +const uint32 kMapSize = 1024 * 10; + +//------------------------------------------------------------------------ +inline uint32 hashPointer (void* p) +{ + return (uint32)((uint64 (p) >> 12) & (kHashSize - 1)); +} + +//------------------------------------------------------------------------ +inline IPtr getUnknownBase (FUnknown* unknown) +{ + FUnknown* result = nullptr; + if (unknown) + unknown->queryInterface (FUnknown::iid, (void**)&result); + + return owned (result); +} + +#if CLASS_NAME_TRACKED +//------------------------------------------------------------------------ +struct Dependency +{ + Dependency (FUnknown* o, IDependent* d) + : obj (o), dep (d), objClass (nullptr), depClass (nullptr) + { + } + + inline bool operator== (const Dependency& d) const { return obj == d.obj; } + inline bool operator!= (const Dependency& d) const { return obj != d.obj; } + inline bool operator< (const Dependency& d) const { return obj < d.obj; } + inline bool operator> (const Dependency& d) const { return obj > d.obj; } + FUnknown* obj; + IDependent* dep; + + FClassID objClass; + FClassID depClass; +}; +#endif + +//------------------------------------------------------------------------ +struct DeferedChange +{ + DeferedChange (FUnknown* o, int32 m = 0) : obj (o), msg (m) {} + ~DeferedChange () {} + DeferedChange (const DeferedChange& r) : obj (r.obj), msg (r.msg) {} + inline bool operator== (const DeferedChange& d) const { return obj == d.obj; } + inline bool operator!= (const DeferedChange& d) const { return obj != d.obj; } + FUnknown* obj; + int32 msg; +}; + +//------------------------------------------------------------------------ +struct UpdateData +{ + UpdateData (FUnknown* o, IDependent** d, uint32 c) + : obj (o), dependents (d), count (c) + { + } + FUnknown* obj; + IDependent** dependents; + uint32 count; + bool operator== (const UpdateData& d) const + { + return d.obj == obj && d.dependents == dependents; + } +}; + +//------------------------------------------------------------------------ +typedef std::deque DeferedChangeList; +typedef DeferedChangeList::const_iterator DeferedChangeListIterConst; +typedef DeferedChangeList::iterator DeferedChangeListIter; + +typedef std::deque UpdateDataList; +typedef UpdateDataList::const_iterator UpdateDataListIterConst; + +#if CLASS_NAME_TRACKED +typedef std::vector DependentList; +#else +typedef std::vector DependentList; +#endif +typedef DependentList::iterator DependentListIter; +typedef DependentList::const_iterator DependentListIterConst; + +#if SMTG_CPP11_STDLIBSUPPORT +typedef std::unordered_map DependentMap; +#else +typedef std::map DependentMap; +#endif +typedef DependentMap::iterator DependentMapIter; +typedef DependentMap::const_iterator DependentMapIterConst; + +struct Table +{ + DependentMap depMap[kHashSize]; + DeferedChangeList defered; + UpdateDataList updateData; +}; + +//------------------------------------------------------------------------ +void updateDone (FUnknown* unknown, int32 message) +{ + if (message != IDependent::kDestroyed) + { + FObject* obj = FObject::unknownToObject (unknown); + if (obj) + obj->updateDone (message); + } +} +} // namespace Update + +//------------------------------------------------------------------------ +static int32 countEntries (Update::DependentMap& map) +{ + int32 total = 0; + Update::DependentMapIterConst iterMap = map.begin (); + while (iterMap != map.end ()) + { + const Update::DependentList& list = iterMap->second; + Update::DependentListIterConst iterList = list.begin (); + while (iterList != list.end ()) + { + total++; + ++iterList; + } + ++iterMap; + } + return total; +} + +//------------------------------------------------------------------------ +UpdateHandler::UpdateHandler () +{ + table = NEW Update::Table; + if (FObject::getUpdateHandler () == nullptr) + FObject::setUpdateHandler (this); +} + +//------------------------------------------------------------------------ +UpdateHandler::~UpdateHandler () +{ + if (FObject::getUpdateHandler () == this) + FObject::setUpdateHandler (nullptr); + delete table; + table = nullptr; +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API UpdateHandler::addDependent (FUnknown* u, IDependent* _dependent) +{ + IPtr unknown = Update::getUnknownBase (u); + if (!unknown || !_dependent) + return kResultFalse; + + FGuard guard (lock); + +#if CLASS_NAME_TRACKED + Update::Dependency dependent (unknown, _dependent); + + FObject* obj = FObject::unknownToObject (unknown); + if (obj) + dependent.objClass = obj->isA (); + obj = FObject::unknownToObject (_dependent); + if (obj) + dependent.depClass = obj->isA (); +#else + IDependent* dependent = _dependent; +#endif + + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIter it = map.find (unknown); + if (it == map.end ()) + { + Update::DependentList list; + list.push_back (dependent); + map[unknown] = list; + } + else + { + (*it).second.push_back (dependent); + } + + return kResultTrue; +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API UpdateHandler::removeDependent (FUnknown* u, IDependent* dependent) +{ + IPtr unknown = Update::getUnknownBase (u); + if (unknown == nullptr && dependent == nullptr) + return kResultFalse; + + FGuard guard (lock); + + Update::UpdateDataListIterConst iter = table->updateData.begin (); + while (iter != table->updateData.end ()) + { + if ((*iter).obj == unknown || unknown == nullptr) + { + for (uint32 count = 0; count < (*iter).count; count++) + { + if ((*iter).dependents[count] == dependent) + (*iter).dependents[count] = 0; + } + } + ++iter; + } + // Remove all objects for the given dependent + if (unknown == nullptr) + { + for (uint32 j = 0; j < Update::kHashSize; j++) + { + Update::DependentMap& map = table->depMap[j]; + Update::DependentMapIter iterMap = map.begin (); + while (iterMap != map.end ()) + { + Update::DependentList& list = (*iterMap).second; + Update::DependentListIter iterList = list.begin (); + while (iterList != list.end ()) + { +#if CLASS_NAME_TRACKED + if ((*iterList).dep == dependent) +#else + if ((*iterList) == dependent) +#endif + { + iterList = list.erase (iterList); + } + else + { + ++iterList; + } + } + ++iterMap; + } + } + } + else + { + bool mustFlush = true; + + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIter iterList = map.find (unknown); + +#if NON_EXISTING_DEPENDENCY_CHECK + SMTG_ASSERT (iterList != map.end () && "ERROR: Trying to remove a non existing dependency!") +#endif + if (iterList != map.end ()) + { + if (dependent == nullptr) // Remove all dependents of object + { + map.erase (iterList); + } + else // Remove one dependent + { + int32 eraseCount = 0; + Update::DependentList& dependentlist = (*iterList).second; + Update::DependentListIter iterDependentlist = dependentlist.begin (); + while (iterDependentlist != dependentlist.end ()) + { +#if CLASS_NAME_TRACKED + if ((*iterDependentlist).dep == dependent) +#else + if ((*iterDependentlist) == dependent) +#endif + { + iterDependentlist = dependentlist.erase (iterDependentlist); + eraseCount++; + if (dependentlist.empty ()) + { + map.erase (iterList); + break; + } + } + else + { + ++iterDependentlist; + mustFlush = false; + } + } + } + } + if (mustFlush) + cancelUpdates (unknown); + } + + return kResultTrue; +} + +//------------------------------------------------------------------------ +tresult UpdateHandler::doTriggerUpdates (FUnknown* u, int32 message, bool suppressUpdateDone) +{ + if (lockUpdates) + return kResultFalse; + IPtr unknown = Update::getUnknownBase (u); + if (!unknown) + return kResultFalse; + + // to avoid crashes due to stack overflow, we reduce the amount of memory reserved for the + // dependents + IDependent* smallDependents[Update::kMapSize / 10]; // 8kB for x64 + IDependent** dependents = smallDependents; + int32 maxDependents = Update::kMapSize / 10; + int32 count = 0; + + { + FGuard guard (lock); // scope for lock + + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIterConst iterList = map.find (unknown); + if (iterList != map.end ()) + { + const Update::DependentList& dependentlist = (*iterList).second; + Update::DependentListIterConst iterDependentlist = dependentlist.begin (); + while (iterDependentlist != dependentlist.end ()) + { +#if CLASS_NAME_TRACKED + dependents[count] = (*iterDependentlist).dep; +#else + dependents[count] = *iterDependentlist; +#endif + count++; + + if (count >= maxDependents) + { + if (dependents == smallDependents) + { + dependents = new IDependent*[Update::kMapSize]; + memcpy (dependents, smallDependents, count * sizeof (dependents[0])); + maxDependents = Update::kMapSize; + } + else + { + SMTG_WARNING ("Dependency overflow") + break; + } + } + ++iterDependentlist; + } + } + + // push update data on the stack + if (count > 0) + { + Update::UpdateData data (unknown, dependents, count); + table->updateData.push_back (data); + } + } // end scope + + int32 i = 0; + while (i < count) + { + if (dependents[i]) + dependents[i]->update (unknown, message); + i++; + } + + if (dependents != smallDependents) + delete[] dependents; + + // remove update data from the stack + if (count > 0) + { + FGuard guard (lock); + + table->updateData.pop_back (); + } + + // send update done message + if (suppressUpdateDone == false) + Update::updateDone (unknown, message); + + return count > 0 ? kResultTrue : kResultFalse; // Object was found and has been updated +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API UpdateHandler::triggerUpdates (FUnknown* u, int32 message) +{ + return doTriggerUpdates (u, message, false); +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API UpdateHandler::deferUpdates (FUnknown* u, int32 message) +{ + IPtr unknown = Update::getUnknownBase (u); + if (!unknown) + return kResultFalse; + + FGuard guard (lock); + + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIterConst iterList = map.find (unknown); + + bool hasDependency = (iterList != map.end ()); + if (hasDependency == false) + { + Update::updateDone (unknown, message); + return kResultTrue; + } + + bool found = false; + Update::DeferedChangeListIterConst iter = table->defered.begin (); + while (iter != table->defered.end ()) + { + if ((*iter).obj == unknown && (*iter).msg == message) + { + found = true; + break; + } + ++iter; + } + + if (!found) + { + Update::DeferedChange change (unknown, message); + table->defered.push_back (change); + } + + return kResultTrue; +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API UpdateHandler::triggerDeferedUpdates (FUnknown* unknown) +{ + Update::DeferedChangeList deferedAgain; + if (!unknown) + { + while (table->defered.empty () == false) + { + // Remove first from queue + lock.lock (); + + FUnknown* obj = table->defered.front ().obj; + int32 msg = table->defered.front ().msg; + table->defered.pop_front (); + + // check if this object is currently being updated. in this case, defer update again... + bool canSignal = true; + Update::UpdateDataListIterConst iter = table->updateData.begin (); + while (iter != table->updateData.end ()) + { + if ((*iter).obj == obj) + { + canSignal = false; + break; + } + ++iter; + } + lock.unlock (); + + if (canSignal) + { + triggerUpdates (obj, msg); + } + else + { + Update::DeferedChange change (obj, msg); + deferedAgain.push_back (change); + } + } + } + else + { + IPtr object = Update::getUnknownBase (unknown); + Update::DeferedChange tmp (object); + + while (true) + { + lock.lock (); + Update::DeferedChangeListIter it = + std::find (table->defered.begin (), table->defered.end (), tmp); + if (it == table->defered.end ()) + { + lock.unlock (); + return kResultTrue; + } + + if ((*it).obj != nullptr) + { + int32 msg = (*it).msg; + table->defered.erase (it); + + // check if this object is currently being updated. in this case, defer update + // again... + bool canSignal = true; + Update::UpdateDataListIterConst iter = table->updateData.begin (); + while (iter != table->updateData.end ()) + { + if ((*iter).obj == object) + { + canSignal = false; + break; + } + ++iter; + } + lock.unlock (); + + if (canSignal) + { + triggerUpdates (object, msg); + } + else + { + Update::DeferedChange change (object, msg); + deferedAgain.push_back (change); + } + } + } + } + + if (deferedAgain.empty () == false) + { + FGuard guard (lock); + + Update::DeferedChangeListIterConst iter = deferedAgain.begin (); + while (iter != deferedAgain.end ()) + { + table->defered.push_back (*iter); + ++iter; + } + } + + return kResultTrue; +} + +//------------------------------------------------------------------------ +tresult PLUGIN_API UpdateHandler::cancelUpdates (FUnknown* u) +{ + IPtr unknown = Update::getUnknownBase (u); + if (!unknown) + return kResultFalse; + + FGuard guard (lock); + + Update::DeferedChange change (unknown, 0); + while (1) + { + auto iter = std::find (table->defered.begin (), table->defered.end (), change); + if (iter != table->defered.end ()) + table->defered.erase (iter); + else + break; + } + + return kResultTrue; +} + +//------------------------------------------------------------------------ +size_t UpdateHandler::countDependencies (FUnknown* object) +{ + FGuard guard (lock); + uint32 res = 0; + + IPtr unknown = Update::getUnknownBase (object); + if (unknown) + { + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIter iterList = map.find (unknown); + if (iterList != map.end ()) + return iterList->second.size (); + } + else + { + for (uint32 j = 0; j < Update::kHashSize; j++) + { + Update::DependentMap& map = table->depMap[j]; + res += countEntries (map); + } + } + return res; +} + +#if DEVELOPMENT +//------------------------------------------------------------------------ +bool UpdateHandler::checkDeferred (FUnknown* object) +{ + IPtr unknown = Update::getUnknownBase (object); + + FGuard guard (lock); + + Update::DeferedChange tmp (unknown); + Update::DeferedChangeListIterConst it = + std::find (table->defered.begin (), table->defered.end (), tmp); + if (it != table->defered.end ()) + return true; + + return false; +} + +//------------------------------------------------------------------------ +bool UpdateHandler::hasDependencies (FUnknown* u) +{ + IPtr unknown = Update::getUnknownBase (u); + if (!unknown) + return false; + + FGuard guard (lock); + + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIterConst iterList = map.find (unknown); + bool hasDependency = (iterList != map.end ()); + + return hasDependency; +} + +//------------------------------------------------------------------------ +void UpdateHandler::printForObject (FObject* obj) const +{ + IPtr unknown = Update::getUnknownBase (obj); + if (!unknown) + return; + + FUnknownPtr dep (obj); + + bool header = false; + + Update::DependentMap& map = table->depMap[Update::hashPointer (unknown)]; + Update::DependentMapIterConst iterList = map.begin (); + while (iterList != map.end ()) + { + const Update::DependentList& dependentlist = (*iterList).second; + Update::DependentListIterConst iterDependentlist = dependentlist.begin (); + while (iterDependentlist != dependentlist.end ()) + { +#if CLASS_NAME_TRACKED + if ((*iterList).first == unknown || (*iterDependentlist).dep == dep.getInterface ()) + { + if (!header) + { + FDebugPrint ("Dependencies for object %8" FORMAT_INT64A " %s\n", (uint64)obj, + obj->isA ()); + header = true; + } + FDebugPrint ("%s %8" FORMAT_INT64A "\n <- %s %8" FORMAT_INT64A "\n", + (*iterDependentlist).depClass, (uint64) (*iterDependentlist).dep, + (*iterDependentlist).objClass, (uint64) ((*iterList).first)); + } +#else + if ((*iterList).first == unknown || (*iterDependentlist) == dep.getInterface ()) + { + if (!header) + { + FDebugPrint ("Dependencies for object %8" FORMAT_INT64A " %s\n", (uint64)obj, + obj->isA ()); + header = true; + } + FDebugPrint ("%8" FORMAT_INT64A "\n <- %8" FORMAT_INT64A "\n", + (uint64) (*iterDependentlist), (uint64) ((*iterList).first)); + } +#endif + ++iterDependentlist; + } + + ++iterList; + } +} +#endif + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.h new file mode 100644 index 0000000000..4f966beed6 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/source/updatehandler.h @@ -0,0 +1,139 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/source/updatehandler.h +// Created by : Steinberg, 2008 +// Description : +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#pragma once + +#include "base/source/fobject.h" +#include "base/thread/include/flock.h" +#include "pluginterfaces/base/iupdatehandler.h" + +namespace Steinberg { + +/// @cond ignore +namespace Update { struct Table; } +/// @endcond + +//------------------------------------------------------------------------ +/** Handle Send and Cancel pending message for a given object*/ +//------------------------------------------------------------------------ +class IUpdateManager : public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** cancel pending messages send by \param object or by any if object is 0 */ + virtual tresult PLUGIN_API cancelUpdates (FUnknown* object) = 0; + /** send pending messages send by \param object or by any if object is 0 */ + virtual tresult PLUGIN_API triggerDeferedUpdates (FUnknown* object = 0) = 0; + static const FUID iid; +}; + +DECLARE_CLASS_IID (IUpdateManager, 0x030B780C, 0xD6E6418D, 0x8CE00BC2, 0x09C834D4) + +//------------------------------------------------------------------------------ +/** +UpdateHandler implements IUpdateManager and IUpdateHandler to handle dependencies +between objects to store and forward messages to dependent objects. + +This implementation is thread save, so objects can send message, add or remove +dependents from different threads. +Do do so it uses mutex, so be aware of locking. +*/ +//------------------------------------------------------------------------------ +class UpdateHandler : public FObject, public IUpdateHandler, public IUpdateManager +{ +public: +//------------------------------------------------------------------------------ + UpdateHandler (); + ~UpdateHandler (); + + using FObject::addDependent; + using FObject::removeDependent; + using FObject::deferUpdate; + + // IUpdateHandler + /** register \param dependent to get messages from \param object */ + virtual tresult PLUGIN_API addDependent (FUnknown* object, IDependent* dependent) SMTG_OVERRIDE; + /** unregister \param dependent to get no messages from \param object */ + virtual tresult PLUGIN_API removeDependent (FUnknown* object, + IDependent* dependent) SMTG_OVERRIDE; + /** send \param message to all dependents of \param object immediately */ + virtual tresult PLUGIN_API triggerUpdates (FUnknown* object, int32 message) SMTG_OVERRIDE; + /** send \param message to all dependents of \param object when idle */ + virtual tresult PLUGIN_API deferUpdates (FUnknown* object, int32 message) SMTG_OVERRIDE; + + // IUpdateManager + /** cancel pending messages send by \param object or by any if object is 0 */ + virtual tresult PLUGIN_API cancelUpdates (FUnknown* object) SMTG_OVERRIDE; + /** send pending messages send by \param object or by any if object is 0 */ + virtual tresult PLUGIN_API triggerDeferedUpdates (FUnknown* object = 0) SMTG_OVERRIDE; + + /// @cond ignore + // obsolete functions kept for compatibility + void checkUpdates (FObject* object = nullptr) { triggerDeferedUpdates (object->unknownCast ()); } + void flushUpdates (FObject* object) { cancelUpdates (object->unknownCast ()); } + void deferUpdate (FObject* object, int32 message) + { + deferUpdates (object->unknownCast (), message); + } + void signalChange (FObject* object, int32 message, bool suppressUpdateDone = false) + { + doTriggerUpdates (object->unknownCast (), message, suppressUpdateDone); + } +#if DEVELOPMENT + bool checkDeferred (FUnknown* object); + bool hasDependencies (FUnknown* object); + void printForObject (FObject* object) const; +#endif + /// @endcond + size_t countDependencies (FUnknown* object = nullptr); + + OBJ_METHODS (UpdateHandler, FObject) + FUNKNOWN_METHODS2 (IUpdateHandler, IUpdateManager, FObject) + SINGLETON (UpdateHandler) +//------------------------------------------------------------------------------ +private: + tresult doTriggerUpdates (FUnknown* object, int32 message, bool suppressUpdateDone); + + Steinberg::Base::Thread::FLock lock; + Update::Table* table = nullptr; + friend struct LockUpdateDependencies; + static bool lockUpdates; +}; + + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/thread/include/flock.h b/modules/juce_audio_processors/format_types/VST3_SDK/base/thread/include/flock.h new file mode 100644 index 0000000000..755456346d --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/thread/include/flock.h @@ -0,0 +1,183 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/thread/include/flock.h +// Created by : Steinberg, 1995 +// Description : locks +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------------- +/** @file base/thread/include/flock.h + Locks. */ +/** @defgroup baseLocks Locks */ +//---------------------------------------------------------------------------------- +#pragma once + +#include "base/source/fobject.h" +#include "pluginterfaces/base/ftypes.h" + +#if SMTG_PTHREADS +#include + +#elif SMTG_OS_WINDOWS +struct CRITSECT // CRITICAL_SECTION +{ + void* DebugInfo; // PRTL_CRITICAL_SECTION_DEBUG DebugInfo; + Steinberg::int32 LockCount; // LONG LockCount; + Steinberg::int32 RecursionCount; // LONG RecursionCount; + void* OwningThread; // HANDLE OwningThread + void* LockSemaphore; // HANDLE LockSemaphore + Steinberg::int32 SpinCount; // ULONG_PTR SpinCount +}; +#endif + +namespace Steinberg { +namespace Base { +namespace Thread { + +//------------------------------------------------------------------------ +/** Lock interface declaration. +@ingroup baseLocks */ +//------------------------------------------------------------------------ +struct ILock +{ +//------------------------------------------------------------------------ + virtual ~ILock () {} + + /** Enables lock. */ + virtual void lock () = 0; + + /** Disables lock. */ + virtual void unlock () = 0; + + /** Tries to disable lock. */ + virtual bool trylock () = 0; +//------------------------------------------------------------------------ +}; + +//------------------------------------------------------------------------ +/** FLock declaration. +@ingroup baseLocks */ +//------------------------------------------------------------------------ +class FLock : public ILock +{ +public: +//------------------------------------------------------------------------ + + /** Lock constructor. + * @param name lock name + */ + FLock (const char8* name = "FLock"); + + /** Lock destructor. */ + ~FLock (); + + //-- ILock ----------------------------------------------------------- + virtual void lock () SMTG_OVERRIDE; + virtual void unlock () SMTG_OVERRIDE; + virtual bool trylock () SMTG_OVERRIDE; + +//------------------------------------------------------------------------ +protected: +#if SMTG_PTHREADS + pthread_mutex_t mutex; ///< Mutex object + +#elif SMTG_OS_WINDOWS + CRITSECT section; ///< Critical section object +#endif +}; + +//------------------------------------------------------------------------ +/** FLockObj declaration. Reference counted lock +@ingroup baseLocks */ +//------------------------------------------------------------------------ +class FLockObject : public FObject, public FLock +{ +public: + OBJ_METHODS (FLockObject, FObject) +}; + +//------------------------------------------------------------------------ +/** FGuard - automatic object for locks. +@ingroup baseLocks */ +//------------------------------------------------------------------------ +class FGuard +{ +public: +//------------------------------------------------------------------------ + + /** FGuard constructor. + * @param _lock guard this lock + */ + FGuard (ILock& _lock) : lock (_lock) { lock.lock (); } + + /** FGuard destructor. */ + ~FGuard () { lock.unlock (); } + +//------------------------------------------------------------------------ +private: + ILock& lock; ///< guarded lock +}; + +//------------------------------------------------------------------------ +/** Conditional Guard - Locks only if valid lock is passed. +@ingroup baseLocks */ +//------------------------------------------------------------------------ +class FConditionalGuard +{ +public: +//------------------------------------------------------------------------ + + /** FConditionGuard constructor. + * @param _lock guard this lock + */ + FConditionalGuard (FLock* _lock) : lock (_lock) + { + if (lock) + lock->lock (); + } + + /** FConditionGuard destructor. */ + ~FConditionalGuard () + { + if (lock) + lock->unlock (); + } + +//------------------------------------------------------------------------ +private: + FLock* lock; ///< guarded lock +}; + +} // Thread +} // Base +} // Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/base/thread/source/flock.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/base/thread/source/flock.cpp new file mode 100644 index 0000000000..c1af97fe25 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/base/thread/source/flock.cpp @@ -0,0 +1,146 @@ +//------------------------------------------------------------------------ +// Project : SDK Base +// Version : 1.0 +// +// Category : Helpers +// Filename : base/thread/source/flock.cpp +// Created by : Steinberg, 1995 +// Description : Locks +// +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Steinberg Media Technologies nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. +//----------------------------------------------------------------------------- + +#define DEBUG_LOCK 0 + +#include "base/thread/include/flock.h" +#include "base/source/fdebug.h" + +//------------------------------------------------------------------------ +#if SMTG_OS_WINDOWS +//------------------------------------------------------------------------ +#ifndef WINVER +#define WINVER 0x0500 +#endif +#ifndef _WIN32_WINNT +#define _WIN32_WINNT WINVER +#endif + +#include +#include +#define INIT_CS(cs) \ + InitializeCriticalSection ((LPCRITICAL_SECTION)&cs); + +#endif + +namespace Steinberg { +namespace Base { +namespace Thread { + + +//------------------------------------------------------------------------ +// FLock implementation +//------------------------------------------------------------------------ +FLock::FLock (const char8* /*name*/) +{ +#if SMTG_PTHREADS + pthread_mutexattr_t mutexAttr; + pthread_mutexattr_init (&mutexAttr); + pthread_mutexattr_settype (&mutexAttr, PTHREAD_MUTEX_RECURSIVE); + if (pthread_mutex_init (&mutex, &mutexAttr) != 0) + {SMTG_WARNING("mutex_init failed")} + pthread_mutexattr_destroy (&mutexAttr); + +#elif SMTG_OS_WINDOWS + INIT_CS (section) +#else +#warning implement FLock! +#endif +} + +//------------------------------------------------------------------------ +FLock::~FLock () +{ +#if SMTG_PTHREADS + pthread_mutex_destroy (&mutex); + +#elif SMTG_OS_WINDOWS + DeleteCriticalSection ((LPCRITICAL_SECTION)§ion); + +#endif +} + +//------------------------------------------------------------------------ +void FLock::lock () +{ +#if DEBUG_LOCK + FDebugPrint ("FLock::lock () %x\n", this); +#endif + +#if SMTG_PTHREADS + pthread_mutex_lock (&mutex); + +#elif SMTG_OS_WINDOWS + EnterCriticalSection ((LPCRITICAL_SECTION)§ion); + +#endif +} + +//------------------------------------------------------------------------ +void FLock::unlock () +{ +#if DEBUG_LOCK + FDebugPrint ("FLock::unlock () %x\n", this); +#endif + +#if SMTG_PTHREADS + pthread_mutex_unlock (&mutex); + +#elif SMTG_OS_WINDOWS + LeaveCriticalSection ((LPCRITICAL_SECTION)§ion); + +#endif +} + +//------------------------------------------------------------------------ +bool FLock::trylock () +{ +#if SMTG_PTHREADS + return pthread_mutex_trylock (&mutex) == 0; + +#elif SMTG_OS_WINDOWS + return TryEnterCriticalSection ((LPCRITICAL_SECTION)§ion) != 0 ? true : false; + +#else + return false; +#endif +} + +} // Thread +} // Base +} // Steinberg + diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/LICENSE.txt b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/LICENSE.txt new file mode 100644 index 0000000000..c653a2ef70 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/LICENSE.txt @@ -0,0 +1,41 @@ +//----------------------------------------------------------------------------- +// LICENSE +// (c) 2018, Steinberg Media Technologies GmbH, All Rights Reserved +//----------------------------------------------------------------------------- +This license applies only to files referencing this license, +for other files of the Software Development Kit the respective embedded license text +is applicable. The license can be found at: www.steinberg.net/sdklicenses_vst3 + +This Software Development Kit is licensed under the terms of the Steinberg VST3 License, +or alternatively under the terms of the General Public License (GPL) Version 3. +You may use the Software Development Kit according to either of these licenses as it is +most appropriate for your project on a case-by-case basis (commercial or not). + +a) Proprietary Steinberg VST3 License +The Software Development Kit may not be distributed in parts or its entirety +without prior written agreement by Steinberg Media Technologies GmbH. +The SDK must not be used to re-engineer or manipulate any technology used +in any Steinberg or Third-party application or software module, +unless permitted by law. +Neither the name of the Steinberg Media Technologies GmbH nor the names of its +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. +Before publishing a software under the proprietary license, you need to obtain a copy +of the License Agreement signed by Steinberg Media Technologies GmbH. +The Steinberg VST SDK License Agreement can be found at: +www.steinberg.net/en/company/developers.html + +THE SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + +b) General Public License (GPL) Version 3 +Details of these licenses can be found at: www.gnu.org/licenses/gpl-3.0.html +//---------------------------------------------------------------------------------- diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.cpp new file mode 100644 index 0000000000..4891cefa15 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.cpp @@ -0,0 +1,106 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/conststringtable.cpp +// Created by : Steinberg, 09/2007 +// Description : constant unicode string table +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#include "conststringtable.h" +#include +#include + +namespace Steinberg { + +static std::map* stringMap; +static std::map* charMap; + +static char16* generateUTF16 (const char8* str); + +//---------------------------------------------------------------------------- +ConstStringTable* ConstStringTable::instance () +{ + static ConstStringTable stringTable; + return &stringTable; +} + +//---------------------------------------------------------------------------- +const char16* ConstStringTable::getString (const char8* str) const +{ + std::map::iterator iter = stringMap->find (str); + if (iter != stringMap->end ()) + return iter->second; + char16* uStr = generateUTF16 (str); + stringMap->insert (std::make_pair (str, uStr)); + return uStr; +} + +//---------------------------------------------------------------------------- +const char16 ConstStringTable::getString (const char8 str) const +{ + std::map::iterator iter = charMap->find (str); + if (iter != charMap->end ()) + return iter->second; + char16 uStr = 0; +#if BYTEORDER == kBigEndian + char8* puStr = (char8*)&uStr; + puStr[1] = str; +#else + uStr = str; +#endif + charMap->insert (std::make_pair (str, uStr)); + return uStr; +} + +//---------------------------------------------------------------------------- +ConstStringTable::ConstStringTable () +{ + stringMap = new std::map; + charMap = new std::map; +} + +//---------------------------------------------------------------------------- +ConstStringTable::~ConstStringTable () +{ + // free out allocated strings + { + std::map::iterator iter = stringMap->begin (); + while (iter != stringMap->end ()) + { + delete[] iter->second; + iter++; + } + } // delete iterator on map before deleting the map + + delete stringMap; + delete charMap; +} + +//---------------------------------------------------------------------------- +char16* generateUTF16 (const char8* str) +{ + int32 len = (int32)strlen (str); + char16* result = new char16[len + 1]; + for (int32 i = 0; i < len; i++) + { +#if BYTEORDER == kBigEndian + char8* pChr = (char8*)&result[i]; + pChr[0] = 0; + pChr[1] = str[i]; +#else + result[i] = str[i]; +#endif + } + result[len] = 0; + return result; +} +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.h new file mode 100644 index 0000000000..177d32712a --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/conststringtable.h @@ -0,0 +1,45 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/conststringtable.h +// Created by : Steinberg, 09/2007 +// Description : constant unicode string table +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "ftypes.h" + +namespace Steinberg { + +//------------------------------------------------------------------------ +/** Constant unicode string table. +Used for conversion from ASCII string literals to char16. +*/ +//------------------------------------------------------------------------ +class ConstStringTable +{ +public: + static ConstStringTable* instance (); + + /** Returns a char16 string of a ASCII string literal*/ + const char16* getString (const char8* str) const; + /** Returns a char16 character of a ASCII character */ + const char16 getString (const char8 str) const; + +protected: + ConstStringTable (); + ~ConstStringTable (); +}; + +//------------------------------------------------------------------------ +} // namespace Steinberg + diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/coreiids.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/coreiids.cpp new file mode 100644 index 0000000000..9cb6313804 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/coreiids.cpp @@ -0,0 +1,36 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interface IID definitions +// Filename : pluginterfaces/base/coreiids.cpp +// Created by : Steinberg, 01/2004 +// Description : Basic Interface +// +//------------------------------------------------------------------------ +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//------------------------------------------------------------------------ + +#include "pluginterfaces/base/funknown.h" +#include "pluginterfaces/base/iupdatehandler.h" +#include "pluginterfaces/base/icloneable.h" +#include "pluginterfaces/base/ibstream.h" + +//------------------------------------------------------------------------ +namespace Steinberg { + + +DEF_CLASS_IID (FUnknown) + +DEF_CLASS_IID (ICloneable) + +DEF_CLASS_IID (IDependent) +DEF_CLASS_IID (IUpdateHandler) + +DEF_CLASS_IID (IBStream) +DEF_CLASS_IID (ISizeableStream) + +//------------------------------------------------------------------------ +} // Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpop.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpop.h new file mode 100644 index 0000000000..6ea4908556 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpop.h @@ -0,0 +1,31 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/falignpop.h +// Created by : Steinberg, 01/2004 +// Description : Restore alignment settings +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------------------- +#if SMTG_OS_MACOS + #if TARGET_API_MAC_CARBON + #if SMTG_PLATFORM_64 + #pragma pack(pop) + #else + #pragma options align=reset + #endif + #endif +#elif defined __BORLANDC__ + #pragma -a- +#elif SMTG_OS_WINDOWS + #pragma pack(pop) +#endif +//--------------------------------------------------------------------------------------------------- diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpush.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpush.h new file mode 100644 index 0000000000..85dde2e5af --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/falignpush.h @@ -0,0 +1,36 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/falignpush.h +// Created by : Steinberg, 01/2004 +// Description : Set alignment settings +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------------------------- +#if SMTG_OS_MACOS + #if TARGET_API_MAC_CARBON + #if SMTG_PLATFORM_64 + #pragma pack(push, 16) + #else + #pragma options align=mac68k + #endif + #endif +#elif defined __BORLANDC__ + #pragma -a8 +#elif SMTG_OS_WINDOWS + #pragma pack(push) + #if SMTG_PLATFORM_64 + #pragma pack(16) + #else + #pragma pack(8) + #endif +#endif +//---------------------------------------------------------------------------------------------- diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fplatform.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fplatform.h new file mode 100644 index 0000000000..6b2b57d99c --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fplatform.h @@ -0,0 +1,208 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/fplatform.h +// Created by : Steinberg, 01/2004 +// Description : Detect platform and set define +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#define kLittleEndian 0 +#define kBigEndian 1 + +#undef PLUGIN_API + +#if !defined (__INTEL_CXX11_MODE__) +#define SMTG_INTEL_CXX11_MODE 0 +#else +#define SMTG_INTEL_CXX11_MODE __INTEL_CXX11_MODE__ +#endif + +#if !defined (__INTEL_COMPILER) +#define SMTG_INTEL_COMPILER 0 +#else +#define SMTG_INTEL_COMPILER __INTEL_COMPILER +#endif + +//----------------------------------------------------------------------------- +// WIN32 AND WIN64 +#if defined (_WIN32) + #define SMTG_OS_LINUX 0 + #define SMTG_OS_MACOS 0 + #define SMTG_OS_WINDOWS 1 + #define SMTG_OS_IOS 0 + #define SMTG_OS_OSX 0 + + #define BYTEORDER kLittleEndian + + #define COM_COMPATIBLE 1 + #define PLUGIN_API __stdcall + #define SMTG_PTHREADS 0 + + #ifndef _CRT_SECURE_NO_WARNINGS + #define _CRT_SECURE_NO_WARNINGS + #endif + + #pragma warning (disable : 4244) // Conversion from 'type1' to 'type2', possible loss of data. + #pragma warning (disable : 4250) // Inheritance via dominance is allowed + #pragma warning (disable : 4996) // deprecated functions + + #pragma warning (3 : 4189) // local variable is initialized but not referenced + #pragma warning (3 : 4238) // nonstandard extension used : class rvalue used as lvalue + + #if defined (_WIN64) // WIN64 only + #define SMTG_PLATFORM_64 1 + #else + #define SMTG_PLATFORM_64 0 + #endif + + #ifndef WIN32 + #define WIN32 1 + #endif + + #ifdef __cplusplus + #define SMTG_CPP11 __cplusplus >= 201103L || _MSC_VER > 1600 || SMTG_INTEL_CXX11_MODE + #define SMTG_CPP11_STDLIBSUPPORT SMTG_CPP11 + #define SMTG_HAS_NOEXCEPT _MSC_VER >= 1900 || (SMTG_INTEL_CXX11_MODE && SMTG_INTEL_COMPILER >= 1300) + #endif +//----------------------------------------------------------------------------- +// LINUX +#elif __gnu_linux__ + #define SMTG_OS_LINUX 1 + #define SMTG_OS_MACOS 0 + #define SMTG_OS_WINDOWS 0 + #define SMTG_OS_IOS 0 + #define SMTG_OS_OSX 0 + + #include + #if __BYTE_ORDER == __LITTLE_ENDIAN + #define BYTEORDER kLittleEndian + #else + #define BYTEORDER kBigEndian + #endif + + #define COM_COMPATIBLE 0 + #define PLUGIN_API + #define SMTG_PTHREADS 1 + + #if __LP64__ + #define SMTG_PLATFORM_64 1 + #else + #define SMTG_PLATFORM_64 0 + #endif + #ifdef __cplusplus + #include + #define SMTG_CPP11 (__cplusplus >= 201103L) + #ifndef SMTG_CPP11 + #error unsupported compiler + #endif + #define SMTG_CPP11_STDLIBSUPPORT 1 + #define SMTG_HAS_NOEXCEPT 1 + #endif +//----------------------------------------------------------------------------- +// Mac and iOS +#elif __APPLE__ + #include + #define SMTG_OS_LINUX 0 + #define SMTG_OS_MACOS 1 + #define SMTG_OS_WINDOWS 0 + #define SMTG_OS_IOS TARGET_OS_IPHONE + #define SMTG_OS_OSX TARGET_OS_MAC && !TARGET_OS_IPHONE + + #if !SMTG_OS_IOS + #ifndef __CF_USE_FRAMEWORK_INCLUDES__ + #define __CF_USE_FRAMEWORK_INCLUDES__ + #endif + #ifndef TARGET_API_MAC_CARBON + #define TARGET_API_MAC_CARBON 1 + #endif + #endif + #if __LP64__ + #define SMTG_PLATFORM_64 1 + #else + #define SMTG_PLATFORM_64 0 + #endif + #if defined (__BIG_ENDIAN__) + #define BYTEORDER kBigEndian + #else + #define BYTEORDER kLittleEndian + #endif + + #define COM_COMPATIBLE 0 + #define PLUGIN_API + #define SMTG_PTHREADS 1 + + #if !defined(__PLIST__) && !defined(SMTG_DISABLE_DEFAULT_DIAGNOSTICS) + #ifdef __clang__ + #pragma GCC diagnostic ignored "-Wswitch-enum" + #pragma GCC diagnostic ignored "-Wparentheses" + #pragma GCC diagnostic ignored "-Wuninitialized" + #if __clang_major__ >= 3 + #pragma GCC diagnostic ignored "-Wtautological-compare" + #pragma GCC diagnostic ignored "-Wunused-value" + #if __clang_major__ >= 4 || __clang_minor__ >= 1 + #pragma GCC diagnostic ignored "-Wswitch" + #pragma GCC diagnostic ignored "-Wcomment" + #endif + #if __clang_major__ >= 5 + #pragma GCC diagnostic ignored "-Wunsequenced" + #if __clang_minor__ >= 1 + #pragma GCC diagnostic ignored "-Wunused-const-variable" + #endif + #endif + #endif + #endif + #endif + #ifdef __cplusplus + #include + #define SMTG_CPP11 (__cplusplus >= 201103L || SMTG_INTEL_CXX11_MODE) + #if defined (_LIBCPP_VERSION) && SMTG_CPP11 + #define SMTG_CPP11_STDLIBSUPPORT 1 + #define SMTG_HAS_NOEXCEPT 1 + #else + #define SMTG_CPP11_STDLIBSUPPORT 0 + #define SMTG_HAS_NOEXCEPT 0 + #endif + #endif +#else + #pragma error unknown platform + +#endif + +#if !SMTG_RENAME_ASSERT +#undef WINDOWS +#undef MAC +#undef PTHREADS +#undef PLATFORM_64 + +#if SMTG_OS_WINDOWS +#define WINDOWS SMTG_OS_WINDOWS +#endif +#if SMTG_OS_MACOS +#define MAC SMTG_OS_MACOS +#endif +#define PLATFORM_64 SMTG_PLATFORM_64 +#define PTHREADS SMTG_PTHREADS +#endif +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +#if SMTG_CPP11 +#define SMTG_OVERRIDE override +#else +#define SMTG_OVERRIDE +#endif +#if SMTG_HAS_NOEXCEPT +#define SMTG_NOEXCEPT noexcept +#else +#define SMTG_NOEXCEPT +#endif diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fstrdefs.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fstrdefs.h new file mode 100644 index 0000000000..2a5882a051 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fstrdefs.h @@ -0,0 +1,291 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/fstrdefs.h +// Created by : Steinberg, 01/2004 +// Description : Definitions for handling strings (Unicode / ASCII / Platforms) +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "ftypes.h" + +//---------------------------------------------------------------------------- +// string methods defines unicode / ASCII +//---------------------------------------------------------------------------- + +// 16 bit string operations +#if SMTG_CPP11 // if c++11 unicode string literals + #define SMTG_CPP11_CAT_PRIVATE_DONT_USE(a,b) a ## b + #if SMTG_OS_WINDOWS + #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(L,x) + #else + #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(u,x) + #endif +#else + #include "conststringtable.h" + #define STR16(x) Steinberg::ConstStringTable::instance ()->getString (x) +#endif + +#ifdef UNICODE + #define STR(x) STR16(x) + #define tStrBufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::tchar)) + +#else + #define STR(x) x + #define tStrBufferSize(buffer) (sizeof(buffer)) +#endif + +#define str8BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char8)) +#define str16BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char16)) + +#if SMTG_OS_WINDOWS +#define FORMAT_INT64A "I64d" +#define FORMAT_UINT64A "I64u" + +#elif SMTG_OS_MACOS || SMTG_OS_LINUX +#define FORMAT_INT64A "lld" +#define FORMAT_UINT64A "llu" +#define stricmp strcasecmp +#define strnicmp strncasecmp +#endif + +#ifdef UNICODE +#define FORMAT_INT64W STR(FORMAT_INT64A) +#define FORMAT_UINT64W STR(FORMAT_UINT64A) + +#define FORMAT_INT64 FORMAT_INT64W +#define FORMAT_UINT64 FORMAT_UINT64W +#else +#define FORMAT_INT64 FORMAT_INT64A +#define FORMAT_UINT64 FORMAT_UINT64A +#endif + + +//---------------------------------------------------------------------------- +// newline +//---------------------------------------------------------------------------- +#if SMTG_OS_WINDOWS +#define ENDLINE_A "\r\n" +#define ENDLINE_W STR ("\r\n") +#elif SMTG_OS_MACOS +#define ENDLINE_A "\r" +#define ENDLINE_W STR ("\r") +#elif SMTG_OS_LINUX +#define ENDLINE_A "\n" +#define ENDLINE_W STR ("\n") +#endif + +#ifdef UNICODE +#define ENDLINE ENDLINE_W +#else +#define ENDLINE ENDLINE_A +#endif + +#if SMTG_OS_WINDOWS && !defined(__GNUC__) && defined(_MSC_VER) && (_MSC_VER < 1900) +#define stricmp _stricmp +#define strnicmp _strnicmp +#define snprintf _snprintf +#endif + +namespace Steinberg { + +//---------------------------------------------------------------------------- +static const tchar kEmptyString[] = { 0 }; +static const char8 kEmptyString8[] = { 0 }; +static const char16 kEmptyString16[] = { 0 }; + +#ifdef UNICODE +static const tchar kInfiniteSymbol[] = { 0x221E, 0 }; +#else +static const tchar* const kInfiniteSymbol = STR ("oo"); +#endif + +//---------------------------------------------------------------------------- +template +inline int32 _tstrlen (const T* wcs) +{ + const T* eos = wcs; + + while (*eos++) + ; + + return (int32) (eos - wcs - 1); +} + +inline int32 tstrlen (const tchar* str) {return _tstrlen (str);} +inline int32 strlen8 (const char8* str) {return _tstrlen (str);} +inline int32 strlen16 (const char16* str) {return _tstrlen (str);} + +//---------------------------------------------------------------------------- +template +inline int32 _tstrcmp (const T* src, const T* dst) +{ + while (*src == *dst && *dst) + { + src++; + dst++; + } + + if (*src == 0 && *dst == 0) + return 0; + else if (*src == 0) + return -1; + else if (*dst == 0) + return 1; + else + return (int32) (*src - *dst); +} + +inline int32 tstrcmp (const tchar* src, const tchar* dst) {return _tstrcmp (src, dst);} +inline int32 strcmp8 (const char8* src, const char8* dst) {return _tstrcmp (src, dst);} +inline int32 strcmp16 (const char16* src, const char16* dst) {return _tstrcmp (src, dst);} + +template +inline int32 strcmpT (const T* first, const T* last); + +template <> +inline int32 strcmpT (const char8* first, const char8* last) { return _tstrcmp (first, last); } + +template <> +inline int32 strcmpT (const char16* first, const char16* last) { return _tstrcmp (first, last); } + +//---------------------------------------------------------------------------- +template +inline int32 _tstrncmp (const T* first, const T* last, uint32 count) +{ + if (count == 0) + return 0; + + while (--count && *first && *first == *last) + { + first++; + last++; + } + + if (*first == 0 && *last == 0) + return 0; + else if (*first == 0) + return -1; + else if (*last == 0) + return 1; + else + return (int32) (*first - *last); +} + +inline int32 tstrncmp (const tchar* first, const tchar* last, uint32 count) {return _tstrncmp (first, last, count);} +inline int32 strncmp8 (const char8* first, const char8* last, uint32 count) {return _tstrncmp (first, last, count);} +inline int32 strncmp16 (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count);} + +template +inline int32 strncmpT (const T* first, const T* last, uint32 count); + +template <> +inline int32 strncmpT (const char8* first, const char8* last, uint32 count) { return _tstrncmp (first, last, count); } + +template <> +inline int32 strncmpT (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count); } + +//---------------------------------------------------------------------------- +template +inline T* _tstrcpy (T* dst, const T* src) +{ + T* cp = dst; + while ((*cp++ = *src++) != 0) // copy string + ; + return dst; +} +inline tchar* tstrcpy (tchar* dst, const tchar* src) {return _tstrcpy (dst, src);} +inline char8* strcpy8 (char8* dst, const char8* src) {return _tstrcpy (dst, src);} +inline char16* strcpy16 (char16* dst, const char16* src) {return _tstrcpy (dst, src);} + +//---------------------------------------------------------------------------- +template +inline T* _tstrncpy (T* dest, const T* source, uint32 count) +{ + T* start = dest; + while (count && (*dest++ = *source++) != 0) // copy string + count--; + + if (count) // pad out with zeros + { + while (--count) + *dest++ = 0; + } + return start; +} + +inline tchar* tstrncpy (tchar* dest, const tchar* source, uint32 count) {return _tstrncpy (dest, source, count);} +inline char8* strncpy8 (char8* dest, const char8* source, uint32 count) {return _tstrncpy (dest, source, count);} +inline char16* strncpy16 (char16* dest, const char16* source, uint32 count) {return _tstrncpy (dest, source, count);} + +//---------------------------------------------------------------------------- +template +inline T* _tstrcat (T* dst, const T* src) +{ + T* cp = dst; + + while (*cp) + cp++; // find end of dst + + while ((*cp++ = *src++) != 0) // Copy src to end of dst + ; + + return dst; +} + +inline tchar* tstrcat (tchar* dst, const tchar* src) {return _tstrcat (dst, src); } +inline char8* strcat8 (char8* dst, const char8* src) {return _tstrcat (dst, src); } +inline char16* strcat16 (char16* dst, const char16* src) {return _tstrcat (dst, src); } + +//---------------------------------------------------------------------------- +inline void str8ToStr16 (char16* dst, const char8* src, int32 n = -1) +{ + int32 i = 0; + for (;;) + { + if (i == n) + { + dst[i] = 0; + return; + } + +#if BYTEORDER == kBigEndian + char8* pChr = (char8*)&dst[i]; + pChr[0] = 0; + pChr[1] = src[i]; +#else + dst[i] = static_cast (src[i]); +#endif + + if (src[i] == 0) + break; + + i++; + } + + while (n > i) + { + dst[i] = 0; + i++; + } +} + +//------------------------------------------------------------------------ +inline bool FIDStringsEqual (FIDString id1, FIDString id2) +{ + return (id1 && id2) ? (strcmp8 (id1, id2) == 0) : false; +} + +static const uint32 kPrintfBufferSize = 4096; + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ftypes.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ftypes.h new file mode 100644 index 0000000000..feda6b0b9b --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ftypes.h @@ -0,0 +1,192 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/ftypes.h +// Created by : Steinberg, 01/2004 +// Description : Basic data types +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "fplatform.h" + +//#define UNICODE_OFF // disable / enable unicode + +#ifdef UNICODE_OFF + #ifdef UNICODE + #undef UNICODE + #endif +#else + #define UNICODE 1 +#endif + +#ifdef UNICODE +#define _UNICODE 1 +#endif + +namespace Steinberg +{ +//----------------------------------------------------------------- +// Integral Types + typedef char int8; + typedef unsigned char uint8; + typedef unsigned char uchar; + + typedef short int16; + typedef unsigned short uint16; + +#if SMTG_OS_WINDOWS && !defined(__GNUC__) + typedef long int32; + typedef unsigned long uint32; +#else + typedef int int32; + typedef unsigned int uint32; +#endif + + static const int32 kMaxLong = 0x7fffffff; + static const int32 kMinLong = (-0x7fffffff - 1); + static const int32 kMaxInt32 = kMaxLong; + static const int32 kMinInt32 = kMinLong; + static const uint32 kMaxInt32u = 0xffffffff; + +#if SMTG_OS_WINDOWS && !defined(__GNUC__) + typedef __int64 int64; + typedef unsigned __int64 uint64; + static const int64 kMaxInt64 = 9223372036854775807i64; + static const int64 kMinInt64 = (-9223372036854775807i64 - 1); +#else + typedef long long int64; + typedef unsigned long long uint64; + static const int64 kMaxInt64 = 0x7fffffffffffffffLL; + static const int64 kMinInt64 = (-0x7fffffffffffffffLL-1); +#endif + static const uint64 kMaxInt64u = uint64 (0xffffffff) | (uint64 (0xffffffff) << 32); + +//----------------------------------------------------------------- +// other Semantic Types + typedef int64 TSize; // byte (or other) sizes + typedef int32 tresult; // result code +//----------------------------------------------------------------- + static const float kMaxFloat = 3.40282346638528860E38; + static const double kMaxDouble = 1.7976931348623158E308; + +#if SMTG_PLATFORM_64 + typedef uint64 TPtrInt; +#else + typedef uint32 TPtrInt; +#endif + +//------------------------------------------------------------------ +// Boolean + typedef uint8 TBool; + +//------------------------------------------------------------------ +// Char / Strings + typedef char char8; +#ifdef _NATIVE_WCHAR_T_DEFINED + typedef __wchar_t char16; +#elif SMTG_CPP11 + typedef char16_t char16; +#else + typedef int16 char16; +#endif + +#ifdef UNICODE + typedef char16 tchar; +#else + typedef char8 tchar; +#endif + + typedef const char8* CStringA; + typedef const char16* CStringW; + typedef const tchar* CString; + inline bool strEmpty (const tchar* str) { return (!str || *str == 0); } + inline bool str8Empty (const char8* str) { return (!str || *str == 0); } + inline bool str16Empty (const char16* str) { return (!str || *str == 0); } + + typedef const char8* FIDString; // identifier as string (used for attributes, messages) + + const FIDString kPlatformStringWin = "WIN"; + const FIDString kPlatformStringMac = "MAC"; + const FIDString kPlatformStringIOS = "IOS"; + const FIDString kPlatformStringLinux = "Linux"; +#if SMTG_OS_WINDOWS + const FIDString kPlatformString = kPlatformStringWin; +#elif SMTG_OS_IOS + const FIDString kPlatformString = kPlatformStringIOS; +#elif SMTG_OS_MACOS + const FIDString kPlatformString = kPlatformStringMac; +#elif SMTG_OS_LINUX + const FIDString kPlatformString = kPlatformStringLinux; +#endif + +//------------------------------------------------------------------------ +/** Coordinates */ + typedef int32 UCoord; + static const UCoord kMaxCoord = ((UCoord)0x7FFFFFFF); + static const UCoord kMinCoord = ((UCoord)-0x7FFFFFFF); +} // namespace Steinberg + + +//---------------------------------------------------------------------------- +/** Byte-order Conversion Macros */ +//---------------------------------------------------------------------------- +#define SWAP_32(l) { \ + unsigned char* p = (unsigned char*)& (l); \ + unsigned char t; \ + t = p[0]; p[0] = p[3]; p[3] = t; t = p[1]; p[1] = p[2]; p[2] = t; } + +#define SWAP_16(w) { \ + unsigned char* p = (unsigned char*)& (w); \ + unsigned char t; \ + t = p[0]; p[0] = p[1]; p[1] = t; } + +#define SWAP_64(i) { \ + unsigned char* p = (unsigned char*)& (i); \ + unsigned char t; \ + t = p[0]; p[0] = p[7]; p[7] = t; t = p[1]; p[1] = p[6]; p[6] = t; \ + t = p[2]; p[2] = p[5]; p[5] = t; t = p[3]; p[3] = p[4]; p[4] = t;} + +namespace Steinberg +{ + static inline void FSwap (int8&) {} + static inline void FSwap (uint8&) {} + static inline void FSwap (int16& i16) { SWAP_16 (i16) } + static inline void FSwap (uint16& i16) { SWAP_16 (i16) } + static inline void FSwap (int32& i32) { SWAP_32 (i32) } + static inline void FSwap (uint32& i32) { SWAP_32 (i32) } + static inline void FSwap (int64& i64) { SWAP_64 (i64) } + static inline void FSwap (uint64& i64) { SWAP_64 (i64) } +} + +// always inline macros (only when RELEASE is 1) +//---------------------------------------------------------------------------- +#if RELEASE + #if SMTG_OS_MACOS || SMTG_OS_LINUX + #define SMTG_ALWAYS_INLINE __inline__ __attribute__((__always_inline__)) + #define SMTG_NEVER_INLINE __attribute__((noinline)) + #elif SMTG_OS_WINDOWS + #define SMTG_ALWAYS_INLINE __forceinline + #define SMTG_NEVER_INLINE __declspec(noinline) + #endif +#endif + +#ifndef SMTG_ALWAYS_INLINE + #define SMTG_ALWAYS_INLINE inline +#endif +#ifndef SMTG_NEVER_INLINE + #define SMTG_NEVER_INLINE +#endif + +#ifndef SMTG_CPP11_STDLIBSUPPORT +// Enable this for old compilers +// #define nullptr NULL +#endif diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.cpp b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.cpp new file mode 100644 index 0000000000..9aed38abb4 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.cpp @@ -0,0 +1,453 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/funknown.cpp +// Created by : Steinberg, 01/2004 +// Description : Basic Interface +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#include "funknown.h" + +#include "fstrdefs.h" + +#include + +#if SMTG_OS_WINDOWS +#include +#endif + +#if SMTG_OS_MACOS +#include +#include + +#if defined (__GNUC__) && (__GNUC__ >= 4) && !__LP64__ +// on 32 bit Mac OS X we can safely ignore the format warnings as sizeof(int) == sizeof(long) +#pragma GCC diagnostic ignored "-Wformat" +#endif + +#endif + +#if SMTG_OS_LINUX +#include +#endif + +namespace Steinberg { + +//------------------------------------------------------------------------ +#if COM_COMPATIBLE +#if SMTG_OS_WINDOWS +#define GuidStruct GUID +#else +struct GuidStruct +{ + uint32 Data1; + uint16 Data2; + uint16 Data3; + uint8 Data4[8]; +}; +#endif +#endif + +static void toString8 (char8* string, const char* data, int32 i1, int32 i2); +static void fromString8 (const char8* string, char* data, int32 i1, int32 i2); +static uint32 makeLong (uint8 b1, uint8 b2, uint8 b3, uint8 b4); + +//------------------------------------------------------------------------ +// FUnknownPrivate +//------------------------------------------------------------------------ +namespace FUnknownPrivate { +//------------------------------------------------------------------------ +int32 PLUGIN_API atomicAdd (int32& var, int32 d) +{ +#if SMTG_OS_WINDOWS + return InterlockedExchangeAdd (&var, d) + d; +#elif SMTG_OS_MACOS + return OSAtomicAdd32Barrier (d, (int32_t*)&var); +#elif SMTG_OS_LINUX + __gnu_cxx::__atomic_add (&var, d); + return var; +#else +#warning implement me! + var += d; + return var; +#endif +} +} // FUnknownPrivate + +//------------------------------------------------------------------------ +// FUID implementation +//------------------------------------------------------------------------ + +FUID::FUID () +{ + memset (data, 0, sizeof (TUID)); +} + +//------------------------------------------------------------------------ +FUID::FUID (uint32 l1, uint32 l2, uint32 l3, uint32 l4) +{ + from4Int (l1, l2, l3, l4); +} + +//------------------------------------------------------------------------ +FUID::FUID (const FUID& f) +{ + memcpy (data, f.data, sizeof (TUID)); +} + +//------------------------------------------------------------------------ +#if SMTG_CPP11_STDLIBSUPPORT +FUID::FUID (FUID&& other) { + memcpy (data, other.data, sizeof (TUID)); +} + +FUID& FUID::operator= (FUID&& other) +{ + memcpy (data, other.data, sizeof (TUID)); + return *this; +} +#endif + +//------------------------------------------------------------------------ +bool FUID::generate () +{ +#if SMTG_OS_WINDOWS + GUID guid; + HRESULT hr = CoCreateGuid (&guid); + switch (hr) + { + case RPC_S_OK: + memcpy (data, (char*)&guid, sizeof (TUID)); + return true; + + case RPC_S_UUID_LOCAL_ONLY: + default: + return false; + } + +#elif SMTG_OS_MACOS + CFUUIDRef uuid = CFUUIDCreate (kCFAllocatorDefault); + if (uuid) + { + CFUUIDBytes bytes = CFUUIDGetUUIDBytes (uuid); + memcpy (data, (char*)&bytes, sizeof (TUID)); + CFRelease (uuid); + return true; + } + return false; + +#else +#warning implement me! + return false; +#endif +} + +//------------------------------------------------------------------------ +bool FUID::isValid () const +{ + TUID nulluid = {0}; + + return memcmp (data, nulluid, sizeof (TUID)) != 0; +} + +//------------------------------------------------------------------------ +FUID& FUID::operator = (const FUID& f) +{ + memcpy (data, f.data, sizeof (TUID)); + return *this; +} + +//------------------------------------------------------------------------ +void FUID::from4Int (uint32 l1, uint32 l2, uint32 l3, uint32 l4) +{ +#if COM_COMPATIBLE + data [0] = (char)((l1 & 0x000000FF) ); + data [1] = (char)((l1 & 0x0000FF00) >> 8); + data [2] = (char)((l1 & 0x00FF0000) >> 16); + data [3] = (char)((l1 & 0xFF000000) >> 24); + data [4] = (char)((l2 & 0x00FF0000) >> 16); + data [5] = (char)((l2 & 0xFF000000) >> 24); + data [6] = (char)((l2 & 0x000000FF) ); + data [7] = (char)((l2 & 0x0000FF00) >> 8); + data [8] = (char)((l3 & 0xFF000000) >> 24); + data [9] = (char)((l3 & 0x00FF0000) >> 16); + data [10] = (char)((l3 & 0x0000FF00) >> 8); + data [11] = (char)((l3 & 0x000000FF) ); + data [12] = (char)((l4 & 0xFF000000) >> 24); + data [13] = (char)((l4 & 0x00FF0000) >> 16); + data [14] = (char)((l4 & 0x0000FF00) >> 8); + data [15] = (char)((l4 & 0x000000FF) ); +#else + data [0] = (char)((l1 & 0xFF000000) >> 24); + data [1] = (char)((l1 & 0x00FF0000) >> 16); + data [2] = (char)((l1 & 0x0000FF00) >> 8); + data [3] = (char)((l1 & 0x000000FF) ); + data [4] = (char)((l2 & 0xFF000000) >> 24); + data [5] = (char)((l2 & 0x00FF0000) >> 16); + data [6] = (char)((l2 & 0x0000FF00) >> 8); + data [7] = (char)((l2 & 0x000000FF) ); + data [8] = (char)((l3 & 0xFF000000) >> 24); + data [9] = (char)((l3 & 0x00FF0000) >> 16); + data [10] = (char)((l3 & 0x0000FF00) >> 8); + data [11] = (char)((l3 & 0x000000FF) ); + data [12] = (char)((l4 & 0xFF000000) >> 24); + data [13] = (char)((l4 & 0x00FF0000) >> 16); + data [14] = (char)((l4 & 0x0000FF00) >> 8); + data [15] = (char)((l4 & 0x000000FF) ); +#endif +} + +//------------------------------------------------------------------------ +void FUID::to4Int (uint32& d1, uint32& d2, uint32& d3, uint32& d4) const +{ + d1 = getLong1 (); + d2 = getLong2 (); + d3 = getLong3 (); + d4 = getLong4 (); +} + +//------------------------------------------------------------------------ +uint32 FUID::getLong1 () const +{ +#if COM_COMPATIBLE + return makeLong (data[3], data[2], data [1], data [0]); +#else + return makeLong (data[0], data[1], data [2], data [3]); +#endif +} + +//------------------------------------------------------------------------ +uint32 FUID::getLong2 () const +{ +#if COM_COMPATIBLE + return makeLong (data[5], data[4], data [7], data [6]); +#else + return makeLong (data[4], data[5], data [6], data [7]); +#endif +} + +//------------------------------------------------------------------------ +uint32 FUID::getLong3 () const +{ +#if COM_COMPATIBLE + return makeLong (data[8], data[9], data [10], data [11]); +#else + return makeLong (data[8], data[9], data [10], data [11]); +#endif +} + +//------------------------------------------------------------------------ +uint32 FUID::getLong4 () const +{ +#if COM_COMPATIBLE + return makeLong (data[12], data[13], data [14], data [15]); +#else + return makeLong (data[12], data[13], data [14], data [15]); +#endif +} + +//------------------------------------------------------------------------ +void FUID::toString (char8* string) const +{ + if (!string) + return; + + #if COM_COMPATIBLE + GuidStruct* g = (GuidStruct*)data; + + char8 s[17]; + Steinberg::toString8 (s, data, 8, 16); + + sprintf (string, "%08X%04X%04X%s", g->Data1, g->Data2, g->Data3, s); + #else + Steinberg::toString8 (string, data, 0, 16); + #endif +} + +//------------------------------------------------------------------------ +bool FUID::fromString (const char8* string) +{ + if (!string || !*string) + return false; + if (strlen (string) != 32) + return false; + + #if COM_COMPATIBLE + GuidStruct g; + char s[33]; + + strcpy (s, string); + s[8] = 0; + sscanf (s, "%x", &g.Data1); + strcpy (s, string + 8); + s[4] = 0; + sscanf (s, "%hx", &g.Data2); + strcpy (s, string + 12); + s[4] = 0; + sscanf (s, "%hx", &g.Data3); + + memcpy (data, &g, 8); + Steinberg::fromString8 (string + 16, data, 8, 16); + #else + Steinberg::fromString8 (string, data, 0, 16); + #endif + + return true; +} + +//------------------------------------------------------------------------ +bool FUID::fromRegistryString (const char8* string) +{ + if (!string || !*string) + return false; + if (strlen (string) != 38) + return false; + + // e.g. {c200e360-38c5-11ce-ae62-08002b2b79ef} + + #if COM_COMPATIBLE + GuidStruct g; + char8 s[10]; + + strncpy (s, string + 1, 8); + s[8] = 0; + sscanf (s, "%x", &g.Data1); + strncpy (s, string + 10, 4); + s[4] = 0; + sscanf (s, "%hx", &g.Data2); + strncpy (s, string + 15, 4); + s[4] = 0; + sscanf (s, "%hx", &g.Data3); + memcpy (data, &g, 8); + + Steinberg::fromString8 (string + 20, data, 8, 10); + Steinberg::fromString8 (string + 25, data, 10, 16); + #else + Steinberg::fromString8 (string + 1, data, 0, 4); + Steinberg::fromString8 (string + 10, data, 4, 6); + Steinberg::fromString8 (string + 15, data, 6, 8); + Steinberg::fromString8 (string + 20, data, 8, 10); + Steinberg::fromString8 (string + 25, data, 10, 16); + #endif + + return true; +} + +//------------------------------------------------------------------------ +void FUID::toRegistryString (char8* string) const +{ + // e.g. {c200e360-38c5-11ce-ae62-08002b2b79ef} + + #if COM_COMPATIBLE + GuidStruct* g = (GuidStruct*)data; + + char8 s1[5]; + Steinberg::toString8 (s1, data, 8, 10); + + char8 s2[13]; + Steinberg::toString8 (s2, data, 10, 16); + + sprintf (string, "{%08X-%04X-%04X-%s-%s}", g->Data1, g->Data2, g->Data3, s1, s2); + #else + char8 s1[9]; + Steinberg::toString8 (s1, data, 0, 4); + char8 s2[5]; + Steinberg::toString8 (s2, data, 4, 6); + char8 s3[5]; + Steinberg::toString8 (s3, data, 6, 8); + char8 s4[5]; + Steinberg::toString8 (s4, data, 8, 10); + char8 s5[13]; + Steinberg::toString8 (s5, data, 10, 16); + + sprintf (string, "{%s-%s-%s-%s-%s}", s1, s2, s3, s4, s5); + #endif +} + +//------------------------------------------------------------------------ +void FUID::print (char8* string, int32 style) const +{ + if (!string) // no string: debug output + { + char8 str [128]; + print (str, style); + +#if SMTG_OS_WINDOWS + OutputDebugStringA (str); + OutputDebugStringA ("\n"); +#else + fprintf (stdout, "%s\n", str); +#endif + return; + } + + uint32 l1, l2, l3, l4; + to4Int (l1, l2, l3, l4); + + switch (style) + { + case kINLINE_UID: + sprintf (string, "INLINE_UID (0x%08X, 0x%08X, 0x%08X, 0x%08X)", l1, l2, l3, l4); + break; + + case kDECLARE_UID: + sprintf (string, "DECLARE_UID (0x%08X, 0x%08X, 0x%08X, 0x%08X)", l1, l2, l3, l4); + break; + + case kFUID: + sprintf (string, "FUID (0x%08X, 0x%08X, 0x%08X, 0x%08X)", l1, l2, l3, l4); + break; + + case kCLASS_UID: + default: + sprintf (string, "DECLARE_CLASS_IID (Interface, 0x%08X, 0x%08X, 0x%08X, 0x%08X)", l1, l2, l3, l4); + break; + } +} + +//------------------------------------------------------------------------ +// helpers +//------------------------------------------------------------------------ +static uint32 makeLong (uint8 b1, uint8 b2, uint8 b3, uint8 b4) +{ + return (uint32(b1) << 24) | (uint32(b2) << 16) | (uint32(b3) << 8) | uint32(b4); +} + +//------------------------------------------------------------------------ +static void toString8 (char8* string, const char* data, int32 i1, int32 i2) +{ + *string = 0; + for (int32 i = i1; i < i2; i++) + { + char8 s[3]; + sprintf (s, "%02X", (uint8)data[i]); + strcat (string, s); + } +} + +//------------------------------------------------------------------------ +static void fromString8 (const char8* string, char* data, int32 i1, int32 i2) +{ + for (int32 i = i1; i < i2; i++) + { + char8 s[3]; + s[0] = *string++; + s[1] = *string++; + s[2] = 0; + + int32 d = 0; + sscanf (s, "%2x", &d); + data[i] = (char)d; + } +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.h new file mode 100644 index 0000000000..f0f5a7171e --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/funknown.h @@ -0,0 +1,466 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/funknown.h +// Created by : Steinberg, 01/2004 +// Description : Basic Interface +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/fplatform.h" +#include "pluginterfaces/base/ftypes.h" +#include "pluginterfaces/base/smartpointer.h" +#include + +//------------------------------------------------------------------------ +/*! \defgroup pluginBase Basic Interfaces +*/ +//------------------------------------------------------------------------ + +//------------------------------------------------------------------------ +// Unique Identifier macros +//------------------------------------------------------------------------ + +#if COM_COMPATIBLE +#define INLINE_UID(l1, l2, l3, l4) \ +{ \ + (::Steinberg::int8)((l1 & 0x000000FF) ), (::Steinberg::int8)((l1 & 0x0000FF00) >> 8), \ + (::Steinberg::int8)((l1 & 0x00FF0000) >> 16), (::Steinberg::int8)((l1 & 0xFF000000) >> 24), \ + (::Steinberg::int8)((l2 & 0x00FF0000) >> 16), (::Steinberg::int8)((l2 & 0xFF000000) >> 24), \ + (::Steinberg::int8)((l2 & 0x000000FF) ), (::Steinberg::int8)((l2 & 0x0000FF00) >> 8), \ + (::Steinberg::int8)((l3 & 0xFF000000) >> 24), (::Steinberg::int8)((l3 & 0x00FF0000) >> 16), \ + (::Steinberg::int8)((l3 & 0x0000FF00) >> 8), (::Steinberg::int8)((l3 & 0x000000FF) ), \ + (::Steinberg::int8)((l4 & 0xFF000000) >> 24), (::Steinberg::int8)((l4 & 0x00FF0000) >> 16), \ + (::Steinberg::int8)((l4 & 0x0000FF00) >> 8), (::Steinberg::int8)((l4 & 0x000000FF) ) \ +} +#else +#define INLINE_UID(l1, l2, l3, l4) \ +{ \ + (::Steinberg::int8)((l1 & 0xFF000000) >> 24), (::Steinberg::int8)((l1 & 0x00FF0000) >> 16), \ + (::Steinberg::int8)((l1 & 0x0000FF00) >> 8), (::Steinberg::int8)((l1 & 0x000000FF) ), \ + (::Steinberg::int8)((l2 & 0xFF000000) >> 24), (::Steinberg::int8)((l2 & 0x00FF0000) >> 16), \ + (::Steinberg::int8)((l2 & 0x0000FF00) >> 8), (::Steinberg::int8)((l2 & 0x000000FF) ), \ + (::Steinberg::int8)((l3 & 0xFF000000) >> 24), (::Steinberg::int8)((l3 & 0x00FF0000) >> 16), \ + (::Steinberg::int8)((l3 & 0x0000FF00) >> 8), (::Steinberg::int8)((l3 & 0x000000FF) ), \ + (::Steinberg::int8)((l4 & 0xFF000000) >> 24), (::Steinberg::int8)((l4 & 0x00FF0000) >> 16), \ + (::Steinberg::int8)((l4 & 0x0000FF00) >> 8), (::Steinberg::int8)((l4 & 0x000000FF) ) \ +} +#endif + +//------------------------------------------------------------------------ +#define DECLARE_UID(name, l1, l2, l3, l4) \ + ::Steinberg::TUID name = INLINE_UID (l1, l2, l3, l4); + +//------------------------------------------------------------------------ +#define EXTERN_UID(name) \ + extern const ::Steinberg::TUID name; + + +#ifdef INIT_CLASS_IID +#define DECLARE_CLASS_IID(ClassName, l1, l2, l3, l4) static const ::Steinberg::TUID ClassName##_iid = INLINE_UID (l1, l2, l3, l4); \ +const ::Steinberg::FUID ClassName::iid (ClassName##_iid); +#else +#define DECLARE_CLASS_IID(ClassName, l1, l2, l3, l4) static const ::Steinberg::TUID ClassName##_iid = INLINE_UID (l1, l2, l3, l4); +#endif +#define DEF_CLASS_IID(ClassName) const ::Steinberg::FUID ClassName::iid (ClassName##_iid); + +#define INLINE_UID_OF(ClassName) ClassName##_iid + +#define INLINE_UID_FROM_FUID(x) INLINE_UID(x.getLong1 (), x.getLong2 (), x.getLong3 (), x.getLong4 ()) + +//------------------------------------------------------------------------ +// FUnknown implementation macros +//------------------------------------------------------------------------ + +#define DECLARE_FUNKNOWN_METHODS \ +public: \ + virtual ::Steinberg::tresult PLUGIN_API queryInterface (const ::Steinberg::TUID _iid, void** obj) SMTG_OVERRIDE; \ + virtual ::Steinberg::uint32 PLUGIN_API addRef () SMTG_OVERRIDE; \ + virtual ::Steinberg::uint32 PLUGIN_API release () SMTG_OVERRIDE; \ +protected : \ + ::Steinberg::int32 __funknownRefCount; \ +public: + +//------------------------------------------------------------------------ + +#define DELEGATE_REFCOUNT(ClassName) \ +public: \ + virtual ::Steinberg::uint32 PLUGIN_API addRef () SMTG_OVERRIDE { return ClassName::addRef (); } \ + virtual ::Steinberg::uint32 PLUGIN_API release () SMTG_OVERRIDE { return ClassName::release (); } + +//------------------------------------------------------------------------ +#define IMPLEMENT_REFCOUNT(ClassName) \ +::Steinberg::uint32 PLUGIN_API ClassName::addRef () \ +{ \ + return ::Steinberg::FUnknownPrivate::atomicAdd (__funknownRefCount, 1); \ +} \ +::Steinberg::uint32 PLUGIN_API ClassName::release () \ +{ \ + if (::Steinberg::FUnknownPrivate::atomicAdd (__funknownRefCount, -1) == 0) \ + { \ + delete this; \ + return 0; \ + } \ + return __funknownRefCount; \ +} + +//------------------------------------------------------------------------ +#define FUNKNOWN_CTOR { __funknownRefCount = 1; } +#define FUNKNOWN_DTOR + +//------------------------------------------------------------------------ +#define QUERY_INTERFACE(iid, obj, InterfaceIID, InterfaceName) \ +if (::Steinberg::FUnknownPrivate::iidEqual (iid, InterfaceIID)) \ +{ \ + addRef (); \ + *obj = static_cast< InterfaceName* >(this); \ + return ::Steinberg::kResultOk; \ +} + +//------------------------------------------------------------------------ +#define IMPLEMENT_QUERYINTERFACE(ClassName, InterfaceName, ClassIID) \ +::Steinberg::tresult PLUGIN_API ClassName::queryInterface (const ::Steinberg::TUID _iid, void** obj) \ +{ \ + QUERY_INTERFACE (_iid, obj, ::Steinberg::FUnknown::iid, InterfaceName) \ + QUERY_INTERFACE (_iid, obj, ClassIID, InterfaceName) \ + *obj = nullptr; \ + return ::Steinberg::kNoInterface; \ +} + +//------------------------------------------------------------------------ +#define IMPLEMENT_FUNKNOWN_METHODS(ClassName,InterfaceName,ClassIID) \ + IMPLEMENT_REFCOUNT (ClassName) \ + IMPLEMENT_QUERYINTERFACE (ClassName, InterfaceName, ClassIID) + +//------------------------------------------------------------------------ +// Result Codes +//------------------------------------------------------------------------ + +namespace Steinberg { + +//------------------------------------------------------------------------ +#if COM_COMPATIBLE +#if SMTG_OS_WINDOWS +enum +{ + kNoInterface = static_cast(0x80004002L), // E_NOINTERFACE + kResultOk = static_cast(0x00000000L), // S_OK + kResultTrue = kResultOk, + kResultFalse = static_cast(0x00000001L), // S_FALSE + kInvalidArgument = static_cast(0x80070057L), // E_INVALIDARG + kNotImplemented = static_cast(0x80004001L), // E_NOTIMPL + kInternalError = static_cast(0x80004005L), // E_FAIL + kNotInitialized = static_cast(0x8000FFFFL), // E_UNEXPECTED + kOutOfMemory = static_cast(0x8007000EL) // E_OUTOFMEMORY +}; +#else +enum +{ + kNoInterface = static_cast(0x80000004L), // E_NOINTERFACE + kResultOk = static_cast(0x00000000L), // S_OK + kResultTrue = kResultOk, + kResultFalse = static_cast(0x00000001L), // S_FALSE + kInvalidArgument = static_cast(0x80000003L), // E_INVALIDARG + kNotImplemented = static_cast(0x80000001L), // E_NOTIMPL + kInternalError = static_cast(0x80000008L), // E_FAIL + kNotInitialized = static_cast(0x8000FFFFL), // E_UNEXPECTED + kOutOfMemory = static_cast(0x80000002L) // E_OUTOFMEMORY +}; +#endif +#else +enum +{ + kNoInterface = -1, + kResultOk, + kResultTrue = kResultOk, + kResultFalse, + kInvalidArgument, + kNotImplemented, + kInternalError, + kNotInitialized, + kOutOfMemory +}; +#endif + +//------------------------------------------------------------------------ +typedef int64 LARGE_INT; // obsolete + +//------------------------------------------------------------------------ +// FUID class declaration +//------------------------------------------------------------------------ +typedef int8 TUID[16]; ///< plain UID type + +//------------------------------------------------------------------------ +/* FUnknown private */ +namespace FUnknownPrivate { +SMTG_ALWAYS_INLINE bool iidEqual (const void* iid1, const void* iid2) +{ + const uint64* p1 = reinterpret_cast (iid1); + const uint64* p2 = reinterpret_cast (iid2); + return p1[0] == p2[0] && p1[1] == p2[1]; +} + +int32 PLUGIN_API atomicAdd (int32& value, int32 amount); +} + +//------------------------------------------------------------------------ +/** Handling 16 Byte Globally Unique Identifiers. +\ingroup pluginBase + +Each interface declares its identifier as static member inside the interface +namespace (e.g. FUnknown::iid). +*/ +//------------------------------------------------------------------------ +class FUID +{ +public: +//------------------------------------------------------------------------ + FUID (); + FUID (uint32 l1, uint32 l2, uint32 l3, uint32 l4); + FUID (const FUID&); + virtual ~FUID () {} + +#if SMTG_CPP11_STDLIBSUPPORT + FUID (FUID&& other); + FUID& operator= (FUID&& other); +#endif + + /** Generates a new Unique Identifier (UID). + Will return true for success. If the return value is false, either no + UID is generated or the UID is not guaranteed to be unique worldwide. */ + bool generate (); + + /** Checks if the UID data is valid. + The default constructor initializes the memory with zeros. */ + bool isValid () const; + + FUID& operator = (const FUID& f); + bool operator == (const FUID& f) const { return ::Steinberg::FUnknownPrivate::iidEqual (data, f.data); } + bool operator < (const FUID& f) const { return memcmp (data, f.data, sizeof (TUID)) < 0; } + bool operator != (const FUID& f) const { return !::Steinberg::FUnknownPrivate::iidEqual (data, f.data); } + + + uint32 getLong1 () const; + uint32 getLong2 () const; + uint32 getLong3 () const; + uint32 getLong4 () const; + + void from4Int (uint32 d1, uint32 d2, uint32 d3, uint32 d4); + void to4Int (uint32& d1, uint32& d2, uint32& d3, uint32& d4) const; + + typedef char8 String [64]; + + /** Converts UID to a string. + The string will be 32 characters long, representing the hexadecimal values + of each data byte (e.g. "9127BE30160E4BB69966670AA6087880"). + + Typical use-case is: + \code + char8[33] strUID = {0}; + FUID uid; + if (uid.generate ()) + uid.toString (strUID); + \endcode + */ + void toString (char8* string) const; + + /** Sets the UID data from a string. + The string has to be 32 characters long, where each character-pair is + the ASCII-encoded hexadecimal value of the corresponding data byte. */ + bool fromString (const char8* string); + + /** Converts UID to a string in Microsoft® OLE format. + (e.g. "{c200e360-38c5-11ce-ae62-08002b2b79ef}") */ + void toRegistryString (char8* string) const; + + /** Sets the UID data from a string in Microsoft® OLE format. */ + bool fromRegistryString (const char8* string); + + enum UIDPrintStyle + { + kINLINE_UID, ///< "INLINE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000)" + kDECLARE_UID, ///< "DECLARE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000)" + kFUID, ///< "FUID (0x00000000, 0x00000000, 0x00000000, 0x00000000)" + kCLASS_UID ///< "DECLARE_CLASS_IID (Interface, 0x00000000, 0x00000000, 0x00000000, 0x00000000)" + }; + /** Prints the UID to a string (or debug output if string is NULL). + \param string is the output string if not NULL. + \param style can be chosen from the FUID::UIDPrintStyle enumeration. */ + void print (char8* string = 0, int32 style = kINLINE_UID) const; + + template + inline explicit FUID (const int8 (&uid)[N]) + { +#if SMTG_CPP11_STDLIBSUPPORT + static_assert (N == sizeof (TUID), "only TUID allowed"); +#endif + memcpy (data, uid, sizeof (TUID)); + } + inline void toTUID (TUID result) const { memcpy (result, data, sizeof (TUID)); } + inline operator const TUID& () const { return data; } + inline const TUID& toTUID () const { return data; } + + static FUID fromTUID (const TUID uid) + { + FUID res; + if (uid) + memcpy (res.data, uid, sizeof (TUID)); + return res; + } + +//------------------------------------------------------------------------ +protected: + TUID data; +}; + +#if SMTG_CPP11_STDLIBSUPPORT +template +inline bool operator== (const FUID& f1, T f2) +{ + static_assert ( + std::is_same::type, FUID>::value, + "Do not compare a FUID with a TUID directly. Either convert the TUID to a FUID and compare them or use FUnknownPrivate::iidEqual"); + return f1.operator== (f2); +} +#endif + +//------------------------------------------------------------------------ +// FUnknown +//------------------------------------------------------------------------ +/** The basic interface of all interfaces. +\ingroup pluginBase + +- The FUnknown::queryInterface method is used to retrieve pointers to other + interfaces of the object. +- FUnknown::addRef and FUnknown::release manage the lifetime of the object. + If no more references exist, the object is destroyed in memory. + +Interfaces are identified by 16 byte Globally Unique Identifiers. +The SDK provides a class called FUID for this purpose. + +\ref howtoClass */ +//------------------------------------------------------------------------ +class FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Query for a pointer to the specified interface. + Returns kResultOk on success or kNoInterface if the object does not implement the interface. + The object has to call addRef when returning an interface. + \param _iid : (in) 16 Byte interface identifier (-> FUID) + \param obj : (out) On return, *obj points to the requested interface */ + virtual tresult PLUGIN_API queryInterface (const TUID _iid, void** obj) = 0; + + /** Adds a reference and return the new reference count. + \par Remarks: + The initial reference count after creating an object is 1. */ + virtual uint32 PLUGIN_API addRef () = 0; + + /** Releases a reference and return the new reference count. + If the reference count reaches zero, the object will be destroyed in memory. */ + virtual uint32 PLUGIN_API release () = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +//------------------------------------------------------------------------ +}; + +DECLARE_CLASS_IID (FUnknown, 0x00000000, 0x00000000, 0xC0000000, 0x00000046) + +//------------------------------------------------------------------------ +// FUnknownPtr +//------------------------------------------------------------------------ +/** FUnknownPtr - automatic interface conversion and smart pointer in one. + This template class can be used for interface conversion like this: + \code + IPtr path = owned (FHostCreate (IPath, hostClasses)); + FUnknownPtr path2 (path); // does a query interface for IPath2 + if (path2) + ... + \endcode +*/ +//------------------------------------------------------------------------ +template +class FUnknownPtr : public IPtr +{ +public: +//------------------------------------------------------------------------ + inline FUnknownPtr (FUnknown* unknown); // query interface + inline FUnknownPtr (const FUnknownPtr& p) : IPtr (p) {} + inline FUnknownPtr () {} + + inline FUnknownPtr& operator=(const FUnknownPtr& p) {IPtr::operator=(p); return *this;} + inline I* operator=(FUnknown* unknown); + inline I* getInterface () { return this->ptr; } +}; + +//------------------------------------------------------------------------ +template +inline FUnknownPtr::FUnknownPtr (FUnknown* unknown) +{ + if (unknown && unknown->queryInterface (I::iid, (void**)&this->ptr) != kResultOk) + this->ptr = 0; +} + +//------------------------------------------------------------------------ +template +inline I* FUnknownPtr::operator=(FUnknown* unknown) +{ + I* newPtr = 0; + if (unknown && unknown->queryInterface (I::iid, (void**)&newPtr) == kResultOk) + { + OPtr rel (newPtr); + return IPtr::operator=(newPtr); + } + + return IPtr::operator=(0); +} + + +//------------------------------------------------------------------------ +// FReleaser (obsolete) +//------------------------------------------------------------------------ +/** Release an interface using automatic object (obsolete). +This class is obsolete and is only kept for compatibility. +The replacement for FReleaser is OPtr. + +Usage example with FReleaser: + \code + void someFunction () + { + IPath* path = pathCreateMethod (); + FReleaser releaser (path); + .... do something with path... + .... path not used anymore, releaser will destroy it when leaving function scope + } + \endcode +Usage example with OPtr: + \code + void someFunction () + { + OPtr path = pathCreateMethod (); + .... do something with path... + .... path not used anymore, OPtr will destroy it when leaving function scope + } + \endcode +*/ +//------------------------------------------------------------------------ +struct FReleaser +{ + FReleaser (FUnknown* u): u (u) {} + ~FReleaser () { if (u) u->release (); } + + FUnknown* u; +}; + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/futils.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/futils.h new file mode 100644 index 0000000000..a3643fff26 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/futils.h @@ -0,0 +1,92 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/futils.h +// Created by : Steinberg, 01/2004 +// Description : Basic utilities +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/ftypes.h" + +namespace Steinberg { +//---------------------------------------------------------------------------- +// min/max/etc. template functions +template +inline const T& Min (const T& a, const T& b) +{ + return b < a ? b : a; +} + +template +inline const T& Max (const T& a, const T& b) +{ + return a < b ? b : a; +} + +template +inline T Abs (const T& value) +{ + return (value >= (T)0) ? value : -value; +} + +template +inline T Sign (const T& value) +{ + return (value == (T)0) ? 0 : ((value >= (T)0) ? 1 : -1); +} + +template +inline T Bound (T minval, T maxval, T x) +{ + if (x < minval) + return minval; + else if (x > maxval) + return maxval; + return x; +} + +template +void Swap (T& t1, T& t2) +{ + T tmp = t1; + t1 = t2; + t2 = tmp; +} + +template +bool IsApproximateEqual (T t1, T t2, T epsilon) +{ + if (t1 == t2) + return true; + T diff = t1 - t2; + if (diff < 0.0) + diff = -diff; + if (diff < epsilon) + return true; + return false; +} + +template +inline T ToNormalized (const T& value, const int32 numSteps) +{ + return value / T (numSteps); +} + +template +inline int32 FromNormalized (const T& norm, const int32 numSteps) +{ + return Min (numSteps, int32 (norm * (numSteps + 1))); +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fvariant.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fvariant.h new file mode 100644 index 0000000000..a0008b62f7 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/fvariant.h @@ -0,0 +1,297 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/fvariant.h +// Created by : Steinberg, 01/2004 +// Description : Basic Interface +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/fstrdefs.h" +#include "pluginterfaces/base/funknown.h" + +//------------------------------------------------------------------------ +namespace Steinberg { + +class FUnknown; + +//------------------------------------------------------------------------ +// FVariant struct declaration +//------------------------------------------------------------------------ +/** A Value of variable type. + \ingroup pluginBase + */ +class FVariant +{ +//------------------------------------------------------------------------ +public: + enum + { + kEmpty = 0, + kInteger = 1 << 0, + kFloat = 1 << 1, + kString8 = 1 << 2, + kObject = 1 << 3, + kOwner = 1 << 4, + kString16 = 1 << 5 + }; + +//------------------------------------------------------------------------ + // ctors + inline FVariant () { memset (this, 0, sizeof (FVariant)); } + inline FVariant (const FVariant& variant); + + inline FVariant (bool b) : type (kInteger), intValue (b) {} + inline FVariant (uint32 v) : type (kInteger), intValue (v) {} + inline FVariant (int64 v) : type (kInteger), intValue (v) {} + inline FVariant (double v) : type (kFloat), floatValue (v) {} + inline FVariant (const char8* str) : type (kString8), string8 (str) {} + inline FVariant (const char16* str) : type (kString16), string16 (str) {} + inline FVariant (FUnknown* obj, bool owner = false) : type (kObject), object (obj) + { + setOwner (owner); + } + inline ~FVariant () { empty (); } + +//------------------------------------------------------------------------ + inline FVariant& operator= (const FVariant& variant); + + inline void set (bool b) + { + setInt (b); + } + + inline void set (uint32 v) + { + setInt (v); + } + + inline void set (int64 v) + { + setInt (v); + } + + inline void set (double v) + { + setFloat (v); + } + + inline void set (const char8* c) + { + setString8 (c); + } + + inline void set (const char16* c) + { + setString16 (c); + } + + inline void setInt (int64 v) + { + empty (); + type = kInteger; + intValue = v; + } + + inline void setFloat (double v) + { + empty (); + type = kFloat; + floatValue = v; + } + inline void setString8 (const char8* v) + { + empty (); + type = kString8; + string8 = v; + } + inline void setString16 (const char16* v) + { + empty (); + type = kString16; + string16 = v; + } + + inline void setObject (FUnknown* obj) + { + empty (); + type = kObject; + object = obj; + } + + template + inline T get () const; + + inline int64 getInt () const { return (type & kInteger) ? intValue : 0; } + inline double getFloat () const { return (type & kFloat) ? floatValue : 0.; } + inline double getNumber () const + { + return (type & kInteger) ? static_cast (intValue) : (type & kFloat) ? floatValue : + 0.; + } + inline const char8* getString8 () const { return (type & kString8) ? string8 : 0; } + inline const char16* getString16 () const { return (type & kString16) ? string16 : 0; } + + inline FUnknown* getObject () const { return (type & kObject) ? object : 0; } + + inline uint16 getType () const { return static_cast (type & ~(kOwner)); } + inline bool isEmpty () const { return getType () == kEmpty; } + inline bool isOwner () const { return (type & kOwner) != 0; } + inline bool isString () const { return (type & (kString8 | kString16)) != 0; } + inline void setOwner (bool state) + { + if (state) + type |= kOwner; + else + type &= ~kOwner; + } + + void empty (); +//------------------------------------------------------------------------ + uint16 type; + union + { + int64 intValue; + double floatValue; + const char8* string8; + const char16* string16; + FUnknown* object; + }; +}; + +//------------------------------------------------------------------------ +inline bool operator== (const FVariant& v1, const FVariant& v2) +{ +#if SMTG_PLATFORM_64 + return v1.type == v2.type && v1.intValue == v2.intValue; +#else + if (v1.type != v2.type) + return false; + if (v1.type & (FVariant::kString8 | FVariant::kString16 | FVariant::kObject)) + return v1.string8 == v2.string8; // pointer type comparisons + return v1.intValue == v2.intValue; // intValue & double comparison + +#endif +} + +template <> +inline bool FVariant::get () const +{ + return getInt () != 0; +} + +template <> +inline uint32 FVariant::get () const +{ + return static_cast (getInt ()); +} + +template <> +inline int32 FVariant::get () const +{ + return static_cast (getInt ()); +} + +template <> +inline int64 FVariant::get () const +{ + return static_cast (getInt ()); +} + +template <> +inline float FVariant::get () const +{ + return static_cast (getFloat ()); +} + +template <> +inline double FVariant::get () const +{ + return getFloat (); +} + +template <> +inline const char8* FVariant::get () const +{ + return getString8 (); +} + +template <> +inline const char16* FVariant::get () const +{ + return getString16 (); +} + +template <> +inline FUnknown* FVariant::get () const +{ + return getObject (); +} + +//------------------------------------------------------------------------ +inline bool operator!= (const FVariant& v1, const FVariant& v2) { return !(v1 == v2); } + +//------------------------------------------------------------------------ +inline FVariant::FVariant (const FVariant& variant) : type (kEmpty) { *this = variant; } + +//------------------------------------------------------------------------ +inline void FVariant::empty () +{ + if (type & kOwner) + { + if ((type & kString8) && string8) + delete[] string8; + else if ((type & kString16) && string16) + delete[] string16; + + else if ((type & kObject) && object) + object->release (); + } + memset (this, 0, sizeof (FVariant)); +} + +//------------------------------------------------------------------------ +inline FVariant& FVariant::operator= (const FVariant& variant) +{ + empty (); + + type = variant.type; + + if ((type & kString8) && variant.string8) + { + string8 = new char8[strlen (variant.string8) + 1]; + strcpy (const_cast (string8), variant.string8); + type |= kOwner; + } + else if ((type & kString16) && variant.string16) + { + int32 len = strlen16 (variant.string16); + string16 = new char16[len + 1]; + char16* tmp = const_cast (string16); + memcpy (tmp, variant.string16, len * sizeof (char16)); + tmp[len] = 0; + type |= kOwner; + } + else if ((type & kObject) && variant.object) + { + object = variant.object; + object->addRef (); + type |= kOwner; + } + else + intValue = variant.intValue; // copy memory + + return *this; +} + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ibstream.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ibstream.h new file mode 100644 index 0000000000..6219255014 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ibstream.h @@ -0,0 +1,89 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/ibstream.h +// Created by : Steinberg, 01/2004 +// Description : Interface for reading/writing streams +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "funknown.h" + +namespace Steinberg { + +//------------------------------------------------------------------------ +/** Base class for streams. +\ingroup pluginBase +- read/write binary data from/to stream +- get/set stream read-write position (read and write position is the same) +*/ +//------------------------------------------------------------------------ + +class IBStream: public FUnknown +{ +public: + enum IStreamSeekMode + { + kIBSeekSet = 0, ///< set absolute seek position + kIBSeekCur, ///< set seek position relative to current position + kIBSeekEnd ///< set seek position relative to stream end + }; + +//------------------------------------------------------------------------ + /** Reads binary data from stream. + \param buffer : destination buffer + \param numBytes : amount of bytes to be read + \param numBytesRead : result - how many bytes have been read from stream (set to 0 if this is of no interest) */ + virtual tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead = 0) = 0; + + /** Writes binary data to stream. + \param buffer : source buffer + \param numBytes : amount of bytes to write + \param numBytesWritten : result - how many bytes have been written to stream (set to 0 if this is of no interest) */ + virtual tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten = 0) = 0; + + /** Sets stream read-write position. + \param pos : new stream position (dependent on mode) + \param mode : value of enum IStreamSeekMode + \param result : new seek position (set to 0 if this is of no interest) */ + virtual tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result = 0) = 0; + + /** Gets current stream read-write position. + \param pos : is assigned the current position if function succeeds */ + virtual tresult PLUGIN_API tell (int64* pos) = 0; +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IBStream, 0xC3BF6EA2, 0x30994752, 0x9B6BF990, 0x1EE33E9B) + +//------------------------------------------------------------------------ +/** Stream with a size. +\ingroup pluginBase +[extends IBStream] when stream type supports it (like file and memory stream) */ +//------------------------------------------------------------------------ +class ISizeableStream: public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Return the stream size */ + virtual tresult PLUGIN_API getStreamSize (int64& size) = 0; + /** Set the steam size. File streams can only be resized if they are write enabled. */ + virtual tresult PLUGIN_API setStreamSize (int64 size) = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; +DECLARE_CLASS_IID (ISizeableStream, 0x04F9549E, 0xE02F4E6E, 0x87E86A87, 0x47F4E17F) + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/icloneable.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/icloneable.h new file mode 100644 index 0000000000..98b62821e3 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/icloneable.h @@ -0,0 +1,42 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/icloneable.h +// Created by : Steinberg, 11/2007 +// Description : Interface for object copies +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "funknown.h" + +namespace Steinberg { + +//------------------------------------------------------------------------ +/** Interface allowing an object to be copied. +[plug & host imp] \n +[released: N4.12] \n +*/ +//------------------------------------------------------------------------ +class ICloneable : public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Create exact copy of the object */ + virtual FUnknown* PLUGIN_API clone () = 0; +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (ICloneable, 0xD45406B9, 0x3A2D4443, 0x9DAD9BA9, 0x85A1454B) + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipersistent.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipersistent.h new file mode 100644 index 0000000000..5da3cc7802 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipersistent.h @@ -0,0 +1,161 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/ipersistent.h +// Created by : Steinberg, 09/2004 +// Description : Plug-In Storage Interfaces +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/funknown.h" + +namespace Steinberg { + +class FVariant; +class IAttributes; +//------------------------------------------------------------------------ +/** Persistent Object Interface. +[plug imp] \n +This interface is used to store/restore attributes of an object. +An IPlugController can implement this interface to handle presets. +The gui-xml for a preset control looks like this: +\code + .... + + .... + +\endcode +The tag data="Preset" tells the host to create a preset controller that handles the +3 values named "preset control", "store preset", and "remove preset". +*/ +//------------------------------------------------------------------------ +class IPersistent: public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** The class ID must be a 16 bytes unique id that is used to create the object. + This ID is also used to identify the preset list when used with presets. */ + virtual tresult PLUGIN_API getClassID (char8* uid) = 0; + /** Store all members/data in the passed IAttributes. */ + virtual tresult PLUGIN_API saveAttributes (IAttributes* ) = 0; + /** Restore all members/data from the passed IAttributes. */ + virtual tresult PLUGIN_API loadAttributes (IAttributes* ) = 0; +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IPersistent, 0xBA1A4637, 0x3C9F46D0, 0xA65DBA0E, 0xB85DA829) + + +typedef FIDString IAttrID; +//------------------------------------------------------------------------ +/** Object Data Archive Interface. +[host imp] \n +- store data/objects/binary/subattributes in the archive +- read stored data from the archive + +All data stored to the archive are identified by a string (IAttrID), which must be unique on each +IAttribute level. + +The basic set/get methods make use of the FVariant class defined in 'funknown.h'. +For a more convenient usage of this interface, you should use the functions defined +in namespace PAttributes (public.sdk/source/common/pattributes.h+cpp) !! + +\ingroup frameworkHostClasses +*/ +//------------------------------------------------------------------------ +class IAttributes: public FUnknown +{ +public: +//------------------------------------------------------------------------ + /*! \name Methods to write attributes + ******************************************************************************************************** */ + //@{ + /** Store any data in the archive. It is even possible to store sub-attributes by creating + a new IAttributes instance via the IHostClasses interface and pass it to the parent in the + FVariant. In this case the archive must take the ownership of the newly created object, which + is true for all objects that have been created only for storing. You tell the archive to take + ownership by adding the FVariant::kOwner flag to the FVariant::type member (data.type |= FVariant::kOwner). + When using the PAttributes functions, this is done through a function parameter.*/ + virtual tresult PLUGIN_API set (IAttrID attrID, const FVariant& data) = 0; + + /** Store a list of data in the archive. Please note that the type of data is not mixable! So + you can only store a list of integers or a list of doubles/strings/etc. You can also store a list + of subattributes or other objects that implement the IPersistent interface.*/ + virtual tresult PLUGIN_API queue (IAttrID listID, const FVariant& data) = 0; + + /** Store binary data in the archive. Parameter 'copyBytes' specifies if the passed data should be copied. + The archive cannot take the ownership of binary data. Either it just references a buffer in order + to write it to a file (copyBytes = false) or it copies the data to its own buffers (copyBytes = true). + When binary data should be stored in the default pool for example, you must always copy it!*/ + virtual tresult PLUGIN_API setBinaryData (IAttrID attrID, void* data, uint32 bytes, bool copyBytes) = 0; + //@} + + /*! \name Methods to read attributes + ******************************************************************************************************** */ + //@{ + /** Get data previously stored to the archive. */ + virtual tresult PLUGIN_API get (IAttrID attrID, FVariant& data) = 0; + + /** Get list of data previously stored to the archive. As long as there are queue members the method + will return kResultTrue. When the queue is empty, the methods returns kResultFalse. All lists except from + object lists can be reset which means that the items can be read once again. \see IAttributes::resetQueue */ + virtual tresult PLUGIN_API unqueue (IAttrID listID, FVariant& data) = 0; + + /** Get the amount of items in a queue. */ + virtual int32 PLUGIN_API getQueueItemCount (IAttrID) = 0; + + /** Reset a queue. If you need to restart reading a queue, you have to reset it. You can reset a queue at any time.*/ + virtual tresult PLUGIN_API resetQueue (IAttrID attrID) = 0; + + /** Reset all queues in the archive.*/ + virtual tresult PLUGIN_API resetAllQueues () = 0; + + /** Read binary data from the archive. The data is copied into the passed buffer. The size of that buffer + must fit the size of data stored in the archive which can be queried via IAttributes::getBinaryDataSize */ + virtual tresult PLUGIN_API getBinaryData (IAttrID attrID, void* data, uint32 bytes) = 0; + /** Get the size in bytes of binary data in the archive. */ + virtual uint32 PLUGIN_API getBinaryDataSize (IAttrID attrID) = 0; + //@} + +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IAttributes, 0xFA1E32F9, 0xCA6D46F5, 0xA982F956, 0xB1191B58) + +//------------------------------------------------------------------------ +/** Extended access to Attributes; supports Attribute retrieval via iteration. +[host imp] \n +[released] C7/N6 \n +\ingroup frameworkHostClasses +*/ +//------------------------------------------------------------------------ +class IAttributes2 : public IAttributes +{ +public: + /** Returns the number of existing attributes. */ + virtual int32 PLUGIN_API countAttributes () const = 0; + /** Returns the attribute's ID for the given index. */ + virtual IAttrID PLUGIN_API getAttributeID (int32 index) const = 0; +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IAttributes2, 0x1382126A, 0xFECA4871, 0x97D52A45, 0xB042AE99) + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipluginbase.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipluginbase.h new file mode 100644 index 0000000000..4370bcea06 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/ipluginbase.h @@ -0,0 +1,436 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/ipluginbase.h +// Created by : Steinberg, 01/2004 +// Description : Basic Plug-in Interfaces +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "funknown.h" +#include "fstrdefs.h" + +namespace Steinberg { + +//------------------------------------------------------------------------ +/** Basic interface to a Plug-in component. +\ingroup pluginBase +- [plug imp] +- initialize/terminate the Plug-in component + +The host uses this interface to initialize and to terminate the Plug-in component. +The context that is passed to the initialize method contains any interface to the +host that the Plug-in will need to work. These interfaces can vary from category to category. +A list of supported host context interfaces should be included in the documentation +of a specific category. */ +//------------------------------------------------------------------------ +class IPluginBase: public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** The host passes a number of interfaces as context to initialize the Plug-in class. + @note Extensive memory allocations etc. should be performed in this method rather than in the class' constructor! + If the method does NOT return kResultOk, the object is released immediately. In this case terminate is not called! */ + virtual tresult PLUGIN_API initialize (FUnknown* context) = 0; + + /** This function is called before the Plug-in is unloaded and can be used for + cleanups. You have to release all references to any host application interfaces. */ + virtual tresult PLUGIN_API terminate () = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IPluginBase, 0x22888DDB, 0x156E45AE, 0x8358B348, 0x08190625) + + +//------------------------------------------------------------------------ +/** Basic Information about the class factory of the Plug-in. +\ingroup pluginBase +*/ +//------------------------------------------------------------------------ +struct PFactoryInfo +{ +//------------------------------------------------------------------------ + enum FactoryFlags + { + kNoFlags = 0, ///< Nothing + kClassesDiscardable = 1 << 0, ///< The number of exported classes can change each time the Module is loaded. If this flag is set, the host does not cache class information. This leads to a longer startup time because the host always has to load the Module to get the current class information. + kLicenseCheck = 1 << 1, ///< Class IDs of components are interpreted as Syncrosoft-License (LICENCE_UID). Loaded in a Steinberg host, the module will not be loaded when the license is not valid + kComponentNonDiscardable = 1 << 3, ///< Component won't be unloaded until process exit + kUnicode = 1 << 4 ///< Components have entirely unicode encoded strings. (True for VST 3 Plug-ins so far) + }; + + enum + { + kURLSize = 256, + kEmailSize = 128, + kNameSize = 64 + }; + +//------------------------------------------------------------------------ + char8 vendor[kNameSize]; ///< e.g. "Steinberg Media Technologies" + char8 url[kURLSize]; ///< e.g. "http://www.steinberg.de" + char8 email[kEmailSize]; ///< e.g. "info@steinberg.de" + int32 flags; ///< (see above) +//------------------------------------------------------------------------ + PFactoryInfo (const char8* _vendor, const char8* _url, const char8* _email, int32 _flags) + { + strncpy8 (vendor, _vendor, kNameSize); + strncpy8 (url, _url, kURLSize); + strncpy8 (email, _email, kEmailSize); + flags = _flags; +#ifdef UNICODE + flags |= kUnicode; +#endif + } +#if SMTG_CPP11 + constexpr PFactoryInfo () : vendor (), url (), email (), flags () {} +#else + PFactoryInfo () { memset (this, 0, sizeof (PFactoryInfo)); } +#endif +}; + +//------------------------------------------------------------------------ +/** Basic Information about a class provided by the Plug-in. +\ingroup pluginBase +*/ +//------------------------------------------------------------------------ +struct PClassInfo +{ +//------------------------------------------------------------------------ + enum ClassCardinality + { + kManyInstances = 0x7FFFFFFF + }; + + enum + { + kCategorySize = 32, + kNameSize = 64 + }; +//------------------------------------------------------------------------ + TUID cid; ///< Class ID 16 Byte class GUID + int32 cardinality; ///< cardinality of the class, set to kManyInstances (see \ref ClassCardinality) + char8 category[kCategorySize]; ///< class category, host uses this to categorize interfaces + char8 name[kNameSize]; ///< class name, visible to the user +//------------------------------------------------------------------------ + + PClassInfo (const TUID _cid, int32 _cardinality, const char8* _category, const char8* _name) + { + memset (this, 0, sizeof (PClassInfo)); + memcpy (cid, _cid, sizeof (TUID)); + if (_category) + strncpy8 (category, _category, kCategorySize); + if (_name) + strncpy8 (name, _name, kNameSize); + cardinality = _cardinality; + } +#if SMTG_CPP11 + constexpr PClassInfo () : cid (), cardinality (), category (), name () {} +#else + PClassInfo () { memset (this, 0, sizeof (PClassInfo)); } +#endif +}; + + +//------------------------------------------------------------------------ +// IPluginFactory interface declaration +//------------------------------------------------------------------------ +/** Class factory that any Plug-in defines for creating class instances. +\ingroup pluginBase +- [plug imp] + +From the host's point of view a Plug-in module is a factory which can create +a certain kind of object(s). The interface IPluginFactory provides methods +to get information about the classes exported by the Plug-in and a +mechanism to create instances of these classes (that usually define the IPluginBase interface). + + An implementation is provided in public.sdk/source/common/pluginfactory.cpp +\see GetPluginFactory +*/ +//------------------------------------------------------------------------ +class IPluginFactory : public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Fill a PFactoryInfo structure with information about the Plug-in vendor. */ + virtual tresult PLUGIN_API getFactoryInfo (PFactoryInfo* info) = 0; + + /** Returns the number of exported classes by this factory. + If you are using the CPluginFactory implementation provided by the SDK, it returns the number of classes you registered with CPluginFactory::registerClass. */ + virtual int32 PLUGIN_API countClasses () = 0; + + /** Fill a PClassInfo structure with information about the class at the specified index. */ + virtual tresult PLUGIN_API getClassInfo (int32 index, PClassInfo* info) = 0; + + /** Create a new class instance. */ + virtual tresult PLUGIN_API createInstance (FIDString cid, FIDString _iid, void** obj) = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IPluginFactory, 0x7A4D811C, 0x52114A1F, 0xAED9D2EE, 0x0B43BF9F) + + +//------------------------------------------------------------------------ +/** Version 2 of Basic Information about a class provided by the Plug-in. +\ingroup pluginBase +*/ +//------------------------------------------------------------------------ +struct PClassInfo2 +{ +//------------------------------------------------------------------------ + TUID cid; ///< Class ID 16 Byte class GUID + int32 cardinality; ///< cardinality of the class, set to kManyInstances (see \ref ClassCardinality) + char8 category[PClassInfo::kCategorySize]; ///< class category, host uses this to categorize interfaces + char8 name[PClassInfo::kNameSize]; ///< class name, visible to the user + + enum { + kVendorSize = 64, + kVersionSize = 64, + kSubCategoriesSize = 128 + }; + + uint32 classFlags; ///< flags used for a specific category, must be defined where category is defined + char8 subCategories[kSubCategoriesSize]; ///< module specific subcategories, can be more than one, logically added by the \c OR operator + char8 vendor[kVendorSize]; ///< overwrite vendor information from factory info + char8 version[kVersionSize]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build) + char8 sdkVersion[kVersionSize]; ///< SDK version used to build this class (e.g. "VST 3.0") + +//------------------------------------------------------------------------ + + PClassInfo2 (const TUID _cid, int32 _cardinality, const char8* _category, const char8* _name, + int32 _classFlags, const char8* _subCategories, const char8* _vendor, const char8* _version, + const char8* _sdkVersion) + { + memset (this, 0, sizeof (PClassInfo2)); + memcpy (cid, _cid, sizeof (TUID)); + cardinality = _cardinality; + if (_category) + strncpy8 (category, _category, PClassInfo::kCategorySize); + if (_name) + strncpy8 (name, _name, PClassInfo::kNameSize); + classFlags = static_cast (_classFlags); + if (_subCategories) + strncpy8 (subCategories, _subCategories, kSubCategoriesSize); + if (_vendor) + strncpy8 (vendor, _vendor, kVendorSize); + if (_version) + strncpy8 (version, _version, kVersionSize); + if (_sdkVersion) + strncpy8 (sdkVersion, _sdkVersion, kVersionSize); + } +#if SMTG_CPP11 + constexpr PClassInfo2 () + : cid () + , cardinality () + , category () + , name () + , classFlags () + , subCategories () + , vendor () + , version () + , sdkVersion () + { + } +#else + PClassInfo2 () { memset (this, 0, sizeof (PClassInfo2)); } +#endif +}; + +//------------------------------------------------------------------------ +// IPluginFactory2 interface declaration +//------------------------------------------------------------------------ +/** Version 2 of class factory supporting PClassInfo2. +\ingroup pluginBase +\copydoc IPluginFactory +*/ +//------------------------------------------------------------------------ +class IPluginFactory2 : public IPluginFactory +{ +public: +//------------------------------------------------------------------------ + /** Returns the class info (version 2) for a given index. */ + virtual tresult PLUGIN_API getClassInfo2 (int32 index, PClassInfo2* info) = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; +DECLARE_CLASS_IID (IPluginFactory2, 0x0007B650, 0xF24B4C0B, 0xA464EDB9, 0xF00B2ABB) + + +//------------------------------------------------------------------------ +/** Unicode Version of Basic Information about a class provided by the Plug-in */ +//------------------------------------------------------------------------ +struct PClassInfoW +{ +//------------------------------------------------------------------------ + TUID cid; ///< see \ref PClassInfo + int32 cardinality; ///< see \ref PClassInfo + char8 category[PClassInfo::kCategorySize]; ///< see \ref PClassInfo + char16 name[PClassInfo::kNameSize]; ///< see \ref PClassInfo + + enum { + kVendorSize = 64, + kVersionSize = 64, + kSubCategoriesSize = 128 + }; + + uint32 classFlags; ///< flags used for a specific category, must be defined where category is defined + char8 subCategories[kSubCategoriesSize];///< module specific subcategories, can be more than one, logically added by the \c OR operator + char16 vendor[kVendorSize]; ///< overwrite vendor information from factory info + char16 version[kVersionSize]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build) + char16 sdkVersion[kVersionSize]; ///< SDK version used to build this class (e.g. "VST 3.0") + +//------------------------------------------------------------------------ + PClassInfoW (const TUID _cid, int32 _cardinality, const char8* _category, const char16* _name, + int32 _classFlags, const char8* _subCategories, const char16* _vendor, const char16* _version, + const char16* _sdkVersion) + { + memset (this, 0, sizeof (PClassInfoW)); + memcpy (cid, _cid, sizeof (TUID)); + cardinality = _cardinality; + if (_category) + strncpy8 (category, _category, PClassInfo::kCategorySize); + if (_name) + strncpy16 (name, _name, PClassInfo::kNameSize); + classFlags = static_cast (_classFlags); + if (_subCategories) + strncpy8 (subCategories, _subCategories, kSubCategoriesSize); + if (_vendor) + strncpy16 (vendor, _vendor, kVendorSize); + if (_version) + strncpy16 (version, _version, kVersionSize); + if (_sdkVersion) + strncpy16 (sdkVersion, _sdkVersion, kVersionSize); + } +#if SMTG_CPP11 + constexpr PClassInfoW () + : cid () + , cardinality () + , category () + , name () + , classFlags () + , subCategories () + , vendor () + , version () + , sdkVersion () + { + } +#else + PClassInfoW () { memset (this, 0, sizeof (PClassInfoW)); } +#endif + + void fromAscii (const PClassInfo2& ci2) + { + memcpy (cid, ci2.cid, sizeof (TUID)); + cardinality = ci2.cardinality; + strncpy8 (category, ci2.category, PClassInfo::kCategorySize); + str8ToStr16 (name, ci2.name, PClassInfo::kNameSize); + classFlags = ci2.classFlags; + strncpy8 (subCategories, ci2.subCategories, kSubCategoriesSize); + + str8ToStr16 (vendor, ci2.vendor, kVendorSize); + str8ToStr16 (version, ci2.version, kVersionSize); + str8ToStr16 (sdkVersion, ci2.sdkVersion, kVersionSize); + } +}; + + +//------------------------------------------------------------------------ +// IPluginFactory3 interface declaration +//------------------------------------------------------------------------ +/** Version 3 of class factory supporting PClassInfoW. +\ingroup pluginBase +\copydoc IPluginFactory +*/ +//------------------------------------------------------------------------ +class IPluginFactory3 : public IPluginFactory2 +{ +public: +//------------------------------------------------------------------------ + /** Returns the unicode class info for a given index. */ + virtual tresult PLUGIN_API getClassInfoUnicode (int32 index, PClassInfoW* info) = 0; + + /** Receives information about host*/ + virtual tresult PLUGIN_API setHostContext (FUnknown* context) = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; +DECLARE_CLASS_IID (IPluginFactory3, 0x4555A2AB, 0xC1234E57, 0x9B122910, 0x36878931) +//------------------------------------------------------------------------ +} // namespace Steinberg + + +//------------------------------------------------------------------------ +#define LICENCE_UID(l1, l2, l3, l4) \ +{ \ + (int8)((l1 & 0xFF000000) >> 24), (int8)((l1 & 0x00FF0000) >> 16), \ + (int8)((l1 & 0x0000FF00) >> 8), (int8)((l1 & 0x000000FF) ), \ + (int8)((l2 & 0xFF000000) >> 24), (int8)((l2 & 0x00FF0000) >> 16), \ + (int8)((l2 & 0x0000FF00) >> 8), (int8)((l2 & 0x000000FF) ), \ + (int8)((l3 & 0xFF000000) >> 24), (int8)((l3 & 0x00FF0000) >> 16), \ + (int8)((l3 & 0x0000FF00) >> 8), (int8)((l3 & 0x000000FF) ), \ + (int8)((l4 & 0xFF000000) >> 24), (int8)((l4 & 0x00FF0000) >> 16), \ + (int8)((l4 & 0x0000FF00) >> 8), (int8)((l4 & 0x000000FF) ) \ +} + + +//------------------------------------------------------------------------ +// GetPluginFactory +//------------------------------------------------------------------------ +/** Plug-in entry point. +\ingroup pluginBase +Any Plug-in must define and export this function. \n +A typical implementation of GetPluginFactory looks like this + \code + IPluginFactory* PLUGIN_API GetPluginFactory () + { + if (!gPluginFactory) + { + static PFactoryInfo factoryInfo = + { + "My Company Name", + "http://www.mywebpage.com", + "mailto:myemail@address.com", + PFactoryInfo::kNoFlags + }; + + gPluginFactory = new CPluginFactory (factoryInfo); + + static PClassInfo componentClass = + { + INLINE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000), // replace by a valid uid + 1, + "Service", // category + "Name" + }; + + gPluginFactory->registerClass (&componentClass, MyComponentClass::newInstance); + } + else + gPluginFactory->addRef (); + + return gPluginFactory; + } + \endcode +\see \ref loadPlugin +*/ +//------------------------------------------------------------------------ +extern "C" +{ + Steinberg::IPluginFactory* PLUGIN_API GetPluginFactory (); + typedef Steinberg::IPluginFactory* (PLUGIN_API *GetFactoryProc) (); +} diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/istringresult.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/istringresult.h new file mode 100644 index 0000000000..90531838cd --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/istringresult.h @@ -0,0 +1,80 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/istringresult.h +// Created by : Steinberg, 01/2005 +// Description : Strings Interface +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/funknown.h" + +namespace Steinberg { + +//------------------------------------------------------------------------ +/** Interface to return an ascii string of variable size. + In order to manage memory allocation and deallocation properly, + this interface is used to transfer a string as result parameter of + a method requires a string of unknown size. +[host imp] or [plug imp] \n +[released: SX 4] */ +//------------------------------------------------------------------------ +class IStringResult : public FUnknown +{ +public: +//------------------------------------------------------------------------ + virtual void PLUGIN_API setText (const char8* text) = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IStringResult, 0x550798BC, 0x872049DB, 0x84920A15, 0x3B50B7A8) + + +//------------------------------------------------------------------------ +/** Interface to a string of variable size and encoding. +[host imp] or [plug imp] \n +[released: ] */ +//------------------------------------------------------------------------ +class IString : public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Assign ASCII string */ + virtual void PLUGIN_API setText8 (const char8* text) = 0; + /** Assign unicode string */ + virtual void PLUGIN_API setText16 (const char16* text) = 0; + + /** Return ASCII string. If the string is unicode so far, it will be converted. + So you need to be careful, because the conversion can result in data loss. + It is save though to call getText8 if isWideString() returns false */ + virtual const char8* PLUGIN_API getText8 () = 0; + /** Return unicode string. If the string is ASCII so far, it will be converted. */ + virtual const char16* PLUGIN_API getText16 () = 0; + + /** !Do not use this method! Early implementations take the given pointer as + internal string and this will cause problems because 'free' will be used to delete the passed memory. + Later implementations will redirect 'take' to setText8 and setText16 */ + virtual void PLUGIN_API take (void* s, bool isWide) = 0; + + /** Returns true if the string is in unicode format, returns false if the string is ASCII */ + virtual bool PLUGIN_API isWideString () const = 0; + +//------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IString, 0xF99DB7A3, 0x0FC14821, 0x800B0CF9, 0x8E348EDF) + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/iupdatehandler.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/iupdatehandler.h new file mode 100644 index 0000000000..c4374c468c --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/iupdatehandler.h @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------ +// Project : Steinberg Module Architecture SDK +// +// Category : Basic Host Service Interfaces +// Filename : pluginterfaces/base/iupdatehandler.h +// Created by : Steinberg, 01/2004 +// Description : Update handling +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/funknown.h" + +namespace Steinberg { + +class IDependent; + +//------------------------------------------------------------------------ +/** Host implements dependency handling for plugins. +[host imp] \n +[get this interface from IHostClasses] \n +[released N3.1] \n + +- Install/Remove change notifications +- Trigger updates when an object has changed + +Can be used between host-objects and the Plug-In or +inside the Plug-In to handle internal updates! + +\see IDependent +\ingroup frameworkHostClasses +*/ +//------------------------------------------------------------------------ +class IUpdateHandler: public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Install update notification for given object. It is essential to + remove all dependencies again using 'removeDependent'! Dependencies + are not removed automatically when the 'object' is released! + \param object : interface to object that sends change notifications + \param dependent : interface through which the update is passed */ + virtual tresult PLUGIN_API addDependent (FUnknown* object, IDependent* dependent) = 0; + + /** Remove a previously installed dependency.*/ + virtual tresult PLUGIN_API removeDependent (FUnknown* object, IDependent* dependent) = 0; + + /** Inform all dependents, that object has changed. + \param object is the object that has changed + \param message is a value of enum IDependent::ChangeMessage, usually IDependent::kChanged - can be + a private message as well (only known to sender and dependent)*/ + virtual tresult PLUGIN_API triggerUpdates (FUnknown* object, int32 message) = 0; + + /** Same as triggerUpdates, but delivered in idle (usefull to collect updates).*/ + virtual tresult PLUGIN_API deferUpdates (FUnknown* object, int32 message) = 0; + static const FUID iid; +}; + +DECLARE_CLASS_IID (IUpdateHandler, 0xF5246D56, 0x86544d60, 0xB026AFB5, 0x7B697B37) + +//------------------------------------------------------------------------ +/** A dependent will get notified about changes of a model. +[plug imp] +- notify changes of a model + +\see IUpdateHandler +\ingroup frameworkHostClasses +*/ +//------------------------------------------------------------------------ +class IDependent: public FUnknown +{ +public: +//------------------------------------------------------------------------ + /** Inform the dependent, that the passed FUnknown has changed. */ + virtual void PLUGIN_API update (FUnknown* changedUnknown, int32 message) = 0; + + enum ChangeMessage + { + kWillChange, + kChanged, + kDestroyed, + kWillDestroy, + + kStdChangeMessageLast = kWillDestroy + }; + //------------------------------------------------------------------------ + static const FUID iid; +}; + +DECLARE_CLASS_IID (IDependent, 0xF52B7AAE, 0xDE72416d, 0x8AF18ACE, 0x9DD7BD5E) + +//------------------------------------------------------------------------ +} // namespace Steinberg diff --git a/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/smartpointer.h b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/smartpointer.h new file mode 100644 index 0000000000..29f7a2ec15 --- /dev/null +++ b/modules/juce_audio_processors/format_types/VST3_SDK/pluginterfaces/base/smartpointer.h @@ -0,0 +1,370 @@ +//----------------------------------------------------------------------------- +// Project : SDK Core +// +// Category : SDK Core Interfaces +// Filename : pluginterfaces/base/smartpointer.h +// Created by : Steinberg, 01/2004 +// Description : Basic Interface +// +//----------------------------------------------------------------------------- +// This file is part of a Steinberg SDK. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this distribution +// and at www.steinberg.net/sdklicenses. +// No part of the SDK, including this file, may be copied, modified, propagated, +// or distributed except according to the terms contained in the LICENSE file. +//----------------------------------------------------------------------------- + +#pragma once + +#include "pluginterfaces/base/fplatform.h" +#if SMTG_CPP11_STDLIBSUPPORT +#include +#endif + +//------------------------------------------------------------------------ +namespace Steinberg { + +//------------------------------------------------------------------------ +// IPtr +//------------------------------------------------------------------------ +/** IPtr - Smart pointer template class. + \ingroup pluginBase + + - can be used as an I* pointer + - handles refCount of the interface + - Usage example: + \code + IPtr path (sharedPath); + if (path) + path->ascend (); + \endcode + */ +//------------------------------------------------------------------------ +template +class IPtr +{ +public: +//------------------------------------------------------------------------ + inline IPtr (I* ptr, bool addRef = true); + inline IPtr (const IPtr&); + + template + inline IPtr (const IPtr& other) : ptr (other.get ()) + { + if (ptr) + ptr->addRef (); + } + + inline IPtr (); + inline ~IPtr (); + + inline I* operator= (I* ptr); + + inline IPtr& operator= (const IPtr& other); + + template + inline IPtr& operator= (const IPtr& other) + { + operator= (other.get ()); + return *this; + } + + inline operator I* () const { return ptr; } // act as I* + inline I* operator-> () const { return ptr; } // act as I* + + inline I* get () const { return ptr; } + +#if SMTG_CPP11_STDLIBSUPPORT + inline IPtr (IPtr&& movePtr) SMTG_NOEXCEPT : ptr (movePtr.take ()) { } + + template + inline IPtr (IPtr&& movePtr) SMTG_NOEXCEPT : ptr (movePtr.take ()) { } + + inline IPtr& operator= (IPtr&& movePtr) SMTG_NOEXCEPT + { + if (ptr) + ptr->release (); + + ptr = movePtr.take (); + return *this; + } + + inline void reset (I* obj = nullptr) + { + if (ptr) + ptr->release(); + ptr = obj; + } + + I* take () SMTG_NOEXCEPT + { + I* out = ptr; + ptr = nullptr; + return out; + } + +#endif +//------------------------------------------------------------------------ +protected: + I* ptr; +}; + +//------------------------------------------------------------------------ +template +inline IPtr::IPtr (I* _ptr, bool addRef) : ptr (_ptr) +{ + if (ptr && addRef) + ptr->addRef (); +} + +//------------------------------------------------------------------------ +template +inline IPtr::IPtr (const IPtr& other) : ptr (other.ptr) +{ + if (ptr) + ptr->addRef (); +} + +//------------------------------------------------------------------------ +template +inline IPtr::IPtr () : ptr (0) +{ +} + +//------------------------------------------------------------------------ +template +inline IPtr::~IPtr () +{ + if (ptr) + ptr->release (); +} + +//------------------------------------------------------------------------ +template +inline I* IPtr::operator= (I* _ptr) +{ + if (_ptr != ptr) + { + if (ptr) + ptr->release (); + ptr = _ptr; + if (ptr) + ptr->addRef (); + } + return ptr; +} + +//------------------------------------------------------------------------ +template +inline IPtr& IPtr::operator= (const IPtr& _ptr) +{ + operator= (_ptr.ptr); + return *this; +} + +//------------------------------------------------------------------------ +/** OPtr - "owning" smart pointer used for newly created FObjects. + \ingroup pluginBase + + FUnknown implementations are supposed to have a refCount of 1 right after creation. + So using an IPtr on newly created objects would lead to a leak. + Instead the OPtr can be used in this case. \n + Example: + \code + OPtr path = FHostCreate (IPath, hostClasses); + // no release is needed... + \endcode + The assignment operator takes ownership of a new object and releases the old. + So its safe to write: + \code + OPtr path = FHostCreate (IPath, hostClasses); + path = FHostCreate (IPath, hostClasses); + path = 0; + \endcode + This is the difference to using an IPtr with addRef=false. + \code + // DONT DO THIS: + IPtr path (FHostCreate (IPath, hostClasses), false); + path = FHostCreate (IPath, hostClasses); + path = 0; + \endcode + This will lead to a leak! + */ +//------------------------------------------------------------------------ +template +class OPtr : public IPtr +{ +public: +//------------------------------------------------------------------------ + inline OPtr (I* p) : IPtr (p, false) {} + inline OPtr (const IPtr& p) : IPtr (p) {} + inline OPtr (const OPtr& p) : IPtr (p) {} + inline OPtr () {} + inline I* operator= (I* _ptr) + { + if (_ptr != this->ptr) + { + if (this->ptr) + this->ptr->release (); + this->ptr = _ptr; + } + return this->ptr; + } +}; + +//------------------------------------------------------------------------ +/** Assigning newly created object to an IPtr. + Example: + \code + IPtr path = owned (FHostCreate (IPath, hostClasses)); + \endcode + which is a slightly shorter form of writing: + \code + IPtr path = OPtr (FHostCreate (IPath, hostClasses)); + \endcode + */ +template +IPtr owned (I* p) +{ + return IPtr (p, false); +} + +/** Assigning shared object to an IPtr. + Example: + \code + IPtr path = shared (iface.getXY ()); + \endcode + */ +template +IPtr shared (I* p) +{ + return IPtr (p, true); +} + +#if SMTG_CPP11_STDLIBSUPPORT +//------------------------------------------------------------------------ +// Ownership functionality +//------------------------------------------------------------------------ +namespace SKI { +namespace Detail { +struct Adopt; +} // Detail + +/** Strong typedef for shared reference counted objects. + * Use SKI::adopt to unwrap the provided object. + * @tparam T Referenced counted type. + */ +template +class Shared +{ + friend struct Detail::Adopt; + T* obj = nullptr; +}; + +/** Strong typedef for transferring the ownership of reference counted objects. + * Use SKI::adopt to unwrap the provided object. + * After calling adopt the reference in this object is null. + * @tparam T Referenced counted type. + */ +template +class Owned +{ + friend struct Detail::Adopt; + T* obj = nullptr; +}; + +/** Strong typedef for using reference counted objects. + * Use SKI::adopt to unwrap the provided object. + * After calling adopt the reference in this object is null. + * @tparam T Referenced counted type. + */ +template +class Used +{ + friend struct Detail::Adopt; + T* obj = nullptr; +}; + +namespace Detail { + +struct Adopt +{ + template + static IPtr adopt (Shared& ref) + { + using Steinberg::shared; + return shared (ref.obj); + } + + template + static IPtr adopt (Owned& ref) + { + using Steinberg::owned; + IPtr out = owned (ref.obj); + ref.obj = nullptr; + return out; + } + + template + static T* adopt (Used& ref) + { + return ref.obj; + } + + template