Slider getValueNormalized changes output depending on middle position
-
I've been trying to track down an annoying bug in my project which is using
getValueNormalized
. And I just realised it's returning the normalized visual value and not the actual normalized knob value.For example if I have a knob with a range of 0 - 50 and I set the value to 25 I would expect the normalized value to be 0.5. However this is only true if the middle position is set to 25. If I set the middle position to 10 HISE will return 0.74 when the knob's value is at 25.
Also affects
setValueNormalized
. In the example above passing in0.5
will set the knob to the middle position, not 25.Is this intentional?
In the meantime here is are two simple functions to get and set the normalised value.
inline function getNormalisedValue(component) { local value = component.getValue(); local min = component.get("min"); local max = component.get("max"); return (value - min) / (max - min); } inline function setNormalisedValue(component, normalisedValue) { local min = component.get("min"); local max = component.get("max"); component.setValue(min + (normalisedValue * (max - min))); }
-
-
-
@d-healey It's intentional, I think, because the whole point of that is so that you can be manipulating the controls without thinking about skew.
Don't your functions do the same, as they don't account for middlePosition?
Use
Math.skew()
. -
@aaronventure But you do have to think about the skew because the middle position affects the output. That's the problem.
My functions don't care about the skew or middle position.
-
@d-healey Well, depends on where you use them. As such, you should use these methods in situations where skew can just give you trouble. Like the graphical stuff or animation.
Can you give me an example where this specifically is an issue for you?
-
@aaronventure said in Slider getValueNormalized changes output depending on middle position:
Can you give me an example where this specifically is an issue for you?
I can't think of an example where I wouldn't want the normalised value to be the normalised value.
In every situation if I set the knob to the centre value (that is the value half way between the min and max) it should return 0.5 regardless of the middle position or skew.
-
@d-healey Ah ok. In that case, did you know you can pass
"middlePosition"
to Math.to0to1()?// prints 0.5 Console.print(Math.to0To1(80, {"min": 10, "max": 90, "middlePosition": 80}));
-
@aaronventure I completely forgot about the 0to1 function.
-
@d-healey Yeah I figured that's why we were running in circles :face_with_tears_of_joy:
-
@aaronventure The original function is still bugged though - or misnamed.
-
@d-healey could be mislabeling - I think it just pulls the same property that you get in LAF (obj.valueNormalized) which has the sole purpose of letting you draw a slider value position without worrying about skew.