Radio buttons - what am I doing wrong?

Hi, I am new to Juce.
I want to implement something like 2 radio buttons for plugin in a way that only one out of 2 buttons is active at the same time or all can be set off.
Actually I did it with setToggleState(), added buttons to value tree state (vts) and graphically it works like a charm, however I can see that button states are not reflected on vts (checked wth getRawParameterValue()).
Te scenario is simple:

  1. 2 buttons are set to off by default
  2. I click on 1st button that is set to on with setToggleState(true)
  3. I click to set 2nd button on (which means that 1st button must be set off without clicking on it-> 1st button setToggleState(false) and 2nd button setToggleState(true)), it is on, and 1st is off, but vts shows that the 1st button is still on so I need to click twice on it (1st button) to force vts to see it as off.

What can I be doing wrong and how to notify value tree state/ audio processor about button state change without clicking on it?
Thanks in advance.

Can you tell us how you are doing this? Are you using a AudioProcessorValueTreeState::ButtonAttachment on the one button that represents the value you want to represent?
(don’t attach both, since the parameter is only on or off. If you connect both buttons, it cannot represent them both at the same time, since they are mutually exclusive by the GroupID)


Thanks Daniel for response!

I am using it in the simplest possible way (please find below the pseudo code).

I attach both buttons using AudioProcessorValueTreeState::ButtonAttachment as I am not using GroupID and setRadioGroupId() as documentation says that button that was clicked ‘on’ cannot be turned to ‘off’- actually I want that to turn it ‘off’ (so both buttons can be set to ‘off’).

Psuedo code:
if (Button1_clicked) { if (!getToggleState(Button1)) {Button1.setToggleState(true); Button2.setToggleState(false);} else //…}
// the same for Button2

In other words I want two buttons to act with one mouse click on single button- set one to ‘on’ and second to ‘off’ (without click on it).

The case here is when Button2 was on, the Button2.setToggleState(false) above does not have an effect on VTS.
I conclude that I must be missing something here- maybe setToggleState(false) is not enough if there’s actually no mouse click on that button. For the button that was clicked setToggleState(true) or setToggleState(false) have always effect on VTS.

You can always try Button:: triggerClick()


Thanks R_J_R.
Actually I finally decided to ask here because I had few triggerClick() unsuccessfull attempts., but I haven’t tested it to enough extent so there’s still some work to do on my side.

However I am really interested why VTS doesn’t get updated upon setToggleState() call. Just for learning purposes. Others might also benefit from the answer from knowledgable people.
So thanks in advance!

It really depends on your implementation I think… In my Radio Button implementation with 4 buttons I do something like this:

void CTimeAdjuster::onLazyButtonClicked()
    if (m_pDisplay == nullptr)
    m_pLazyButton->setToggleState (true, dontSendNotification);
    m_pRushedButton->setToggleState (false, dontSendNotification);
    m_pTightButton->setToggleState (false, dontSendNotification);
    m_pNaturalButton->setToggleState (false, dontSendNotification);
    m_pDisplay->humanizeModeChanged (lazy);

and in humanizeModeChanged() I’ll update/modify the MIDI sequence (in your case the processor variables). Otherwise you’ll get multiple callbacks which could be a problem (you’d want to make sure the button set to true were always last… and hope the callbacks happen in order).


Hi Rail,

thank you again. I am doing it exactly the same way, except the audio part- I first want to do UI because it is easy (in relation to audio processing), end then audio part. If such approach is wrong- please state it clearly :slight_smile: