From 9654f4a7e9217e71aee044afd0f5ef858f1db86a Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Tue, 7 Nov 2023 12:04:49 +0000 Subject: [PATCH] VST3: Only update parameters from a process block if they've changed --- .../format_types/juce_VST3Common.h | 11 +++++++++-- .../format_types/juce_VST3PluginFormat.cpp | 10 ++++------ .../juce_audio_processors/utilities/juce_FlagCache.h | 6 +++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VST3Common.h b/modules/juce_audio_processors/format_types/juce_VST3Common.h index 879bcab18d..48e2286a8a 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3Common.h +++ b/modules/juce_audio_processors/format_types/juce_VST3Common.h @@ -1737,8 +1737,15 @@ public: Steinberg::Vst::ParamID getParamID (Steinberg::int32 index) const noexcept { return paramIds[(size_t) index]; } - void set (Steinberg::int32 index, float value) { floatCache.setValueAndBits ((size_t) index, value, 1); } - void setWithoutNotifying (Steinberg::int32 index, float value) { floatCache.setValue ((size_t) index, value); } + void set (Steinberg::int32 index, float value) + { + floatCache.setValueAndBits ((size_t) index, value, 1); + } + + float exchangeWithoutNotifying (Steinberg::int32 index, float value) + { + return floatCache.exchangeValue ((size_t) index, value); + } float get (Steinberg::int32 index) const noexcept { return floatCache.get ((size_t) index); } diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index faaa843036..107506a3e9 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -2244,7 +2244,7 @@ public: for (const auto* item : queues) { auto* ptr = item->ptr.get(); - callback (ptr->getParameterIndex(), ptr->getParameterId(), ptr->get()); + callback (ptr->getParameterId(), ptr->get()); } } @@ -2291,8 +2291,8 @@ public: */ void setValueWithoutUpdatingProcessor (float newValue) { - pluginInstance.cachedParamValues.setWithoutNotifying (vstParamIndex, newValue); - sendValueChangedMessageToListeners (newValue); + if (! exactlyEqual (pluginInstance.cachedParamValues.exchangeWithoutNotifying (vstParamIndex, newValue), newValue)) + sendValueChangedMessageToListeners (newValue); } String getText (float value, int maximumLength) const override @@ -2753,10 +2753,8 @@ public: processor->process (data); - outputParameterChanges->forEach ([&] (Steinberg::int32 index, Vst::ParamID id, float value) + outputParameterChanges->forEach ([&] (Vst::ParamID id, float value) { - cachedParamValues.setWithoutNotifying (index, value); - if (auto* param = getParameterForID (id)) param->setValueWithoutUpdatingProcessor (value); }); diff --git a/modules/juce_audio_processors/utilities/juce_FlagCache.h b/modules/juce_audio_processors/utilities/juce_FlagCache.h index cd808dcd34..d4260766bb 100644 --- a/modules/juce_audio_processors/utilities/juce_FlagCache.h +++ b/modules/juce_audio_processors/utilities/juce_FlagCache.h @@ -140,17 +140,17 @@ public: size_t size() const noexcept { return values.size(); } - void setValue (size_t index, float value) + float exchangeValue (size_t index, float value) { jassert (index < size()); - values[index].store (value, std::memory_order_relaxed); + return values[index].exchange (value, std::memory_order_relaxed); } void setBits (size_t index, uint32_t bits) { flags.set (index, bits); } void setValueAndBits (size_t index, float value, uint32_t bits) { - setValue (index, value); + exchangeValue (index, value); setBits (index, bits); }