Class: Patch::IO::MIDI::Input
- Inherits:
-
Object
- Object
- Patch::IO::MIDI::Input
- Defined in:
- lib/patch/io/midi/input.rb
Overview
MIDI Input functions
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Is the input active?.
-
#disable(patch) ⇒ Boolean
Clear message handlers.
-
#initialize(id, device, options = {}) ⇒ Input
constructor
A new instance of Input.
-
#listen(patch, &callback) ⇒ Boolean
Specify a mpatch context and handler callback to use when messages are received.
-
#start ⇒ Boolean
Start listening for MIDI messages.
-
#stop ⇒ Boolean
Stop the MIDI listener.
Constructor Details
#initialize(id, device, options = {}) ⇒ Input
Returns a new instance of Input.
16 17 18 19 20 21 |
# File 'lib/patch/io/midi/input.rb', line 16 def initialize(id, device, = {}) @log = [:log] @id = id @device = get_input(device) @listener = MIDIEye::Listener.new(@device) unless @device.nil? end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
10 11 12 |
# File 'lib/patch/io/midi/input.rb', line 10 def device @device end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/patch/io/midi/input.rb', line 10 def id @id end |
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
10 11 12 |
# File 'lib/patch/io/midi/input.rb', line 10 def listener @listener end |
Instance Method Details
#active? ⇒ Boolean
Is the input active?
36 37 38 |
# File 'lib/patch/io/midi/input.rb', line 36 def active? @listener.running? end |
#disable(patch) ⇒ Boolean
Clear message handlers
53 54 55 56 |
# File 'lib/patch/io/midi/input.rb', line 53 def disable(patch) @listener.event.clear true end |
#listen(patch, &callback) ⇒ Boolean
Specify a mpatch context and handler callback to use when messages are received
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/patch/io/midi/input.rb', line 62 def listen(patch, &callback) if !@listener.nil? @listener.listen_for(:class => [MIDIMessage::ControlChange]) do |event| handle_event_received(patch, event, &callback) end true else false end end |
#start ⇒ Boolean
Start listening for MIDI messages
25 26 27 28 29 30 31 32 |
# File 'lib/patch/io/midi/input.rb', line 25 def start if !@listener.nil? @listener.run(:background => true) true else false end end |
#stop ⇒ Boolean
Stop the MIDI listener
42 43 44 45 46 47 48 49 |
# File 'lib/patch/io/midi/input.rb', line 42 def stop if !@listener.nil? @listener.stop true else false end end |