History:
2009-12-12: Add a mpc script to refresh my current mpd playlist (the autohotkey has been updated consequently)


This document explains how to install mpd (Music Player Daemon) on windows using cygwin.
Once installed, the player should be able to handle the following audio formats:
- mp3
- flac
- ogg


I. cygwin 1.7 Installation
1. Run the cygwin 1.7 setup program
It is important to install cygwin release 1.7; with the previous cygwin versions some structures are not defined in the netdb.h and you will get one of the following error while compiling mpd

src/listen.c: In function `listen_add_host':
src/listen.c:223: error: storage size of 'hints' isn't known



2. Download the following cygwin packages:
- Admin/cygrunsrv
- Database/SQLite3-devel
- Devel/autoconf
- Devel/automake
- Devel/gcc
- Devel/make
- Devel/pkg-config
- Libs/glib2-devel
- Libs/zlib-devel
- Libs/libiconv


3. Choose some of the cygwin audio packages:
- Audio/Flac
- Audio/libogg
- Audio/vorbis
- Audio/libao-Devel
- Audio/libao2


II. Installation of mad library to handle mp3

1. Download the latest following packages from http://www.underbit.com/products/mad in /home/username/mad directory:
- libid3tag (I have downloaded libid3tag-0.15.1b.tar.gz)
- libmad (I have downloaded libmad-0.15.1b.tar.gz)
- madplay (I have downloaded madplay-0.15.2b.tar.gz)
- README (it is always a good idea to read this file)


2. Run the Cygwin Bash Shell and type the following commands:

cd mad
tar -xzvf libid3tag*.gz
tar -xzvf madplay*.gz
tar -xzvf libmad*.gz



go into the libmad directory, configure, compile and install the libmad library:

cd libmad-0.15.1b
./configure
make
make install



go into the libid3tag directory, configure, compile and install the libid3tag library:

cd ../libid3tag-0.15.1b
make
make install



go into the madplay directory, configure, compile and install the madplay program

cd ../madplay-0.15.2b
make
make install



Check if madplay is able to play mp3 file:

madplay file.mp3



III. Install mpd
1. Download the very latest stable version of mpd on the site http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki in /home/username/mpd directory
I have downloaded the package mpd-0.15.2.tar.gz


2. Run the Cygwin Bash Shell and type the following commands:

Untar the mpd source files:

cd mpd
tar -xzvf mpd*.gz



Go into the mpd directory, configure, compile and install the mpd program:
Since the ./configure program was not able to find my libmad and id3tag libraries, I have also to add --disable-vorbis-encoder; the glib 2.10 was shipped with cygwin was too old (glib 2.12 is required - I didn't try to install the latest glib)

I have also to add --disable-un; the compilation has failed with an undefined symbol SO_PASSCRED error:

cd mpd-0.15.2
ID3TAG_CFLAGS=-I/usr/local/include ID3TAG_LIBS="-lid3tag -lz" MAD_CFLAGS=-I/usr/local/include MAD_LIBS=-lmad ./configure --disable-vorbis-encoder --disable-un
make
make install
cp /usr/local/share/doc/mpd/mpdconf.example /etc/mpd.conf



IV mpd configuration
1. Edit /etc/mpd.conf and customize as appropriate.
1.1. I have commented out the music_directory line and set its value as follows:
music_directory "/cygdrive/c/Documents and Settings/nicetuna/Mes documents/My Music/MP3"


1.2. I have replaced all ~/.mpd/ by /home/nicetuna/_mpd/
*Be careful, with ~ the service "mpd service" (VI.) won't start - it is important to use absolute paths rather than relative ones.

I have created the _mpd directory (if you don't do so, the database creation will fail).

I have created the playlists directory under the _mpd directory.


1.3. I have added the following, so mpd is able to handle ao

# An example of an ao output:
#
audio_output {
type "ao"
name "My ao Device"
# device "/dev/dsp" # optional
# format "44100:16:2" # optional
# mixer_device "/dev/mixer" # optional
# mixer_control "PCM" # optional
#
}



1.4. Since I have noticed some saturation, I have added the following entry

audio_output_format "48000:16:2"



2. Create the local database

mpd.exe --create-db



V Install as a service with cygserver

1. In the "control panel/system", "advanced tab", "Environment variables", create the new global variable "CYGWIN" whose value is "server" and restart the system.


2. If the service cygserver is not already installed, run /usr/bin/cygserver-config


3. Install the mpd service
3.1. locate mpd by:

which mpd



3.2. Install the mpd service

cygrunsrv -I "mpd service" -p /usr/local/bin/mpd -e "CYGWIN=server"



VI Assign hotkeys to mpc
1. Download and intall autohotkey from http://www.autohotkey.com


2. Cutomize your keys in autohotkey
My keys were customized as follows:

- Left key: mpc prev
- Right key: mpc next
- Space key: toggle the play mode on/off
- F9: Rip a CD usign CDex
- F11: Update and shuffle the playlist
- F12: toggle the previous defined keys on and off



The corresponding autohotkey script is as follows:

; mpc prev
Left::
RunWait, C:\cygwin\bin\mpc.exe prev
return

; mpc next
Right::
RunWait, C:\cygwin\bin\mpc.exe next
return

; mpc space
Space::
RunWait, C:\cygwin\bin\mpc.exe toggle
return

;CDex ripper
F9::
IfWinNotActive, CDex Version, , WinActivate, CDex Version,
sleep, 200
IfWinExist, Found Inexact Match
{
WinActivate ; Automatically uses the window found above.
Send, {ENTER}
}
WinWaitActive, CDex Version,
Hotkey, F9, toggle
Send, {F9}
Hotkey, F9, toggle
return

; update and shuffle the playlist
F12::
RunWait, C:\cygwin\bin\mpc_refresh.bat
return

; toggle the keys
F12::
Hotkey, Left, toggle
Hotkey, Right, toggle
Hotkey, Space, toggle
Hotkey, F9, toggle
return



3. Drag and drop your autohotkey script (and your CDex shortcut) in your start menu


4. Create the C:\cygwin\bin\mpc_refresh.bat as follows

@ECHO OFF

"%~dp0mpc.exe" update

:LOOP
"%~dp0mpc.exe" | FINDSTR /B /C:"Updating DB" 1>NUL 2>&1

IF NOT ERRORLEVEL 1 CALL :SLEEP && GOTO LOOP

"%~dp0mpc.exe" crop
"%~dp0mpc.exe" add /
"%~dp0mpc.exe" shuffle
"%~dp0mpc.exe" play

GOTO :EOF

:SLEEP
SET SLEEP=%~1

IF "%SLEEP%" == "" SET SLEEP=1

IF NOT EXIST "%~dp0SLEEP_%SLEEP%.VBS" (
ECHO wscript.sleep 1000 * %SLEEP% >"%~dp0SLEEP_%SLEEP%.VBS"
)

CSCRIPT //NOLOGO "%~dp0SLEEP_%SLEEP%.VBS"

GOTO :EOF



VII To be able to send commands from another computer:


4.1. Install a mpc client (mpc.exe)


4.2. Create the following commands in the same directory as mpc.exe and create the necessary shortcuts:


4.2.1. Command "next":
Create the mpc_next.bat as follows:

@ECHO OFF

SET MPD_HOST=The IP address of the mpd computer

"%~dp0mpc.exe" next



4.2.2. Command "prev":
Create the mpc_prev.bat as follows:

@ECHO OFF

SET MPD_HOST=The IP address of the mpd computer

"%~dp0mpc.exe" prev



4.2.3. Command "play/stop":
Create the mpc_play_stop.bat as follows:

@ECHO OFF

SET MPD_HOST=The IP address of the mpd computer

"%~dp0mpc.exe" toggle



4.2.4. Command "refresh playlist":
Create the mpc_refresh.bat as follows:

@echo off

set MPD_HOST=The IP address of the mpd computer

"%~dp0mpc.exe" update

:loop
"%~dp0mpc.exe" | FINDSTR /B /C:"Updating DB" 1>NUL 2>&1

IF NOT ERRORLEVEL 1 CALL :SLEEP && GOTO LOOP

"%~dp0mpc.exe" crop
"%~dp0mpc.exe" add /
"%~dp0mpc.exe" shuffle
"%~dp0mpc.exe" play

GOTO :EOF

:SLEEP
SET SLEEP=%~1

IF "%SLEEP%" == "" SET SLEEP=1

IF NOT EXIST "%~dp0SLEEP_%SLEEP%.VBS" (
ECHO wscript.sleep 1000 * %SLEEP% >"%~dp0SLEEP_%SLEEP%.VBS"
)
CSCRIPT //NOLOGO "%~dp0SLEEP_%SLEEP%.VBS"

GOTO :EOF