Skip to content

Instantly share code, notes, and snippets.

@adamjmurray
Created July 22, 2009 20:40
Show Gist options
  • Save adamjmurray/152255 to your computer and use it in GitHub Desktop.
Save adamjmurray/152255 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment