Class: MIDIWinMM::Input

Inherits:
Object
  • Object
show all
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

Device::WinmmCallbackFlag

Instance Attribute Summary collapse

Attributes included from Device

#enabled, #id, #info, #name, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Device

all_by_type, #initialize

Instance Attribute Details

#bufferObject (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

.allObject



96
97
98
# File 'lib/midi-winmm/input.rb', line 96

def self.all
  Device.all_by_type[:input]
end

.clearObject



143
144
145
146
# File 'lib/midi-winmm/input.rb', line 143

def @buffer.clear
  super
  @pointer = 0
end

.firstObject



88
89
90
# File 'lib/midi-winmm/input.rb', line 88

def self.first
  Device.first(:input)
end

.lastObject



92
93
94
# File 'lib/midi-winmm/input.rb', line 92

def self.last
  Device.last(:input)
end

Instance Method Details

#closeObject

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(options = {}, &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

#getsObject

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 queued_messages?
  end
  msgs = queued_messages
  @pointer = @buffer.length
  msgs
end

#gets_sObject 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