Why no logarithmic slider?

I thought I must have missed something (and maybe I did), but to me it looks like there is no quick way of setting a slider as logarithmic (I mean logarithmic translation between position and value).
This is a functionality that has to be extremly common in audio applications when working with stuff like frequency or filter quality. Why is there no in-built solution for this in JUCE yet?

Just to clarify, I’m not looking for a solution on how to achieve this. I already have my LogSlider class working. I’m just baffled by a fact that to achieve this I had to write my own implementation instead of just “flicking a switch” somewhere or specifying it directly in the constructor.

You don’t need to subclass. Slider maps positions to values with a NormalisableRange. You can approximate a log mapping with the range’s skew, but for true log mapping you can create a NormalisableRange supplying your ValueRemapFunctions for 0to1 and 1to0. Then you set it to the Slider. If you connect a Slider to a processor parameter with a SliderAttachment, it will use the NormalisableRange set in the parameter’s constructor. For example, I create the ranges for my frequency parameters with

juce::NormalisableRange<float> freqRange (float min, float max)
{
    auto range{ std::log2 (max / min) };
    return { min, max,
        [=](float min, float, float v) { return std::exp2 (v * range) * min; },
        [=](float min, float, float v) { return std::log2 (v / min) / range; },
        [](float min, float max, float v) { return std::clamp (v, min, max); }
    };
}
4 Likes