class Knj::Amixer

This class is a Ruby-interface to the amixer-binary. It can read and set the volume.

Attributes

args[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/knj/amixer.rb, line 5
def initialize(args = {})
  @args = {
    :amixer_bin => "/usr/bin/amixer",
    :aplay_bin => "/usr/bin/aplay"
  }.merge(args)
  
  @devices = {}
end

Public Instance Methods

devices() click to toggle source

Returns a hash with devices.

# File lib/knj/amixer.rb, line 15
def devices
  ret = %x[#{@args[:aplay_bin]} -l]
  
  ret.scan(/card (\d+): (.+?) \[(.+?)\],/) do |match|
    id = match[0]
    
    if !@devices.key?(id)
      @devices[id] = Knj::Amixer::Device.new(
        :amixer => self,
        :id => id,
        :name => match[2],
        :code => match[1]
      )
    end
  end
  
  return @devices
end