Problem with sliders textbox display in JUCE 5.4.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).
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 ?

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

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

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

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

    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.

1 Like

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.

We’ll look at this.

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

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(" %"); },

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

Happy ADC !

@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:

Thanks for the fix :slight_smile:

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:
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.

1 Like

Just what I needed. Thank you!

Hi @ed95, thanks for your work!

Unfortunately, it’s still not quite back to previous functionality. Now it works for great for integers but is stuck to 2 decimal places for all non-integer values. Previously, if the interval was set to, say, 0.1f it would show 1d.p. while an interval of 0.005f would show 3d.p. etc.

The following code restores the previous functionality perfectly (taken from juce_AudioProcessorParameters.cpp):

if (stringFromValueFunction == nullptr)
	// figure out the number of DPs needed to display all values at this
	// interval setting.
	int numDecimalPlaces = 7;

	if (range.interval != 0.0)
		int v = std::abs(roundToInt(range.interval * 10000000));

		while ((v % 10) == 0 && numDecimalPlaces > 0)
			v /= 10;

    stringFromValueFunction = [numDecimalPlaces] (float v, int length)
        String asText (v, numDecimalPlaces);
        return length > 0 ? asText.substring (0, length) : asText;

Any chance it could be added?

This should do it:


Wonderful! Thanks :slight_smile: