[SOLVED] Logarithmic slider - Slider class override freezes the Component


Hello !

I’m only on my second day of JUCE (and C++ for that matter), so the issue might be very stupid, but please bear with me.

I want a a logarithmic Slider. I originally tried with a skew of 1/e, but it wasn’t right, so I went through a lot of posts to see how I could implement it.

I saw Jules said to override proportionOfLengthToValue and valueToProportionOfLength to achieve that.
So far, I’ve created a subclass of Slider, called, LogSlider, which implements all this in the following fashion:

    x: proportion           (0) |-----------|(1)
    y: value         (minValue) |-----------|(maxValue)

    To get a logarithmic scale, we have to solve the following: 
    y = a * exp(b * x)
    (x1;y1) = (0;minValue)
    (x2;y2) = (1;maxValue)

    B and A have to be computed at instantiation and every time minValue or maxValue are changed.

    b = (log(y2/y1)) / (x2 - x1)
    a = y1 / (exp(b * x1)) OR a = y2 / (exp(b * x2))
    So in our case, 
    b = log(maxValue/minValue)
    a = minValue

void LogSlider::updateLogCoefficients()
    a = getMinimum();
    b = log(getMaximum() / getMinimum());

// TODO: optimize with exp / log approximations
double LogSlider::proportionOfLengthToValue(double proportion)
    double value = a * exp(b * proportion);
    return value;
double LogSlider::valueToProportionOfLength(double value)
    double proportion = log(value / a) / b;
    return proportion;

void LogSlider::setRange(double newMinimum, double newMaximum, double newInterval)
    Slider::setRange(newMinimum, newMaximum, newInterval);

The issue I’m having now is the sliders have no “thumbs”.
I think the paint() method is broken because of the subclass, somehow.

How could I either fix the paint() method, or implement the scaling without overriding the Slider class ?

Thank you for your time.

EDIT: I just realised I also need to change LogSlider::setRange() to prevent non-strictly-positive values for newMinimum and newMaximum. Possible culprit right there.

EDIT2: It was that stupid. minimumValue was 0, and froze the component. I now have a working prototype. I’ll have to see how I can correctly prevent those non-strictly-positive values.