Class: UniMIDI::Input

Inherits:
Object
  • Object
show all
Extended by:
Device::ClassMethods
Includes:
Device::InstanceMethods
Defined in:
lib/unimidi/input.rb

Overview

A MIDI input device

Class Method Summary collapse

Instance Method Summary collapse

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

.allArray<Input>

All MIDI input devices – used to populate the class

Returns:



11
12
13
# File 'lib/unimidi/input.rb', line 11

def self.all
  Loader.devices(:direction => :input)
end

Instance Method Details

#bufferArray<Hash>

The device buffer

Returns:

  • (Array<Hash>)


17
18
19
# File 'lib/unimidi/input.rb', line 17

def buffer
  @device.buffer
end

#clear_bufferArray

Clears the input buffer

Returns:

  • (Array)


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

Parameters:

  • args (*Object)

Returns:

  • (Array<Hash>)


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

Parameters:

  • args (*Object)

Returns:

  • (Array<Hash>)


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

Parameters:

  • args (*Object)

Returns:

  • (Array<Fixnum>)


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

Parameters:

  • args (*Object)

Returns:

  • (Array<Hash>)


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]

Parameters:

  • args (*Object)

Returns:

  • (Array<Fixnum>)


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"

Parameters:

  • args (*Object)

Returns:

  • (String)


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

Parameters:

  • args (*Object)

Returns:

  • (Array<Hash>)


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