Page 1 of 1

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

Posted: Sun May 27, 2018 7:40 am
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 :)

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

Posted: Sun May 27, 2018 12:21 pm
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.

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

Posted: Sun May 27, 2018 2:46 pm
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

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

Posted: Sun May 27, 2018 3:30 pm
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.

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

Posted: Sun May 27, 2018 5:13 pm
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

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

Posted: Sun May 27, 2018 5:39 pm
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.

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

Posted: Sun May 27, 2018 5:50 pm
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

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

Posted: Sun May 27, 2018 6:00 pm
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

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

Posted: Sun May 27, 2018 8:02 pm
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: