Table of Contents

MPD plugin

example config

Here is my (michu / neophob.com) mpd widget config (v0.81):

Plugin MPD {
    enabled 1
    server 'localhost'
    port 6600
#    password 'secret'
    minUpdateTime 500
}	    

#
# display artist and album, scrolling
#
Widget mpd-combo {
    class 'Text'
    expression mpd::artist() . '/' . mpd::title() 
    width 20
    align 'A'
    speed scroller
    update tack
}

#
# display current song id and number of total song
#
Widget mpd-posid {
    class 'Text'
    expression mpd::getMpdPlaylistGetCurrentId().' of ' .mpd::getMpdPlaylistLength()
    width 11
    align 'L'
    update tack
}

#
# display 30s the mpd uptime (ex. UP:2d03h32m) then 30s the current song id and number of total songs (ex. 267 of 734)
#
Widget mpd-toggler {
    class 'Text'
    expression ( (mpd::getMpdUptime()%60)<31 ? ('UP:'.mpd::formatTimeDDHHMM( mpd::getMpdUptime() ) ) : (mpd::getMpdPlaylistGetCurrentId().' of ' .mpd::getMpdPlaylistLength()) )
    width 11
    align 'L'
    update tack
}

#
# display playerstate (play, pause, stop, unknown)
#
Widget mpd-playerstatus {
    class 'Text'
    expression (mpd::getStateInt() == 1 ? 'PLAYING' : '').(mpd::getStateInt() == 2 ? 'PAUSED ' : '').(mpd::getStateInt() == 3 ? 'STOPPED' : '').(mpd::getStateInt() == 0 ? 'UNKNOWN' : '')
    width 7
    align 'L'
    update tack
}

#
# get repeat/random
# example: REP/RND, REP/---, ---/RND, ---/---
#
Widget mpd-reprnd {
    class  'Text'
    expression (mpd::getRepeatInt()>0 ? 'REP' : '---') . '/' . (mpd::getRandomInt()>0 ? 'RND' : '---')
    width  7
    align  'L'
    update tack
}

#
# display track position example: <00:48/04:33>
#
Widget mpd-tracktime {
    class  'Text'
    expression mpd::formatTimeMMSS( mpd::elapsedTimeSec() ).'/'.mpd::formatTimeMMSS( mpd::totalTimeSec() )
    width  11
    align  'L'
    update tack
}

#
# display uptime of mpd, example: <0d06h51m>
#
Widget mpd-uptime {
    class  'Text'
    expression 'UP:'.mpd::formatTimeDDHHMM( mpd::getMpdUptime() )
    width  11
    align  'L'
    update 10000    
}

#
# small playbar and track time
# 
Widget smallMP3Bar_part1 {
    class 'Bar'
    expression mpd::elapsedTimeSec()
    length 14
    min 0
    max mpd::totalTimeSec()
    direction 'E'
    style 'H'
    update tack
}

#
# display volume
#
Widget mpd-vol {
    class  'Text'
    expression 'VOL:'.mpd::getVolume()
    width  7
    align  'R'
    update tack
}

Widget smallMP3Bar_part2 {
    class  'Text'
    expression '/'.mpd::formatTimeMMSS( mpd::totalTimeSec() )
    width  6
    update tack
    align  'L'
}

#
# display volume
#
Widget mpd-vol {
    class  'Text'
    expression 'VOL:'.mpd::getVolume()
    width  7
    align  'R'
    update tack   
}

Widget mpd-bitrate {
    class  'Text'
    expression mpd::bitRate().'k'
    width  6
    update tack
    align  'L'
}

# example:
#   +--------------------+	+--------------------+
#   ¦ad/It's A Fire      ¦	¦ Portishead/It's A F¦
#   ¦***           /03:48¦	¦*********     /03:48¦
#   ¦REP/RND PLAYING 128k¦	¦REP/RND PLAYING 128k¦
#   ¦UP:2d03h33m  VOL:100¦	¦267 of 734   VOL:100¦
#   +--------------------+	+--------------------+

Layout L20x4 {
    Row1 {
	Col1  'mpd-combo'
    }
    Row2 {
	Col1 'smallMP3Bar_part1'
	Col15 'smallMP3Bar_part2'
    }
    Row3 {
        Col1 'mpd-reprnd'
	Col9 'mpd-playerstatus'
	Col17 'mpd-bitrate'
    }    
    Row4 {
        Col1 'mpd-toggler'
	Col14 'mpd-vol'
    }    
}

Variables {
    t_onesec 	1000
    t_500m 	500
    tack 500
    tick 100
    tacku 100
    scroller 300
}

Display CFA634 {
        Driver   'Crystalfontz'
        Model    '634'
        Port     '/dev/ttyUSB0'
#    	Speed     38400
        Contrast  65
        Backlight 20
        Icons 1
}

Display 'CFA634'
Layout 'L20x4'  

