Class: Knj::Amixer

Inherits:
Object show all
Defined in:
lib/knj/amixer.rb

Overview

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

Defined Under Namespace

Classes: Device, Mixer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Amixer

Returns a new instance of Amixer.



5
6
7
8
9
10
11
12
# 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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/knj/amixer.rb', line 3

def args
  @args
end

Instance Method Details

#devicesObject

Returns a hash with devices.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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