Module: MIDIWinMM::Device

Included in:
Input, Output
Defined in:
lib/midi-winmm/device.rb

Overview

Module containing methods used by both input and output devices when using the WinMM driver interface

Constant Summary collapse

WinmmCallbackFlag =

we plan to use a callback to collect events

0x30000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledObject (readonly) Also known as: enabled?

Returns the value of attribute enabled.



10
11
12
# File 'lib/midi-winmm/device.rb', line 10

def enabled
  @enabled
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/midi-winmm/device.rb', line 10

def id
  @id
end

#infoObject (readonly)

Returns the value of attribute info.



10
11
12
# File 'lib/midi-winmm/device.rb', line 10

def info
  @info
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/midi-winmm/device.rb', line 10

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/midi-winmm/device.rb', line 10

def type
  @type
end

Class Method Details

.allObject



21
22
23
# File 'lib/midi-winmm/device.rb', line 21

def self.all
  all_by_type.values.flatten
end

.all_by_typeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/midi-winmm/device.rb', line 25

def self.all_by_type
  types = { :input => Input,
          :output => Output }
  available_devices = { :input => [], :output => [] }
  count = 0
  types.each do |type, klass|
   (0..(Map::cfunc(type, :getNumDevs)-1)).each do |i|
      data = Map::DeviceInfo[type].new
      Map::cfunc(type, :getDevCapsA, i, data.to_ptr, Map::DeviceInfo[type].size)
      name = data[:szPname].to_s
      dev = klass.new(i, name, :info => data)
      available_devices[type] << dev
    end
  end
  available_devices
end

.first(type) ⇒ Object

select the first device of type type



43
44
45
# File 'lib/midi-winmm/device.rb', line 43

def self.first(type)
  all_by_type[type].first
end

.last(type) ⇒ Object

select the last device of type type



48
49
50
# File 'lib/midi-winmm/device.rb', line 48

def self.last(type)
  all_by_type[type].last
end

Instance Method Details

#initialize(id, name, options = {}, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/midi-winmm/device.rb', line 14

def initialize(id, name, options = {}, &block)
  @id = id
  @info = options[:info]
  @type = self.class.name.split('::').last.downcase.to_sym
  @name = name
end