Another "Ruby if then" question

For general discussion related FlowStone
Post Reply
User avatar
kortezzzz
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Another "Ruby if then" question

Post 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?
TheOm
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: Another "Ruby if then" question

Post by TheOm »

Maybe use a case statement with ranges like this:
Attachments
midi velocity.fsm
(380 Bytes) Downloaded 848 times
User avatar
kortezzzz
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Another "Ruby if then" question

Post 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 :)
TheOm
Posts: 103
Joined: Tue Jan 28, 2014 7:35 pm
Location: Germany

Re: Another "Ruby if then" question

Post by TheOm »

It works for floats and ints.
And of course you can also have a default value with an else branch.
Attachments
case.fsm
(341 Bytes) Downloaded 873 times
User avatar
kortezzzz
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Another "Ruby if then" question

Post 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-)
Perfect Human Interface
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Another "Ruby if then" question

Post 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
Post Reply