I’m working on a plugin that can either sync several parameters with the DAW or let the user choose their own values, controlled by a few toggle buttons. A simplified version is (imagine these are buttons)
[ALL] [X] [Y] [Z]
XYZ are things like BPM, time signature, etc…
The behaviour I currently have working OK is:
- if the user toggles [ALL] on then [XYZ] get all toggled on
- if the user toggles one non-[ALL] button off, then [ALL] is toggled off
- if the user toggling one of [XYZ] makes all 3 be on, then [ALL] gets toggled on
I would also like to implement that if the user toggles [ALL] off then all the rest get toggled off (ie. the opposite of 1)
My code looks something like
void ButtonArea::buttonClicked(juce::Button* button) {
{
if ( button == &syncAllToggle ) {
if ( syncAllToggle.getToggleState() ) {
syncXToggle.setToggleState( true, juce::sendNotification );
syncYToggle.setToggleState( true, juce::sendNotification );
syncZToggle.setToggleState( true, juce::sendNotification );
// return;
}
// syncXToggle.setToggleState( false, juce::sendNotification );
// syncYToggle.setToggleState( false, juce::sendNotification );
// syncZToggle.setToggleState( false, juce::sendNotification );
} else if ( !button->getToggleState() ) {
syncAllToggle.setToggleState( false, juce::sendNotification );
} else if ( syncXToggle.getToggleState() &&
syncYToggle.getToggleState() &&
syncZToggle.getToggleState() ) {
syncAllToggle.setToggleState( true, juce::sendNotification );
}
}
The problem I have with my approach is that the buttons are tied to Values and APVTS params, so I need to send a notification when using setToggleState, but that calls clicked.
If I uncomment the code above, when the user toggles one of [XYZ] off, [ALL] gets toggled off which in turns all remaining buttons off.
The closest I’ve got is by not sending a notification in the first else if, but then that doesn’t get picked up by the APVTS so the host doesn’t write it to the state and when the plugin restarts the buttons will be in an invalid combo (i.e. [ALL] will be on but one of [XYZ] is off)
Being able to tell apart a programmatic toggle from a “real” user click would be ideal but I don’t know if there’s a way to do it, or how others have solved this?
TIA
Edit: Also tried the solution mentioned here but it’s the same as not sending the notification i.e. it’s not saved in the APVTS.