From 5380f2be8c363c5b3cfca809f87173ed94afe1f1 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Mon, 30 Mar 2009 00:01:50 +0200 Subject: [PATCH] support the 'consume' mode --- src/command.c | 2 ++ src/command.h | 1 + src/libmpdclient.c | 11 +++++++++++ src/libmpdclient.h | 4 ++++ src/mpdclient.c | 7 +++++++ src/mpdclient.h | 1 + src/screen.c | 13 +++++++++++++ src/screen_help.c | 1 + 8 files changed, 40 insertions(+) diff --git a/src/command.c b/src/command.c index b0a230e..695c11b 100644 --- a/src/command.c +++ b/src/command.c @@ -148,6 +148,8 @@ static command_definition_t cmds[] = { N_("Toggle random mode") }, { { 'y', 0, 0 }, 0, CMD_SINGLE, "single", N_("Toggle single mode") }, + { { 'C', 0, 0 }, 0, CMD_CONSUME, "consume", + N_("Toggle consume mode") }, { { 'x', 0, 0 }, 0, CMD_CROSSFADE, "crossfade", N_("Toggle crossfade mode") }, { { 21, 0, 0 }, 0, CMD_DB_UPDATE, "db-update", diff --git a/src/command.h b/src/command.h index a1d5858..7d6fb1a 100644 --- a/src/command.h +++ b/src/command.h @@ -49,6 +49,7 @@ typedef enum { CMD_DELETE, CMD_REPEAT, CMD_SINGLE, + CMD_CONSUME, CMD_CROSSFADE, CMD_DB_UPDATE, CMD_VOLUME_UP, diff --git a/src/libmpdclient.c b/src/libmpdclient.c index e800fb3..4cf2d80 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -651,6 +651,7 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) { status->repeat = 0; status->random = 0; status->single = 0; + status->consume = 0; status->playlist = -1; status->playlistLength = -1; status->state = -1; @@ -684,6 +685,9 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) { else if(strcmp(re->name,"single")==0) { status->single = atoi(re->value); } + else if(strcmp(re->name,"consume")==0) { + status->consume = atoi(re->value); + } else if(strcmp(re->name,"playlist")==0) { status->playlist = strtol(re->value,NULL,10); } @@ -1410,6 +1414,13 @@ void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode) { free(string); } +void mpd_sendConsumeCommand(mpd_Connection * connection, int consumeMode) { + char * string = malloc(strlen("consume")+25); + sprintf(string,"consume \"%i\"\n",consumeMode); + mpd_executeCommand(connection,string); + free(string); +} + void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange) { char * string = malloc(strlen("setvol")+25); sprintf(string,"setvol \"%i\"\n",volumeChange); diff --git a/src/libmpdclient.h b/src/libmpdclient.h index 4a7c2b6..de0bb61 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -200,6 +200,8 @@ typedef struct mpd_Status { int random; /* 1 if single is on, 0 otherwise */ int single; + /* 1 if consume is on, 0 otherwise */ + int consume; /* playlist length */ int playlistLength; /* playlist, use this to determine when the playlist has changed */ @@ -462,6 +464,8 @@ void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode); void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode); +void mpd_sendConsumeCommand(mpd_Connection * connection, int consumeMode); + void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange); /* WARNING: don't use volume command, its deprecated */ diff --git a/src/mpdclient.c b/src/mpdclient.c index aa420ee..b1d927b 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -391,6 +391,13 @@ mpdclient_cmd_single(mpdclient_t *c, gint value) return mpdclient_finish_command(c); } +gint +mpdclient_cmd_consume(mpdclient_t *c, gint value) +{ + mpd_sendConsumeCommand(c->connection, value); + return mpdclient_finish_command(c); +} + gint mpdclient_cmd_crossfade(mpdclient_t *c, gint value) { diff --git a/src/mpdclient.h b/src/mpdclient.h index a532d45..dc7cbf9 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -58,6 +58,7 @@ gint mpdclient_cmd_clear(mpdclient_t *c); gint mpdclient_cmd_repeat(mpdclient_t *c, gint value); gint mpdclient_cmd_random(mpdclient_t *c, gint value); gint mpdclient_cmd_single(mpdclient_t *c, gint value); +gint mpdclient_cmd_consume(mpdclient_t *c, gint value); gint mpdclient_cmd_crossfade(mpdclient_t *c, gint value); gint mpdclient_cmd_db_update(mpdclient_t *c, gchar *path); gint mpdclient_cmd_volume(mpdclient_t *c, gint value); diff --git a/src/screen.c b/src/screen.c index 75e9668..e245f0d 100644 --- a/src/screen.c +++ b/src/screen.c @@ -207,6 +207,8 @@ paint_top_window2(const char *header, mpdclient_t *c) g_strlcat(flags, "z", sizeof(flags)); if (c->status->single) g_strlcat(flags, "s", sizeof(flags)); + if (c->status->consume) + g_strlcat(flags, "c", sizeof(flags)); if (c->status->crossfade) g_strlcat(flags, "x", sizeof(flags)); if (c->status->updatingDb) @@ -611,6 +613,7 @@ screen_update(mpdclient_t *c) static int repeat = -1; static int random_enabled = -1; static int single = -1; + static int consume = -1; static int crossfade = -1; static int dbupdate = -1; @@ -620,6 +623,7 @@ screen_update(mpdclient_t *c) repeat = c->status->repeat; random_enabled = c->status->random; single = c->status->single; + consume = c->status->consume; crossfade = c->status->crossfade; dbupdate = c->status->updatingDb; } @@ -639,6 +643,11 @@ screen_update(mpdclient_t *c) _("Single is on") : _("Single is off")); + if (consume != c->status->consume) + screen_status_printf(c->status->consume ? + _("Consume is on") : + _("Consume is off")); + if (crossfade != c->status->crossfade) screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade); @@ -649,6 +658,7 @@ screen_update(mpdclient_t *c) repeat = c->status->repeat; single = c->status->single; + consume = c->status->consume; random_enabled = c->status->random; crossfade = c->status->crossfade; dbupdate = c->status->updatingDb; @@ -792,6 +802,9 @@ screen_client_cmd(mpdclient_t *c, command_t cmd) case CMD_SINGLE: mpdclient_cmd_single(c, !c->status->single); break; + case CMD_CONSUME: + mpdclient_cmd_consume(c, !c->status->consume); + break; case CMD_CROSSFADE: if (c->status->crossfade) mpdclient_cmd_crossfade(c, 0); diff --git a/src/screen_help.c b/src/screen_help.c index 9af853b..540fc94 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -90,6 +90,7 @@ static help_text_row_t help_text[] = { { 0, CMD_REPEAT, NULL }, { 0, CMD_RANDOM, NULL }, { 0, CMD_SINGLE, NULL }, + { 0, CMD_CONSUME, NULL }, { 0, CMD_CROSSFADE, NULL }, { 0, CMD_SHUFFLE, NULL }, { 0, CMD_DB_UPDATE, NULL }, -- 2.30.2