[Ruby] Linear Scale Transform (now with Midi Example)

Post any examples or modules that you want to share here
Post Reply
mikefiction
Posts: 1
Joined: Wed Feb 06, 2013 1:25 am

[Ruby] Linear Scale Transform (now with Midi Example)

Post by mikefiction »

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:

Code: Select all

new_value = ( ( old_value - old_min ) / (old_max - old_min) ) * (new_max - new_min) + new_min
Attachments
Ruby_Linear_Scale_Midi.fsm
(20.89 KiB) Downloaded 1413 times
Ruby_Linear_Scale_Example.fsm
(11.95 KiB) Downloaded 1398 times
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: [Ruby] Linear Scale Transform (now with Midi Example)

Post by trogluddite »

Hi Mike, welcome to the forum.

Great to see such a nicely documented example in a first post - and thanks for the credit on the MIDI readout. :D

The MIDI one could be worked up into quite a nice step sequencer example, I think. Here's a step (sorry, bad pun!) in that direction, that demonstrates how to use a couple of method definitions and event scheduling - to capture only the counter changes, and also to create some note-offs...
Ruby_Linear_Scale_Midi-3.fsm
(21 KiB) Downloaded 1468 times
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Post Reply