Skip to content

Instantly share code, notes, and snippets.

@mshkrebtan
Created April 1, 2018 11:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshkrebtan/d8a75ad0e483d95606f2acd2d4f6cafb to your computer and use it in GitHub Desktop.
Save mshkrebtan/d8a75ad0e483d95606f2acd2d4f6cafb to your computer and use it in GitHub Desktop.
MPD Alarm Clock
#!/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
@mshkrebtan
Copy link
Author

A Cron job example:

0 7 * * * /home/mshkrebtan/bin/mpd-alarm.sh 20 30 "Alarm Clock"

@mshkrebtan
Copy link
Author

mshkrebtan commented Apr 1, 2018

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