class AMixer2019
file: amixer2019.rb description: A wrapper around the command-line program amixer.
Public Class Methods
new(notch: 5, fade_interval: 0.15, debug: false)
click to toggle source
# File lib/amixer2019.rb, line 9 def initialize(notch: 5, fade_interval: 0.15, debug: false) @notch, @fade_interval, @debug = notch, fade_interval, debug @control = `amixer scontrols`[/(?<=')[^']+/] query(`amixer get '#{@control}'`) end
Public Instance Methods
fade(raw_val, interval: @fade_interval)
click to toggle source
fades the volume up or down to the volume percentage
# File lib/amixer2019.rb, line 20 def fade(raw_val, interval: @fade_interval) val = raw_val.to_i return 'volume must be between 0 and 100' if val < 0 or val > 100 @volume.method(val > @volume ? :upto : :downto).call(val.to_i).each do |x| sleep interval; setvol(x.to_s + '%') end @volume end
mute()
click to toggle source
# File lib/amixer2019.rb, line 33 def mute() sset 'mute' end
muted?()
click to toggle source
# File lib/amixer2019.rb, line 34 def muted?() @muted end
toggle()
click to toggle source
# File lib/amixer2019.rb, line 35 def toggle() sset 'toggle' end
unmute()
click to toggle source
# File lib/amixer2019.rb, line 36 def unmute() sset 'unmute' end
vol_down()
click to toggle source
# File lib/amixer2019.rb, line 37 def vol_down() setvol(-@notch) end
vol_up()
click to toggle source
# File lib/amixer2019.rb, line 38 def vol_up() setvol(+@notch) end
volume()
click to toggle source
# File lib/amixer2019.rb, line 39 def volume() @volume end
Also aliased as: vol
volume=(val)
click to toggle source
# File lib/amixer2019.rb, line 40 def volume=(val) setvol(val) end
Also aliased as: vol=
Private Instance Methods
query(r)
click to toggle source
# File lib/amixer2019.rb, line 63 def query(r) puts 'r: ' + r.inspect if @debug h = r.match(/(?<volume>\d+)%\] .*\[(?<toggle>on|off)\]/) @volume = h[:volume].to_i @muted = h[:toggle] == 'off' end
setvol(val)
click to toggle source
# File lib/amixer2019.rb, line 51 def setvol(val) return sset(val) if val.is_a?(String) and val =~ /%$/ if val.to_i + @volume >= 0 and val.to_i + @volume <= 100 then sset("%s%%" % [@volume + val.to_i]) else @volume end end
sset(switch)
click to toggle source
# File lib/amixer2019.rb, line 47 def sset(switch) query(`amixer sset #{@control} #{switch}`) end