AudioProcessorValueTreeState problems with skew and numDecimals


#1

Hi,
I have problems with Slider after Attachment:

Slider TimeSlider;
TimeSlider.setRange(1.0, 5000.0);
TimeSlider.setSkewFactorFromMidPoint(500.0);
TimeSlider.numDecimals = 1;

this works perfect.
But after using Attachment neither the skew nor the numDecimals work anymore:

auto normRange = NormalisableRange<float>(0.0f, 5000.0f);
parameters.push_back(std::make_unique<AudioParameterFloat>(paramID, "DECAY",   normRange, 100.0f, " ms"));

Time_Attachment.reset(new SliderAttachment(valueTreeState, paramID, TimeSlider));
TimeSlider.setSkewFactorFromMidPoint(500.0);
TimeSlider.numDecimals = 1;

I’ve also tried this one:

auto normRange = NormalisableRange<float>(0.0f, 5000.0f);
normRange.setSkewForCentre(500.f);
parameters.push_back(std::make_unique<AudioParameterFloat>(paramID, "DECAY", normRange, 100.0f, " ms"));
Time_Attachment.reset(new SliderAttachment(valueTreeState, paramID, TimeSlider));

It shows a strange behaviour: the Slider is still linear, but the mouse move is exponential, in the beginning small changes per distance and in the end big changes for the same distance moved.

Is there another way to get it to work?
Why are the “normal” Slider properties never available after Attachment to APVTS?

Thanks


#2

My Bad: disappointed_relieved:
I made a mistake in my overriden drawRotarySlider()

The last code works perfect:

auto normRange = NormalisableRange<float>(0.0f, 5000.0f);
normRange.setSkewForCentre(500.f);
parameters.push_back(std::make_unique<AudioParameterFloat>(paramID, "DECAY", normRange, 100.0f, " ms"));
Time_Attachment.reset(new SliderAttachment(valueTreeState, paramID, TimeSlider));

but:

TimeSlider.setSkewFactorFromMidPoint(500.0);
TimeSlider.setNumDecimalPlacesToDisplay (1);

does not work.


#3

The attachment class sets custom text/value conversion lambdas for the slider. When the lambdas are present the slider doesn’t use the numDecimals attribute since its not handling the actual text conversion itself

I’m not sure why the changing the slider’s skew isn’t working for you… that should be able to be altered even after the SliderAttachment is made. Is the attachment somehow not using those setRange()/setSkewFactor() calls starting at line 544? That could explain it since those conversion lambdas inside the else body don’t account for range skew at all


#4

Thank you @TonyAtHarrison for those details. I will dive into ASAP


#5

I found the problem:
in line 542 in APVTS (see code above)

if (range.interval != 0.0f || range.skew != 1.0f)
{
slider.setRange (range.start, range.end, range.interval);
slider.setSkewFactor (range.skew, range.symmetricSkew);
}

This code destroys the skew set by

Slider.setSkewFactorFromMidPoint(x)

and it destroys numDecimalPlacesToDisplay set by

Slider.setNumDecimalPlacesToDisplay(i);

slider.setRange() calls slider.updateRange() and here numDecimalPlaces will be calculated from the “Interval” Parameter in the NormalisableRange.
This means Interval and numDecimalPlaces are bound, meaning if you want less decimals you get big jumps in your slider. It is not possible to have a smooth slider with only 1 decimalToShow.
This might often be okay, but is defenitly not okay in many cases.
IMHO this should not be bound, Interval and numDecimalsToShow should be independent and a design parameter for every developer.

I would appreciate to be able to set numDecimalsToShow seperate in the NormalisableRange.
Maybe it is set by default to -1, and then updateRange() can calculate numDecimals, like it is right now.

An other way would be not to override numDecimalPlaces in updateRange() if it was set in

Slider.setNumDecimalPlacesToDisplay();    

hope this makes sense


#6

Same problem here @ed95 @tpoole with numDecimalPlaces


#7

The idea behind all of this was that once a parameter is attached to a slider, the slider will delegate text handling to the parameter. So, to get a set number of decimal places you can use the stringFromValue parameter of the AudioParameterFloat constructor.