Created
April 1, 2018 11:13
-
-
Save mshkrebtan/d8a75ad0e483d95606f2acd2d4f6cafb to your computer and use it in GitHub Desktop.
MPD Alarm Clock
This file contains hidden or 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/bash | |
# Volume to start with | |
mpc_volume=$1 | |
# Fade-in time in seconds | |
fade_in_time=$2 | |
# Alarm Clock playlist | |
playlist="$3" | |
function get_mpc_volume() { | |
mpc_volume="$(mpc volume)" | |
mpc_volume="${mpc_volume##volume:}" | |
mpc_volume="${mpc_volume%%%}" | |
echo "${mpc_volume}" | |
} | |
mpc -q volume $mpc_volume | |
mpc -q clear | |
mpc -q load "$playlist" | |
mpc -q shuffle | |
mpc -q play | |
# Increase volume gradually every second | |
while [[ $mpc_volume -lt 100 ]]; do | |
(( mpc_volume = $(get_mpc_volume) )) | |
(( fade_in_time -= 1 )) | |
(( volume_inc_step = (100 - $mpc_volume) / $fade_in_time )) | |
mpc -q volume "+${volume_inc_step}" | |
sleep 1 | |
done |
See what happens when we set the same volume with mpc
2 times consecutively:
$ mpc volume 20
Red Hot Chili Peppers - Wet Sand
[playing] #1/1 2:35/5:11 (49%)
volume: 21% repeat: off random: off single: off consume: off
$ mpc volume 20
Red Hot Chili Peppers - Wet Sand
[playing] #1/1 2:38/5:11 (50%)
volume: 19% repeat: off random: off single: off consume: off
Decibels magic. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A Cron job example: