Configure MPD. Edit a ~/.mpd/mpd.conf file as follows. We will use SunAudio (audio(4)) as backend.
music_directory "~/Music"
playlist_directory "~/.mpd/playlist"
log_file "~/.mpd/log"
pid_file "~/.mpd/pid"
state_file "~/.mpd/state"
sticker_file "~/.mpd/stick"
bind_to_address "127.0.0.1"
port "6600"
max_connections "5"
auto_update "yes"
mixer_type "software"
filesystem_charset "UTF-8"
database {
plugin "simple"
path "~/.mpd/db"
}
audio_output {
type "solaris"
name "sunaudio"
device "/dev/audio"
}
# optional, only needed for visualizers
# adjust the fifo path to something user-writable
audio_output {
type "fifo"
name "my_fifo"
path "/tmp/run/1000/mpd.fifo"
format "44100:16:2"
}
5. environment
MPD_HOST="127.0.0.1"
MPD_PORT="6600"
MPC_FORMAT="%title% \n%artist% - %album%"
First run
# first run mpd in foreground to check everything is in place.
# mpd shall scan the music directory for songs and add them
# to the database
$ mpd --no-daemon --verbose --stderr
If anything went right you can add /usr/pkg/bin/mpd &
to your X startup script.
Testing playback
With mpd running in background this time, let's test playback using the mpc
client.
$ mpc searchadd title "satellite of love"
$ mpc play
Satellite of love
The Velvet Underground -
[playing] #1/1 0:00/3:43 (0%)
volume:100% repeat: off random: off single: off consume: off
Using vimpc
Edit a ~/.vimpcrc file as follows:
echo Parsing config file
"-- colours
" hi <prop> <bg> <fg>
hi tab default white
hi status default white
hi current default green
hi id default yellow
hi pager default magenta
hi error default red
hi progress default cyan
"-- settings
" default tab
set window playlist
" tabs to open upon startup
set windows help,library,browse,playlist
" stop playing music upon exiting
set stoponquit
set autoscroll
set colour
"highlight search result
set hlsearch
"wrap search results
set searchwrap
"case insensitive searching
set ignorecase
set sortignorethe
set sortignorecase
set mouse
set local-music-dir ~/Music
set libraryformat %n \| {%t}|{%f}$E$R $H[$H%l$H]$H
set songformat {%a - %b - %t}|{%f}$E$R [%l]
" set songformat {%a$A33%b$A66%t}|{%f}$E$R [%l]
" set songformat {%?}|{%f}$E$R $H[$H%l$H]$H
" set songformat {{%?}|{%?}}|{%f}$E$R $H[$H%l$H]$H
"-- bindings
map q ZQ
map Q ZQ
map <C-N> gt
map <C-P> gT
map gf :browse<C-M>gg/
map gs :shuffle<C-M>
map ga :addall<C-M>:shuffle<C-M>
map gl :load
map 'a :findartist!
map 'g :findgenre!
map 'b :findalbum!
map <BS> f
map <Space> p
"-- autocmds
" playlist consume
"consume on
" update database
update
"turn on shuffle
shuffle
"start playing
"play 1
echo Config File Complete
As you can see, vimpc has a strongly vi-influenced command syntax and lexicon.
At this point you can launch the client in a terminal emulator or in wscons and test it. The first panel is a help screen which will allow you to quickly become comfortable with the client.
Desktop notifications
I use the following mpdnotify
script, to display the currently playing song (requires libnotify, ffmpeg and a running notification daemon).
#!/bin/sh
LIBRARY="${HOME}/Music"
ICONPATH="${HOME}/.icons/Sardi-Ghost-Flexible"
DEFAULT_IMG="${ICONPATH}/scalable/apps/gnome-music.svg"
FFMPEG="/usr/pkg/bin/ffmpeg"
if [ -x "$FFMPEG" ]; then \
ffmpeg -y -i "$(mpc --format "$LIBRARY"/%file% \
| head -n 1)" /tmp/mpd_cover.jpg > /dev/null 2>&1
else
notify-send -u critical "ffmpeg not found"
fi
[ -n "$DBUS_SESSION_BUS_ADDRESS" ] && \
notify-send -u low -i /tmp/mpd_cover.jpg "Now Playing ♫" \
"$(mpc --format "%title% \n%artist% - %album%" current)" || \
notify-send -u low -i $DEFAULT_IMG "Now Playing ♫" \
"$(mpc --format "%title% \n%artist% - %album%" current)"
The following vol
script displays the current volume level (percentage) as a desktop notification.
#!/bin/sh
VOL=$(mixerctl -n outputs.master | cut -d , -f 1 | \
awk '{print $1/254*100}' | cut -d . -f 1)
notify-send "volume: $VOL %
Volume and multimedia keys bindings in CTWM
Inside your ~/.ctwmrc, you may add:
# scripts path
define(`bindir',`/home/_logname_/.bin')
# Now playing
"s" = m4 : all : f.exec "bindir/mpdnotify &"
# Volume keys
"XF86AudioLowerVolume" = : all : f.exec "mixerctl -w outputs.master-=3,3 ; sh bindir/vol"
"XF86AudioRaiseVolume" = : all : f.exec "mixerctl -w outputs.master+=3,3 ; sh bindir/vol"
"XF86AudioMute" = : all : f.exec "mixerctl -w outputs.master.mute=on ; sh bindir/vol"
# Multimedia Keys
"XF86AudioPlay" = : all : f.exec "mpc play > /dev/null 2>&1 ; sh bindir/mpdnotify"
"XF86AudioStop" = : all : f.exec "mpc pause > /dev/null 2>&1 ; notify-send 'playback stopped'"
"XF86AudioPrev" = : all : f.exec "mpc prev > /dev/null 2>&1 ; sh bindir/mpdnotify"
"XF86AudioNext" = : all : f.exec "mpc next > /dev/null 2>&1 ; sh bindir/mpdnotify"
This:
- will bind volume keys to a suitable mixerctl command which lowers or increases volume by 3% and triggers the
vol
script.
- will bind multimedia keys to suitable mpc commands and trigger desktop notifications by invoking the
mpdnotify
script.
Result
The result is like follows (forgive my monochrome .Xdefaults and fancy out some colors):
