Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

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

Post any examples or modules that you want to share here

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

Postby mikefiction » 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:
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 1231 times
Ruby_Linear_Scale_Example.fsm
(11.95 KiB) Downloaded 1204 times
mikefiction
 
Posts: 1
Joined: Wed Feb 06, 2013 1:25 am

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

Postby trogluddite » Fri Mar 01, 2013 1:31 am

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 1272 times
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK


Return to User Examples

Who is online

Users browsing this forum: No registered users and 18 guests