Module: AlsaRawMIDI::Device

Included in:
Input, Output
Defined in:
lib/alsa-rawmidi/device.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledObject (readonly) Also known as: enabled?

has the device been initialized?



12
13
14
# File 'lib/alsa-rawmidi/device.rb', line 12

def enabled
  @enabled
end

#idObject

has the device been initialized?



12
13
14
# File 'lib/alsa-rawmidi/device.rb', line 12

def id
  @id
end

#nameObject (readonly)

has the device been initialized?



12
13
14
# File 'lib/alsa-rawmidi/device.rb', line 12

def name
  @name
end

#subnameObject (readonly)

has the device been initialized?



12
13
14
# File 'lib/alsa-rawmidi/device.rb', line 12

def subname
  @subname
end

#system_idObject (readonly)

has the device been initialized?



12
13
14
# File 'lib/alsa-rawmidi/device.rb', line 12

def system_id
  @system_id
end

#typeObject (readonly)

has the device been initialized?



12
13
14
# File 'lib/alsa-rawmidi/device.rb', line 12

def type
  @type
end

Class Method Details

.allObject

all devices of both types



67
68
69
# File 'lib/alsa-rawmidi/device.rb', line 67

def self.all
  all_by_type.values.flatten
end

.all_by_typeObject

a Hash of :input and :output devices



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/alsa-rawmidi/device.rb', line 47

def self.all_by_type
  available_devices = { :input => [], :output => [] }
  device_count = 0
  32.times do |i|
    card = Soundcard.find(i)
    unless card.nil?
      available_devices.keys.each do |type|
        devices = card.subdevices[type]
        devices.each do |dev|
          dev.send(:id=, device_count)
          device_count += 1
        end
        available_devices[type] += devices
      end
    end
  end
  available_devices
end

.first(type) ⇒ Object

select the first device of type type



37
38
39
# File 'lib/alsa-rawmidi/device.rb', line 37

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

.last(type) ⇒ Object

select the last device of type type



42
43
44
# File 'lib/alsa-rawmidi/device.rb', line 42

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

Instance Method Details

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/alsa-rawmidi/device.rb', line 24

def initialize(options = {}, &block)
  @id = options[:id]
  @name = options[:name]
  @subname = options[:subname]
  @system_id = options[:system_id]
  
  # cache the type name so that inspecting the class isn't necessary each time
  @type = self.class.name.split('::').last.downcase.to_sym

  @enabled = false
end