From 1bf9ebb4b113bf2dc3c4537974cd81f1cca67a97 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 9 Feb 2022 13:06:20 +0000 Subject: [PATCH] VST3 Host: Avoid calling initialize twice on objects that implement both IComponent and IEditController --- .../format_types/juce_VST3PluginFormat.cpp | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index 2b6e980749..05997fc7cd 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -1348,9 +1348,7 @@ struct VST3PluginWindow : public AudioProcessorEditor, warnOnFailure (view->setFrame (this)); view->queryInterface (Steinberg::IPlugViewContentScaleSupport::iid, (void**) &scaleInterface); - if (scaleInterface != nullptr) - warnOnFailure (scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor)); - + setContentScaleFactor(); resizeToFit(); } @@ -1598,11 +1596,24 @@ private: void updatePluginScale() { if (scaleInterface != nullptr) - warnOnFailure (scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor)); + setContentScaleFactor(); else resizeToFit(); } + void setContentScaleFactor() + { + if (scaleInterface != nullptr) + { + const auto result = scaleInterface->setContentScaleFactor ((Steinberg::IPlugViewContentScaleSupport::ScaleFactor) nativeScaleFactor); + ignoreUnused (result); + + #if ! JUCE_MAC + ignoreUnused (warnOnFailure (result)); + #endif + } + } + //============================================================================== Atomic refCount { 1 }; VSTComSmartPtr view; @@ -1676,16 +1687,33 @@ struct VST3ComponentHolder // transfers ownership to the plugin instance! AudioPluginInstance* createPluginInstance(); + bool isIComponentAlsoIEditController() const + { + if (component == nullptr) + { + jassertfalse; + return false; + } + + return VSTComSmartPtr().loadFrom (component); + } + bool fetchController (VSTComSmartPtr& editController) { if (! isComponentInitialised && ! initialise()) return false; + editController.loadFrom (component); + // Get the IEditController: TUID controllerCID = { 0 }; - if (component->getControllerClassId (controllerCID) == kResultTrue && FUID (controllerCID).isValid()) + if (editController == nullptr + && component->getControllerClassId (controllerCID) == kResultTrue + && FUID (controllerCID).isValid()) + { editController.loadFrom (factory, controllerCID); + } if (editController == nullptr) { @@ -1702,9 +1730,6 @@ struct VST3ComponentHolder } } - if (editController == nullptr) - editController.loadFrom (component); - return (editController != nullptr); } @@ -2220,7 +2245,7 @@ public: editController->setComponentHandler (nullptr); - if (isControllerInitialised) + if (isControllerInitialised && ! holder->isIComponentAlsoIEditController()) editController->terminate(); holder->terminate(); @@ -2252,8 +2277,10 @@ public: if (! (isControllerInitialised || holder->fetchController (editController))) return false; - // (May return an error if the plugin combines the IComponent and IEditController implementations) - editController->initialize (holder->host->getFUnknown()); + // If the IComponent and IEditController are the same, we will have + // already initialized the object at this point and should avoid doing so again. + if (! holder->isIComponentAlsoIEditController()) + editController->initialize (holder->host->getFUnknown()); isControllerInitialised = true; editController->setComponentHandler (holder->host);