From 0a5872e156c316c2bb51d1d70c27be5ec0cf60c8 Mon Sep 17 00:00:00 2001 From: Spencer Williams Date: Mon, 14 Apr 2025 15:28:09 -0400 Subject: Add mpc format string support --- mpc-bar.m | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mpc-bar.m b/mpc-bar.m index 3363d1d..90ff0e3 100644 --- a/mpc-bar.m +++ b/mpc-bar.m @@ -27,6 +27,7 @@ #include #include "ini.h" +#include "mpc/song_format.h" #define VERSION "0.2" #define TITLE_MAX_LENGTH 96 @@ -48,6 +49,7 @@ static NSString *formatTime(unsigned int t) { struct config { char *host; + char *host, *format; unsigned port; }; @@ -59,6 +61,8 @@ static int handler(void *userdata, const char *section, const char *name, c->host = strdup(value); } else if (MATCH("connection", "port")) { c->port = atoi(value); + } else if (MATCH("display", "format")) { + c->format = strdup(value); } else { return 0; } @@ -88,6 +92,7 @@ static int handler(void *userdata, const char *section, const char *name, - (void)initConfig { config.host = NULL; config.port = 0; + config.format = "[%name%: &[[%artist%|%performer%|%composer%|%albumartist%] - ]%title%]|%name%|[[%artist%|%performer%|%composer%|%albumartist%] - ]%title%|%file%"; } - (void)readConfigFile { const char *path = [[NSHomeDirectory() @@ -202,17 +207,9 @@ static int handler(void *userdata, const char *section, const char *name, else [menuButton setImage:nil]; - const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); - const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0); - - if (artist) - [output appendString:utf8String(artist)]; - if (artist && title) - [output appendString:@" - "]; - if (title) - [output appendString:utf8String(title)]; - if (!(artist || title)) - [output appendString:utf8String(mpd_song_get_uri(song))]; + char *s = format_song(song, config.format); + [output appendString:utf8String(s)]; + free(s); } else { [output setString:@"No song playing"]; [menuButton setImage:nil]; -- cgit v1.2.3