"Last" green primitive action - Ruby version. Possible?

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

"Last" green primitive action - Ruby version. Possible?

Post by kortezzzz »

Heya,

Was wondering if Ruby can output the last coming parameter(s) of one or more inputs, just like the green "Last"version does. If it can, which parameters can be instantly processed and how? I believe Arrays, integers, floats, strings and red clips are no problem. But what about a full midi event (status, channel, data1, data2) ?

I mean let's say I have 2 midi inputs that each of them gets a random signal from 2 sources, one at the time. Can I instantly output each of them by using "Last" method?

Examples for all kind of situations (midi and non-midi) are welcome :)
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: "Last" green primitive action - Ruby version. Possible?

Post by KG_is_back »

Code: Select all

def event v
output v
end

This should do the job. You can add arbitrary many inputs and it will send the last one to the first output.
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: "Last" green primitive action - Ruby version. Possible?

Post by Spogg »

KG_is_back wrote:

Code: Select all

def event v
output v
end

This should do the job. You can add arbitrary many inputs and it will send the last one to the first output.


Oh dear. I thought I understood event handling. I thought the order was input (index), value and time.
So I would have put def event i,v
If you just put def event v does Ruby know you mean value and not input?

Cheers

Spogg
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: "Last" green primitive action - Ruby version. Possible?

Post by KG_is_back »

There are 4 separate versions of event method

Code: Select all

event()
event(value)
event(input,value)
event(input,value,time)


the first two are a little obscure, because they are usable in only the simplest cases. The last one is redundant because you can always access current time-stamp via time method.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: "Last" green primitive action - Ruby version. Possible?

Post by tulamide »

I say this without having checked it in a RubyEdit, but I'm pretty sure that's wrong.

You can't just have event(v), it MUST be event(i, v). From the user guide, chapter 8:

For more advanced data handling you can define an event method. This is a special method which FlowStone looks for whenever it receives data at an input. The event method can have up to 3 input parameters:

▪ i - references the input at which the data arrived
▪ v - value that arrived at the input
▪ t - time at which the data arrived (schematic time in seconds)

You can have 0,1,2 or all 3 input parameters but you must add them in the order. So for example, you can have no parameters or
you can have i on its own
or i and v
or i and v and t
but you can't have v on its own or i and t without v.


EDIT: KG, Ruby doesn't support method overloading
"There lies the dog buried" (German saying translated literally)
User avatar
kortezzzz
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: "Last" green primitive action - Ruby version. Possible?

Post by kortezzzz »

KG_is_back wrote:

Code: Select all

def event v
output v
end

This should do the job. You can add arbitrary many inputs and it will send the last one to the first output.


I'm sorry KG, but it doesn't work for me. Tried it with integers, strings and floats pramenters.
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: "Last" green primitive action - Ruby version. Possible?

Post by Spogg »

This is from an exercise I set myself early in my learning process.

It might be shit but it does work!

Cheers

Spogg
Attachments
Last changed float .fsm
(95.21 KiB) Downloaded 885 times
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: "Last" green primitive action - Ruby version. Possible?

Post by tulamide »

Am I being ignored? Why so neglecting? Just replace "v" with "i,v" in KGs example and it should work.

Code: Select all

def event(i, v)
  output v
end
"There lies the dog buried" (German saying translated literally)
User avatar
kortezzzz
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: "Last" green primitive action - Ruby version. Possible?

Post by kortezzzz »

It works, tula :)

Sorry, but I missed the syntax at your first comment. When you wrote it clearly at the last, I understood. It may sound obvious to you, but people with no coding skills sometime miss the context until you clearly write the code :lol:
Post Reply