midi scheduler in ruby

Discussion in 'Ruby' started by Gaspard Bucher, Sep 25, 2007.

  1. 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
     
    Gaspard Bucher, Sep 25, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Codemonkey
    Replies:
    8
    Views:
    9,581
  2. Hugo Villeneuve

    Java MIDI output device to MIDI Yoke.

    Hugo Villeneuve, Jul 4, 2003, in forum: Java
    Replies:
    0
    Views:
    969
    Hugo Villeneuve
    Jul 4, 2003
  3. Gilly
    Replies:
    6
    Views:
    434
    Ken Starks
    May 4, 2008
  4. Asbjørn Bjørnstad
    Replies:
    0
    Views:
    447
    Asbjørn Bjørnstad
    Oct 9, 2008
  5. Lawrence Oluyede

    Event scheduler in Ruby

    Lawrence Oluyede, May 18, 2005, in forum: Ruby
    Replies:
    2
    Views:
    146
    John Labovitz
    May 18, 2005
Loading...

Share This Page