You are not logged in.

#1 2008-04-05 16:19:43

bruenig
Member
Registered: 2007-05-20
Posts: 175

dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

I made a similar volume bar with pygtk earlier. This is the same concept but more attractive for tiling window managers. For this you will need the following dependencies: dzen2, alsa-utils, sed, coreutils, bash.

The basic idea is that you bind multimedia keys to this program and then when you press them, a volume bar pops up briefly showing the change.

Here is a close up screen.
nlxwr4.png

Here is what it looks like on the entire screen:
http://i28.tinypic.com/swzs4k.png

Here is the script, notice that the look and placement and other things are customized by editing the variables at the top of the script. IF is the amixer interface (most likely Master) and SECS is the seconds you want the volume bar to linger after displaying. The rest is obvious. Just copy and paste this into a text file in the PATH called "dvol" and chmod +x it.

#!/bin/bash

#Customize this stuff
IF="Master"
SECS="1"

FONT="fixed"
BG="grey"
FG="black"
XPOS="550"
YPOS="400"
WIDTH="205"

#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  exit
}

#Argument Parsing
case "$1" in
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
if [ "$MUTE" = "off]" ]; then
  VOL="0"
else
  VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
fi

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -l 1 -x "$XPOS" -y "$YPOS" -w "$WIDTH" -fn "$FONT" -bg "$BG" -fg "$FG" -e 'onstart=uncollapse' < "$PIPE" 
   rm -f "$PIPE") &
fi

#Feed the pipe!
(echo "Volume" ; echo "$VOL" | dbar ; sleep "$SECS") > "$PIPE"

The usage information can be found with dvol --help. But here it is:

usage: dvol [option] [argument]

Options:
     -i, --increase - increase volume by `argument'
     -d, --decrease - decrease volume by `argument'
     -t, --toggle   - toggle mute on and off
     -h, --help     - display this

Edit: Added FONT variable.

Last edited by bruenig (2008-04-06 18:51:26)

Offline

#2 2008-04-05 17:12:39

Gigamo
Member
Registered: 2008-01-19
Posts: 394

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

This is awesome! Thanks. smile

Offline

#3 2008-04-05 19:50:19

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Thanks for this, bruenig. I was a big fan of your changevol script as well.

Edit:

As an FYI, it might be nice to include the FONT variable as well.  I've added it to mine so I can use terminus instead of terminal (or whatever the default font is).

Thanks again!

Last edited by thayer (2008-04-05 20:37:03)


thayer williams ~ cinderwick.ca

Offline

#4 2008-09-18 04:23:02

Evanlec
Member
From: NH, USA
Registered: 2007-12-16
Posts: 141
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

this is indeed lovely wink

simple and easy to setup

++

Offline

#5 2008-11-17 14:54:29

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Hey these are great! I've been using the changevol script for a while now... Have you considered putting these in AUR? I know I'd appreciate not having to find the thread or copy from a previous installation if I'm building a new system...


.:[My Blog] || [My GitHub]:.

Offline

#6 2008-11-17 15:03:48

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

For those of you who like a more graphical output I modified the script slightly:

#!/bin/bash

#Customize this stuff
IF="PCM"
SECS="1"

BG="#43464f"
FG="#9ab8c2"
XPOS="860"
YPOS="0"
WIDTH="250"
ICON=~/YOUR_ICON_PATH/spkr_01.xbm
#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  exit
}

#Argument Parsing
case "$1" in
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
if [ "$MUTE" = "off]" ]; then
  VOL="0"
else
  VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
fi

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -tw 250 -x "$XPOS" -y "$YPOS" -w "$WIDTH" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE" 
   rm -f "$PIPE") &
fi

#Feed the pipe!
(echo "$VOL" | gdbar -l "^i(${ICON}) " -fg "$FG" -bg "$BG" -w 230 ; sleep "$SECS") > "$PIPE"

EDIT:

Screenshot: veHF6

EDIT2: Thanks for pointing it out rson451

Last edited by Ashren (2008-11-18 14:27:22)

Offline

#7 2008-11-17 15:09:41

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Ashren,  looks like you could strip all the FONT stuff out of yours, you don't output any text at all.  Looks good though.

Last edited by rson451 (2008-11-17 16:28:55)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#8 2008-11-17 16:05:16

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

ashren: beatiful!
For ashren's version you also need dzen2-gadgets (which contains gdbar)
On my system there is no spkr_01.xbm btw. (I only have some gtk themes and tango installed, that's it)

edit: whoa.. gdbar is the shit : http://dzen.geekmode.org/dwiki/doku.php … bar-styles

Last edited by Dieter@be (2008-11-17 16:12:51)


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#9 2008-11-17 16:49:57

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Dieter@be: Thanks, I forgot to mention the gdbar bit.

To get the icons look here: http://dzen.geekmode.org/dwiki/doku.php … icon-packs

Offline

#10 2008-11-17 16:55:51

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Great stuff! I've modified this a bit further:

* volume bar can now have separate foreground and background colours from the title window and icon
* width of bar is now adjustable to compensate for different icons/fonts (originally pushing it to 100% sent the bar outside the title window)
* height variable offers vertical padding

Here's a gaudy screenshot to show the differences:
dvolbar_20081117.png

FYI: gdbar is included in the standard dzen2 package.

#!/bin/bash
#
# dvolbar - OSD Volume utility 
#

#Customize this stuff
IF="Master"         # audio channel: Master|PCM
SECS="1"            # sleep $SECS
BG="#ff9900"        # background colour of window
FG="#ffffff"        # foreground colour of text/icon
BAR_FG="#ffffff"    # foreground colour of volume bar
BAR_BG="#444444"    # background colour of volume bar
XPOS="705"          # horizontal positioning
YPOS="500"          # vertical positioning
HEIGHT="30"         # window height
WIDTH="250"         # window width
BAR_WIDTH="165"     # width of volume bar
ICON=~/path/to/icon.xbm
FONT="-*-dina-medium-r-*-*-13-*-*-*-*-*-*-*"

#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  exit
}

#Argument Parsing
case "$1" in
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
if [ "$MUTE" = "off]" ]; then
  VOL="0"
else
  VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
fi

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE" 
   rm -f "$PIPE") &
fi

#Feed the pipe!
(echo "$VOL" | gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS") > "$PIPE"

Last edited by thayer (2008-11-17 16:58:16)


thayer williams ~ cinderwick.ca

Offline

#11 2008-11-17 17:00:11

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

thayer wrote:

FYI: gdbar is included in the standard dzen2 package.

Oops, you're right.  I was getting 'gdbar: command not found' errors when I first tried this script (and i had dzen2 installed)
*/me scratches head*


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#12 2008-11-17 23:29:19

bruenig
Member
Registered: 2007-05-20
Posts: 175

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Wow, this thread certainly took off recently. And I thought it was dead.

Offline

#13 2009-01-28 17:44:40

kcbanner
Member
From: Toronto, Canada
Registered: 2006-08-28
Posts: 43
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

I will package this for AUR bruenig if that is ok with you?

Offline

#14 2009-01-28 17:56:16

bruenig
Member
Registered: 2007-05-20
Posts: 175

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

kcbanner wrote:

I will package this for AUR bruenig if that is ok with you?

Go for it

Offline

#15 2009-02-19 01:59:15

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

hi! i love this script! but im looking forward to make it a full size top bar like the screenshot but i cant seem to get the second line right...

53394746.png

i certainly love to have this in a one line bar like this

VOLUME: 80% [=============    ]

so i can edit this script to show other things like battery, disk space, etc


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#16 2009-02-19 09:17:40

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Thanks to the bumping I've just found this thread, thanks for this script! I have it bound in Xmonad to ctrl-alt j/k for dvol -d 1 and dvol -i 1 respectively, and h/l for mpc prev and mpc next (Yes, weird I know, but I'm used to it now tongue)

Offline

#17 2009-02-21 16:03:35

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

I have edited it to be a top bar instead

