Midi scheduler in ruby

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[i] && e.time <= @events[i])
i += 1
end
if @events[i]
@events[i…i] << [e, i]
else
@events << e
end
end
end

Many thanks for your insight.

Gaspard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs