AnalogTapeModel

Physical modelling signal processing for analog tape recording
Log | Files | Refs | Submodules | README | LICENSE

commit 846baf026bdb5684c0b787c458126f580a9edab9
parent 9af3571d2cec79cde6a1473c9e5576518365ede7
Author: jatinchowdhury18 <jatinchowdhury18@gmail.com>
Date:   Tue, 17 May 2022 11:12:19 +0100

Make sure parameter change UI interactions are happening on message thread (#265)

* Make sure parameter change UI interactions are happening on message thread

* Apply clang-format

* Use AsyncUpdater instead of Messagemanager::callAsync

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Diffstat:
MPlugin/Source/GUI/OnOff/OnOffManager.cpp | 26+++++++++++++++++++++++---
MPlugin/Source/GUI/OnOff/OnOffManager.h | 10++++++++--
MPlugin/Source/GUI/Visualizers/MixGroupViz.cpp | 17++++++++++++++++-
MPlugin/Source/GUI/Visualizers/MixGroupViz.h | 10++++++++--
4 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/Plugin/Source/GUI/OnOff/OnOffManager.cpp b/Plugin/Source/GUI/OnOff/OnOffManager.cpp @@ -9,7 +9,7 @@ std::unordered_map<String, StringArray> createTriggerMap() { String ("ifilt_onoff"), StringArray ({ "Low Cut", "High Cut", "Makeup" }) }, { String ("hyst_onoff"), StringArray ({ "Bias", "Saturation", "Drive" }) }, { String ("tone_onoff"), StringArray ({ "Bass", "Treble", "Transition Frequency" }) }, - { String ("loss_onoff"), StringArray ({ "Gap", "Thickness", "Spacing", "Speed", "3.75 ips", "7.5 ips", "15 ips", "30 ips" }) }, + { String ("loss_onoff"), StringArray ({ "Gap", "Thickness", "Spacing", "Azimuth", "Speed", "3.75 ips", "7.5 ips", "15 ips", "30 ips" }) }, { String ("chew_onoff"), StringArray ({ "Chew Depth", "Chew Frequency", "Chew Variance" }) }, { String ("deg_onoff"), StringArray ({ "Depth", "Amount", "Variance", "Envelope", "0.1x" }) }, { String ("flutter_onoff"), StringArray ({ "Flutter Depth", "Flutter Rate", "Wow Depth", "Wow Rate", "Wow Variance", "Wow Drift" }) }, @@ -69,7 +69,27 @@ void OnOffManager::parameterChanged (const String& paramID, float newValue) { if (const auto triggerMapIter = triggerMap.find (paramID); triggerMapIter != triggerMap.end()) { - StringArray compNames { triggerMapIter->second }; - toggleEnableDisable (proc->getActiveEditor(), compNames, (bool) newValue); + componentsToToggle = &triggerMapIter->second; + turningOn = (bool) newValue; + + if (MessageManager::existsAndIsCurrentThread()) + onOffButtonToggled(); + else + triggerAsyncUpdate(); } } + +void OnOffManager::handleAsyncUpdate() +{ + onOffButtonToggled(); +} + +void OnOffManager::onOffButtonToggled() +{ + if (componentsToToggle == nullptr) + return; + + auto compNames = StringArray { *componentsToToggle }; + toggleEnableDisable (proc->getActiveEditor(), compNames, turningOn); + componentsToToggle = nullptr; +} diff --git a/Plugin/Source/GUI/OnOff/OnOffManager.h b/Plugin/Source/GUI/OnOff/OnOffManager.h @@ -4,20 +4,26 @@ #include <JuceHeader.h> /** Utility class to enable/disable components triggered by audio parameter changes */ -class OnOffManager : private AudioProcessorValueTreeState::Listener +class OnOffManager : private AudioProcessorValueTreeState::Listener, + private AsyncUpdater { public: OnOffManager (AudioProcessorValueTreeState& vts, const AudioProcessor* proc); - ~OnOffManager(); + ~OnOffManager() override; void setOnOffForNewEditor (AudioProcessorEditor* editor); void parameterChanged (const String& parameterID, float newValue) override; private: + void handleAsyncUpdate() override; + void onOffButtonToggled(); + AudioProcessorValueTreeState& vts; const AudioProcessor* proc; const std::unordered_map<String, StringArray> triggerMap; + const StringArray* componentsToToggle = nullptr; + bool turningOn = false; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OnOffManager) }; diff --git a/Plugin/Source/GUI/Visualizers/MixGroupViz.cpp b/Plugin/Source/GUI/Visualizers/MixGroupViz.cpp @@ -13,7 +13,22 @@ MixGroupViz::~MixGroupViz() void MixGroupViz::parameterValueChanged (int, float newValue) { - setMixGroupColour (int (newValue * MixGroupsConstants::numMixGroups)); + newMixGroupIndex = int (newValue * MixGroupsConstants::numMixGroups); + + if (MessageManager::existsAndIsCurrentThread()) + mixGroupChanged(); + else + triggerAsyncUpdate(); +} + +void MixGroupViz::handleAsyncUpdate() +{ + mixGroupChanged(); +} + +void MixGroupViz::mixGroupChanged() +{ + setMixGroupColour (newMixGroupIndex); } void MixGroupViz::setMixGroupColour (int mixGroupIdx) diff --git a/Plugin/Source/GUI/Visualizers/MixGroupViz.h b/Plugin/Source/GUI/Visualizers/MixGroupViz.h @@ -5,11 +5,12 @@ #include <JuceHeader.h> class MixGroupViz : public Component, - private AudioProcessorParameter::Listener + private AudioProcessorParameter::Listener, + private AsyncUpdater { public: MixGroupViz (AudioProcessorParameter* mixGroupParam); - ~MixGroupViz(); + ~MixGroupViz() override; void parameterValueChanged (int parameterIndex, float newValue) override; void parameterGestureChanged (int, bool) override {} @@ -17,9 +18,14 @@ public: void setMixGroupColour (int mixGroupIdx); private: + void handleAsyncUpdate() override; + void mixGroupChanged(); + Colour circleColour; AudioProcessorParameter* mixGroupParam; + int newMixGroupIndex = 0; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MixGroupViz) };