Skip to content

Commit

Permalink
More custom attachment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Mar 20, 2024
1 parent ee16a95 commit 64fb2ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ ParameterAttachment<Param, Callback>::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));
});
}

Expand Down Expand Up @@ -77,8 +77,8 @@ void ParameterAttachment<Param, Callback>::setValueAsPartOfGesture (ParamElement
template <typename Param, typename Callback>
void ParameterAttachment<Param, Callback>::manuallyTriggerUpdate() const
{
if (param != nullptr && updateCallback.hasValue())
(*updateCallback) (ParameterTypeHelpers::getValue (*param));
if (param != nullptr)
updateCallback (ParameterTypeHelpers::getValue (*param));
}

template <typename Param, typename Callback>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ParameterAttachment
template <typename Func>
void callIfParameterValueChanged (ParamElementType newValue, Func&& func);

juce::Optional<Callback> updateCallback;
Callback updateCallback {};
ScopedCallback valueChangedCallback;

JUCE_LEAK_DETECTOR (ParameterAttachment)

Check warning on line 69 in modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_ParameterAttachment.h#L69

Added line #L69 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace ParameterAttachmentHelpers
template <typename Attachment>
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;
Expand All @@ -18,10 +19,10 @@ namespace ParameterAttachmentHelpers
template <typename T>
void operator() (T val)
{
attach.setValue (val);
attach->setValue (val);
}

Attachment& attach;
Attachment* attach = nullptr;
};

template <typename ParamType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,19 @@ TEST_CASE ("Custom Parameter Attachment Test", "[state][attachments]")

using State = chowdsp::PluginStateImpl<Params>;

SECTION ("Setup Test")
{
State state;
auto& param = state.params.param;
State state;
auto& param = state.params.param;

juce::Component comp;
chowdsp::ParameterAttachment<chowdsp::BoolParameter> attach { param, state, [&comp] (bool val) { comp.setVisible (val); } };
juce::Component comp;
chowdsp::ParameterAttachment<chowdsp::BoolParameter> 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());
}

0 comments on commit 64fb2ba

Please sign in to comment.