From 6feeb7dcddef300676d4c2c078cdba4cbcd3ae44 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 30 Aug 2022 17:29:35 +0100 Subject: [PATCH] VST3 Host: Avoid updating bus layout and activation of activated plug-ins According to the VST3 spec, activateBus and setBusArrangements shall not be called when a plugin is in the 'activated' state. Previously, if prepareToPlay was called twice in a row on a hosted VST3 plugin, during the second call the plug-in would already be activated, but its bus layout would still be adjusted. Now, we always ensure that the plugin is inactive before the bus properties are adjusted. --- .../format_types/juce_VST3PluginFormat.cpp | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index cfa7b3cf26..fd96781fb1 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -2511,6 +2511,11 @@ public: using namespace Vst; + // If the plugin has already been activated (prepareToPlay has been called twice without + // a matching releaseResources call) deactivate it so that the speaker layout and bus + // activation can be updated safely. + deactivate(); + ProcessSetup setup; setup.symbolicSampleSize = isUsingDoublePrecision() ? kSample64 : kSample32; setup.maxSamplesPerBlock = estimatedSamplesPerBlock; @@ -2565,19 +2570,7 @@ public: void releaseResources() override { const SpinLock::ScopedLockType lock (processMutex); - - if (! isActive) - return; // Avoids redundantly calling things like setActive - - isActive = false; - - if (processor != nullptr) - warnOnFailureIfImplemented (processor->setProcessing (false)); - - if (holder->component != nullptr) - warnOnFailure (holder->component->setActive (false)); - - setStateForAllMidiBuses (false); + deactivate(); } bool supportsDoublePrecisionProcessing() const override @@ -3104,6 +3097,22 @@ public: } private: + void deactivate() + { + if (! isActive) + return; + + isActive = false; + + if (processor != nullptr) + warnOnFailureIfImplemented (processor->setProcessing (false)); + + if (holder->component != nullptr) + warnOnFailure (holder->component->setActive (false)); + + setStateForAllMidiBuses (false); + } + //============================================================================== #if JUCE_LINUX || JUCE_BSD SharedResourcePointer runLoop;