Module: UniMIDI::Input::StreamReader

Included in:
UniMIDI::Input
Defined in:
lib/unimidi/input/stream_reader.rb

Instance Method Summary collapse

Instance Method Details

#gets(*args) ⇒ Array<Hash>

Returns any data in the input buffer that have been received since the last call to a StreamReader method. If a StreamReader method has not yet been called, all data received since the program was initialized will be returned

The data is returned 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

Parameters:

  • args (*Object)

Returns:

  • (Array<Hash>)


23
24
25
26
27
# File 'lib/unimidi/input/stream_reader.rb', line 23

def gets(*args)
  @device.gets(*args)
rescue SystemExit, Interrupt
  exit
end

#gets_data(*args) ⇒ Array<Integer>

Returns any data in the input buffer that have been received since the last call to a StreamReader method. If a StreamReader method has not yet been called, all data received since the program was initialized will be returned

Similar to Input#gets except that the returned message data as an array of data bytes such as

[144, 60, 100, 128, 60, 100, 144, 40, 120]

Parameters:

  • args (*Object)

Returns:

  • (Array<Integer>)


59
60
61
62
# File 'lib/unimidi/input/stream_reader.rb', line 59

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

Returns any data in the input buffer that have been received since the last call to a StreamReader method. If a StreamReader method has not yet been called, all data received since the program was initialized will be returned

Similar to Input#gets except that the returned message data as a string of data such as

"90406080406090447F"

Parameters:

  • args (*Object)

Returns:

  • (String)


73
74
75
76
# File 'lib/unimidi/input/stream_reader.rb', line 73

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

Returns any data in the input buffer that have been received since the last call to a StreamReader method. If a StreamReader method has not yet been called, all data received since the program was initialized will be returned

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 }
]

Parameters:

  • args (*Object)

Returns:

  • (Array<Hash>)


42
43
44
45
46
# File 'lib/unimidi/input/stream_reader.rb', line 42

def gets_s(*args)
  @device.gets_s(*args)
rescue SystemExit, Interrupt
  exit
end