Knob non linear value

Hi,

I have knob which goes to 0.5 to 2.5, with a CC goes to 0 - 127, but I need that 1. match 64.

in the value text I have this code :

JS{{
var val = @{knob_speedfree_@{parent.variables.ID}}
var result = (val / 127 * 2 + 0.5)
result = result.toFixed(2);
return result
}}

knob_nonlinear.json (19.8 KB)

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
1 Like

thank you I’ve tried much more complicated solution that was not working
I will soon share this patch which contains vst and m4l devices.

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
}}

but having total weird result ?!
knob_nonlinear.json (25.0 KB)

You’re applying the multiplication to the “else” part of the conditional.

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 :slight_smile:

 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
    }}

You can use console.log to inspect your variables (f12 to open the console), this should help you pinpoint the problem.

1 Like

when looking the result the console is writing the right value but not in the template.

Then something else is affecting the text’s value, a script in the knob maybe ?

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.

knob_nonlinear.json (24.4 KB)

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 think some general math/js learning could help here -> https://www.google.com/webhp?q=js+value+scale+range

1 Like

I’m sorry but it’s not very clear to me : what expected exactly ? If you can break it down clearly then writing the code should be easier.

for the 64 to 127 midi CC of the knob

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

This line

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:

((val - 64) / 63 * (val2 - 1) + 1)

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. ><

I get it !!!

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
}}

btw was it the best syntax to get the result ?