EDIT: for some reason, you need to wait for the number of secs specified in $SECS, and the bar doesn't have a fixed size, it resizes with every volume change)

#!/bin/bash

#Customize this stuff
IF="Master"
SECS="3"

FONT="-*-fixed-medium-r-*-*-18-*-*-*-*-*-iso8859-*"
BG="black"
FG="grey"
XPOS="0"
YPOS="0"
WIDTH="1024"

#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  exit
}

#Argument Parsing
case "$1" in
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
if [ "$MUTE" = "off]" ]; then
  VOL="0"
else
  VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
fi

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -l 1 -x "$XPOS" -y "$YPOS" -w "$WIDTH" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
   rm -f "$PIPE") &
fi

#Feed the pipe!
(echo VOLUME: $(echo "$VOL" | dbar) ; sleep "$SECS") >> "$PIPE"

Last edited by leo2501 (2009-02-21 16:13:44)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#18 2009-02-21 16:21:39

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

same with only the percentage value, for some reason, you need to wait for the number of secs specified in $SECS, i think because of the "-e onstart=uncollapse" variable in dzen2

#!/bin/bash

#Customize this stuff
IF="PCM"
SECS="3"

FONT="-*-fixed-medium-r-*-*-18-*-*-*-*-*-iso8859-*"
BG="black"
FG="grey"
XPOS="0"
YPOS="0"
WIDTH="1024"

#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  exit
}

#Argument Parsing
case "$1" in
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
if [ "$MUTE" = "off]" ]; then
  VOL="0"
else
  VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
fi

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -l 1 -x "$XPOS" -y "$YPOS" -w "$WIDTH" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
   rm -f "$PIPE") &
fi

#Feed the pipe!
(echo "VOLUME: "$VOL"%"; sleep "$SECS") >> "$PIPE"

Last edited by leo2501 (2009-02-21 16:36:27)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#19 2009-04-16 22:01:01

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

hey guys, i've been using this script since the OP, but last weekend i switched to OSS.  i've put two scripts together so i get the same usage/graphical feedback but with oss.  here it is in case anyone else wants to make the switch.

#!/bin/bash
#
# ossvol is a simple script to manage oss volume levels and muting.
#
# Script by: Daniel J Griffiths <ghost1227@archlinux.us>
#
# Dzen magic by: bruenig
#
###

# Configure stuff
VOLSTORE=~/.volume
CHANNEL="vmix0-outvol"
ARGUMENT=$2

# dzen stuff
SECS="1"            # sleep $SECS
BG="#080808"        # background colour of window
FG="#ffffff"        # foreground colour of text/icon
BAR_FG="#ffffff"    # foreground colour of volume bar
BAR_BG="#080808"    # background colour of volume bar
XPOS="750"          # horizontal positioning
YPOS="515"          # vertical positioning
HEIGHT="50"         # window height
WIDTH="400"         # window width
BAR_WIDTH="300"     # width of volume bar
ICON="$HOME/.icons/dvol/spkr_02.xbm"
FONT="fixed"

# You shouldn't have to edit below here.
PIPE="/tmp/dvolpipe"

err() {
        echo "$1"
        exit 1
}
usage() {
        echo "usage: ossvol [option] [argument]"
        echo
        echo "Options:"
        echo "     -i, --increase - increase volume by [argument]"
        echo "     -d, --decrease - decrease volume by [argument]"
        echo "     -t, --toggle   - toggle mute on and off"
        echo "     -h, --help     - display this"
        exit
}
toggle() {
        if [ -f $VOLSTORE ]; then
                ossmix $CHANNEL `cat $VOLSTORE`
                rm $VOLSTORE
        else
                VOLUME=$(ossmix $CHANNEL | awk '{print $10}' | awk -F : '{print $1}')
                ossmix $CHANNEL 0
                echo $VOLUME > $VOLSTORE
        fi
}
increase() {
        if [ -f $VOLSTORE ]; then
                TMPVOL=`cat $VOLSTORE`
                NEWVOL=`expr $TMPVOL + $ARGUMENT`
                ossmix $CHANNEL +$NEWVOL
                rm $VOLSTORE
        else
                ossmix $CHANNEL +$ARGUMENT
        fi
}
decrease() {
        if [ -f $VOLSTORE ]; then
                TMPVOL=`cat $VOLSTORE`
                NEWVOL=`expr $TMPVOL - $ARGUMENT`
                ossmix $CHANNEL -- -$NEWVOL
                rm $VOLSTORE
        else
                ossmix $CHANNEL -- -$ARGUMENT
        fi
}
case "$1" in
        '-i'|'--increase')
        increase
        ;;
        '-d'|'--decrease')
        decrease
        ;;
        '-t'|'--toggle')
        toggle
        ;;
        '-h'|'--help')
        usage
        ;;
        *)
        err "Unrecognized option \`$1', see ossvol --help"
        ;;
