From 71823a3259b1d6f9d54347ca35f8178ef4009884 Mon Sep 17 00:00:00 2001 From: jatinchowdhury18 Date: Sun, 26 Nov 2023 14:41:35 -0700 Subject: [PATCH] Only send parameter gestures if a parameter is connected to a juce::AudioProcessor (#471) * Only send parameter gestures if a parameter is connected to a juce::AudioProcessor * Add DummyPluginState * Fixing shadow warning * More shadow fixes --- .../Backend/chowdsp_PluginState.h | 15 ++++++++++++++- .../Backend/chowdsp_PluginStateImpl.cpp | 4 ++-- .../Backend/chowdsp_PluginStateImpl.h | 2 +- .../Frontend/chowdsp_ParameterAttachment.cpp | 9 +++++---- .../Frontend/chowdsp_ParameterAttachment.h | 1 + 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginState.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginState.h index 7f86bdd37..7333a4230 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginState.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginState.h @@ -17,10 +17,11 @@ class PluginState /** Initialises the plugin state with a given set of parameters. */ void initialise (ParamHolder& parameters, - juce::AudioProcessor* processor = nullptr, + juce::AudioProcessor* proc = nullptr, juce::UndoManager* um = nullptr) { params = ¶meters; + processor = proc; undoManager = um; listeners.emplace (parameters); if (processor != nullptr) @@ -80,6 +81,7 @@ class PluginState mainThreadAction.call (std::forward (func), couldBeAudioThread); } + juce::AudioProcessor* processor = nullptr; juce::UndoManager* undoManager = nullptr; private: @@ -89,4 +91,15 @@ class PluginState JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginState) }; + +/** A "dummy" plugin state that does absolutely nothing! */ +struct DummyPluginState : PluginState +{ + void serialize (juce::MemoryBlock&) const override {} + void deserialize (const juce::MemoryBlock&) override {} + + NonParamState non_params {}; + [[nodiscard]] NonParamState& getNonParameters() override { return non_params; } + [[nodiscard]] const NonParamState& getNonParameters() const override { return non_params; } +}; } // namespace chowdsp diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp index 29b1affc6..acb2d4b09 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.cpp @@ -7,9 +7,9 @@ PluginStateImpl::PluginStateImpl } template -PluginStateImpl::PluginStateImpl (juce::AudioProcessor& processor, juce::UndoManager* um) +PluginStateImpl::PluginStateImpl (juce::AudioProcessor& proc, juce::UndoManager* um) { - initialise (params, &processor, um); + initialise (params, &proc, um); } template diff --git a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h index 3f1e26291..76b5ee5fc 100644 --- a/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h +++ b/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_PluginStateImpl.h @@ -20,7 +20,7 @@ class PluginStateImpl : public PluginState explicit PluginStateImpl (juce::UndoManager* um = nullptr); /** Constructs the state and adds all the state parameters to the given processor */ - explicit PluginStateImpl (juce::AudioProcessor& processor, juce::UndoManager* um = nullptr); + explicit PluginStateImpl (juce::AudioProcessor& proc, juce::UndoManager* um = nullptr); /** Serializes the plugin state to the given MemoryBlock */ void serialize (juce::MemoryBlock& data) const override; diff --git a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp index bb0fc650d..10f80a2ef 100644 --- a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp +++ b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp @@ -4,10 +4,11 @@ namespace chowdsp { template ParameterAttachment::ParameterAttachment (Param& parameter, - PluginState& pluginState, + PluginState& plugState, Callback&& callback) - : ParameterAttachment (parameter, pluginState.getParameterListeners(), std::forward (callback)) + : ParameterAttachment (parameter, plugState.getParameterListeners(), std::forward (callback)) { + pluginState = &plugState; } template @@ -28,14 +29,14 @@ ParameterAttachment::ParameterAttachment (Param& parameter, template void ParameterAttachment::beginGesture() { - if (param != nullptr) + if (param != nullptr && pluginState != nullptr && pluginState->processor != nullptr) param->beginChangeGesture(); } template void ParameterAttachment::endGesture() { - if (param != nullptr) + if (param != nullptr && pluginState != nullptr && pluginState->processor != nullptr) param->endChangeGesture(); } diff --git a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h index 70a78197d..951502e1b 100644 --- a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h +++ b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h @@ -52,6 +52,7 @@ class ParameterAttachment void setValueAsPartOfGesture (ParamElementType newValue); ParamType* param = nullptr; + PluginState* pluginState = nullptr; private: template