You are not logged in.

#26 2010-08-08 09:44:37

supulton
Member
Registered: 2008-12-31
Posts: 58

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

my main mixer control (PCM) is unable to use the 'toggle' function for some reason i've never investigated, so i modified the script to set the volume to 0, then back to the previous volume.

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

#Customize this stuff
IF="PCM"            # 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="550"          # horizontal positioning
YPOS="400"          # vertical positioning
HEIGHT="30"         # window height
WIDTH="250"         # window width
BAR_WIDTH="165"     # width of volume bar
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON=~/.icons/dzen/xbm8x8/spkr_01.xbm
MUTE_ICON=~/.icons/dzen/xbm8x8/spkr_02.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
}

mute_toggle() {
    VOL_FILE="/tmp/cur_vol"
    CUR_VOL=$(amixer get "$IF" | gawk '/Right.+/ {gsub("\\[","", $5);gsub("%\\]", "", $5);printf("%s",$5)}')
    if [[ $CUR_VOL -gt 0 ]]; then
        echo $CUR_VOL > $VOL_FILE
        amixer -q set "$IF" 0%
        ICON=$MUTE_ICON
    else
        VOL=$(cat $VOL_FILE)
        amixer -q set "$IF" ${VOL}%
        rm -f $VOL_FILE
    fi
}

#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')
      mute_toggle
      MUTE=1
    ;;
  ''|'-h'|'--help')
    usage
    ;;
  *)
    err "Unrecognized option \`$1', see dvol --help"
    ;;
esac

#Actual volume changing (readability low)
if [[ -z $MUTE ]]; then
    AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
    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"

Offline

#27 2010-12-17 04:12:50

zeltak
Member
From: New England
Registered: 2010-08-07
Posts: 168

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

hya guys

using paldepind example script and it works like a charm apart for the fact i get no % text just the icon and bar..i have terminus installed and dzen2-xft-xpm-xinerama-svn ..any idea why

thx

zeltaj

Offline

#28 2010-12-17 09:49:20

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

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

zeltak wrote:

using paldepind example script and it works like a charm apart for the fact i get no % text just the icon and bar..i have terminus installed and dzen2-xft-xpm-xinerama-svn ..any idea why

Yeah, you're using svn. The svn version only shows the bar, while the stable release shows percentage+bar. This is why I keep an old gdbar around, only dzen2 itself is from svn, so I get xft. That, and the old gdbar has a conky-style bar.

Offline

#29 2011-08-01 11:16:08

jeetu
Member
Registered: 2011-08-01
Posts: 2

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

I have modified the script so as to handle pulseaudio.
The reference scripts are from the above messages and
http://crunchbanglinux.org/forums/topic … edia-keys/
Also I apologize for the color combination. They were for testing purpose only. Change them to suit your need.:)

#!/bin/bash
#
# filename: pulsevolbar.sh
# Usage:
#      pulsevolbar.sh <increase/decrease/mute>
# 
#
#Customize this stuff

SECS="1"            # sleep $SECS
BG="#8E35EF"        # background colour of window
FG="#FFFF00"        # foreground colour of text/icon
BAR_FG="#F52887"    # foreground colour of volume bar
BAR_BG="#41A317"    # background colour of volume bar
XPOS="705"          # horizontal positioning
YPOS="800"          # vertical positioning
HEIGHT="30"         # window height
WIDTH="250"         # window width
BAR_WIDTH="150"     # width of volume bar
ICON=~/.pulse/dzen_icons/vol-hi.xbm
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON_VOL=~/.pulse/dzen_icons/vol-hi.xbm
ICON_VOL_MUTE=~/.pulse/dzen_icons/vol-mute.xbm
ICON=$ICON_VOL

# No need to customize this variable
PIPE="/tmp/pulesvolpipe"

set_volume()
{
    CURVOL=$1
    pactl set-sink-volume 0 $CURVOL
    echo $CURVOL > ~/.pulse/volume # Write the new volume to disk to be read the next time the script is run.
}

#### Create ~/.pulse/mute if not exists
ls ~/.pulse/mute &> /dev/null
if [[ $? != 0 ]]
then
    echo "false" > ~/.pulse/mute