esac

# Using named pipe to determine whether previous call still exists
# Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
   rm -f "$PIPE") &
fi

# Feed the pipe!
VOL=$(ossmix $CHANNEL | awk '{print $10}' | cut -d '.' -f 1)
VOL=$(expr $VOL \* 100 / 25)
(echo "$VOL" | gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH"; sleep "$SECS") >> "$PIPE"

exit 0

thanks!

Offline

#20 2010-07-20 05:02:39

olsmokey
Member
Registered: 2010-07-20
Posts: 2

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Love these scripts, thanks for sharing!

One issue though: when I toggle the mute function, I was kind of expecting the volume bar to go empty. I've spent a while trying to get this functionality to present itself, but I'm afraid I just don't understand the volume-changing part very well at all. I'm also considering changing the icon to an empty speaker, and maybe having the color be red. The script I'm using is thayer's with only size and color modifications. If anyone who uses this has had any luck, please help me out!

Thanks

Offline

#21 2010-07-21 21:36:50

palaga
Member
Registered: 2010-07-21
Posts: 1

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

I modified Ashren's version and used Thayer's icons. The modification centers the whole thing, adds a mute icon and interface indication. The interface may be given in an extra argument. To center everything, it uses xdpyinfo and awk.

mute.pngpcm.png

#!/bin/bash

#Customize this stuff
IF="Master"
SECS="2"

BG="#43464f"
FG="#9ab8c2"
WIDTH="250"
WIDTH_BAR=$(($WIDTH - 150))
WINDOW_WIDTH=$(xdpyinfo | awk '$1 ~ /dimensions/ {split($2,arr,"x"); print int(arr[1])}')
WINDOW_HEIGHT=$(xdpyinfo | awk '$1 ~ /dimensions/ {split($2,arr,"x"); print int(arr[2])}')
XPOS=$((($WINDOW_WIDTH / 2) - ($WIDTH / 2)))
YPOS=$(($WINDOW_HEIGHT / 2))

ICON_VOL=~/.dzen2/thayer/vol-hi.xbm
ICON_VOL_MUTE=~/.dzen2/thayer/vol-mute.xbm
ICON=$ICON_VOL

#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument] [interface]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  echo
  echo "The interface could be specified by the interface"
  echo "parameter. If it is not specified, the IF var will be"
  echo "used."
  exit
}

#Argument Parsing
case "$1" in
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

# Optional interface parameter:
if [ $AMIXARG == "toggle" ]; then
    IF=${2:-$IF}
else
    IF=${3:-$IF}
fi


#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
if [ "$MUTE" = "off]" ]; then
  ICON=$ICON_VOL_MUTE
else
  ICON=$ICON_VOL
fi

VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -tw $WIDTH -x "$XPOS" -y "$YPOS" -w "$WIDTH" -bg "$BG" -fg "$FG" < "$PIPE"; rm -f "$PIPE") &
fi

#Feed the pipe!
(echo "$VOL" | gdbar -l "$IF ^i(${ICON}) " -fg "$FG" -bg "$BG" -w $WIDTH_BAR ; sleep "$SECS") > "$PIPE"

