Class: MIDIJRuby::Input
- Inherits:
-
Object
- Object
- MIDIJRuby::Input
- Includes:
- Device
- Defined in:
- lib/midi-jruby/input.rb
Overview
Input device class
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Attributes included from Device
#description, #enabled, #id, #name, #type, #vendor
Class Method Summary collapse
-
.all ⇒ Array<Input>
All inputs.
- .clear ⇒ Object
-
.first ⇒ Input
Select the first input.
-
.last ⇒ Input
Select the last input.
Instance Method Summary collapse
-
#close ⇒ Boolean
Close this input.
-
#enable(_options = {}) ⇒ Input
(also: #open, #start)
Enable this the input for use; can be passed a block.
-
#gets ⇒ Array<Hash>
(also: #read)
An 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_s ⇒ Array<Hash>
(also: #gets_bytestr, #gets_hex)
Same as Input#gets but returns message data as string of hex digits: [ { :data => “904060”, :timestamp => 904 }, { :data => “804060”, :timestamp => 1150 }, { :data => “90447F”, :timestamp => 1300 } ].
Methods included from Device
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
8 9 10 |
# File 'lib/midi-jruby/input.rb', line 8 def buffer @buffer end |
Class Method Details
.all ⇒ Array<Input>
All inputs
90 91 92 |
# File 'lib/midi-jruby/input.rb', line 90 def self.all Device.all_by_type[:input] end |
.clear ⇒ Object
111 112 113 114 |
# File 'lib/midi-jruby/input.rb', line 111 def @buffer.clear @pointer = 0 super end |
.first ⇒ Input
Select the first input
78 79 80 |
# File 'lib/midi-jruby/input.rb', line 78 def self.first Device.first(:input) end |
.last ⇒ Input
Select the last input
84 85 86 |
# File 'lib/midi-jruby/input.rb', line 84 def self.last Device.last(:input) end |
Instance Method Details
#close ⇒ Boolean
Close this input
70 71 72 73 74 |
# File 'lib/midi-jruby/input.rb', line 70 def close @listener.kill API.close_input(@device) @enabled = false end |
#enable(_options = {}) ⇒ Input Also known as: open, start
Enable this the input for use; can be passed a block
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/midi-jruby/input.rb', line 50 def enable( = {}) unless @enabled initialize_input @enabled = true end if block_given? begin yield(self) ensure close end else self end end |
#gets ⇒ Array<Hash> Also known as: read
An 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 }
]
The data is an array of numeric bytes The timestamp is the number of millis since this input was enabled
22 23 24 25 26 27 |
# File 'lib/midi-jruby/input.rb', line 22 def gets loop until = @pointer = @buffer.length end |
#gets_s ⇒ Array<Hash> Also known as: gets_bytestr, gets_hex
Same as Input#gets but returns message data as string of hex digits: [
{ :data => "904060", :timestamp => 904 },
{ :data => "804060", :timestamp => 1150 },
{ :data => "90447F", :timestamp => 1300 }
]
38 39 40 41 42 |
# File 'lib/midi-jruby/input.rb', line 38 def gets_s = gets .each { || [:data] = numeric_bytes_to_hex_string([:data]) } end |