fi

####Create ~/.pulse/volume if not exists
ls ~/.pulse/volume &> /dev/null
if [[ $? != 0 ]]
then
    echo "65536" > ~/.pulse/volume
fi

CURVOL=`cat ~/.pulse/volume`     # Reads in the current volume
MUTE=`cat ~/.pulse/mute`          # Reads mute state
if [[ $MUTE == "true" ]]    # Sets the icon to mute_icon as the increase or decrease will not make speaker speak
then
    ICON=$ICON_VOL_MUTE
fi

if [[ $1 == "increase" ]]
then
    CURVOL=$(($CURVOL + 3277))    # 3277 is 5% of the total volume, you can change this to suit your needs.
    if [[ $CURVOL -ge 65536 ]]
    then
        CURVOL=65536        
    fi
    set_volume $CURVOL
elif [[ $1 == "decrease" ]]
then
    CURVOL=$(($CURVOL - 3277))
    if [[ $CURVOL -le 0 ]]
    then
        CURVOL=0        
    fi
    set_volume $CURVOL
elif [[ $1 == "mute" ]]
then
    if [[ $MUTE == "false" ]]
    then
        pactl set-sink-mute 0 1
        echo "true" > ~/.pulse/mute
    ICON=$ICON_VOL_MUTE
    else
        pactl set-sink-mute 0 0
        echo "false" > ~/.pulse/mute    
    ICON=$ICON_VOL
    fi
fi

# showing in dzen2
if [ ! -e "$PIPE" ];
# if pipe file does not exists 
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 $[$CURVOL *  100 / 65536]| dzen2-gdbar  -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH"  ; sleep "$SECS" ) > "$PIPE"

Offline

#30 2011-08-17 09:36:18

barbuk
Member
Registered: 2010-08-19
Posts: 6

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

Hi guys,

Very nice script ! But I have a problem with the files .pulse/volume & .pulse/mute. If you change something in pulseaudio via mpd for exemple, the volume or muted state are never write in the files. So why not grab the volume and the muted state in pacmd ?

For the volume :

# Get current volume. return a %
function get_volume(){
    MIXER=$(pacmd list-sinks 0 | grep -i "volume: 0:")
    echo $MIXER | cut -d ' ' -f 3 | cut -d '%' -f 1
}
# For the real volume, you have to * 65536 / 100
VOL=$(get_volume)
CURVOL=$[$VOL * 65536 / 100]

For the muted state :

# Get muted ? return yes or no
function get_muted(){
    MUTED=$(pacmd list-sinks 0 | grep muted | cut -d ' ' -f 2)
    echo $MUTED
}
MUTE=$(get_muted)          # Reads mute state

And you juste have to change "false" by "no" in

if [[ $MUTE == "false" ]]

Thx for the original script, my xf86audio keys are happy now smile

Offline

#31 2011-08-18 15:13:54

jeetu
Member
Registered: 2011-08-01
Posts: 2

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

I m pasting the new script with the recommended changes.
Also now the volume bar centers itself accordingly as per the resolution.
But the setting of volume through mpd still does not reflect as the script reads/sets the main output volume, but mpd sets/reads the application volume. (Correct me if I am wrong as I am new to pulseaudio)

#!/bin/bash
#
# filename: pulsevolbar.sh
# Usage:
#      pulsevolbar.sh <increase/decrease/mute>
# 
#
#Customize this stuff
SECS="1"            # sleep $SECS
BG="#8E35EF"        # background colour of window
FG="#FFFF00"        # foreground colour of text/icon
BAR_FG="#F52887"    # foreground colour of volume bar
BAR_BG="#41A317"    # background colour of volume bar
HEIGHT="30"         # window height
WIDTH="250"         # window width
BAR_WIDTH="150"     # width of volume bar
ICON=~/.pulse/dzen_icons/vol-hi.xbm
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON_VOL=~/.icons/dzen_icons/vol-hi.xbm
ICON_VOL_MUTE=~/.icons/dzen_icons/vol-mute.xbm
ICON=$ICON_VOL
PULSE_MAX_VOL=65536

# No need to customize this variable
PIPE="/tmp/pulesvolpipe"

