[Ruby] Linear Scale Transform (now with Midi Example)
Posted: Thu Feb 28, 2013 8:28 pm
1st post 
This Ruby math element transforms a scale linearly from standard 0-1 scale to whatever scale you have use for.
You can hard code the min/max numbers or make them externally selectable as shown in the example.
I don't know how many greens it would take to do this function and I'm not going to try
You can of course change the numbers from any "old" scale to any "new" scale - You can scale up, down or sideways, haha - i.e 0-10 to 2-10 etc...
I scaled it back again to show accuracy - turn the knob and you'll see it's not 100% accurate all the time - but we're talking on the micro number level - nothing that's ever affected any application I've used this for.
You can use integer output instead of float if you need whole numbers as shown in the example as well.
To give an idea of more advanced uses - I've used a similar technique with float arrays for sample accurate midi velocity and CC# sequencing in a Ruby arpeggiator, but that is beyond the scope of this simple demonstration.
(See edit)
This could be done in one line if you need a hard-coded linear scale transform.
edit: I've attached a more advanced Midi example using a float array transformed to 1-127 sending velocity data
Here's the math:
This Ruby math element transforms a scale linearly from standard 0-1 scale to whatever scale you have use for.
You can hard code the min/max numbers or make them externally selectable as shown in the example.
I don't know how many greens it would take to do this function and I'm not going to try
You can of course change the numbers from any "old" scale to any "new" scale - You can scale up, down or sideways, haha - i.e 0-10 to 2-10 etc...
I scaled it back again to show accuracy - turn the knob and you'll see it's not 100% accurate all the time - but we're talking on the micro number level - nothing that's ever affected any application I've used this for.
You can use integer output instead of float if you need whole numbers as shown in the example as well.
To give an idea of more advanced uses - I've used a similar technique with float arrays for sample accurate midi velocity and CC# sequencing in a Ruby arpeggiator, but that is beyond the scope of this simple demonstration.
(See edit)
This could be done in one line if you need a hard-coded linear scale transform.
edit: I've attached a more advanced Midi example using a float array transformed to 1-127 sending velocity data
Here's the math:
Code: Select all
new_value = ( ( old_value - old_min ) / (old_max - old_min) ) * (new_max - new_min) + new_min