# mpd / mpc: fade in / out script

> mpc-fade: a shell script to fade MPD volume in (wake up) or out (sleep) on any Linux with mpd and mpc, restoring volume and playlist.

- URL: https://guillaumeplayground.net/mpd-mpc-fade-in-out-script/
- Author: Guillaume (https://guillaumeplayground.net/about/)
- Published: 2013-05-30
- Updated: 2017-01-10
- Section: Computing & hacking
- Topics: mpd
- Source: Guillaume playground

**mpc-fade**

For the ones like me who want to wake up with music and go to sleep with music, here is a little script to make the magic around mpd.  
It will work on any linux with mpd and mpc (mpd client).  
On the mele, you have a led extra when mpc-fade is running.

Here it is: [mpc-fade](https://guillaumeplayground.net/share/mpc-fade)  
‘chmod a+x’ the file.

It keeps the volume and the playlist from the previous mpd run.

In fade-in (wake-up), it will raise the volume until it reaches the previous mpd volume and keep playing.

In fade-out (sleep), it will down the volume until it reached the given limit, stop mpd and restore the previous volume.

During the fade, mpd repeat mode is activated.

**Usage:**

```
Usage: mpc-fade [OPTION]  
 OPTION:
   -d       : daemonize - for crontab or lirc irexec

 ARG:
   diff-vol : volume from start to end
              * negative: fade-out (and stop)
              * positive: fade-in (and continue to play)
   duration : fade-in/out duration
```

**Tuning**

You can edit mpc-fade and change the BACKUP\_ALBUM.  
In case your mpd have no active playlist, it will load this album.

**Example:**

A fade-in (wake-up during 15 min.)

```
./mpc-fade 50 900
```

A fade-out (sleep in 30 min.)

```
./mpc-fade -50 1800
```

**In crontab:**

Create a “/etc/cron.d/wakeup-cron”.  
Wake-up at 7:30 from Monday to Friday in 2 minutes.  
Wake-up at 9:30 from Saturday to Sunday in 4 minutes.

```
30 7 * * 1,2,3,4,5	root	/mpc-fade -d 60 120
30 9 * * 6,7		root	/mpc-fade -d 60 240
```

**Mechanize in lirc with irexec**

Sleep in 20 minutes on POWER button press.  
In your lircd configured, add in your .lircrc something like that:

```
begin
     prog = irexec
     button = POWER
     config = /mpc-fade -d -60 1200
     repeat = 0
end
```
