From 0e47da1474f4cb50b756bab46e445fe4c8e44ffc Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 22 Apr 2021 16:46:03 +0100 Subject: [PATCH] VST Client: Ensure audioMasterIOChanged is sent when latency is updated --- .../VST/juce_VST_Wrapper.cpp | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) 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 72320aa36c..d510863984 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -1327,23 +1327,44 @@ private: void update (const ChangeDetails& details) { if (details.latencyChanged) + { owner.vstEffect.initialDelay = owner.processor->getLatencySamples(); + callbackBits |= audioMasterIOChangedBit; + } if (details.parameterInfoChanged || details.programChanged) - triggerAsyncUpdate(); + callbackBits |= audioMasterUpdateDisplayBit; + + triggerAsyncUpdate(); } private: void handleAsyncUpdate() override { + const auto callbacksToFire = callbackBits.exchange (0); + if (auto* callback = owner.hostCallback) { - callback (&owner.vstEffect, Vst2::audioMasterUpdateDisplay, 0, 0, nullptr, 0); - callback (&owner.vstEffect, Vst2::audioMasterIOChanged, 0, 0, nullptr, 0); + struct FlagPair + { + Vst2::AudioMasterOpcodesX opcode; + int bit; + }; + + constexpr FlagPair pairs[] { { Vst2::audioMasterUpdateDisplay, audioMasterUpdateDisplayBit }, + { Vst2::audioMasterIOChanged, audioMasterIOChangedBit } }; + + for (const auto& pair : pairs) + if ((callbacksToFire & pair.bit) != 0) + callback (&owner.vstEffect, pair.opcode, 0, 0, nullptr, 0); } } + static constexpr auto audioMasterUpdateDisplayBit = 1 << 0; + static constexpr auto audioMasterIOChangedBit = 1 << 1; + JuceVSTWrapper& owner; + std::atomic callbackBits { 0 }; }; static JuceVSTWrapper* getWrapper (Vst2::AEffect* v) noexcept { return static_cast (v->object); }