sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3dde5a0be4ba118a1112a2e69a4c27e9b6742ee3
parent 03b8177d5f2390b8c7c4b8822c2faf60f5de707f
Author: Thuban <thuban@singularity.fr>
Date:   Thu, 20 Jun 2013 14:04:00 +0200

very simple mpd status

Diffstat:
Mdwm.suckless.org/dwmstatus/index.md | 1+
Adwm.suckless.org/dwmstatus/mpdstatus.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md @@ -41,6 +41,7 @@ add them here as file or as code example. tmpinfo function. It prints line after line the content of /tmp/dwmbuf. * [Simple function to have uptime](uptime.c) +* [Simple function to have mpd title/artist info](mpdstatus.c) Questions --------- diff --git a/dwm.suckless.org/dwmstatus/mpdstatus.c b/dwm.suckless.org/dwmstatus/mpdstatus.c @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <mpd/client.h> + +/* add to config.mk : +# mpd ++ MPDLIB = -lmpdclient ++ MPDFLAG = -DMPD + +- LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ++ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${MPDLIB} + +- CPPFLAGS = -DVERSION=\"${VERSION}\" ++ CPPFLAGS = ${MPDFLAG} -DVERSION=\"${VERSION}\" +*/ +/* simple function to retrieve mpd status */ +char * +getmpdstat() { + struct mpd_song * song = NULL; + const char * title = NULL; + const char * artist = NULL; + char * retstr = NULL; + int elapsed = 0, total = 0; + struct mpd_connection * conn = mpd_connection_new(NULL, 0, 30000); + if (mpd_connection_get_error(conn)) return(""); + + mpd_command_list_begin(conn, true); + mpd_send_status(conn); + mpd_send_current_song(conn); + mpd_command_list_end(conn); + + struct mpd_status* theStatus = mpd_recv_status(conn); + if (!theStatus) return(""); + else + if (mpd_status_get_state(theStatus) == MPD_STATE_PLAY) { + mpd_response_next(conn); + song = mpd_recv_song(conn); + title = smprintf("%s",mpd_song_get_tag(song, MPD_TAG_TITLE, 0)); + artist = smprintf("%s",mpd_song_get_tag(song, MPD_TAG_ARTIST, 0)); + elapsed = mpd_status_get_elapsed_time(theStatus); + total = mpd_status_get_total_time(theStatus); + mpd_song_free(song); + retstr = smprintf("%d:%d/%d:%d %s - %s", + elapsed/60, elapsed%60, + total/60, total%60, + artist, title); + } + else retstr = smprintf(""); + mpd_response_finish(conn); + mpd_connection_free(conn); + return retstr; +} +