diff --git a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp index b3341258d..0472ab449 100644 --- a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp +++ b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.cpp @@ -20,10 +20,10 @@ ParameterAttachment::ParameterAttachment (Param& parameter, { valueChangedCallback = listeners.addParameterListener (*param, ParameterListenerThread::MessageThread, - [this, c = std::move (callback)]() mutable + [this]() mutable { if (param != nullptr) - c (ParameterTypeHelpers::getValue (*param)); + updateCallback (ParameterTypeHelpers::getValue (*param)); }); } @@ -77,8 +77,8 @@ void ParameterAttachment::setValueAsPartOfGesture (ParamElement template void ParameterAttachment::manuallyTriggerUpdate() const { - if (param != nullptr && updateCallback.hasValue()) - (*updateCallback) (ParameterTypeHelpers::getValue (*param)); + if (param != nullptr) + updateCallback (ParameterTypeHelpers::getValue (*param)); } template diff --git a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h index bc0cbffa0..7527b2cdc 100644 --- a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h +++ b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h @@ -63,7 +63,7 @@ class ParameterAttachment template void callIfParameterValueChanged (ParamElementType newValue, Func&& func); - juce::Optional updateCallback; + Callback updateCallback {}; ScopedCallback valueChangedCallback; JUCE_LEAK_DETECTOR (ParameterAttachment) diff --git a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachmentHelpers.h b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachmentHelpers.h index 6ad784835..5957e59cb 100644 --- a/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachmentHelpers.h +++ b/modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachmentHelpers.h @@ -9,7 +9,8 @@ namespace ParameterAttachmentHelpers template struct SetValueCallback { - explicit SetValueCallback (Attachment& a) : attach (a) {} + SetValueCallback() = default; + explicit SetValueCallback (Attachment& a) : attach (&a) {} SetValueCallback (const SetValueCallback&) = default; SetValueCallback& operator= (const SetValueCallback&) = default; SetValueCallback (SetValueCallback&&) noexcept = default; @@ -18,10 +19,10 @@ namespace ParameterAttachmentHelpers template void operator() (T val) { - attach.setValue (val); + attach->setValue (val); } - Attachment& attach; + Attachment* attach = nullptr; }; template diff --git a/tests/plugin_tests/chowdsp_plugin_state_test/ParameterAttachmentsTest.cpp b/tests/plugin_tests/chowdsp_plugin_state_test/ParameterAttachmentsTest.cpp index 63b12eb1c..6c45b7dd2 100644 --- a/tests/plugin_tests/chowdsp_plugin_state_test/ParameterAttachmentsTest.cpp +++ b/tests/plugin_tests/chowdsp_plugin_state_test/ParameterAttachmentsTest.cpp @@ -364,17 +364,19 @@ TEST_CASE ("Custom Parameter Attachment Test", "[state][attachments]") using State = chowdsp::PluginStateImpl; - SECTION ("Setup Test") - { - State state; - auto& param = state.params.param; + State state; + auto& param = state.params.param; - juce::Component comp; - chowdsp::ParameterAttachment attach { param, state, [&comp] (bool val) { comp.setVisible (val); } }; + juce::Component comp; + chowdsp::ParameterAttachment attach { param, state, [&comp] (bool val) + { comp.setVisible (val); } }; - REQUIRE (! comp.isVisible()); + REQUIRE (! comp.isVisible()); - attach.manuallyTriggerUpdate(); - REQUIRE (comp.isVisible()); - } + attach.manuallyTriggerUpdate(); + REQUIRE (comp.isVisible()); + + chowdsp::ParameterTypeHelpers::setValue (false, *param); + state.getParameterListeners().updateBroadcastersFromMessageThread(); + REQUIRE (! comp.isVisible()); }