Timed output in Ruby
Posted: Sun May 28, 2017 11:10 am
Hi all,
I'm building my own kind of 'preset handler'.
It is supposed to read a text file and then send it out as SYSEX to a vintage synth.
The issue is that SYSEX commands should be timed out with a decent delay between one another.
Assume 'one commans a second' rate (it is much faster in reality of course).
So, I'm trying to read a text file, for various reasons the number of lines is unknown, assume 10-25.
The file has headers and errors, so I'm filtering out only the commands that start with 'cmd', as a basic filter.
The ruby module should output at one-line-a-second speed.
I've tried 'sleep' which doesn't work in Flowstone... Any other ideas, similar to 'sleep' ?
I've tried a 'busy loop' (just count to 1000) but it is system dependant. Not a fan of this solution.
This is what I have:
('s' is the string input to the ruby code)
Any ideas ?
Code is attached as well.
I'm building my own kind of 'preset handler'.
It is supposed to read a text file and then send it out as SYSEX to a vintage synth.
The issue is that SYSEX commands should be timed out with a decent delay between one another.
Assume 'one commans a second' rate (it is much faster in reality of course).
So, I'm trying to read a text file, for various reasons the number of lines is unknown, assume 10-25.
The file has headers and errors, so I'm filtering out only the commands that start with 'cmd', as a basic filter.
The ruby module should output at one-line-a-second speed.
I've tried 'sleep' which doesn't work in Flowstone... Any other ideas, similar to 'sleep' ?
I've tried a 'busy loop' (just count to 1000) but it is system dependant. Not a fan of this solution.
This is what I have:
('s' is the string input to the ruby code)
Code: Select all
#
def event i,v,t
len = @s.split(/\r/).length
@i = 0
while @i < (len-2) do
#Take three first chars of the line
a = @s.split(/\r/)[@i].split[0][0..2]
if ( a == 'cmd')
output 0, @s.split(/\r/)[@i]
#Busy loop (Sleep is not functional in FlowStone)
#for j in 0..100
# output 1, j
#end
end
@i = @i + 1
end
end
Any ideas ?
Code is attached as well.