Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mshkrebtan mshkrebtan commented Apr 1, 2018

A Cron job example:

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

This comment has been minimized.

Copy link
Owner Author

@mshkrebtan 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