The new option “minUpdateTime” defines how long plugin_mpd.c should wait (in ms) until it reconnects to the mpd server. A “minUpdateTime 500” will update the values each 1/2 second. If you query this plugin more than the minUpdateTime it will return a cached value.

Functions

mpd::artistreturn artist of the current song
mpd::titlereturn title of the current song
mpd::albumreturn album of the current song
mpd::filereturn filename of the current song
mpd::totalTimeSecreturn play time of the current song, return value is in seconds!
mpd::elapsedTimeSecreturn play time of the current song, return value is in seconds!
mpd::bitRatereturn bitRate of current the song
mpd::getRepeatIntreturn if mpd will repeat (1: yes, 0: no)
mpd::getRandomIntreturn if mpd is plaing randomly
mpd::getStateIntreturn if mpd plaing state, 0=unknown, 1=play, 2=pause, 3=stop
mpd::getVolumereturns mpd volume
mpd::getSongsInDbreturn the ammount of mpd songs in the current db
mpd::getMpdUptimereturns how long mpd is up, return value is in seconds
mpd::getMpdPlayTimereturns how long mpd is plaing sound, return value is in seconds
mpd::getMpdDbPlayTimereturns how long mpd is up, return value is in seconds
mpd::getMpdPlaylistLengthreturns how many tracks are in the mpd db
mpd::getMpdPlaylistGetCurrentIdreturns the current track id
mpd::formatTimeMMSSthis function will format a second value into HH:MM (ex. 02:33)
mpd::formatTimeDDHHMMthis function will format a second value into DD:HH:MM (ex. 0d02h33m)

New since v0.8:

mpd::getSamplerateHzreturns samplerate of current song in hz
mpd::getAudioChannelsreturns audio channel of current track

New since v0.83:

mpd::cmdNextSongnext song
mpd::cmdPrevSongprev song
mpd::cmdStopSongstop song
mpd::cmdTogglePauseSongtoggle pause
mpd::cmdVolUpincrease volume
mpd::cmdVolDowndecrease volume
mpd::cmdToggleRandomtoggle random play
mpd::cmdToggleRepeattoggle repeat

Charset

Attention: plugin_mpd returns string non-converted. MPD uses UTF-8 internal for strings (this means for artist, track…) - so you probably need to convert the string, an example:

Widget mpd-ascii-artist {
    class 'Text'
    expression iconv('UTF-8', 'ISO-8859-1', mpd::artist()) 
    width 20
    align 'P'
    speed scroller
    update tack
}

So make sure you use the plugin_iconv!

Dev

You need libmpdclient to compile this plugin, src: http://www.musicpd.org/libmpdclient.shtml. \
If you want more information about this plugin or a openwrt binary visit http://www.neophob.com/serendipity/index.php?/archives/114-LCD4Linux-for-OpenWRT,-SVN-Version-including-patched-plugin_mpd.html.

Debug

If you run into some stange errors, use the integrated debug functions of lcd4linux:

root@OpenWrt:/# lcd4linux -Fvvq
Version 0.10.2-SVN-796 starting
plugin_cfg.c: Variable scroller = '300' (300)
plugin_cfg.c: Variable t_500m = '500' (500)
plugin_cfg.c: Variable t_onesec = '1000' (1000)
plugin_cfg.c: Variable tack = '500' (500)
plugin_cfg.c: Variable tacku = '100' (100)
plugin_cfg.c: Variable tick = '100' (100)
plugin_gps.c: v0.2
[[:KVV]] Using station 89
[[:KVV]] Using default port 80
[[:KVV]] Using default refresh interval of 60 seconds
[[:KVV]] Default abbreviation setting: off
plugin_mpd.c: [[:MPD]] v0.7, check lcd4linux configuration file...
[[:MPD]] empty 'Plugin:MPD.password' entry in /etc/lcd4linux.conf, assuming none
plugin_mpd.c: [[:MPD]] connection detail: [[:localhost:6600]]
plugin_mpd.c: [[:MPD]] done
lcd4linux.c: initializing driver Crystalfontz
Crystalfontz: $Rev: 840 $
Crystalfontz: using model '634'
Crystalfontz: using port '/dev/ttyUSB0' at 19200 baud
Crystalfontz: reserving 4 of 8 user-defined characters for icons
Crystalfontz: using 0 GPI's and 0 GPO's
initializing layout 'L20x4'
lcd4linux.c: starting main loop
plugin_mpd.c: [[:MPD]] not connected, try to reconnect...
plugin_mpd.c: [[:MPD]] connection ok...

The message “MPD not connected, try to reconnect…” is normal, as this plugin checks if the client is connected to the MPD server, if not a connection will established.

Example

As TRAC refuse my images, I need to specify my website: http://www.neophob.com/serendipity/index.php?/archives/136-Asus-WL500GP-+-OpenWrt-+-Lcd4linux-Jukebox.html - there you can find some “in-use” images.