System Volume Control (rfe)

Asked by orbisvicis on 2010-06-02

In order to control my system volume, I used to bind my laptop media keys like this:
spawn "command='amixer -q set Master 5%+'; pgrep -f \"^$command$\" || exec $command")
XF86XK_AudioLowerVolume 0x1008FF11
XF86XK_AudioRaiseVolume 0x1008FF13

which, would unfortunately spawn lots of subshells if I held down the keys:
/bin/sh -c "command='amixer -q set Master 5%+'; pgrep -f \"^$command$\" || exec $command")"
... x100
pgrep -f amixer -q set Master 5%+'
... x100
amixer -q set Master 5%+'
... x100

All these asynchronous backgrounded amixer process would try accessing the volume at once, the result being that even though the volume channels remain locked, the channels go out of sync. So for example, channel 0 of Master would be at "50%" while channel 1 of Master would be at "76%". Annoying.

Now I do:

trap 'adjust_volume 5 -' SIGRTMIN+5
trap 'adjust_volume 5 +' SIGRTMAX-5

function adjust_volume {
    if [[ "$run_times" -eq 0 ]]; then
        amixer -q set Master "$1%$2"
        run_times=$((run_times + 1))

while : ; do
    sleep 0.05

Which is great, but requires starting a separate service in ~/.xinitrc or whatever rocks your boat.
And then I found panflute, so I thought the two could be combined... as so:

on "org.mpris.panflute" add a new "/System" object with the following methods:
RaiseVolume or RaiseSystemVolume
LowerVolume or LowerSystemVolume
that behave in the same manner as the bash script, that is
"dbus-send --session --print-reply --type=method_call --dest=org.mpris.panflute /System org.freedesktop.MediaPlayer.RaiseVolume string:5%-" will only lower the volume by 5% every X seconds per dbus request.

Even better, instead of using amixer, this can be accomplished through pyalsaaudio.

Question information

English Edit question
Panflute Edit question
No assignee Edit question
Last query:
Last reply:
Paul Kuliniewicz (kuliniew) said : #1

I think this is really outside the scope of what Panflute is trying to do. I think you'd be better served getting whatever GNOME uses to control the master volume via the media keys working correctly. That's something I can't help you with, though.

Can you help with this problem?

Provide an answer of your own, or ask orbisvicis for more information if necessary.

To post a message you must log in.