class AlsaRawMIDI::Soundcard

Attributes

id[R]
subdevices[R]

Public Class Methods

find(id) click to toggle source

Find a soundcard by its ID @param [Integer] id @return [Soundcard]

# File lib/alsa-rawmidi/soundcard.rb, line 20
def self.find(id)
  @soundcards ||= {}
  if API::Soundcard.exists?(id)
    @soundcards[id] ||= Soundcard.new(id)
  end
end
new(id) click to toggle source

@param [Integer] id

# File lib/alsa-rawmidi/soundcard.rb, line 8
def initialize(id)
  @subdevices = {
    :input => [],
    :output => []
  }
  @id = id
  populate_subdevices
end

Private Instance Methods

new_device(direction, device_hash) click to toggle source

Instantiate a new device object @param [Hash] @return [Input, Output]

# File lib/alsa-rawmidi/soundcard.rb, line 46
def new_device(direction, device_hash)
  device_class = case direction
  when :input then Input
  when :output then Output
  end
  device_properties = {
    :system_id => device_hash[:id],
    :name => device_hash[:name],
    :subname => device_hash[:subname]
  }
  device_class.new(device_properties)
end
populate_subdevices() click to toggle source

@return [Hash]

# File lib/alsa-rawmidi/soundcard.rb, line 30
def populate_subdevices
  device_ids = API::Soundcard.get_device_ids(@id)
  device_ids.each do |device_id|
    @subdevices.keys.each do |direction|
      devices = API::Soundcard.get_subdevices(direction, @id, device_id) do |device_hash|
        new_device(direction, device_hash)
      end
      @subdevices[direction] += devices
    end
  end
  @subdevices
end