Signed-off-by: Romain Bignon <rom...@peerfuse.org> --- doc/mpc-bashrc | 2 +- doc/mpc.1 | 3 +++ src/command.c | 22 ++++++++++++++++++++++ src/command.h | 1 + src/libmpdclient.c | 12 ++++++++++++ src/libmpdclient.h | 4 ++++ src/main.c | 1 + src/status.c | 6 +++++- 8 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/doc/mpc-bashrc b/doc/mpc-bashrc index 07f2580..91a23e5 100644 --- a/doc/mpc-bashrc +++ b/doc/mpc-bashrc @@ -57,7 +57,7 @@ COMPREPLY=($(compgen -W "${hold}" | sed "$scrub")) return 0 ;; - repeat|random|single) + repeat|random|single|consume) COMPREPLY=($(compgen -W "0 1 true false yes no on off" "${cur}")) return 0 ;; diff --git a/doc/mpc.1 b/doc/mpc.1 index 77740a5..59cdf1a 100644 --- a/doc/mpc.1 +++ b/doc/mpc.1 @@ -102,6 +102,9 @@ Toggle repeat mode if state ("on" or "off") is not specified. .B single <on|off> Toggle single mode if state ("on" or "off") is not specified. .TP +.B consume <on|off> +Toggle consume mode if state ("on" or "off") is not specified. +.TP .B rm <file> Deletes a specific playlist. .TP diff --git a/src/command.c b/src/command.c index 1cdef39..ffca54d 100644 --- a/src/command.c +++ b/src/command.c @@ -904,6 +904,28 @@ int cmd_single ( int argc, char ** argv, mpd_Connection * conn ) return 1; } +int cmd_consume ( int argc, char ** argv, mpd_Connection * conn ) +{ + int mode; + + if(argc==1) { + mode = get_boolean(argv[0]); + if (mode < 0) + return -1; + } + else { + mpd_Status * status; + status = getStatus(conn); + mode = !status->consume; + mpd_freeStatus(status); + } + + mpd_sendConsumeCommand(conn,mode); + my_finishCommand(conn); + + return 1; +} + int cmd_crossfade ( int argc, char ** argv, mpd_Connection * conn ) { int seconds; diff --git a/src/command.h b/src/command.h index 44ce035..4bec65a 100644 --- a/src/command.h +++ b/src/command.h @@ -51,6 +51,7 @@ int cmd_volume ( int argc, char ** argv, mpd_Connection * conn ) ; int cmd_repeat ( int argc, char ** argv, mpd_Connection * conn ); int cmd_random ( int argc, char ** argv, mpd_Connection * conn ); int cmd_single ( int argc, char ** argv, mpd_Connection * conn ); +int cmd_consume ( int argc, char ** argv, mpd_Connection * conn ); int cmd_crossfade ( int argc, char ** argv, mpd_Connection * conn ); int cmd_enable( int argc, char ** argv, mpd_Connection * conn ); int cmd_disable( int argc, char ** argv, mpd_Connection * conn ); diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 74b6a80..738e203 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -679,6 +679,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; @@ -712,6 +713,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); } @@ -1522,6 +1526,14 @@ void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode) { free(string); } +void mpd_sendConsumeCommand(mpd_Connection * connection, int consumeMode) { + int len = strlen("consume")+2+INTLEN+3; + char *string = malloc(len); + snprintf(string, len, "consume \"%i\"\n", consumeMode); + mpd_executeCommand(connection,string); + free(string); +} + void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange) { int len = strlen("setvol")+2+INTLEN+3; char *string = malloc(len); diff --git a/src/libmpdclient.h b/src/libmpdclient.h index ef09e4c..80bc5af 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -237,6 +237,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 */ @@ -511,6 +513,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 depreacted */ diff --git a/src/main.c b/src/main.c index 417edeb..42e62e3 100644 --- a/src/main.c +++ b/src/main.c @@ -83,6 +83,7 @@ static struct command { {"repeat", 0, 1, 0, cmd_repeat, "<on|off>", "Toggle repeat mode, or specify state"}, {"random", 0, 1, 0, cmd_random, "<on|off>", "Toggle random mode, or specify state"}, {"single", 0, 1, 0, cmd_single, "<on|off>", "Toggle single mode, or specify state"}, + {"consume", 0, 1, 0, cmd_consume, "<on|off>", "Toggle consume mode, or specify state"}, {"search", 2, -1, 0, cmd_search, "<type> <query>", "Search for a song"}, {"find", 2, -1, 0, cmd_find, "<type> <query>", "Find a song (exact match)"}, {"list", 1, -1, 0, cmd_list, "<type> [<type> <query>]", "Show all tags of <type>"}, diff --git a/src/status.c b/src/status.c index 9da6942..9bdd241 100644 --- a/src/status.c +++ b/src/status.c @@ -116,7 +116,11 @@ void print_status (mpd_Connection *conn) else printf("off "); printf("single: "); - if(status->single) printf("on \n"); + if(status->single) printf("on "); + else printf("off "); + + printf("consume: "); + if(status->consume) printf("on \n"); else printf("off\n"); if (status->error != NULL) -- 1.5.6.5 ------------------------------------------------------------------------------ _______________________________________________ Musicpd-dev-team mailing list Musicpd-dev-team@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team