class MIDIInstrument::Listener
A light wrapper for MIDIEye::Listener
Public Class Methods
new(sources)
click to toggle source
@param [Array<UniMIDI::Input>, UniMIDI::Input] sources
# File lib/midi-instrument/listener.rb, line 12 def initialize(sources) @listener = MIDIEye::Listener.new([sources].flatten) end
Public Instance Methods
add(*messages)
click to toggle source
Manually add messages to the MIDI input buffer @param [Array<MIDIMessage>, MIDIMessage, *MIDIMessage] args @return [Array<MIDIMessage>]
# File lib/midi-instrument/listener.rb, line 19 def add(*messages) [messages].flatten.map do |message| report = { :message => message, :timestamp => Time.now.to_f } @listener.event.enqueue_all(report) report end end
Also aliased as: <<
inputs()
click to toggle source
The active inputs @return [Array<UniMIDI::Input>]
# File lib/midi-instrument/listener.rb, line 39 def inputs @listener.sources end
join()
click to toggle source
Join the listener thread
# File lib/midi-instrument/listener.rb, line 32 def join start if !@listener.running? @listener.join end
receive(match = {}, &callback)
click to toggle source
Bind a message callback @param [Hash] match @param [Proc] callback @return [Boolean]
# File lib/midi-instrument/listener.rb, line 52 def receive(match = {}, &callback) @listener.listen_for(match, &callback) start if !@listener.running? true end
start()
click to toggle source
Start the listener
# File lib/midi-instrument/listener.rb, line 44 def start @listener.start(:background => true) end