diff --git a/src/mpd.c b/src/mpd.c index 333fd2bb..b984d997 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -731,7 +731,7 @@ mpd_command_status(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) (status.repeat == REPEAT_OFF ? 0 : 1), status.shuffle, (status.repeat == REPEAT_SONG ? 1 : 0), - 0 /* consume: not supported by forked-daapd, always return 'off' */, + status.consume, queue_version, queue_length, state); @@ -840,6 +840,39 @@ mpd_command_stats(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) return 0; } +/* + * Command handler function for 'consume' + * Sets the consume mode, expects argument argv[1] to be an integer with + * 0 = disable consume + * 1 = enable consume + */ +static int +mpd_command_consume(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) +{ + int enable; + int ret; + + if (argc < 2) + { + ret = asprintf(errmsg, "Missing argument for command 'consume'"); + if (ret < 0) + DPRINTF(E_LOG, L_MPD, "Out of memory\n"); + return ACK_ERROR_ARG; + } + + ret = safe_atoi32(argv[1], &enable); + if (ret < 0) + { + ret = asprintf(errmsg, "Argument doesn't convert to integer: '%s'", argv[1]); + if (ret < 0) + DPRINTF(E_LOG, L_MPD, "Out of memory\n"); + return ACK_ERROR_ARG; + } + + player_consume_set(enable); + return 0; +} + /* * Command handler function for 'random' * Sets the shuffle mode, expects argument argv[1] to be an integer with @@ -3759,7 +3792,7 @@ static struct mpd_command mpd_handlers[] = */ { .mpdcommand = "consume", - .handler = mpd_command_ignore + .handler = mpd_command_consume }, { .mpdcommand = "crossfade", diff --git a/src/player.c b/src/player.c index 17ea5172..3acf2175 100644 --- a/src/player.c +++ b/src/player.c @@ -190,6 +190,7 @@ static int clear_queue_on_stop_disabled; static enum play_status player_state; static enum repeat_mode repeat; static char shuffle; +static char consume; /* Playback timer */ #if defined(__linux__) @@ -1221,6 +1222,9 @@ source_check(void) #endif history_add(cur_playing->id, cur_playing->item_id); + if (consume) + db_queue_delete_byitemid(cur_playing->item_id); + /* Stop playback */ if (!cur_playing->play_next) { @@ -2064,6 +2068,7 @@ get_status(void *arg, int *retval) memset(status, 0, sizeof(struct player_status)); status->shuffle = shuffle; + status->consume = consume; status->repeat = repeat; status->volume = master_volume; @@ -2519,6 +2524,7 @@ playback_next_bh(void *arg, int *retval) { struct player_source *ps; int ret; + uint32_t item_id; /* * The upper half is playback_pause, therefor the current playing item is @@ -2535,6 +2541,8 @@ playback_next_bh(void *arg, int *retval) if (cur_streaming->output_start > cur_streaming->stream_start) history_add(cur_streaming->id, cur_streaming->item_id); + item_id = cur_streaming->item_id; + ps = source_next(); if (!ps) { @@ -2559,6 +2567,9 @@ playback_next_bh(void *arg, int *retval) return COMMAND_END; } + if (consume) + db_queue_delete_byitemid(item_id); + /* Silent status change - playback_start() sends the real status update */ player_state = PLAY_PAUSED; @@ -3029,6 +3040,18 @@ shuffle_set(void *arg, int *retval) return COMMAND_END; } +static enum command_state +consume_set(void *arg, int *retval) +{ + union player_arg *cmdarg = arg; + + consume = cmdarg->intval; + + listener_notify(LISTENER_OPTIONS); + + *retval = 0; + return COMMAND_END; +} /* * Removes all items from the history */ @@ -3286,6 +3309,18 @@ player_shuffle_set(int enable) return ret; } +int +player_consume_set(int enable) +{ + union player_arg cmdarg; + int ret; + + cmdarg.intval = enable; + + ret = commands_exec_sync(cmdbase, consume_set, NULL, &cmdarg); + return ret; +} + void player_queue_clear_history() { @@ -3415,6 +3450,7 @@ player_init(void) player_state = PLAY_STOPPED; repeat = REPEAT_OFF; shuffle = 0; + consume = 0; history = (struct player_history *)calloc(1, sizeof(struct player_history)); diff --git a/src/player.h b/src/player.h index faec7da3..000d3c77 100644 --- a/src/player.h +++ b/src/player.h @@ -44,6 +44,7 @@ struct player_status { enum play_status status; enum repeat_mode repeat; char shuffle; + char consume; int volume; @@ -130,6 +131,9 @@ player_repeat_set(enum repeat_mode mode); int player_shuffle_set(int enable); +int +player_consume_set(int enable); + void player_queue_clear_history(void);