Created
February 26, 2017 13:30
A script to fade volume when toggling MPD via mpc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. ¯\_(ツ)_/¯