Module: MIDICommunications::Input::StreamReader
- Included in:
- MIDICommunications::Input
- Defined in:
- lib/midi-communications/input/stream_reader.rb
Overview
Methods for reading MIDI messages from an input device.
Provides multiple methods for retrieving MIDI data in different formats: numeric bytes, hex strings, or raw data arrays.
Instance Method Summary collapse
-
#gets(*args) ⇒ Array<Hash>
Reads MIDI messages from the input buffer.
-
#gets_data(*args) ⇒ Array<Integer>
Reads MIDI data as a flat array of bytes.
-
#gets_data_s(*args) ⇒ String
(also: #gets_data_bytestr, #gets_data_hex)
Reads MIDI data as a concatenated hex string.
-
#gets_s(*args) ⇒ Array<Hash>
(also: #gets_bytestr, #gets_hex)
Reads MIDI messages as hex strings.
Instance Method Details
#gets(*args) ⇒ Array<Hash>
Reads MIDI messages from the input buffer.
Returns all messages received since the last read. Each message includes the MIDI data and a timestamp.
29 30 31 32 33 |
# File 'lib/midi-communications/input/stream_reader.rb', line 29 def gets(*args) @device.gets(*args) rescue SystemExit, Interrupt exit end |
#gets_data(*args) ⇒ Array<Integer>
Reads MIDI data as a flat array of bytes.
Returns all message data concatenated into a single array, without timestamps.
65 66 67 68 |
# File 'lib/midi-communications/input/stream_reader.rb', line 65 def gets_data(*args) arr = gets(*args) arr.map { |msg| msg[:data] }.inject(:+) end |
#gets_data_s(*args) ⇒ String Also known as: gets_data_bytestr, gets_data_hex
Reads MIDI data as a concatenated hex string.
Returns all message data concatenated into a single hex string, without timestamps.
81 82 83 84 |
# File 'lib/midi-communications/input/stream_reader.rb', line 81 def gets_data_s(*args) arr = gets_bytestr(*args) arr.map { |msg| msg[:data] }.join end |
#gets_s(*args) ⇒ Array<Hash> Also known as: gets_bytestr, gets_hex
Reads MIDI messages as hex strings.
Similar to #gets but returns data as hex strings instead of byte arrays.
46 47 48 49 50 |
# File 'lib/midi-communications/input/stream_reader.rb', line 46 def gets_s(*args) @device.gets_s(*args) rescue SystemExit, Interrupt exit end |