You are not logged in.
Pages: 1
I'm trying to get xosd to display the volume of my PCM channel when I change it using a hotkey. So far I've gotten this far. I'm not too sure how I would go about specifying the channel when it changes and for it to display when the key is pressed.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <xosd.h>
int main (int argc, char *argv[])
{
xosd *osd;
int i = 0;
osd = xosd_create (2);
if (osd == NULL)
{
perror ("Could not create \"osd\"");
exit (1);
}
xosd_set_font (osd, "lucidasans-24");
xosd_set_colour (osd, "#666666");
xosd_set_shadow_offset (osd, 2);
xosd_set_pos (osd, XOSD_bottom);
xosd_set_vertical_offset (osd, 48);
xosd_set_align (osd, XOSD_left);
xosd_set_horizontal_offset (osd, 250);
xosd_set_bar_length(osd, 50);
for (i = 0; i <= 100; i += 5)
{
xosd_display (osd, 0, XOSD_percentage, i);
sleep (3);
xosd_destroy (osd);
exit (0);
}
}
Offline
I actually whipped together a shell script to do this:
/home/travis/bin/volume
#!/bin/bash
action=$1; shift
# Unmute the volume and increase/decrease it
# Arg 1: volume change to set (1+ or 1-)
set_volume() {
amixer sset Master unmute &> /dev/null &
volume=$(amixer sset PCM $1 unmute | \
grep "Left: Playback" | \
grep -o "\[[0-9]*%\]" | \
tr '[%]' ' ')
}
# Get the current volume %
# No args
get_volume() {
volume=$(amixer sget PCM | \
grep "Left: Playback" | \
grep -o "\[[0-9]*%\]" | \
tr '[%]' ' ')
}
# Toggle Master volume mute on/off
# No args
mute_volume() {
status=$(amixer sset Master toggle | \
grep "Left: Playback" | \
grep -o "\[on\]\|\[off\]" | \
tr '[]' ' ')
}
# Use xosd to show a volume guage on the screen
# Arg 1: Current volume as percent of full volume
# Arg 2: (optional) Text to show above bar
show_volume() {
killall -9 -q osd_cat &>/dev/null
killall -9 -q xosd &>/dev/null
/home/travis/bin/xosd --text "$( [ "z$2" = "z" ] && echo Volume: $1% || echo $2 )" \
--barmode=percentage \
--percentage=$1
}
case "$action" in
incr)
delta=1+
set_volume $delta
show_volume $volume
;;
decr)
delta=1-
set_volume $delta
show_volume $volume
;;
mute)
mute_volume
case "$status" in
off)
show_volume 0 "Muted"
;;
on)
get_volume
show_volume $volume
;;
esac
;;
*)
echo "Usage: $0 {incr|decr|mute}"
;;
esac
I think it's based on other scripts I found around the net (possibly heavily) - it's been a while since I've looked at it.
Basically you'd use some other utility (I use XFCE's keybindings) to map your volume up key to /path/to/volume/script incr, your down key to /path/to/volume/script decr, and the mute key to /path/to/volume/script mute
Hope that helps
-edit-
Oops, you'll need this too:
/home/travis/bin/xosd
#!/bin/sh
exec /usr/bin/osd_cat \
--font='-*-lucida-bold-r-*-*-*-240-*-*-*-216-*-*' \
--shadow=1 \
--color=red \
--pos=bottom \
--align=center \
--delay=2 \
${1+"$@"}
-edit again-
Made some cleanups to my old, ugly script.
Last edited by Cerebral (2007-12-19 02:33:16)
Offline
Thanks. I've been playing around with it but can't get it to work. Am I able to live the xosd like that or do I have to run some command to make t executable?
Offline
I use the Keytouch program for the on screen sound display. Very nice (tactile sound strip on the laptop here). It looks very basic (progress bar with a percentage in it) but it still looks a whole lot better than xosd .
Last edited by B (2007-12-19 04:12:49)
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
I couldn't get that to work but I think that if I use my xosd I posted but told it to cat the alsa status file instead of "i", it'd work. I just can't find that file.
Offline
AFAIK, there isn't an "alsa status file" - you might be able to link into alsa just like you did with xosd and get your information through method calls into the alsa library.
Google around for alsa programming and see if you can find anything.
Offline
Thanks. I've been playing around with it but can't get it to work. Am I able to live the xosd like that or do I have to run some command to make t executable?
Well, both scripts you'll need to make executable with chmod o+x /path/to/script
Offline
That's weird, I tried that last night and it didn't work, but it did this morning. Now just to make in change by more than one percent.
Offline
Is /etc/asound.state what you are looking for?
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
Sadly not. Close though. Really, the scripts Cerebral gave me worked perfectly if I could just change the amount the volume changes.
Offline
That's weird, I tried that last night and it didn't work, but it did this morning. Now just to make in change by more than one percent.
See where it says delta=1+ and delta=1- in the volume script? Just change that 1 to a higher number.
Offline
I don't know how I missed that. I was looking at the top where it said "# Arg 1: volume change to set (1+ or 1-)" and was so confused because it was commented out.
Offline
If nothing comes up when you run "volume mute", try changing "tr '[]' ' '" to "tr -d '[]'" in mute_volume(). The extra spaces makes it so that $status doesn't match anything in the "case".
At least. that was the case for me...
Last edited by profylno (2008-09-23 05:40:13)
Offline
Pages: 1