diff --git a/src/db.c b/src/db.c index 3b50f06b..31a968c5 100644 --- a/src/db.c +++ b/src/db.c @@ -5069,10 +5069,11 @@ db_queue_delete_byposrelativetoitem(uint32_t pos, uint32_t item_id, char shuffle * * @param item_id Queue item id * @param pos_to target position in the queue (zero-based) + * @þaram shuffle If 1 move item in the shuffle queue * @return 0 on success, -1 on failure */ int -db_queue_move_byitemid(uint32_t item_id, int pos_to) +db_queue_move_byitemid(uint32_t item_id, int pos_to, char shuffle) { char *query; int pos_from; @@ -5081,7 +5082,7 @@ db_queue_move_byitemid(uint32_t item_id, int pos_to) db_transaction_begin(); // Find item with the given item_id - pos_from = db_queue_get_pos(item_id, 0); + pos_from = db_queue_get_pos(item_id, shuffle); if (pos_from < 0) { db_transaction_rollback(); @@ -5089,7 +5090,11 @@ db_queue_move_byitemid(uint32_t item_id, int pos_to) } // Update pos for all items after the item with given item_id - query = sqlite3_mprintf("UPDATE queue SET pos = pos - 1 WHERE pos > %d;", pos_from); + if (shuffle) + query = sqlite3_mprintf("UPDATE queue SET shuffle_pos = shuffle_pos - 1 WHERE shuffle_pos > %d;", pos_from); + else + query = sqlite3_mprintf("UPDATE queue SET pos = pos - 1 WHERE pos > %d;", pos_from); + ret = db_query_run(query, 1, 0); if (ret < 0) { @@ -5098,7 +5103,11 @@ db_queue_move_byitemid(uint32_t item_id, int pos_to) } // Update pos for all items from the given pos_to - query = sqlite3_mprintf("UPDATE queue SET pos = pos + 1 WHERE pos >= %d;", pos_to); + if (shuffle) + query = sqlite3_mprintf("UPDATE queue SET shuffle_pos = shuffle_pos + 1 WHERE shuffle_pos >= %d;", pos_to); + else + query = sqlite3_mprintf("UPDATE queue SET pos = pos + 1 WHERE pos >= %d;", pos_to); + ret = db_query_run(query, 1, 0); if (ret < 0) { @@ -5107,7 +5116,11 @@ db_queue_move_byitemid(uint32_t item_id, int pos_to) } // Update item with the given item_id - query = sqlite3_mprintf("UPDATE queue SET pos = %d where id = %d;", pos_to, item_id); + if (shuffle) + query = sqlite3_mprintf("UPDATE queue SET shuffle_pos = %d where id = %d;", pos_to, item_id); + else + query = sqlite3_mprintf("UPDATE queue SET pos = %d where id = %d;", pos_to, item_id); + ret = db_query_run(query, 1, 0); if (ret < 0) { diff --git a/src/db.h b/src/db.h index 4f524dcd..15d844b6 100644 --- a/src/db.h +++ b/src/db.h @@ -750,7 +750,7 @@ int db_queue_delete_byposrelativetoitem(uint32_t pos, uint32_t item_id, char shuffle); int -db_queue_move_byitemid(uint32_t item_id, int pos_to); +db_queue_move_byitemid(uint32_t item_id, int pos_to, char shuffle); int db_queue_move_bypos(int pos_from, int pos_to); diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index 0e590602..5b973276 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -984,7 +984,7 @@ dacp_queueitem_add(const char *query, const char *queuefilter, const char *sort, if (ret < 0) return -1; - if (status.shuffle) + if (status.shuffle && mode != 1) return 0; return id; @@ -1797,6 +1797,7 @@ dacp_reply_playqueueedit_add(struct evhttp_request *req, struct evbuffer *evbuf, int ret; int quirkyquery; struct db_queue_item *queue_item; + struct player_status status; mode = 1; @@ -1879,6 +1880,14 @@ dacp_reply_playqueueedit_add(struct evhttp_request *req, struct evbuffer *evbuf, if (queue_item) { + player_get_status(&status); + + if (status.shuffle) + { + DPRINTF(E_DBG, L_DACP, "Start shuffle queue with item %d\n", queue_item->id); + db_queue_move_byitemid(queue_item->id, 0, status.shuffle); + } + DPRINTF(E_DBG, L_DACP, "Song queue built, starting playback at index %d\n", queue_item->pos); ret = player_playback_start_byitem(queue_item); free_queue_item(queue_item, 0); diff --git a/src/mpd.c b/src/mpd.c index fcaada98..ea498811 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -1841,7 +1841,7 @@ mpd_command_moveid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) return ACK_ERROR_ARG; } - ret = db_queue_move_byitemid(songid, to_pos); + ret = db_queue_move_byitemid(songid, to_pos, 0); if (ret < 0) { ret = asprintf(errmsg, "Failed to move song with id '%s' to index '%s'", argv[1], argv[2]);