Slider Skew problem

Hello everybody,
setting up a logarithmic slider for frequencies I encounter the following problem:

Bildschirmfoto 2024-10-04 um 10.39.29

with the skewfactor 0.2 I shoud retrieve equal distances between doubling values, but the first doubling step (20 - 40) is far to big…

as I altered the lookAndFeel for the left slider and was not sure, if I created this problem there, I put a standard slider as a reference to the right with the same skew settings

    testSlider.setRange(20.f, 20000.f, .1);
    testSlider.setSkewFactor(0.2f);

and the result seems to be the same…

any clue, what could be wrong?

(as orientation I took this link: https://jucestepbystep.wordpress.com/logarithmic-sliders/

Any help appreciated,
thank you,
Michael

I always thought this was caused by float values being too small for accuracy.

Actually, everything is correct here:

np.power((40-20)/(20000-20), 0.2)

which gives 0.25123891104434765~25%.

You should write your own convertFrom0To1Func and convertTo0To1Func.

All parameters used here (and internally) are doubles…

AudioParameterFloat only allows NormalisableRange<float>
So the skew code is all done in floats, isn’t it?

It’s just a juce::Slider. It uses doubles internally.

Thanks, but I changed everything to doubles, and nothing changes…

… which would mean I had to write and use my own NormalisableRangeClass? could try to do that, but I still do not understand, why my slider represents its values so different from the example in the link ( https://jucestepbystep.wordpress.com/logarithmic-sliders/ )

No, you have to create an instance of NormalisableRange with your own remap functions, then assign that to the slider with setNormalisableRange.

If you look at the code in NormalisableRange::convertTo0to1, in absence of custom remap functions the normalised value is computed as pow((v - min) / (max - min)), skew). A log mapping would be (log(v) - log(min)) / (log(max) - log(min)). There is no value of skew that will give you a log mapping. The value suggested in the tutorial will match the ends and the midpoint, but nothing else:

log

2 Likes

oh thanks, kamedin, just found that out, and also the convertFrom0To1, which shoud be exp(v * (log(max) - log(min)) + log(min)) , if I’m not wrong. Now I only miss the correct syntax in creating the instance of the range…
maybe you could give me an example of that, how to correctly write the ValueRemapFunction?

Interesting, so it has nothing to do with converting to float parameter and then back again?

not at all…
it would had helped, if there was some more detailed description or tutorial…

template <typename ValueT>
juce::NormalisableRange<ValueT> logRange (ValueT min, ValueT max)
{
    ValueT rng{ std::log (max / min) };
    return { min, max,
        [=](ValueT min, ValueT, ValueT v) { return std::exp (v * rng) * min; },
        [=](ValueT min, ValueT, ValueT v) { return std::log (v / min) / rng; }
    };
}
2 Likes

It took me some time to find out how to use this…
but now it’s working wonderful!

thanks a lot, dear Laureano!!!

Bildschirmfoto 2024-10-09 um 17.13.08

1 Like