Programatically trigger button presses and combo box selections


#1

i wrote my plugin before fully understanding all the new AudioProcessorParameter stuff.

so, all my buttons and combo boxes and sliders are sending their values to the pluginProcessor in their “buttonWasClicked” methods like this:

else if (buttonThatWasClicked == autoEvolveButton)
{
    //[UserButtonCode_autoEvolveButton] -- add your button handler code here..
    processor.setAutoEvolveToggle (getIntIndex(), autoEvolveButton->getToggleState());
    //[/UserButtonCode_autoEvolveButton]
}

the problem i’ve got now, is that i am using AudioProcessorValueTreeState::ButtonAttachment and its siblings to save my plugin’s state, and that all works well…

but when i set the state loading the plugin, it seems that these “buttonThatWasClicked” functions are never called…as it seems they only get called when you physically click the mouse.

next time i will surely use the AudioParameterInt classes etc…but this plugin is nearly finished, and it would be quite an effort to gut it all and use the new classes…

so, is there a programatic way to trigger the “buttonThatWasClicked” method from the AudioProcessorValueTreeState::ButtonAttachment class?


#2

Yes, that’s what they are designed for. You can call them programmatically, but I would rather change the design, because that would mean that you put logic into the gui part, that belongs into the model (your AudioProcessorValueTreeState). Keep in mind, that your plugin should be able to survive and behave correctly without your gui, e.g. using the generic editor…

The ButtonAttachment already keeps model and gui in sync. If you want to react to changes, then you can use either a ValueTree::Listener or a AudioProcessorValueTreeState::Listener::parameterChanged().
That one get’s called no matter if the parameter changed because of a mouse click or because of restoring the state during loading.

OR you can also react on Button::Listener::stateChanged(), that should also be called no matter, if the button was clicked or if the ButtonAttachment changes the state. I think it is not called, when you call Button::setToggleState(shouldBeOn, dontSendNotification);


#3

thank you once again Daniel. You are pretty much my hero at the moment.

I made my processor an AudioProcessorValueTreeState::Listener, and implemented the parameterChanged method as you suggested, and also did change my design, so that now nothing is handled in the UI that is not UI related.

the only small hiccup i found, was that the parameterChanged method was not initialising values if they remianed the same as their default. (because obviously in that case they are not ‘changed’) But anyway, that was easy to work around.

all looking pretty good now! My first proper Juce project is shaping up nicely. Thanks for the big big help!