Code

support the 'consume' mode
authorRomain Bignon <romain@peerfuse.org>
Sun, 29 Mar 2009 22:01:50 +0000 (00:01 +0200)
committerRomain Bignon <romain@peerfuse.org>
Sun, 29 Mar 2009 22:01:50 +0000 (00:01 +0200)
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 b0a230e8d32c2a89c86423b2c62c60ba23027668..695c11bececcb43e2c3ae35851ac89731217c857 100644 (file)
@@ -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",
index a1d5858d974d582332f4f0e658310b6f91de48ec..7d6fb1ae0f48dbb095d2179bff7daa717e917200 100644 (file)
@@ -49,6 +49,7 @@ typedef enum {
        CMD_DELETE,
        CMD_REPEAT,
        CMD_SINGLE,
+       CMD_CONSUME,
        CMD_CROSSFADE,
        CMD_DB_UPDATE,
        CMD_VOLUME_UP,
index e800fb3c97d3e9c03a6fb87a6e9a2504fadab925..4cf2d80b120983092f8632b4e8b2f9f4da6ecc46 100644 (file)
@@ -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);
index 4a7c2b670948e459b62b0553e776f9df1c71bdb6..de0bb618195570f141898c8b2034cdf97993120d 100644 (file)
@@ -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 */
index aa420eec1280455d922894bde4e1ab8489243654..b1d927b63e74cf1497385f01eaa39fa66104da1c 100644 (file)
@@ -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)
 {
index a532d45282d50541f83f94c8a6bb722349204f89..dc7cbf976b8d4939822fdbbc8f3cf8cee1082aa5 100644 (file)
@@ -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);
index 75e9668d9d32782e1ac65a795ef95309b5a10085..e245f0d449b0290bdbd3b71d9b6114ae501eb69f 100644 (file)
@@ -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);
index 9af853bfd948e0e26aa48a2c6a2de4fb132f1ec0..540fc94ba3c1b22881b8fda507a24e67b3b1126d 100644 (file)
@@ -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 },