var result = val < 64 ? // if val < 64
(val / 64 * 0.5 + 0.5) : // convert 0-64 range to 0.5-1.0
((val - 64) / 63 * 1.5 + 1) // else: convert 64-127 range to 1.0-2.5
I was adding a multiplicator factor on the knob (2x, 4x, 8x)
JS{{
var val = @{knob_speedfree_@{parent.variables.ID}}
var val2 = Math.round(@{switch_multiplier_@{parent.variables.ID}}/16)
var result = val < 64 ? // if val < 64
(val / 64 * 0.5 + 0.5) : // convert 0-64 range to 0.5-1.0
((val - 64) / (63 +1))*val2 // else: convert 64-127 range to 1.0-2.5
result = result.toFixed(2);
return result
}}
Still have some drop and glitch value ?!
the idea was to only multiplies the 64 to 127 part so the else conditional was perfect.
It’s not so important but I was scratching my head for this one
JS{{
var val = @{knob_speedfree_@{parent.variables.ID}}
var val2 = Math.round(@{switch_multiplier_@{parent.variables.ID}}/16)
var result = val < 64 ? // if val < 64
(val / 64 * 0.5 + 0.5) : // convert 0-64 range to 0.5-1.0
((val - 64) / 64) // else: convert 64-127 range to 1.0-2.0
result = result.toFixed(2)*val2;
return result
}}
All was fine, just too much experiment in this template, delete everything keep only the knob and the text, it was working perfectly.
I wish to work before midnight
This templates is finished ! will share it soon.
thank you so much for your help
In fact the 64 - 127 part is not working in the expected way.
For the 2x multiplier the result is fine
but for the 4x and 8x I get the a 1 to 5 or 1 to 9 range value.
I tried a min/max range value but nothing seems to worked.
JS{{
var val = @{knob_speedfree_@{parent.variables.ID}}
var val2 = Math.round(@{switch_multiplier_@{parent.variables.ID}}/16)
var result = val < 64 ? // if val < 64
(val / 64 * 0.5 + 0.5) : // convert 0-64 range to 0.5-1.0
((val - 64) / 63 * val2 + 1)// else: convert 64-127 range to 1.0-2.0
result = result.toFixed(2); // limit to 2 decimal
console.log(result); // f12 to see the log
return result
}}
I need to display value between 1 and the multiplier button switch (2x, 4x, 8x)
Currently it’s working for 2x, but for 4x and 8x value have a range of 1 to multiplier +1
so for 4x I get 1 to 5
and for 8x : 1 to 9
var val2 = Math.round(@{switch_multiplier_@{parent.variables.ID}}/16)
Is wrong, it returns 1 when the multiplier is 2 and that’s the reason why the conversion works for this multiplier (it shouldn’t). You should fix that first, then the conversion should be corrected to:
the line is “I think” correct (I set the cc value of the button to 8 instead of 0 to get 1)
but maybe I should get back to 0 and then
say if val2 = 0 set 1.
I’ll try to find the solution. ><
JS{{
var val = @{knob_speedfree_@{parent.variables.ID}}
var val2 = @{switch_multiplier_@{parent.variables.ID}} == 0 ?
val2 = 2 :
Math.round(@{switch_multiplier_@{parent.variables.ID}}/16)
var result = val < 64 ? // if val < 64
(val / 64 * 0.5 + 0.5) : // convert 0-64 range to 0.5-1.0
((val - 64) / 63 * (val2 - 1) + 1)// else: convert 64-127 range to 1.0-2.0
result = result.toFixed(2);
console.log(result);
return result
}}