Skip to content

Commit

Permalink
Only send parameter gestures if a parameter is connected to a juce::A…
Browse files Browse the repository at this point in the history
…udioProcessor (#471)

* Only send parameter gestures if a parameter is connected to a juce::AudioProcessor

* Add DummyPluginState

* Fixing shadow warning

* More shadow fixes
  • Loading branch information
jatinchowdhury18 authored Nov 26, 2023
1 parent d095de4 commit 71823a3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &parameters;
processor = proc;
undoManager = um;
listeners.emplace (parameters);
if (processor != nullptr)
Expand Down Expand Up @@ -80,6 +81,7 @@ class PluginState
mainThreadAction.call (std::forward<Callable> (func), couldBeAudioThread);
}

juce::AudioProcessor* processor = nullptr;
juce::UndoManager* undoManager = nullptr;

private:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ PluginStateImpl<ParameterState, NonParameterState, Serializer>::PluginStateImpl
}

template <typename ParameterState, typename NonParameterState, typename Serializer>
PluginStateImpl<ParameterState, NonParameterState, Serializer>::PluginStateImpl (juce::AudioProcessor& processor, juce::UndoManager* um)
PluginStateImpl<ParameterState, NonParameterState, Serializer>::PluginStateImpl (juce::AudioProcessor& proc, juce::UndoManager* um)
{
initialise (params, &processor, um);
initialise (params, &proc, um);
}

template <typename ParameterState, typename NonParameterState, typename Serializer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ namespace chowdsp
{
template <typename Param, typename Callback>
ParameterAttachment<Param, Callback>::ParameterAttachment (Param& parameter,
PluginState& pluginState,
PluginState& plugState,
Callback&& callback)
: ParameterAttachment (parameter, pluginState.getParameterListeners(), std::forward<Callback> (callback))
: ParameterAttachment (parameter, plugState.getParameterListeners(), std::forward<Callback> (callback))
{
pluginState = &plugState;
}

template <typename Param, typename Callback>
Expand All @@ -28,14 +29,14 @@ ParameterAttachment<Param, Callback>::ParameterAttachment (Param& parameter,
template <typename Param, typename Callback>
void ParameterAttachment<Param, Callback>::beginGesture()
{
if (param != nullptr)
if (param != nullptr && pluginState != nullptr && pluginState->processor != nullptr)
param->beginChangeGesture();
}

template <typename Param, typename Callback>
void ParameterAttachment<Param, Callback>::endGesture()
{
if (param != nullptr)
if (param != nullptr && pluginState != nullptr && pluginState->processor != nullptr)
param->endChangeGesture();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ParameterAttachment
void setValueAsPartOfGesture (ParamElementType newValue);

ParamType* param = nullptr;
PluginState* pluginState = nullptr;

private:
template <typename Func>
Expand Down

0 comments on commit 71823a3

Please sign in to comment.