# Lets find the appropriate positioning for the volume bar
XRES=`xdpyinfo|grep 'dimensions:'|awk '{print $2}'|cut -dx -f1`
XPOS=$[$XRES / 2 - $WIDTH / 2]          # horizontal positioning
YRES=`xdpyinfo|grep 'dimensions:'|awk '{print $2}'|cut -dx -f2`
YPOS=$[$YRES * 4 / 5]          # vertical positioning

# Sets the desired volume
function set_volume()
{
	CURVOL=$1
	pactl set-sink-volume 0 $CURVOL
}

# Gets the current volume
function get_volume()
{
    MIXER=$(pacmd list-sinks 0 | grep -i "volume: 0:")
    echo $MIXER | cut -d ' ' -f 3 | cut -d '%' -f 1
}

# Get muted ? returns yes or no
function get_muted()
{
    MUTED=$(pacmd list-sinks 0 | grep muted | cut -d ' ' -f 2)
    echo $MUTED
}

VOL=$(get_volume)
CURVOL=$[$VOL * $PULSE_MAX_VOL / 100 ]
MUTE=$(get_muted)         # Reads mute state
if [[ $MUTE == "yes" ]]	# Sets the icon to mute_icon as the increase or decrease will not make speaker speak
then
    ICON=$ICON_VOL_MUTE
fi

if [[ $1 == "increase" ]]
then
    CURVOL=$(($CURVOL + 3277))	# 3277 is 5% of the total volume, you can change this to suit your needs.
    if [[ $CURVOL -ge $PULSE_MAX_VOL ]]
    then
        CURVOL=$PULSE_MAX_VOL        
    fi
    set_volume $CURVOL
elif [[ $1 == "decrease" ]]
then
    CURVOL=$(($CURVOL - 3277))
    if [[ $CURVOL -le 0 ]]
    then
        CURVOL=0        
    fi
    set_volume $CURVOL
elif [[ $1 == "mute" ]]
then
    if [[ $MUTE == "no" ]]
    then
        pactl set-sink-mute 0 1
	ICON=$ICON_VOL_MUTE
    else
        pactl set-sink-mute 0 0
	ICON=$ICON_VOL
    fi
fi

# showing in dzen2
if [ ! -e "$PIPE" ];
# if pipe file does not exists 
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 $[$CURVOL *  100 / $PULSE_MAX_VOL]| dzen2-gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH"  ; sleep "$SECS" ) > "$PIPE"

PS: Man, the fifo thing was elegent. Kudos to the original author. I learned a new thing. (for me atleast)

Offline

#32 2012-01-15 15:13:02

dakatapetrov
Member
From: Sofia, Bulgaria
Registered: 2012-01-15
Posts: 9
Website

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

Hey, can someone post the content of his ~/.config/openbox/rc.xml, because I have problem making my multimedia keys work =/

Offline

#33 2012-01-28 12:22:31

kittykatt
Member
From: Missouri, USA
Registered: 2009-11-04
Posts: 260
Website

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

Using this with PekWM. Works GREAT.


- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -

Offline

#34 2012-01-28 18:13:56

el mariachi
Member
Registered: 2007-11-30
Posts: 595

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

hey guys! how did you find out which were your keys? I'm using dwm/monsterwm. I remember I used something like XF86audioMute or something like that, for the key's name in the config file.

Offline

#35 2012-01-28 18:18:56

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

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

They're always the same: XF86AudioRaiseVolume, XF86AudioLowerVolume, XF86AudioMute

Offline

#36 2012-01-28 20:40:50

kittykatt
Member
From: Missouri, USA
Registered: 2009-11-04
Posts: 260
Website

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

el mariachi wrote:

hey guys! how did you find out which were your keys? I'm using dwm/monsterwm. I remember I used something like XF86audioMute or something like that, for the key's name in the config file.

The command `xev` could help you find that out, as well.


- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -

Offline

#37 2012-04-01 08:41:49

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

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

jeetu wrote:

I m pasting the new script with the recommended changes.
Also now the volume bar centers itself accordingly as per the resolution.
But the setting of volume through mpd still does not reflect as the script reads/sets the main output volume, but mpd sets/reads the application volume. (Correct me if I am wrong as I am new to pulseaudio)

