Skip to content

Instantly share code, notes, and snippets.

@lcpz
Created February 26, 2017 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcpz/76e315bc27c6cdf7edd5021964b88df1 to your computer and use it in GitHub Desktop.
Save lcpz/76e315bc27c6cdf7edd5021964b88df1 to your computer and use it in GitHub Desktop.
A script to fade volume when toggling MPD via mpc
#!/bin/sh
# A script to fade volume when toggling MPD via mpc
mpc=`which mpc`
# volume commands, customize here
decrease="amixer -q set Master 1%-"
increase="amixer -q set Master 1%+"
if [ $# -ne 2 ] ; then
echo "usage: mpc-fade <volume fade percentage> <fade length in secs>"
# example: $ mpc-fade 20 4
exit 1
fi
VOLUME=$1
fade() {
while [ $VOLUME -ge 0 ] ; do
$1
VOLUME=$(($VOLUME-1))
sleep .1 # 0.1 seconds
done
}
playing=$(mpc status | grep playing)
if [ ${#playing} -gt 0 ] ; then
fade "$decrease"
mpc toggle -q
else
mpc toggle -q
fade "$increase"
fi
exit 0
# eof
@Pablo1107
Copy link

Pablo1107 commented Jan 10, 2019

https://gist.github.com/Pablo1107/1d61cfa39e683289d96301230bf88fa5

This also sets volume to current volume so the fade out always goes to 0 and you can pass an argument to set in how many seconds it fade out, the only bug is that always add 2 seconds for some reason. ¯\_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment