midi scheduler in ruby

G

Gaspard Bucher

I am writing ruby wrappers around rtMidi
(http://www.music.mcgill.ca/~gary/rtmidi/) and need to trigger "note
off".

This is the api I wish to implement:
@midiout = RtMidi.new('port name')
note = 62
velocity = 100
duration = 0.25 # 1/4
@midiout.play(note, velocity, duration)

When a note is played, a first midi event is created for the velocity,
then, a little later a second for the note off:
[note on ]
[wait ]
[note off]

1. What is the best way to implement such a scheduler ?

2. Should I create a thread in C that checks for events in a buffer ?

3. Should this scheduler be implemented in Ruby ?
class Scheduler
def initialize
@events = []
Thread.new
while(true) do
sleep 0.01 # ?
if @events[0] && @events[0].time >= Time.now
@events.shift.trigger
end
end
end
end

def <<(e)
i = 0
while(@events && e.time <= @events)
i += 1
end
if @events
@events[i..i] << [e, i]
else
@events << e
end
end
end

Many thanks for your insight.

Gaspard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,000
Messages
2,570,252
Members
46,848
Latest member
CristineKo

Latest Threads

Top