From 9a244cf15e550359f08dc6a9c8f8284ad0831621 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Fri, 27 Mar 2009 15:54:31 +0100 Subject: [PATCH] support the new 'single' state feature --- 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 | 19 ++++++++++++++++--- src/screen_help.c | 1 + 8 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index 9df837e..b0a230e 100644 --- a/src/command.c +++ b/src/command.c @@ -146,6 +146,8 @@ static command_definition_t cmds[] = { N_("Toggle repeat mode") }, { { 'z', 0, 0 }, 0, CMD_RANDOM, "random", N_("Toggle random mode") }, + { { 'y', 0, 0 }, 0, CMD_SINGLE, "single", + N_("Toggle single 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 eb3b6e2..a1d5858 100644 --- a/src/command.h +++ b/src/command.h @@ -48,6 +48,7 @@ typedef enum { CMD_CLEAR, CMD_DELETE, CMD_REPEAT, + CMD_SINGLE, CMD_CROSSFADE, CMD_DB_UPDATE, CMD_VOLUME_UP, diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 6f68dda..e800fb3 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -650,6 +650,7 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) { status->volume = -1; status->repeat = 0; status->random = 0; + status->single = 0; status->playlist = -1; status->playlistLength = -1; status->state = -1; @@ -680,6 +681,9 @@ mpd_Status * mpd_getStatus(mpd_Connection * connection) { else if(strcmp(re->name,"random")==0) { status->random = atoi(re->value); } + else if(strcmp(re->name,"single")==0) { + status->single = atoi(re->value); + } else if(strcmp(re->name,"playlist")==0) { status->playlist = strtol(re->value,NULL,10); } @@ -1399,6 +1403,13 @@ void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode) { free(string); } +void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode) { + char * string = malloc(strlen("single")+25); + sprintf(string,"single \"%i\"\n",singleMode); + 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 2e94f17..4a7c2b6 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -198,6 +198,8 @@ typedef struct mpd_Status { int repeat; /* 1 if random is on, 0 otherwise */ int random; + /* 1 if single is on, 0 otherwise */ + int single; /* playlist length */ int playlistLength; /* playlist, use this to determine when the playlist has changed */ @@ -458,6 +460,8 @@ void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode); void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode); +void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode); + 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 a1766d9..aa420ee 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -384,6 +384,13 @@ mpdclient_cmd_random(mpdclient_t *c, gint value) return mpdclient_finish_command(c); } +gint +mpdclient_cmd_single(mpdclient_t *c, gint value) +{ + mpd_sendSingleCommand(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 fe13a2f..a532d45 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -57,6 +57,7 @@ gint mpdclient_cmd_shuffle_range(mpdclient_t *c, guint start, guint end); 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_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 85f1250..75e9668 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1,7 +1,7 @@ /* ncmpc (Ncurses MPD Client) * (c) 2004-2009 The Music Player Daemon Project * Project homepage: http://musicpd.org - + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -91,7 +91,7 @@ screen_switch(const struct screen_functions *sf, struct mpdclient *c) screen_paint(c); } -void +void screen_swap(struct mpdclient *c, const struct mpd_song *song) { if (song != NULL) @@ -204,7 +204,9 @@ paint_top_window2(const char *header, mpdclient_t *c) if (c->status->repeat) g_strlcat(flags, "r", sizeof(flags)); if (c->status->random) - g_strlcat(flags, "z", sizeof(flags));; + g_strlcat(flags, "z", sizeof(flags)); + if (c->status->single) + g_strlcat(flags, "s", sizeof(flags)); if (c->status->crossfade) g_strlcat(flags, "x", sizeof(flags)); if (c->status->updatingDb) @@ -608,6 +610,7 @@ screen_update(mpdclient_t *c) #ifndef NCMPC_MINI static int repeat = -1; static int random_enabled = -1; + static int single = -1; static int crossfade = -1; static int dbupdate = -1; @@ -616,6 +619,7 @@ screen_update(mpdclient_t *c) if (repeat < 0) { repeat = c->status->repeat; random_enabled = c->status->random; + single = c->status->single; crossfade = c->status->crossfade; dbupdate = c->status->updatingDb; } @@ -630,6 +634,11 @@ screen_update(mpdclient_t *c) _("Random is on") : _("Random is off")); + if (single != c->status->single) + screen_status_printf(c->status->single ? + _("Single is on") : + _("Single is off")); + if (crossfade != c->status->crossfade) screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade); @@ -639,6 +648,7 @@ screen_update(mpdclient_t *c) } repeat = c->status->repeat; + single = c->status->single; random_enabled = c->status->random; crossfade = c->status->crossfade; dbupdate = c->status->updatingDb; @@ -779,6 +789,9 @@ screen_client_cmd(mpdclient_t *c, command_t cmd) case CMD_RANDOM: mpdclient_cmd_random(c, !c->status->random); break; + case CMD_SINGLE: + mpdclient_cmd_single(c, !c->status->single); + 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 964a5a3..9af853b 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -89,6 +89,7 @@ static help_text_row_t help_text[] = { { 0, CMD_NONE, NULL }, { 0, CMD_REPEAT, NULL }, { 0, CMD_RANDOM, NULL }, + { 0, CMD_SINGLE, NULL }, { 0, CMD_CROSSFADE, NULL }, { 0, CMD_SHUFFLE, NULL }, { 0, CMD_DB_UPDATE, NULL }, -- 2.30.2