Class: PM::InputInstrument
- Inherits:
-
Instrument
- Object
- Instrument
- PM::InputInstrument
- Defined in:
- lib/patchmaster/instrument.rb
Overview
When a connection is started, it adds itself to this InputInstrument’s @connections. When it ends, it removes itself.
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
-
#triggers ⇒ Object
Returns the value of attribute triggers.
Attributes inherited from Instrument
Instance Method Summary collapse
- #add_connection(conn) ⇒ Object
-
#initialize(sym, name, port_num, use_midi = true) ⇒ InputInstrument
constructor
If
port
is nil (the normal case), creates either a real or a mock port. -
#midi_in(bytes) ⇒ Object
Passes MIDI bytes on to triggers and to each output connection.
- #remove_connection(conn) ⇒ Object
-
#start ⇒ Object
Poll for more MIDI input and process it.
- #stop ⇒ Object
Constructor Details
#initialize(sym, name, port_num, use_midi = true) ⇒ InputInstrument
If port
is nil (the normal case), creates either a real or a mock port
25 26 27 28 29 30 |
# File 'lib/patchmaster/instrument.rb', line 25 def initialize(sym, name, port_num, use_midi=true) super(sym, name, port_num, input_port(port_num, use_midi)) @connections = [] @triggers = [] @listener = nil end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
21 22 23 |
# File 'lib/patchmaster/instrument.rb', line 21 def connections @connections end |
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
22 23 24 |
# File 'lib/patchmaster/instrument.rb', line 22 def listener @listener end |
#triggers ⇒ Object
Returns the value of attribute triggers.
21 22 23 |
# File 'lib/patchmaster/instrument.rb', line 21 def triggers @triggers end |
Instance Method Details
#add_connection(conn) ⇒ Object
32 33 34 |
# File 'lib/patchmaster/instrument.rb', line 32 def add_connection(conn) @connections << conn end |
#midi_in(bytes) ⇒ Object
Passes MIDI bytes on to triggers and to each output connection.
58 59 60 61 |
# File 'lib/patchmaster/instrument.rb', line 58 def midi_in(bytes) @triggers.each { |trigger| trigger.signal(bytes) } @connections.each { |conn| conn.midi_in(bytes) } end |
#remove_connection(conn) ⇒ Object
36 37 38 |
# File 'lib/patchmaster/instrument.rb', line 36 def remove_connection(conn) @connections.delete(conn) end |
#start ⇒ Object
Poll for more MIDI input and process it.
41 42 43 44 45 46 |
# File 'lib/patchmaster/instrument.rb', line 41 def start PatchMaster.instance.debug("instrument #{name} start") @port.clear_buffer @listener = MIDIEye::Listener.new(@port).listen_for { |event| midi_in(event[:message].to_bytes) } @listener.run(:background => true) end |
#stop ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/patchmaster/instrument.rb', line 48 def stop PatchMaster.instance.debug("instrument #{name} stop") @port.clear_buffer if @listener @listener.close @listener = nil end end |