Double precision in slider values and AudioParameterFloat

Hi all,
I am trying to solve a problem of having sliders values rounded to 2 decimal places. An audio parameter which has a value of 0.1234 in the processor will be set to a value of 0.12 in the editor by attempting to move sliders to their correct positions after a DAW preset reload using setStateInformation.

    auto& params = processor.getParameters();
    juce::AudioParameterFloat* dryGainParameter2 = (juce::AudioParameterFloat*)params.getUnchecked(1);
    mDryGainSlider.setValue(*dryGainParameter2);

I tried this code also which doesn’t work ( slider value doesn’t move )

mDelayOneGainSlider.setValue(processor.getParameter(1))

I have been stuck here for a week now posting every day. I cant seem to figure out what it going on.

I tried this

mDryGainSlider.setValue(float(*dryGainParameter2));

tried this too

    auto gainVal = dryGainParameter2->operator float();
    mDryGainSlider.setValue(gainVal);

tried this too

   juce::NormalisableRange<float> myRange(0.0, 1.0, 0.0001);
    //addParameter(mDryGainParameter = new juce::AudioParameterFloat("drygain", "Dry Gain", 0.000f, 1.0f , 0.501f));
    addParameter(mDryGainParameter = new juce::AudioParameterFloat("drygain", "Dry Gain", myRange, 0.512f ));

I tried this too :

mDryGainSlider.setRange(0.0f, 1.0f, 0.0001f );

I am pretty sure that dereferencing this pointer is what is losing the precision :

    auto& params = processor.getParameters();
    juce::AudioParameterFloat* dryGainParameter2 = (juce::AudioParameterFloat*)params.getUnchecked(1);
    //mDryGainSlider.setValue(float(*dryGainParameter2));
    double gainVal = double(*dryGainParameter2);

Any ideas would be appreciated thanks Sean

Well still talking to myself here like a lunatic.
I am stepping thru it all with Xcode’s glorius debugger.

At the outset.

a “gain” parameter is set like this

addParameter(mDryGainParameter = new juce::AudioParameterFloat("drygain", "Dry Gain", 0.000f, 2 , 0.501f));

debugger says value is

value std::__1::atomic 0.500999987

The default value was 0.501f

After moving the slider to a random value :
The text box next to the slider says its value is :
0.4089687

after clicking the button at that breakpoint
The value of that parameter is now
value std::__1::atomic 0.409999996

Eventually after updating the value

    auto& params = processor.getParameters();
    juce::AudioParameterFloat* dryGainParameter2 = (juce::AudioParameterFloat*)params.getUnchecked(1);
    
    //mDryGainSlider.setValue(float(*dryGainParameter2));
    double gainVal = double(*dryGainParameter2);
    //mDryGainSlider.setValue(juce::AudioParameterFloat*)params.getUnchecked(1))
    mDryGainSlider.setValue(gainVal);
    double gainSliderVal = mDryGainSlider.getValue();

the value of the text box becomes

0.4100000

If instead of moving the slider I just put in 0.4211000 as the value of the slider in the text box.

The value of the parameter is now
value std::__1::atomic 0.419999987

I added a variable to look at the interval of that slider

double gainSLiderInterval = mDryGainSlider.getInterval();

this is the value returned in the debugger . an interval of zero ?
gainSLiderInterval double 0

I wish this documentation said a bit more because I am pretty sure it is here where the issue is happening

â—† getValue()

double Slider::getValue ( ) const

Returns the slider’s current value.

I tried changing the default interval of the slider like this but it didnt change the strange rounding behaviour.

mDryGainSlider.setRange(0.0f, 1.0f, 0.0001f );

I guess I can start digging into the JUCE codebase to try and dig out what is happening.

Sean

I didn’t comment because I can’t really follow. Your last findings seem to show the parameter being quantized with an interval of 0.01. I don’t add parameters directly, I use APVTS and connect controls with attachments. Slider attachments will make the slider use the interval of the parameter, set in its constructor as part of its NormalisableRange. I usually set intervals to 0 to avoid this quantization, then solve the snapping of sliders differently. Remember floats are exact only for integers, powers of 2 and its sums. 0.125f is an exact float (2^-3), 0.1f is not. You can check it here.

Thanks so much for the reply.
The interval of the slider was set to zero. I looked that up in the debugger.
I also tried over-riding it with all sorts of values using this

mDryGainSlider.setRange(0.0f, 1.0f, 0.0001f );

That link is very cool that might help here!!
I wish I could find out where the quantization is happening !
I will keep plugging away pardon the pun.
Sean

FIXED IT !!!

    //addParameter(mDryGainParameter = new juce::AudioParameterFloat("drygain", "Dry Gain", 0.0f, 1.0f , 0.5f));
    addParameter (mDryGainParameter = new juce::AudioParameterFloat ("gain",                                      // parameter ID
                                                        "Gain",                                      // parameter name
                                                        juce::NormalisableRange<float> (0.0f, 1.0f), // parameter range
                                                        0.5f)); 

1 Like