From 05141480e237901f70c57f3d2e87e8289240ae3f Mon Sep 17 00:00:00 2001 From: chme Date: Mon, 5 Nov 2018 21:35:17 +0100 Subject: [PATCH] [player/db] Increment queue version if shuffle mode is turned off This fixes showing the wrong queue in the player web interface after turing shuffle mode off. --- src/db.c | 14 ++++++++++++++ src/db.h | 3 +++ src/player.c | 34 ++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/db.c b/src/db.c index 433f8294..28caf442 100644 --- a/src/db.c +++ b/src/db.c @@ -5963,6 +5963,20 @@ db_queue_reshuffle(uint32_t item_id) return ret; } +/* + * Increment queue version (triggers queue change event) + */ +int +db_queue_inc_version() +{ + int queue_version; + + queue_version = queue_transaction_begin(); + queue_transaction_end(0, queue_version); + + return 0; +} + int db_queue_get_count() { diff --git a/src/db.h b/src/db.h index 906d3f9a..823985df 100644 --- a/src/db.h +++ b/src/db.h @@ -853,6 +853,9 @@ db_queue_move_byposrelativetoitem(uint32_t from_pos, uint32_t to_offset, uint32_ int db_queue_reshuffle(uint32_t item_id); +int +db_queue_inc_version(void); + int db_queue_get_count(); diff --git a/src/player.c b/src/player.c index 9d2443d1..63e88e34 100644 --- a/src/player.c +++ b/src/player.c @@ -2852,29 +2852,31 @@ static enum command_state shuffle_set(void *arg, int *retval) { union player_arg *cmdarg = arg; + char new_shuffle; uint32_t cur_id; - switch (cmdarg->intval) - { - case 1: - if (!shuffle) - { - cur_id = cur_streaming ? cur_streaming->item_id : 0; - db_queue_reshuffle(cur_id); - } - /* FALLTHROUGH */ - case 0: - shuffle = cmdarg->intval; - break; + new_shuffle = (cmdarg->intval == 0) ? 0 : 1; - default: - DPRINTF(E_LOG, L_PLAYER, "Invalid shuffle mode: %d\n", cmdarg->intval); - *retval = -1; - return COMMAND_END; + // Ignore unchanged shuffle mode requests + if (new_shuffle == shuffle) + goto out; + + // Update queue and notify listeners + if (new_shuffle) + { + cur_id = cur_streaming ? cur_streaming->item_id : 0; + db_queue_reshuffle(cur_id); + } + else + { + db_queue_inc_version(); } + // Update shuffle mode and notify listeners + shuffle = new_shuffle; listener_notify(LISTENER_OPTIONS); + out: *retval = 0; return COMMAND_END; }