Implementing a parameter Reset button

I am trying to implement a UI control (IBButtonControl) that when “pressed” will reset several of the plugin’s parameters to their default values. I thought this could be done by adding an ActionFunction to the button control but I obviously don’t know how because what I tried below doesn’t work:

    pGraphics->AttachControl(new IBButtonControl(532, 472, bYButton, [](IControl* pCaller)
       {
       pCaller->SetAnimation([&](IControl* pCaller)
            {
            auto progress = pCaller->GetAnimationProgress();
            if (progress > 1.)
                {
                pCaller->OnEndAnimation();
                return;
                }
            pCaller->SetValue(Clip(progress + .5, 0., 1.));
            }, 100);

        }), kResetButton, "Reset");

    pGraphics->GetControlWithTag(kResetButton)->SetActionFunction([&](IControl* pCaller)
    {
        GetParam(kWidthControl)->SetToDefault();
        GetParam(kDepthControl)->SetToDefault();
        GetParam(kMixControl)->SetToDefault();
        GetParam(kVolumeControl)->SetToDefault();
    });

I have studied IPlugControls but admit I am lost on how to make this work. Any help appreciated!

In your code you are setting an action function in the IBButtonControl CTor and then overriding it with SetActionFunction(). You can use an “AnimationEndFunction” to do something when the button has been pressed and returned to its resting state, like this…

    pGraphics->AttachControl(new IVKnobControl(pGraphics->GetBounds().GetCentredInside(100), kGain));
    pGraphics->AttachControl(new IBButtonControl(100,100, pGraphics->LoadBitmap("button.png", 10)))
    ->SetAnimationEndActionFunction([&](IControl* pCaller){
      GetParam(kGain)->SetToDefault();
      SendCurrentParamValuesFromDelegate();
    });
2 Likes

Thank you for the reply.

I tried what you posted here and it almost works. The “reset” button resets all the controls but for some reason SendCurrentParamValuesFromDelegate() isn’t updating the associated parameters (e.g., OnParameterChange doesn’t get called).

I tried adding OnParamChange(kGain) after SendCurrentParamValuesFromDelegate() but debugger shows the parameter value retrieved by GetParam(kGain)->Value() is not the default value.

I’m still missing something here. Will dig into this more and post back what I find.

OK, I have it working now with one added change - I added a call to OnParamChange(kGain) before SendCurrentParamValuesFromDelegate() like this:

pGraphics->AttachControl(new IBButtonControl(100,100, pGraphics->LoadBitmap("button.png", 10)))
    ->SetAnimationEndActionFunction([&](IControl* pCaller){
      GetParam(kGain)->SetToDefault();
      OnParamChange(kGain);          <<<<<<<<<<<<<<Added
      SendCurrentParamValuesFromDelegate();
    });