How to control the decimal places in a parameter added by ValueTree?

I’ve been experimenting with the AudioProcessorValueTreeState for adding parameters in a plugin, and I’m wondering: If you have a float parameter, how do you specify the number of decimal places displayed, and how do you specify the increment value?

For example, I added a float parameter into a ValueTree initialization:

               std::make_unique<AudioParameterFloat> ("rep",            // parameterID
                                                       "Replications",            // parameter name
                                                       0.0f,              // minimum value
                                                       10.0f,              // maximum value
                                                       3.0f),             // default value

I want this parameter to display a single decimal place, and to increment by single decimal places, i.e. 0.1.

I tried:

    replicationsSlider.setNumDecimalPlacesToDisplay (1);

But it doesn’t have any effect. It still displays 2 decimal places and increments by 0.01.

There are two things, first, if you use the constructor, where you supply the NormalisableRange, you have much more control, e.g. step size and even logarithmic scales:

std::make_unique<AudioParameterFloat> ("rep",            // parameterID
                                       "Replications",                   // parameter name
                                       NormalisableRange<float> (0.0f,   // minimum value
                                                                10.0f,   // maximum value
                                                                 0.1f),  // step size
                                       3.0f),                            // default value
                                       String(),       // label
                                       AudioProcessorParameter::genericParameter,
                                       [](float value, int) { return String (value, 1); },
                                       [](const String& text) { return text.getFloatValue(); }

And furthermore you can add the lambdas for the number conversion. The SliderAttachment will propagate those to the Slider (and it probably overwrote your decimalsToDisplay settings)

1 Like

Try using NormalisableRange - intervalValue

NormalisableRange<<#typename ValueType#>>(<#ValueType rangeStart#>, <#ValueType rangeEnd#>, <#ValueType intervalValue#>, <#ValueType skewFactor#>)

like so:

auto normRange = NormalisableRange<float>(0.0f, 10.0f, 0.1f);
std::make_unique<AudioParameterFloat> ("rep",            // parameterID
                                       "Replications",            // parameter name
                                        normRange,
                                        3.0f),             // default value

Thanks, I appreciate the help!