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.
-
#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.
Blocks until at least one message has arrived, and then returns every message that accumulated. It never returns an empty array.
This is part of the contract every platform adapter implements, not an accident of one of them — see PhysicalLayer. A reader loop therefore needs no delay of its own, and adding one only delays the messages that are already waiting.
34 35 36 37 38 |
# File 'lib/midi-communications/input/stream_reader.rb', line 34 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.
Blocks as #gets does, and returns all message data concatenated into a single array, without timestamps.
71 72 73 74 |
# File 'lib/midi-communications/input/stream_reader.rb', line 71 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.
87 88 89 90 |
# File 'lib/midi-communications/input/stream_reader.rb', line 87 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.
Blocks exactly as #gets does, and returns the same messages with
:data as a hex string instead of an array of bytes.
52 53 54 55 56 |
# File 'lib/midi-communications/input/stream_reader.rb', line 52 def gets_s(*args) @device.gets_s(*args) rescue SystemExit, Interrupt exit end |