Skip to content

Instantly share code, notes, and snippets.

@adamjmurray
Created July 22, 2009 20:40
Show Gist options
  • Select an option

  • Save adamjmurray/152255 to your computer and use it in GitHub Desktop.

Select an option

Save adamjmurray/152255 to your computer and use it in GitHub Desktop.

Revisions

  1. adamjmurray created this gist Jul 22, 2009.
    29 changes: 29 additions & 0 deletions stuck note prevention in midiator
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # Make MIDIator cleanup at program termination:
    class MIDIator::Driver
    alias orig_init initialize
    alias orig_note_on note_on
    alias orig_note_off note_off

    def initialize(*params)
    orig_init(*params)
    @held_notes = Hash.new {|hash,key| hash[key]={} }
    at_exit do
    @held_notes.each do |channel,notes|
    notes.each do |note,velocity|
    orig_note_off(note, channel, velocity)
    end
    end
    close
    end
    end

    def note_on( note, channel, velocity )
    orig_note_on( note, channel, velocity )
    @held_notes[channel][note] = velocity
    end

    def note_off( note, channel, velocity = 0 )
    orig_note_off( note, channel, velocity )
    @held_notes[channel].delete(note)
    end
    end