Class: UniMIDI::Input
- Inherits:
-
Object
- Object
- UniMIDI::Input
- Extended by:
- Device::ClassMethods
- Includes:
- Device::InstanceMethods
- Defined in:
- lib/unimidi/input.rb
Overview
A MIDI input device
Class Method Summary collapse
-
.all ⇒ Array<Input>
All MIDI input devices â used to populate the class.
Instance Method Summary collapse
-
#buffer ⇒ Array<Hash>
The device buffer.
-
#clear_buffer ⇒ Array
Clears the input buffer.
-
#gets(*args) ⇒ Array<Hash>
Plucks data from the input buffer and returns it as array of MIDI event hashes as such: [ { :data => [144, 60, 100], :timestamp => 1024 }, { :data => [128, 60, 100], :timestamp => 1100 }, { :data => [144, 40, 120], :timestamp => 1200 } ].
-
#gets_buffer(*args) ⇒ Array<Hash>
Gets any messages in the buffer in the same format as Input#gets, without removing them from the buffer.
-
#gets_buffer_data(*args) ⇒ Array<Fixnum>
Gets any messages in the buffer in the same format as Input#gets_data without removing them from the buffer.
-
#gets_buffer_s(*args) ⇒ Array<Hash>
Gets any messages in the buffer in the same format as Input#gets_s, without removing them from the buffer.
-
#gets_data(*args) ⇒ Array<Fixnum>
Plucks data from the input buffer and returns it as an array of data bytes such as [144, 60, 100, 128, 60, 100, 144, 40, 120].
-
#gets_data_s(*args) ⇒ String
(also: #gets_data_bytestr, #gets_data_hex)
Plucks data from the input buffer and returns it as a string of data such as â90406080406090447Fâ.
-
#gets_s(*args) ⇒ Array<Hash>
(also: #gets_bytestr, #gets_hex)
Plucks data from the input buffer and returns it as array of MIDI event hashes.
Methods included from Device::ClassMethods
[], each, find_by_name, first, last, list, use
Methods included from Device::InstanceMethods
#close, included, #initialize, #open, #pretty_name
Class Method Details
Instance Method Details
#buffer ⇒ Array<Hash>
The device buffer
17 18 19 |
# File 'lib/unimidi/input.rb', line 17 def buffer @device.buffer end |
#clear_buffer ⇒ Array
Clears the input buffer
86 87 88 |
# File 'lib/unimidi/input.rb', line 86 def clear_buffer @device.buffer.clear end |
#gets(*args) ⇒ Array<Hash>
Plucks data from the input buffer and returns it as array of MIDI event hashes as such:
[
{ :data => [144, 60, 100], :timestamp => 1024 },
{ :data => [128, 60, 100], :timestamp => 1100 },
{ :data => [144, 40, 120], :timestamp => 1200 }
]
In this case, the data is an array of Numeric bytes The timestamp is the number of millis since this input was enabled Arguments are passed to the underlying device object
35 36 37 38 39 |
# File 'lib/unimidi/input.rb', line 35 def gets(*args) @device.gets(*args) rescue SystemExit, Interrupt exit end |
#gets_buffer(*args) ⇒ Array<Hash>
Gets any messages in the buffer in the same format as Input#gets, without removing them from the buffer
93 94 95 |
# File 'lib/unimidi/input.rb', line 93 def gets_buffer(*args) @device.buffer end |
#gets_buffer_data(*args) ⇒ Array<Fixnum>
Gets any messages in the buffer in the same format as Input#gets_data without removing them from the buffer
107 108 109 |
# File 'lib/unimidi/input.rb', line 107 def gets_buffer_data(*args) @device.buffer.map { |msg| msg[:data] } end |
#gets_buffer_s(*args) ⇒ Array<Hash>
Gets any messages in the buffer in the same format as Input#gets_s, without removing them from the buffer
100 101 102 |
# File 'lib/unimidi/input.rb', line 100 def gets_buffer_s(*args) @device.buffer.map { |msg| msg[:data] = TypeConversion.numeric_byte_array_to_hex_string(msg[:data]); msg } end |
#gets_data(*args) ⇒ Array<Fixnum>
Plucks data from the input buffer and returns it as an array of data bytes such as
[144, 60, 100, 128, 60, 100, 144, 40, 120]
66 67 68 69 |
# File 'lib/unimidi/input.rb', line 66 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
Plucks data from the input buffer and returns it as a string of data such as
"90406080406090447F"
77 78 79 80 |
# File 'lib/unimidi/input.rb', line 77 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
Plucks data from the input buffer and returns it as array of MIDI event hashes. Similar to Input#gets except that the returned message data as string of hex digits eg:
[
{ :data => "904060", :timestamp => 904 },
{ :data => "804060", :timestamp => 1150 },
{ :data => "90447F", :timestamp => 1300 }
]
52 53 54 55 56 |
# File 'lib/unimidi/input.rb', line 52 def gets_s(*args) @device.gets_s(*args) rescue SystemExit, Interrupt exit end |