I created a AudioParameterFloat . I set and get it using a juce::Value
It seems like only two decimal places are used. How can I change that?
Thank You!
I found the solution!
Previously, I used the smaller AudioParameterFoat constructor, which just requires a min,max and default value…
By using the bigger constructor , it is possible to adjust the floating point precision / decimal places by defining the normalisable Range with an interval Value .
You could also just set the number of decimal places/significant figures when you convert the value to a string using the lambdas you can pass into the AudioParameterFloat
constructor:
"threshold",
"Threshold",
NormalisableRange<float>(-60.f, 0.f),
-60.f,
String(),
AudioProcessorParameter::genericParameter,
[this](float value, int) -> String {
if (value == -60.f)
return "-INFdB";
auto text = contrast::pretifyValue(value, 3) + "dB";
if (text[0] != '-')
text = "-" + text;
return text;
},
[this](const String& text) -> float {
return text.getFloatValue();
}
);
return static_cast<ReturnType>(juce::roundToInt(value));
}
//==================================================================================================================
/** Returns a String that can be used to display the given value.
This will round the number to the given number of significant figures
(where 0 counts as a significant figure) and returns the value as a
String.
*/
inline String pretifyValue(float value, int numSignificantFigures)
{
const auto numDigitsBeforePoint = value == 0.f ? 1 : jmax(1, floor(std::log10(std::abs(value)) + 1));
// If the number of digits before the decimal point (i.e. for 203.1,
// it would be 3) is greater than the required number of significant
// figures, round the number to the nearest number of sig figs.
// (For example 203.1 with 2 sigfigs is 200).
if (numDigitsBeforePoint > numSignificantFigures)
{
const auto difference = numDigitsBeforePoint - numSignificantFigures;
1 Like