Note: make sure you set the correct path for the volume and mute icons.

Offline

#22 2010-07-24 20:36:22

bruenig
Member
Registered: 2007-05-20
Posts: 175

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

@palaga

Using two awks can really slow that thing down. At least switch to an array

WINDOW=( $(xdpyinfo | awk -F ' |x' '/dimensions/ {print $7 " " $8}') )

WINDOW[0] will be widht and WINDOW[1] will be height.

Or, to speed it up even more grep -F and some cuts would actually probably be faster than awking while using regex (which is way heavier than some realize).

Offline

#23 2010-08-07 14:13:45

paldepind
Member
From: Århus, Denmark
Registered: 2010-02-17
Posts: 141

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

I'm using thayers version but I got a small problem. When the sound level is between 61 and 99 it renders incorrectly, like shown in the image. I haven't configured it at all an I got the dina font installed so I've got no idea what the problem is. Is there anyone who can reproduce this, or give me a solution?

dvol.gif

Last edited by paldepind (2010-08-07 14:14:16)

Offline

#24 2010-08-07 14:26:24

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

paldepind wrote:

I'm using thayers version but I got a small problem. When the sound level is between 61 and 99 it renders incorrectly, like shown in the image. I haven't configured it at all an I got the dina font installed so I've got no idea what the problem is. Is there anyone who can reproduce this, or give me a solution?

I could be wrong, but I seem to recall it was an issue with Dina.  Looking at my current config (which works) I switched back to Terminus.


thayer williams ~ cinderwick.ca

Offline

#25 2010-08-07 16:08:10

paldepind
Member
From: Århus, Denmark
Registered: 2010-02-17
Posts: 141

Re: dvol - dzen2 volume bar (good for multimedia keys and tiling wms)

Yop, you are right. I changed the font to terminus too, and it works now.

I've edited thayer's version so that it has a mute icon in the same way as palaga's. It looks like this:
dvol.gif

#!/bin/bash
#
# dvolbar - OSD Volume utility
#

#Customize this stuff
IF="Master"         # audio channel: Master|PCM
SECS="1"            # sleep $SECS
BG="#111111"        # background colour of window
FG="#eeeeee"        # foreground colour of text/icon
BAR_FG="#ffffff"    # foreground colour of volume bar
BAR_BG="#777777"    # background colour of volume bar
XPOS="705"          # horizontal positioning
YPOS="500"          # vertical positioning
HEIGHT="30"         # window height
WIDTH="250"         # window width
BAR_WIDTH="165"     # width of volume bar
ICON=~/vol-hi.xbm
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON_VOL=~/vol-hi.xbm
ICON_VOL_MUTE=~/vol-mute.xbm
ICON=$ICON_VOL

#Probably do not customize
PIPE="/tmp/dvolpipe"

err() {
  echo "$1"
  exit 1
}

usage() {
  echo "usage: dvol [option] [argument]"
  echo
  echo "Options:"
  echo "     -i, --increase - increase volume by \`argument'"
  echo "     -d, --decrease - decrease volume by \`argument'"
  echo "     -t, --toggle   - toggle mute on and off"
  echo "     -h, --help     - display this"
  exit 
}   
    
#Argument Parsing
case "$1" in 
  '-i'|'--increase')
    [ -z "$2" ] && err "No argument specified for increase."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%+"
    ;;
  '-d'|'--decrease')
    [ -z "$2" ] && err "No argument specified for decrease."
    [ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
    AMIXARG="${2}%-"
    ;;
  '-t'|'--toggle')
    AMIXARG="toggle"
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
MUTE="$(cut -d '[' -f 4 <<<"$AMIXOUT")"
VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
if [ "$MUTE" = "off]" ]; then
  ICON=$ICON_VOL_MUTE
else
  ICON=$ICON_VOL
fi

#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
  mkfifo "$PIPE"
  (dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
   rm -f "$PIPE") &
fi

#Feed the pipe!
(echo "$VOL" | gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS") > "$PIPE"

Offline

Board footer

Powered by FluxBB