Class: MIDIInstrument::Listener
- Inherits:
-
Object
- Object
- MIDIInstrument::Listener
- Extended by:
- Forwardable
- Defined in:
- lib/midi-instrument/listener.rb
Overview
A light wrapper for MIDIEye::Listener
Instance Method Summary collapse
-
#add(*messages) ⇒ Array<MIDIMessage>
(also: #<<)
Manually add messages to the MIDI input buffer.
-
#initialize(sources) ⇒ Listener
constructor
A new instance of Listener.
-
#inputs ⇒ Array<UniMIDI::Input>
The active inputs.
-
#join ⇒ Object
Join the listener thread.
-
#receive(match = {}, &callback) ⇒ Boolean
Bind a message callback.
-
#start ⇒ Object
Start the listener.
Constructor Details
#initialize(sources) ⇒ Listener
Returns a new instance of Listener.
12 13 14 |
# File 'lib/midi-instrument/listener.rb', line 12 def initialize(sources) @listener = MIDIEye::Listener.new([sources].flatten) end |
Instance Method Details
#add(*messages) ⇒ Array<MIDIMessage> Also known as: <<
Manually add messages to the MIDI input buffer
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/midi-instrument/listener.rb', line 19 def add(*) [].flatten.map do || report = { :message => , :timestamp => Time.now.to_f } @listener.event.enqueue_all(report) report end end |
#inputs ⇒ Array<UniMIDI::Input>
The active inputs
39 40 41 |
# File 'lib/midi-instrument/listener.rb', line 39 def inputs @listener.sources end |
#join ⇒ Object
Join the listener thread
32 33 34 35 |
# File 'lib/midi-instrument/listener.rb', line 32 def join start if !@listener.running? @listener.join end |
#receive(match = {}, &callback) ⇒ Boolean
Bind a message callback
52 53 54 55 56 |
# File 'lib/midi-instrument/listener.rb', line 52 def receive(match = {}, &callback) @listener.listen_for(match, &callback) start if !@listener.running? true end |
#start ⇒ Object
Start the listener
44 45 46 |
# File 'lib/midi-instrument/listener.rb', line 44 def start @listener.start(:background => true) end |