Class: RtMidi::In
- Inherits:
-
Object
- Object
- RtMidi::In
- Defined in:
- lib/rtmidi/in.rb
Overview
Object for handling MIDI input. The Ruby representation of a RtMidiIn C++ object..
Instance Method Summary collapse
-
#close_port ⇒ Object
Close the port, if opened.
-
#close_ports ⇒ Object
deprecated
Deprecated.
use #close_port
-
#initialize ⇒ In
constructor
Create a new instance.
-
#open_port(index) ⇒ Object
Open the MIDI input port at the given index.
-
#port_count ⇒ Object
The number of MIDI input ports available.
-
#port_name(index) ⇒ Object
The name of the MIDI input port at the given index.
-
#port_names ⇒ Object
The list of all MIDI input port names.
-
#receive_channel_message {|Fixnum, Fixnum, Fixnum| ... } ⇒ Object
Setup a callback block to handle incoming MIDI channel messages from opened ports.
-
#receive_message {|*Fixnum| ... } ⇒ Object
(also: #set_callback)
Setup a callback block to handle all incoming MIDI messages from opened ports.
-
#stop_receiving ⇒ Object
(also: #cancel_callback)
Cancel the current receive callback, if any.
Constructor Details
#initialize ⇒ In
Create a new instance.
9 10 11 12 |
# File 'lib/rtmidi/in.rb', line 9 def initialize @midiin = Interface::midiin_new() at_exit{ Interface::midiin_delete @midiin } end |
Instance Method Details
#close_port ⇒ Object
Close the port, if opened.
44 45 46 |
# File 'lib/rtmidi/in.rb', line 44 def close_port() Interface::midiin_close_port(@midiin) end |
#close_ports ⇒ Object
use #close_port
49 50 51 52 |
# File 'lib/rtmidi/in.rb', line 49 def close_ports puts "Deprecated, use #close_port instead" close_port end |
#open_port(index) ⇒ Object
only one port may be open per RtMidi::In instance
Open the MIDI input port at the given index.
38 39 40 |
# File 'lib/rtmidi/in.rb', line 38 def open_port(index) Interface::midiin_open_port(@midiin, index) end |
#port_count ⇒ Object
The number of MIDI input ports available.
15 16 17 |
# File 'lib/rtmidi/in.rb', line 15 def port_count @port_count ||= Interface::midiin_port_count(@midiin) end |
#port_name(index) ⇒ Object
The name of the MIDI input port at the given index.
21 22 23 |
# File 'lib/rtmidi/in.rb', line 21 def port_name(index) port_names[index] end |
#port_names ⇒ Object
The list of all MIDI input port names.
The index of a port in this list is the index to be passed to #port_name and #open_port.
31 32 33 |
# File 'lib/rtmidi/in.rb', line 31 def port_names @port_names ||= (0...port_count).map{|port_index| Interface::midiin_port_name(@midiin, port_index) } end |
#receive_channel_message {|Fixnum, Fixnum, Fixnum| ... } ⇒ Object
Only one receive callback may be active per RtMidi::In instance. Calling this method or #receive_message multiple times will replace the previous receive callback.
Setup a callback block to handle incoming MIDI channel messages from opened ports. The block should receive 3 bytes (Ruby Fixnum integers)
All messages are assumed to have 3 bytes. SysEx messages will be ignored. Some channel messages only have 2 bytes in which case the 3rd byte is 0.
This is more efficient than #receive_message and should be used when handling only MIDI channel messages.
75 76 77 78 79 80 |
# File 'lib/rtmidi/in.rb', line 75 def &callback cancel_callback # otherwise first callback wins. I think last wins is more intuitive Interface::midiin_ignore_types(@midiin, true, true, true) # Ignore sysex, timing, or active sensing messages. Interface::midiin_set_callback(@midiin, callback) @callback_set = true end |
#receive_message {|*Fixnum| ... } ⇒ Object Also known as: set_callback
Only one receive callback may be active per RtMidi::In instance. Calling this method or #receive_message multiple times will replace the previous receive callback.
Setup a callback block to handle all incoming MIDI messages from opened ports. The block should receive a variable number of Ruby Fixnum integers. SysEx messages will be passed to the callback.
This is less efficient than #receive_channel_message and should only be used when handling SysEx, timing, or active sensing messages.
103 104 105 106 107 108 |
# File 'lib/rtmidi/in.rb', line 103 def &callback cancel_callback # otherwise first callback wins. I think last wins is more intuitive Interface::midiin_ignore_types(@midiin, false, false, false) # Don't ignore sysex, timing, or active sensing messages. Interface::midiin_set_varargs_callback(@midiin, ->(bytes,size){ yield *bytes.read_array_of_uchar(size) }) @callback_set = true end |
#stop_receiving ⇒ Object Also known as: cancel_callback
Cancel the current receive callback, if any.
116 117 118 119 120 121 |
# File 'lib/rtmidi/in.rb', line 116 def stop_receiving if @callback_set Interface::midiin_cancel_callback(@midiin) @callback_set = false end end |