Bool parameters With AudioProcessorValueTreeState


#1

Hi ,
I am moving from AudioParameterFloat and AudioParameterBool to AudioProcessorValueTreeState.
But I don’t find informations about having an equivalent of a bool parameter with the createAndAddParameter method of the AudioProcessorValueTreeState.

So my question is can we emulate a bool behavior with a parameter created with the “createAndAddParameter()” method?

Thanks a lot,

C.


#2

Yes, absolutely. Here’s a template using lambdas for the valueToText and textToValue functions:

state.createAndAddParameter("filterModID",
                            "Filter Mod",
                            String(),
                            NormalisableRange<float> (0.0f, 1.0f, 1.0f),
                            0.0f,
                            [](float value)
                                {
                                    return value < 0.5 ? "Off" : "On";
                                },
                            [](const String& text)
                                {
                                    if (text == "Off") return 0.0f;
	                                if (text == "On")  return 1.0f;
	                                return 0.0f;
                                }
				            false, true, true);

#3

Thanks a lot, it is really helpfull!