class Knj::Amixer::Mixer

This class controls each mixer.

Public Class Methods

new(args) click to toggle source
# File lib/knj/amixer.rb, line 103
def initialize(args)
  @args = args
end

Public Instance Methods

name() click to toggle source

Returns the name of the mixer (example: Master).

# File lib/knj/amixer.rb, line 108
def name
  return @args[:name]
end
vol(args = {}) click to toggle source

Returns the volume-value as an integer (or as the percent if {:percent => true} if given in arguments).

# File lib/knj/amixer.rb, line 123
def vol(args = {})
  ret = %x[#{@args[:amixer].args[:amixer_bin]} -c #{@args[:device].id} sget "#{@args[:name]}"]
  raise "No content for mixer: '#{@args[:name]}'." if !ret
  
  match = ret.match(/(Capture|Playback) (\d+) \[(\d+%)\]/)
  raise "Couldnt figure out volume for '#{@args[:name]}' from:\n'#{ret}'\n" if !match
  
  return match[3].to_i if args[:percent]
  return match[2].to_i
end
vol=(newvol) click to toggle source

Sets a new value for the volume.

# File lib/knj/amixer.rb, line 135
def vol=(newvol)
  ret = %x[#{@args[:amixer].args[:amixer_bin]} -c #{@args[:device].id} sset "#{@args[:name]}" "#{newvol}"]
  #NOTE: Do some error handeling here?
end
vol_add(add_vol) click to toggle source

Adds a number to the volume.

# File lib/knj/amixer.rb, line 141
def vol_add(add_vol)
  vol = self.vol
  newvol = vol + add_vol.to_i
  newvol = 0 if newvol < 0
  self.vol=(newvol)
end
volume?() click to toggle source

Returns a bool. If the mixer supports volume-operations (some mixers are just switches and doenst support volume).

# File lib/knj/amixer.rb, line 113
def volume?
  ret = %x[#{@args[:amixer].args[:amixer_bin]} -c #{@args[:device].id} sget "#{@args[:name]}"]
  raise "No content for mixer: '#{@args[:name]}'." if !ret
  
  match = ret.match(/(Capture|Playback) (\d+) \[(\d+%)\]/)
  return false if !match
  return true
end