[dacp] Start playback from selected song in shuffle mode (#379)

This commit is contained in:
chme 2017-04-17 10:46:24 +02:00 committed by ejurgensen
parent 3a35a51cb9
commit 3f10dac2f7
4 changed files with 30 additions and 8 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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]);