Class: AlsaRawMIDI::Input
- Inherits:
-
Object
- Object
- AlsaRawMIDI::Input
- Includes:
- Device
- Defined in:
- lib/alsa-rawmidi/input.rb
Overview
Input device class
Constant Summary collapse
- BufferSize =
256
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
Instance Method Summary collapse
-
#close ⇒ Object
close this input.
-
#enable(options = {}, &block) ⇒ Object
(also: #open, #start)
enable this the input for use; can be passed a block.
-
#gets ⇒ Object
(also: #read)
returns 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 ⇒ Object
(also: #gets_bytestr, #gets_hex)
same as 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
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
14 15 16 |
# File 'lib/alsa-rawmidi/input.rb', line 14 def buffer @buffer end |
Class Method Details
.all ⇒ Object
89 90 91 |
# File 'lib/alsa-rawmidi/input.rb', line 89 def self.all Device.all_by_type[:input] end |
.clear ⇒ Object
98 99 100 101 |
# File 'lib/alsa-rawmidi/input.rb', line 98 def @buffer.clear super @pointer = 0 end |
Instance Method Details
#close ⇒ Object
close this input
74 75 76 77 78 79 |
# File 'lib/alsa-rawmidi/input.rb', line 74 def close Thread.kill(@listener) Map.snd_rawmidi_drain(@handle) Map.snd_rawmidi_close(@handle) @enabled = false end |
#enable(options = {}, &block) ⇒ Object Also known as: open, start
enable this the input for use; can be passed a block
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/alsa-rawmidi/input.rb', line 52 def enable( = {}, &block) handle_ptr = FFI::MemoryPointer.new(FFI.type_size(:int)) Map.snd_rawmidi_open(handle_ptr, nil, @system_id, Map::Constants[:SND_RAWMIDI_NONBLOCK]) @handle = handle_ptr.read_int @enabled = true @start_time = Time.now.to_f initialize_buffer spawn_listener! unless block.nil? begin yield(self) ensure close end else self end end |
#gets ⇒ Object Also known as: read
returns 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
27 28 29 30 31 32 33 |
# File 'lib/alsa-rawmidi/input.rb', line 27 def gets until end msgs = @pointer = @buffer.length msgs end |
#gets_s ⇒ Object Also known as: gets_bytestr, gets_hex
same as gets but returns message data as string of hex digits as such:
[
{ :data => "904060", :timestamp => 904 },
{ :data => "804060", :timestamp => 1150 },
{ :data => "90447F", :timestamp => 1300 }
]
43 44 45 46 47 |
# File 'lib/alsa-rawmidi/input.rb', line 43 def gets_s msgs = gets msgs.each { |m| m[:data] = numeric_bytes_to_hex_string(m[:data]) } msgs end |