Set TextButton Toggle State

Hi everyone,
I’m struggling here trying to find a way to switch TextButton Toggle State…
For now when presetButton gets clicked and clicked again, automation in the DAW goes on and off wich is fine to me.
Now my understanding is that everytime presetButton gets clicked AudioParameterBool goes true then false.
What i’m trying to do is that everytime presetButton2 gets clicked, presetButton automation goes back off and vice versa…

params.push_back(std::make_unique<juce::AudioParameterBool>("PRESET", "Preset", false));
params.push_back(std::make_unique<juce::AudioParameterBool>("PRESET2", "Preset2", false));

i’ve tryed many ways (getToggleState, setToggleState…) but there s obvously something that i missunderstand there

    addAndMakeVisible(presetButton);
	presetButton.setClickingTogglesState(true);
	presetButtonAttachment = std::make_unique<juce::AudioProcessorValueTreeState::ButtonAttachment>(audioProcessor.apvts, "PRESET", presetButton);
	
	presetButton.onClick = [this]()

	{ //??//}

    addAndMakeVisible(presetButton);
	presetButton.setClickingTogglesState(true);
	presetButtonAttachment = std::make_unique<juce::AudioProcessorValueTreeState::ButtonAttachment>(audioProcessor.apvts, "PRESET2", presetButton);
	
	presetButton.onClick = [this]()

	{ //??//}

would any body get a clue?
Thanks a lot!

Without having tried it out, but I don’t think you need to set the setClickingTogglesState, since the attachment will probably take care of it!
Have you had a look at the tutorial here?

1 Like

Thanks a lot replying, i tryed both already…

I think that is the wrong idea for presets. Automation describes a state, not an event.
Generically an event would be MIDI, but in your case I think a Choice or Int parameter for the selected preset might be more appropriate. Or not automate it at all. Often the preset sets the parameters that are already stored, so it is kind of redundant information.

I don’t have much experience with the built in preset system, I don’t think that is stored as automation at all. Maybe that helps to rethink the problem.

1 Like

Ok thanks a lot,

I think i had to explain better what preset meant there at the first place, i’m just setting sliders value by clicking at the button.

presetButton.onClick sets wanted sliders values.
(on/off automation goes on when clicked and off when clicked again keeping same sliders values, wich is fine )

When presetButton2.onClick sets another bunch of values.

Now I’m trying to find a way to put back off presetButton automation when presetButton2.onClick without having to click again presetButton.

Thanks a lot a sorry for newbies trouble :wink:

No worries. What I struggle to understand is: Why automating the button, when that is nothing you want stored anyway?
If the user puts the playhead anywhere in the timeline, the automation makes sure to set the appropriate values.
It will set all the parameters that are stored anyway, be it automated or as constant state.
But it won’t care if your preset button was triggered somewhen before. That is an event that is finished.

1 Like

yeah you got the point :wink: now that you make me think that way it seems pointless to make thoose automation.
Thanks a lot for your time !