Code

support the new 'single' state feature
authorRomain Bignon <romain@peerfuse.org>
Fri, 27 Mar 2009 14:54:31 +0000 (15:54 +0100)
committerRomain Bignon <romain@peerfuse.org>
Fri, 27 Mar 2009 14:54:31 +0000 (15:54 +0100)
src/command.c
src/command.h
src/libmpdclient.c
src/libmpdclient.h
src/mpdclient.c
src/mpdclient.h
src/screen.c
src/screen_help.c

index 9df837e85ca998eac22c64c651d321643d62c161..b0a230e8d32c2a89c86423b2c62c60ba23027668 100644 (file)
@@ -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",
index eb3b6e28902c1cfbd1560e3ac929e7951d20807d..a1d5858d974d582332f4f0e658310b6f91de48ec 100644 (file)
@@ -48,6 +48,7 @@ typedef enum {
        CMD_CLEAR,
        CMD_DELETE,
        CMD_REPEAT,
+       CMD_SINGLE,
        CMD_CROSSFADE,
        CMD_DB_UPDATE,
        CMD_VOLUME_UP,
index 6f68ddaffe763103c272814cc9cc8cfec123e419..e800fb3c97d3e9c03a6fb87a6e9a2504fadab925 100644 (file)
@@ -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);
index 2e94f17a0583d3b828486c7d73df96a6a9fdba16..4a7c2b670948e459b62b0553e776f9df1c71bdb6 100644 (file)
@@ -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 */
index a1766d9a47baf9e5beb5a668b9fb8de76c3496ac..aa420eec1280455d922894bde4e1ab8489243654 100644 (file)
@@ -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)
 {
index fe13a2f8536c46ec4ea8e1e17663e789dcf7bddd..a532d45282d50541f83f94c8a6bb722349204f89 100644 (file)
@@ -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);
index 85f1250ae31ed258831fc356f58d9912d2c9a87d..75e9668d9d32782e1ac65a795ef95309b5a10085 100644 (file)
@@ -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);
index 964a5a3fdc1da7623ccea5a1116e33625b221eb1..9af853bfd948e0e26aa48a2c6a2de4fb132f1ec0 100644 (file)
@@ -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 },