Toggles not toggling consistently

I have 2 toggle buttons in the same panel.

When I read the apvts to save my preset, the toggle state gets out of sync and sometimes I have to click the toggle twice to get the value to where I want it

   for (const auto& parameter : apvts.state) {
        const juce::String paramID = parameter.getProperty("id").toString();
        if (auto* param = apvts.getParameter(paramID)) {
//            // Check if the parameter is locked based on its ID prefix
//            if (!((paramID.startsWith("INVERSION") && processor.theInversions.isLocked())
//                || (paramID.startsWith("DURATION") && processor.theDurations.isLocked())
//                || (paramID.startsWith("FIXEDVOICE") && processor.theFixedVoices.isLocked())
//                || (paramID.startsWith("SWING") && processor.theSwings.isLocked())
//                || (paramID.startsWith("VELOCITY") && processor.theVelocities.isLocked())
//                || (paramID.startsWith("VOICING") && processor.theVoicings.isLocked())
//                || (paramID.startsWith("VOICINGPHASE") && processor.theVoicingPhases.isLocked())
//                || (paramID.startsWith("MODWHEEL") && processor.theModwheels.isLocked())
//                || (paramID.startsWith("MUTE") && processor.theMutes.isLocked())
//                || (paramID.startsWith("I_LFO") && processor.theInversions.isLocked())
//                || (paramID.startsWith("D_LFO") && processor.theDurations.isLocked())
//                || (paramID.startsWith("FV_LFO") && processor.theFixedVoices.isLocked())
//                || (paramID.startsWith("SWING_LFO") && processor.theSwings.isLocked())
//                || (paramID.startsWith("V_LFO") && processor.theVelocities.isLocked())
//                || (paramID.startsWith("VOC_LFO") && processor.theVoicings.isLocked())
//                || (paramID.startsWith("MOD_LFO") && processor.theModwheels.isLocked())
//                || (paramID.startsWith("VP_LFO") && processor.theVoicingPhases.isLocked())
//                || (paramID.startsWith("M_LFO") && processor.theMutes.isLocked()))) {
//                // If the parameter is not locked, save its value to the preset
////                presets[i].parameterValues[paramID] = param->getValue();
//            }

my code is mostly commented out but the problem only resolves (toggles working perfectly)
If I comment out

if ( auto * param = apvts.getParameter(paramID)) {

The problem with the toggles syncing correctly goes away.

Another way I can make the problem with the toggles go away is to map them in Abelton, then they work/sync flawlessly

If I subsequently remove the Ableton mapping, the problem returns.

is not used anywhere outside of that block of (mostly commented out) code.

I used to have your same problem, where the state of the graphic component wasn’t reflecting the state of the parameter attached to it.
This happened to me because when loading the preset something was blocking the parameterChanged() method to be called correctly. My advice would be to verify that your parameterChanged() gets called how it’s supposed to be called and that if there any if-else inside it make sure it is set properly.

Hope it helps!

-Giacomo

1 Like