Skip to content

Instantly share code, notes, and snippets.

@badboy
Created January 6, 2010 15:31
Show Gist options
  • Save badboy/270336 to your computer and use it in GitHub Desktop.
Save badboy/270336 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
VOLSTORE = File.expand_path('~/.volume')
CHANNEL = 'vmix0-outvol'
MAX_VOLUME = 25
def osd_percentage(perc)
fork {
`osd_cat -b percentage -p bottom -c "#285577" -d 1 -A right -o 20 -P #{perc}`
}
end
def ossmix(*args)
`ossmix #{CHANNEL} #{args.map{|e|e.to_s}.join(' ')}`
end
def get_cur_volume
`ossmix #{CHANNEL}`.split(/ /)[9]
end
def toggle
if File.exists?(VOLSTORE)
ossmix File.read(VOLSTORE)
FileUtils.rm VOLSTORE
else
cur_volume = get_cur_volume
ossmix 0
File.open(VOLSTORE, 'w') { |f| f << cur_volume }
end
end
def raise_vol
ossmix '--', '+1'
end
def lower_vol
ossmix '--', '-1'
end
def show_actual_volume
vol = ((get_cur_volume.to_f / MAX_VOLUME) * 100).to_i
osd_percentage vol
end
if ARGV.size != 1
STDERR.puts <<-EOF
usage: #{$1} [raise|lower|toggle]
EOF
exit 1
end
case ARGV.first
when 'raise'
raise_vol
when 'lower'
lower_vol
when 'toggle'
toggle
else
STDERR.puts 'unknown'
end
show_actual_volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment