Merge pull request #620 from chme/player_shuffle

Fixes for shuffle mode in player web interface
This commit is contained in:
chme 2018-11-17 19:50:29 +01:00 committed by GitHub
commit 225b69595c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 34 deletions

View File

@ -4788,7 +4788,7 @@ db_queue_add_start(struct db_queue_add_info *queue_add_info, int pos)
}
int
db_queue_add_end(struct db_queue_add_info *queue_add_info, int ret)
db_queue_add_end(struct db_queue_add_info *queue_add_info, char reshuffle, uint32_t item_id, int ret)
{
char *query;
@ -4800,6 +4800,12 @@ db_queue_add_end(struct db_queue_add_info *queue_add_info, int ret)
ret = db_query_run(query, 1, 0);
}
// Reshuffle after adding new items
if (ret == 0 && reshuffle)
{
ret = queue_reshuffle(item_id, queue_add_info->queue_version);
}
queue_transaction_end(ret, queue_add_info->queue_version);
return ret;
}
@ -5963,6 +5969,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()
{

View File

@ -794,7 +794,7 @@ int
db_queue_add_start(struct db_queue_add_info *queue_add_info, int pos);
int
db_queue_add_end(struct db_queue_add_info *queue_add_info, int ret);
db_queue_add_end(struct db_queue_add_info *queue_add_info, char reshuffle, uint32_t item_id, int ret);
int
db_queue_add_item(struct db_queue_add_info *queue_add_info, struct db_queue_item *item);
@ -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();

View File

@ -145,11 +145,14 @@ library_add_media(struct media_file_info *mfi)
int
library_queue_add(const char *path, int position, int *count, int *new_item_id)
{
struct player_status status;
int i;
int ret;
DPRINTF(E_DBG, L_LIB, "Add items for path '%s' to the queue\n", path);
player_get_status(&status);
ret = LIBRARY_PATH_INVALID;
for (i = 0; sources[i] && ret == LIBRARY_PATH_INVALID; i++)
{
@ -159,7 +162,7 @@ library_queue_add(const char *path, int position, int *count, int *new_item_id)
continue;
}
ret = sources[i]->queue_add(path, position, count, new_item_id);
ret = sources[i]->queue_add(path, position, status.shuffle, status.item_id, count, new_item_id);
if (ret == LIBRARY_OK)
{

View File

@ -84,7 +84,7 @@ struct library_source
/*
* Add item for the given path to the current queue
*/
int (*queue_add)(const char *path, int position, int *count, int *new_item_id);
int (*queue_add)(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id);
};
void

View File

@ -1676,7 +1676,7 @@ map_media_file_to_queue_item(struct db_queue_item *queue_item, struct media_file
}
static int
queue_add_stream(const char *path, int position, int *count, int *new_item_id)
queue_add_stream(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
{
struct media_file_info mfi;
struct db_queue_item item;
@ -1694,7 +1694,7 @@ queue_add_stream(const char *path, int position, int *count, int *new_item_id)
if (ret == 0)
{
ret = db_queue_add_item(&queue_add_info, &item);
ret = db_queue_add_end(&queue_add_info, ret);
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
if (ret == 0)
{
if (count)
@ -1711,11 +1711,11 @@ queue_add_stream(const char *path, int position, int *count, int *new_item_id)
}
static int
queue_add(const char *uri, int position, int *count, int *new_item_id)
queue_add(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
{
if (strncasecmp(uri, "http://", strlen("http://")) == 0)
{
queue_add_stream(uri, position, count, new_item_id);
queue_add_stream(uri, position, reshuffle, item_id, count, new_item_id);
return LIBRARY_OK;
}

View File

@ -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)
new_shuffle = (cmdarg->intval == 0) ? 0 : 1;
// 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);
}
/* FALLTHROUGH */
case 0:
shuffle = cmdarg->intval;
break;
default:
DPRINTF(E_LOG, L_PLAYER, "Invalid shuffle mode: %d\n", cmdarg->intval);
*retval = -1;
return COMMAND_END;
else
{
db_queue_inc_version();
}
// Update shuffle mode and notify listeners
shuffle = new_shuffle;
listener_notify(LISTENER_OPTIONS);
out:
*retval = 0;
return COMMAND_END;
}

View File

@ -997,7 +997,7 @@ map_track_to_queueitem(struct db_queue_item *item, const struct spotify_track *t
}
static int
queue_add_track(const char *uri, int position, int *count, int *new_item_id)
queue_add_track(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
{
json_object *response;
struct spotify_track track;
@ -1019,7 +1019,7 @@ queue_add_track(const char *uri, int position, int *count, int *new_item_id)
if (ret == 0)
{
ret = db_queue_add_item(&queue_add_info, &item);
ret = db_queue_add_end(&queue_add_info, ret);
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
if (ret == 0)
{
if (count)
@ -1068,7 +1068,7 @@ queue_add_album_tracks(json_object *item, int index, int total, void *arg)
}
static int
queue_add_album(const char *uri, int position, int *count, int *new_item_id)
queue_add_album(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
{
char *album_endpoint_uri = NULL;
char *endpoint_uri = NULL;
@ -1088,7 +1088,7 @@ queue_add_album(const char *uri, int position, int *count, int *new_item_id)
ret = request_pagingobject_endpoint(endpoint_uri, queue_add_album_tracks, NULL, NULL, true, &param);
ret = db_queue_add_end(&param.queue_add_info, ret);
ret = db_queue_add_end(&param.queue_add_info, reshuffle, item_id, ret);
if (ret == 0 && count)
*count = param.queue_add_info.count;
@ -1137,7 +1137,7 @@ queue_add_playlist_tracks(json_object *item, int index, int total, void *arg)
}
static int
queue_add_playlist(const char *uri, int position, int *count, int *new_item_id)
queue_add_playlist(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
{
char *endpoint_uri;
struct db_queue_add_info queue_add_info;
@ -1151,7 +1151,7 @@ queue_add_playlist(const char *uri, int position, int *count, int *new_item_id)
ret = request_pagingobject_endpoint(endpoint_uri, queue_add_playlist_tracks, NULL, NULL, true, &queue_add_info);
ret = db_queue_add_end(&queue_add_info, ret);
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
if (ret == 0 && count)
*count = queue_add_info.count;
@ -1161,21 +1161,21 @@ queue_add_playlist(const char *uri, int position, int *count, int *new_item_id)
}
static int
queue_add(const char *uri, int position, int *count, int *new_item_id)
queue_add(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
{
if (strncasecmp(uri, "spotify:track:", strlen("spotify:track:")) == 0)
{
queue_add_track(uri, position, count, new_item_id);
queue_add_track(uri, position, reshuffle, item_id, count, new_item_id);
return LIBRARY_OK;
}
else if (strncasecmp(uri, "spotify:album:", strlen("spotify:album:")) == 0)
{
queue_add_album(uri, position, count, new_item_id);
queue_add_album(uri, position, reshuffle, item_id, count, new_item_id);
return LIBRARY_OK;
}
else if (strncasecmp(uri, "spotify:", strlen("spotify:")) == 0)
{
queue_add_playlist(uri, position, count, new_item_id);
queue_add_playlist(uri, position, reshuffle, item_id, count, new_item_id);
return LIBRARY_OK;
}