Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
{
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 @@
template <typename Param, typename Callback>
void ParameterAttachment<Param, Callback>::beginGesture()
{
if (param != nullptr)
if (param != nullptr && pluginState != nullptr && pluginState->processor != nullptr)

Check warning on line 32 in modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp#L32

Added line #L32 was not covered by tests
param->beginChangeGesture();
}

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

Check warning on line 39 in modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp#L39

Added line #L39 was not covered by tests
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
Loading