From dd684b1a5dbf93661bb0e39d90253557603d21d4 Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Mon, 26 Mar 2018 09:54:40 +0100 Subject: [PATCH] Fixed a parameter change recursion issue in the VST and AU wrappers --- .../juce_audio_plugin_client/AU/juce_AU_Wrapper.mm | 12 ++++++++++++ .../VST/juce_VST_Wrapper.cpp | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm index 1d0e9d0f4a..417b1910b9 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -131,6 +131,8 @@ public: isBypassed (false), mapper (*juceFilter) { + inParameterChangedCallback = false; + #ifdef JucePlugin_PreferredChannelConfigurations short configs[][2] = {JucePlugin_PreferredChannelConfigurations}; const int numConfigs = sizeof (configs) / sizeof (short[2]); @@ -963,6 +965,8 @@ public: if (auto* param = juceFilter->getParameters()[index]) { param->setValue (value); + + inParameterChangedCallback = true; param->sendValueChangedMessageToListeners (value); } else @@ -1085,6 +1089,12 @@ public: void audioProcessorParameterChanged (AudioProcessor*, int index, float /*newValue*/) override { + if (inParameterChangedCallback.get()) + { + inParameterChangedCallback = false; + return; + } + sendAUEvent (kAudioUnitEvent_ParameterValueChange, index); } @@ -1665,6 +1675,8 @@ private: int totalInChannels, totalOutChannels; HeapBlock pulledSucceeded; + ThreadLocalValue inParameterChangedCallback; + //============================================================================== Array channelInfo; Array> supportedInputLayouts, supportedOutputLayouts; 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 8831d6263f..df83c1e5d3 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -260,6 +260,8 @@ public: : hostCallback (cb), processor (af) { + inParameterChangedCallback = false; + // VST-2 does not support disabling buses: so always enable all of them processor->enableAllBuses(); @@ -723,6 +725,8 @@ public: if (auto* param = processor->getParameters()[index]) { param->setValue (value); + + inParameterChangedCallback = true; param->sendValueChangedMessageToListeners (value); } else @@ -740,6 +744,12 @@ public: void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) override { + if (inParameterChangedCallback.get()) + { + inParameterChangedCallback = false; + return; + } + if (hostCallback != nullptr) hostCallback (&vstEffect, hostOpcodeParameterChanged, index, 0, 0, newValue); } @@ -1477,6 +1487,8 @@ private: HeapBlock cachedInArrangement, cachedOutArrangement; + ThreadLocalValue inParameterChangedCallback; + static JuceVSTWrapper* getWrapper (VstEffectInterface* v) noexcept { return static_cast (v->effectPointer); } bool isProcessLevelOffline() @@ -1828,6 +1840,8 @@ private: { auto value = param->getValueForText (String::fromUTF8 ((char*) args.ptr)); param->setValue (value); + + inParameterChangedCallback = true; param->sendValueChangedMessageToListeners (value); return 1;