Problem with sliders textbox display in JUCE 5.4.1


#1

Hi !
The slider textbox seems to be working differently in JUCE 5.4.1.
Here is a picture of two versions of the same plug-in, same source code, in 5.4.1 (top) and 5.3.2 (bottom).
Err-Disp-01
The 5.3.2 displays “correctly” the values, with 3, 3, 4 and 7 decimal places, as expected from the increments given in the slider ranges, while the 5.4.1 displays only 2, 2, 2 and 5 decimal places. Moreover, the suffix " %" is not displayed.
Is there something that I need to change in my code to adapt to the new versions ?
Regards.


#2

Can you post the code that you are using to set up the sliders?


#3

Thanks for your answer.

This is the related code:

In PluginProcessor.h:

    AudioProcessorValueTreeState parameters;
    float* l1beginParameter  = nullptr;
    float* l1endParameter  = nullptr;
    float* l1speedParameter  = nullptr;

In PluginProcessor.cpp:

        parameters.createAndAddParameter ("l1begin",       // parameterID
                                          "Begin",       // parameter name
                                          "",           // parameter label (suffix)
                                          NormalisableRange<float> (0.0f, 100.0f, 0.001f),    // range
                                          0.0f,         // default value
                                          nullptr,
                                          nullptr);

       parameters.createAndAddParameter ("l1end",       // parameterID
                                          "End",       // parameter name
                                          "",           // parameter label (suffix)
                                          NormalisableRange<float> (0.0f, 100.0f, 0.001f),    // range
                                          100.0f,         // default value
                                          nullptr,
                                          nullptr);

       parameters.createAndAddParameter ("l1speed",       // parameterID
                                          "Speed",       // parameter name
                                          "",           // parameter label (suffix)
                                          NormalisableRange<float> (-4.0f, 4.0f, 0.0001f),    // range
                                          1.0f,         // default value
                                          nullptr,
                                          nullptr);

         
    parameters.state = ValueTree (Identifier ("OrangeV01"));

    looper1.beginPar = parameters.getRawParameterValue ("l1begin");
    looper1.endPar = parameters.getRawParameterValue ("l1end");
    looper1.speedPar = parameters.getRawParameterValue ("l1speed");

In PluginEditor.h":

    OrangejuceAudioProcessor& processor;
    AudioProcessorValueTreeState& valueTreeState;

    Label  allLabels[3];
    Slider  allSliders [3];
    typedef AudioProcessorValueTreeState::SliderAttachment SliderAttachment;
    std::unique_ptr<SliderAttachment> l1beginAttachment;
    std::unique_ptr<SliderAttachment> l1endAttachment;
    std::unique_ptr<SliderAttachment> l1speedAttachment;

    std::unique_ptr<Slider> newSlider;
    Identifier sliderName;

In PluginEditor.cpp:

     allLabels[0].setText ("Loop start", dontSendNotification);
     addAndMakeVisible (allLabels[0]);

     allLabels[1].setText ("Loop end", dontSendNotification);
     addAndMakeVisible (allLabels[1]);

     allLabels[2].setText ("Loop speed", dontSendNotification);
     addAndMakeVisible (allLabels[2]);

     addAndMakeVisible (allSliders[0]);
     l1beginAttachment.reset (new SliderAttachment (valueTreeState, "l1begin", allSliders[0]));
     allSliders[0].setTextValueSuffix(" %");
     allSliders[0].setPopupDisplayEnabled (true, false, this);

     addAndMakeVisible (allSliders[1]);
     l1endAttachment.reset (new SliderAttachment (valueTreeState, "l1end", allSliders[1]));
     allSliders[1].setTextValueSuffix(" %");

     addAndMakeVisible (allSliders[2]);
     l1speedAttachment.reset (new SliderAttachment (valueTreeState, "l1speed", allSliders[2]));
     allSliders[2].setColour(Slider::thumbColourId, Colours::lightseagreen);
     
     // Test : this slider is not automatically managed
     newSlider = std::make_unique<Slider>();
     addAndMakeVisible (* newSlider);
     newSlider->setColour(Slider::thumbColourId, Colours::red);
     sliderName = Identifier("newSlider");

I think this is all that is related to the parameters and the sliders.
Regards.


#4

I’m having the same problem. Using almost identical code to Jack461. All of my suffixes disappeared this morning when I updated to JUCE 5.4.1.


#5

We’ll look at this.

At the moment everyone on the JUCE team is busy preparing ADC, so please bear with us!


#6

No problem. I’m using the following code :slight_smile:

#include <stdio.h>

String dbEdit(double db, int decn)
{
    constexpr int bsize {64};
    constexpr int fsize {8};
    char buff[bsize];
    char fmtf[fsize];
    decn = decn<0 ? 0 : decn>16 ? 16 : decn;
    sprintf(fmtf, "%%.%df", decn);
    snprintf(buff, bsize, fmtf, db);
    return String(buff);
}
...
        parameters.createAndAddParameter ("l1begin",       // parameterID
                                          "Begin",       // parameter name
                                          "",           // parameter label (suffix)
                                          NormalisableRange<float> (0.0f, 100.0f, 0.001f),    // range
                                          0.0f,         // default value
                                          [] (float p) { return dbEdit(double(p), 3) + String(" %"); },
                                          nullptr);

The dbEdit function edits a double (or a float) with “decn” decimal digits, and the lambda lets me add the appropriate suffix…

Happy ADC !


#7

@t0m Just wanted to bump this and see if there has been any movement or if it’s worth rolling back to JUCE 5.3.2 for the foreseeable future. The code @Jack461 posted would work fine but it means going through all my plugins and all parameters, which is a bit of a pain :slight_smile:


#8

#9

Thanks for the fix :slight_smile:


#10

Hi @t0m, I’ve pulled the develop branch of JUCE and there still seems to be something not quite right, compared to previous versions. The number of decimal places used to be set based on the step size of the NormalisableRange. For example, when setting up a parameter in the APVTS, using

NormalisableRange<float> (0.0f, 10.0f, 1.f)

would display in the slider text box as an integer with a value from 0 to 10. Now it is displaying with a decimal place, but still stepping by the correct amount. Is it possible to have this back to the previous functionality that was so handy? For now, I will roll back to JUCE 5.3.2.

EDIT: I’ve had a very quick look this morning and it appears to be because ‘textFromValueFunction’ in the Slider isn’t nullptr even though that is what I set it to when creating the parameter. This means that formatting isn’t taken from the NormalisableRange, but from whatever is being set as the textFromValueFunction.

EDIT 2: The cause might be here: https://github.com/WeAreROLI/JUCE/commit/1f63493031e1e42d3986fba722d125466cb55fec#diff-1ec75d23db30b69cffab9854fa6697f4R578
It seems like textFromValueFunction and valueFromTextFunction are always set when in the SliderAttachment, even if set to nullptr. Previously there was a check for this.