Page 1 of 1

Another "Ruby if then" question

Posted: Sat Aug 23, 2014 1:42 pm
by kortezzzz
Hi
In my last post, Iv requested a kinda "IF THEN" module, based on ruby hashes.
This time, wondering if there is any chance to code a ruby "if then" module that
based on "<", ">" as well.

Well, the idea is a ruby modole with one input (midi), one output (float). the ruby module
should extract velocity info from the midi input, compare it with given values and send specific values to the output
when the velocity value is greater then x or smaller then x.

Any chance to make it with ruby?

Re: Another "Ruby if then" question

Posted: Sat Aug 23, 2014 2:38 pm
by TheOm
Maybe use a case statement with ranges like this:

Re: Another "Ruby if then" question

Posted: Sat Aug 23, 2014 8:00 pm
by kortezzzz
Thanks TheOm,

Works great! In principle, can the input type get replaced by any kind of input? for instance, can we use integer input (or any other) instead of midi input by switching the first line of the code? i believe this kind of module can be very useful to any of us.

Thanks :)

Re: Another "Ruby if then" question

Posted: Sat Aug 23, 2014 9:03 pm
by TheOm
It works for floats and ints.
And of course you can also have a default value with an else branch.

Re: Another "Ruby if then" question

Posted: Sun Aug 24, 2014 5:42 am
by kortezzzz
Works perfectly :D

Thanks a lot, man. That's very useful tool. recommend everybody to put in their toolbox. One day you will need it, no doubt.

8-)

Re: Another "Ruby if then" question

Posted: Sun Aug 24, 2014 9:56 am
by Perfect Human Interface
Wow, so simple and yet so useful! Thanks TheOm! Ruby really breathed new life into this thing didn't she? :D