# Implementing a parameter Reset button

**URL:** <https://iplug2.discourse.group/t/implementing-a-parameter-reset-button/752>\
**Category:** Made with iPlug2\
**Created:** [23 January 2023 02:40 UTC](https://iplug2.discourse.group/t/implementing-a-parameter-reset-button/752 "2023-01-23T02:40:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RexMartin2](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@RexMartin2](https://iplug2.discourse.group/u/RexMartin2)\
**Post date:** [23 January 2023 02:40 UTC](https://iplug2.discourse.group/t/implementing-a-parameter-reset-button/752/1 "2023-01-23T02:40:46Z")

</div>

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:

```auto
    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!

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [23 January 2023 08:03 UTC](https://iplug2.discourse.group/t/implementing-a-parameter-reset-button/752/2 "2023-01-23T08:03:46Z")

</div>

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…

```auto
    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();
    });

```

---

<div class="post-metadata">

**Author:** ![RexMartin2](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@RexMartin2](https://iplug2.discourse.group/u/RexMartin2)\
**Post date:** [23 January 2023 16:52 UTC](https://iplug2.discourse.group/t/implementing-a-parameter-reset-button/752/3 "2023-01-23T16:52:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RexMartin2](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@RexMartin2](https://iplug2.discourse.group/u/RexMartin2)\
**Post date:** [24 January 2023 01:36 UTC](https://iplug2.discourse.group/t/implementing-a-parameter-reset-button/752/4 "2023-01-24T01:36:58Z")

</div>

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

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

```
