Class: AlsaRawMIDI::Input
- Inherits:
-
Object
- Object
- AlsaRawMIDI::Input
- Includes:
- Device
- Defined in:
- lib/alsa-rawmidi/input.rb
Overview
Input device class
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Attributes included from Device
#enabled, #id, #name, #subname, #system_id, #type
Class Method Summary collapse
-
.all ⇒ Array<Input>
All available inputs.
- .clear ⇒ Object
-
.first ⇒ Input
The first input available.
-
.last ⇒ Input
The last input available.
Instance Method Summary collapse
-
#close ⇒ Boolean
Close this input.
-
#enable(_options = {}) ⇒ Input
(also: #open, #start)
Enable this the input for use; yields.
-
#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)
Like Input#gets but returns message data as string of hex digits as such: [ { :data => “904060”, :timestamp => 904 }, { :data => “804060”, :timestamp => 1150 }, { :data => “90447F”, :timestamp => 1300 } ].
Methods included from Device
Methods included from Device::ClassMethods
#all, #all_by_type, #first, #last
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
8 9 10 |
# File 'lib/alsa-rawmidi/input.rb', line 8 def buffer @buffer end |
Class Method Details
.all ⇒ Array<Input>
All available inputs
97 98 99 |
# File 'lib/alsa-rawmidi/input.rb', line 97 def self.all Device.all_by_type[:input] end |
.clear ⇒ Object
108 109 110 111 |
# File 'lib/alsa-rawmidi/input.rb', line 108 def @buffer.clear super @pointer = 0 end |
Instance Method Details
#close ⇒ Boolean
Close this input
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/alsa-rawmidi/input.rb', line 72 def close if @enabled Thread.kill(@listener) API::Device.close(@resource) @enabled = false true else false end end |
#enable(_options = {}) ⇒ Input Also known as: open, start
Enable this the input for use; yields
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/alsa-rawmidi/input.rb', line 50 def enable( = {}) unless @enabled @start_time = Time.now.to_f @resource = API::Input.open(@system_id) @enabled = true initialize_buffer spawn_listener end if block_given? begin yield(self) ensure close end end self 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/alsa-rawmidi/input.rb', line 22 def gets loop until msgs = @pointer = @buffer.length msgs end |
#gets_s ⇒ Array<Hash> Also known as: gets_bytestr, gets_hex
Like Input#gets but returns message data as string of hex digits as such:
[
{ :data => "904060", :timestamp => 904 },
{ :data => "804060", :timestamp => 1150 },
{ :data => "90447F", :timestamp => 1300 }
]
38 39 40 41 42 |
# File 'lib/alsa-rawmidi/input.rb', line 38 def gets_s msgs = gets msgs.each { |m| m[:data] = TypeConversion.numeric_bytes_to_hex_string(m[:data]) } msgs end |