I dont get how this works. It does change volume, but the dzen stuff is not working. I only get a completely purple rectangle, which always looks the same.
Also what is "dzen2-gdbar"?

➜  ~  ./pulsevolbar.sh increase
./pulsevolbar.sh: line 100: dzen2-gdbar: command not found

Last edited by Rasi (2012-04-01 08:43:46)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#38 2012-04-01 15:17:01

ivoarch
Member
Registered: 2011-03-31
Posts: 436

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


I love GnuEmacs, GnuScreen, ratpoison, and conkeror.
Github )||( Weblog

Offline

#39 2012-06-20 09:33:06

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

Here's my variation: dvol.

Light and dark schemes shown in normal and muted states:

tZWVybA
tZWVybQ
tZWVybg
tZWVybw

Last edited by bloom (2012-06-20 09:33:25)


gh · da · ds

Offline

#40 2012-06-20 14:38:09

el mariachi
Member
Registered: 2007-11-30
Posts: 595

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

where are the dzen colors?

Offline

#41 2012-06-20 17:20:51

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

el mariachi wrote:

where are the dzen colors?

dvol_colors-dark
dvol_colors-light


gh · da · ds

Offline

#42 2012-09-12 16:21:25

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

One small improvement:

if [ ! -p "$TMP_FIFO" ] ; then
    [ -e "$TMP_FIFO" ] && rm "$TMP_FIFO"

instead of

if [ ! -e "$TMP_FIFO" ] ; then

gh · da · ds

Offline

#43 2012-09-23 14:32:42

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

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

Mhh, I get an error but it shouldn't be that critical, what might cause this? Dvol script still works.

[~] dvol lower
/home/shn/bin/center_rect: line 30: printf: /home/shn/bin/center_rect: invalid number
[~]

Last edited by Shinryuu (2012-09-23 15:07:30)

Offline

#44 2012-09-27 15:31:28

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

Shinryuu wrote:

Mhh, I get an error but it shouldn't be that critical, what might cause this?

What's the output of

sres

?


gh · da · ds

Offline

#45 2012-09-27 15:40:11

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

It is rare, but multiple instances of dzen2 can reach that part of
the code (producing a blank window):

    mkfifo "$TMP_FIFO"
    (dzen2 -h "$bar_height" -w "$bar_width" $xy_pos -fn "$bar_font" -bg "$bar_bg" -fg "$bar_fg" < "$TMP_FIFO"
    rm "$TMP_FIFO") &

This should be replaced with:

    if mkfifo "$TMP_FIFO" ; then
        (dzen2 -h "$bar_height" -w "$bar_width" $xy_pos -fn "$bar_font" -bg "$bar_bg" -fg "$bar_fg" < "$TMP_FIFO"
        rm "$TMP_FIFO") &
    fi

(This has nothing to do with Shinryuu's issue.)

Last edited by bloom (2012-09-27 15:41:12)


gh · da · ds

Offline

#46 2012-09-27 19:45:30

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

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

Ah, I didn't notice your question. It seems I solved my issue by fiddling with center_rect where I changed "xoffset and yoffset" to simple pixels numbers.

xoffset=1580
yoffset=52

sres (laptop)

1366x768

sres (pc)

1920x1080

Offline

#47 2012-09-27 20:56:51

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

Could you add

echo "$xoffset $yoffset"

after

xoffset=$1
yoffset=$2

in center_rect
And give me the output of

center_rect 300x40

?

Last edited by bloom (2012-09-27 20:57:37)


gh · da · ds

Offline

#48 2012-09-28 04:05:48

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

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

Sure and here's the results.

laptop

533 242
533 242

pc

810 346
810 346

I fiddled with center_rect a little bit more and I found this out, I typed "xoffset" "yoffset" lines again and the error is now gone with my laptop, maybe I had an extra empty space/line?

Last edited by Shinryuu (2012-09-28 04:14:44)

Offline

#49 2012-09-28 08:27:09

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

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

I don't see anything wrong with those outputs. I'm glad you could sort things out.


gh · da · ds

Offline

Board footer

Powered by FluxBB