Class: MIDIWinMM::Input
- Inherits:
-
Object
- Object
- MIDIWinMM::Input
- Includes:
- Device
- Defined in:
- lib/midi-winmm/input.rb
Overview
Input device class for the WinMM driver interface
Constant Summary collapse
- BufferSize =
256
Constants included from Device
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Attributes included from Device
#enabled, #id, #info, #name, #type
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
close the device.
-
#enable(options = {}, &block) ⇒ Object
(also: #start, #open)
initializes this device.
-
#gets ⇒ Object
returns an array of MIDI event hashes as such: [ { :data => [144, 90, 100], :timestamp => 1024 }, { :data => [128, 90, 100], :timestamp => 1100 }, { :data => [146, 60, 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.
13 14 15 |
# File 'lib/midi-winmm/input.rb', line 13 def buffer @buffer end |
Class Method Details
.all ⇒ Object
96 97 98 |
# File 'lib/midi-winmm/input.rb', line 96 def self.all Device.all_by_type[:input] end |
.clear ⇒ Object
143 144 145 146 |
# File 'lib/midi-winmm/input.rb', line 143 def @buffer.clear super @pointer = 0 end |
Instance Method Details
#close ⇒ Object
close the device
81 82 83 84 85 86 |
# File 'lib/midi-winmm/input.rb', line 81 def close Map.winmm_func(:midiInUnprepareHeader, @handle, @header.pointer, @header.size) Map.winmm_func(:midiInStop, @handle) Map.winmm_func(:midiInClose, @handle) @enabled = false end |
#enable(options = {}, &block) ⇒ Object Also known as: start, open
initializes this device
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/midi-winmm/input.rb', line 16 def enable( = {}, &block) init_input_buffer handle_ptr = FFI::MemoryPointer.new(FFI.type_size(:int)) initialize_local_buffer @event_callback = get_event_callback Map.winmm_func(:midiInOpen, handle_ptr, @id, @event_callback, 0, Device::WinmmCallbackFlag) @handle = handle_ptr.read_int Map.winmm_func(:midiInPrepareHeader, @handle, @header.pointer, @header.size) Map.winmm_func(:midiInAddBuffer, @handle, @header.pointer, @header.size) Map.winmm_func(:midiInStart, @handle) @enabled = true unless block.nil? begin yield(self) ensure close end else self end end |
#gets ⇒ Object
returns an array of MIDI event hashes as such: [
{ :data => [144, 90, 100], :timestamp => 1024 },
{ :data => [128, 90, 100], :timestamp => 1100 },
{ :data => [146, 60, 120], :timestamp => 1200 }
]
message data is an array of Numeric bytes
56 57 58 59 60 61 62 |
# File 'lib/midi-winmm/input.rb', line 56 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 }
]
72 73 74 75 76 |
# File 'lib/midi-winmm/input.rb', line 72 def gets_s msgs = gets msgs.each { |msg| msg[:data] = numeric_bytes_to_hex_string(msg[:data]) } msgs end |