I am trying to change the behavior of one of my sliders to have a bipolar exponential skew. In other words, the slider should go from -value to +value, with the middle value at zero, and an exponential increase in the value as you go away from the mid value, with the sign added on as needed.
It is probably easier to explain this with some code. This calculates a bipolar exponential warping that goes from -maxValue to maxValue, with a bit of a “dead zone” around the center of the slider value:
if(sliderValue>0.501f)
displayValue=0.02f*powf(10.f, (1.f/0.499f)*(sliderValue-0.501f)*log10f(maxValue/0.02f));
else if (sliderValue<0.499f)
displayValue=-0.02f*powf(10.f, (1.f/0.499f)*(0.499f-sliderValue)*log10f(maxValue/0.02f));
else
displayValue=0.0f;
So, is there any way to do this with the existing Slider class, with some version of the Slew functions that I don’t know about? Or should I create my own subclass of the Slider class to perform this function?
I think that subclassing is the way to go. I came across the proportionOfLengthToValue() and valueToProportionOfLength() virtual functions in the Slider class definition, and these might be useful for creating the warpings I am looking for. It might be useful to add min, max and default values as members of the subclass data structure, with the appropriate set and get functions, and use these to calculate the translation of the “real world” slider values to values that work for VST and RTAS.
I’ll graph out your functions in Excel to see how they match the math library functions. As these would be for the UI only, I’m not sure how often they would be called. I tend to use the “pure” transcendentals in my internal calculations, but with a check to see if the value has changed and needs to be recalculated.