From d0615041f084021887e069a3edca8113b90e1996 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 2 Sep 2021 16:43:13 +0100 Subject: [PATCH] Plugin clients: Avoid notifying listeners when parameters have not changed --- .../AU/juce_AU_Wrapper.mm | 9 ++--- .../VST/juce_VST_Wrapper.cpp | 23 ++++++------ .../VST3/juce_VST3_Wrapper.cpp | 35 +++++++------------ 3 files changed, 28 insertions(+), 39 deletions(-) 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 37f0486712..c35d55a07a 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -1029,10 +1029,11 @@ public: { auto value = inValue / getMaximumParameterValue (param); - param->setValue (value); - - inParameterChangedCallback = true; - param->sendValueChangedMessageToListeners (value); + if (value != param->getValue()) + { + inParameterChangedCallback = true; + param->setValueNotifyingHost (value); + } return noErr; } 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 84df483a05..d0b42aed28 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -703,12 +703,7 @@ public: void setParameter (int32 index, float value) { if (auto* param = juceParameters.getParamForIndex (index)) - { - param->setValue (value); - - inParameterChangedCallback = true; - param->sendValueChangedMessageToListeners (value); - } + setValueAndNotifyIfChanged (*param, value); } static void setParameterCB (Vst2::AEffect* vstInterface, int32 index, float value) @@ -1433,6 +1428,15 @@ private: static void checkWhetherMessageThreadIsCorrect() {} #endif + void setValueAndNotifyIfChanged (AudioProcessorParameter& param, float newValue) + { + if (param.getValue() == newValue) + return; + + inParameterChangedCallback = true; + param.setValueNotifyingHost (newValue); + } + //============================================================================== template void deleteTempChannels (VstTempBuffers& tmpBuffers) @@ -1716,12 +1720,7 @@ private: { if (! LegacyAudioParameter::isLegacy (param)) { - auto value = param->getValueForText (String::fromUTF8 ((char*) args.ptr)); - param->setValue (value); - - inParameterChangedCallback = true; - param->sendValueChangedMessageToListeners (value); - + setValueAndNotifyIfChanged (*param, param->getValueForText (String::fromUTF8 ((char*) args.ptr))); return 1; } } 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 f654ba54f4..33f3adafd0 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -622,6 +622,15 @@ class JuceVST3Component; static thread_local bool inParameterChangedCallback = false; +static void setValueAndNotifyIfChanged (AudioProcessorParameter& param, float newValue) +{ + if (param.getValue() == newValue) + return; + + const InParameterChangedCallbackSetter scopedSetter { inParameterChangedCallback }; + param.setValueNotifyingHost (newValue); +} + //============================================================================== class JuceVST3EditController : public Vst::EditController, public Vst::IMidiMapping, @@ -745,14 +754,7 @@ public: // otherwise we get parallel streams of parameter value updates // during playback if (! owner.vst3IsPlaying) - { - auto value = static_cast (v); - - param.setValue (value); - - const InParameterChangedCallbackSetter scopedSetter { inParameterChangedCallback }; - param.sendValueChangedMessageToListeners (value); - } + setValueAndNotifyIfChanged (param, (float) v); changed(); return true; @@ -2363,13 +2365,7 @@ public: void setBypassed (bool shouldBeBypassed) { if (auto* bypassParam = comPluginInstance->getBypassParameter()) - { - auto floatValue = (shouldBeBypassed ? 1.0f : 0.0f); - bypassParam->setValue (floatValue); - - const InParameterChangedCallbackSetter scopedSetter { inParameterChangedCallback }; - bypassParam->sendValueChangedMessageToListeners (floatValue); - } + setValueAndNotifyIfChanged (*bypassParam, shouldBeBypassed ? 1.0f : 0.0f); } //============================================================================== @@ -3109,15 +3105,8 @@ public: else #endif { - auto floatValue = static_cast (value); - if (auto* param = comPluginInstance->getParamForVSTParamID (vstParamID)) - { - param->setValue (floatValue); - - const InParameterChangedCallbackSetter scopedSetter { inParameterChangedCallback }; - param->sendValueChangedMessageToListeners (floatValue); - } + setValueAndNotifyIfChanged (*param, (float) value); } } }