mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 07:05:57 -05:00
reshuffle only songs in the UpNext queue
This commit is contained in:
parent
b195e76f11
commit
9527e06f71
73
src/player.c
73
src/player.c
@ -655,6 +655,8 @@ player_queue_make(struct query_params *qp, const char *sort)
|
|||||||
|
|
||||||
q_head->pl_prev = q_tail;
|
q_head->pl_prev = q_tail;
|
||||||
q_tail->pl_next = q_head;
|
q_tail->pl_next = q_head;
|
||||||
|
q_head->shuffle_prev = q_tail;
|
||||||
|
q_tail->shuffle_next = q_head;
|
||||||
|
|
||||||
return q_head;
|
return q_head;
|
||||||
}
|
}
|
||||||
@ -971,8 +973,11 @@ source_stop(struct player_source *ps)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Shuffles the items between head and tail (excluding head and tail)
|
||||||
|
*/
|
||||||
static struct player_source *
|
static struct player_source *
|
||||||
source_shuffle(struct player_source *head)
|
source_shuffle(struct player_source *head, struct player_source *tail)
|
||||||
{
|
{
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
struct player_source **ps_array;
|
struct player_source **ps_array;
|
||||||
@ -982,15 +987,31 @@ source_shuffle(struct player_source *head)
|
|||||||
if (!head)
|
if (!head)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (!tail)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!shuffle)
|
||||||
|
{
|
||||||
ps = head;
|
ps = head;
|
||||||
nitems = 0;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
nitems++;
|
ps->shuffle_next = ps->pl_next;
|
||||||
|
ps->shuffle_prev = ps->pl_prev;
|
||||||
ps = ps->pl_next;
|
ps = ps->pl_next;
|
||||||
}
|
}
|
||||||
while (ps != head);
|
while (ps != head);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count items in queue (excluding head and tail)
|
||||||
|
ps = head->shuffle_next;
|
||||||
|
nitems = 0;
|
||||||
|
while (ps != tail)
|
||||||
|
{
|
||||||
|
nitems++;
|
||||||
|
ps = ps->shuffle_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct array for number of items in queue
|
||||||
ps_array = (struct player_source **)malloc(nitems * sizeof(struct player_source *));
|
ps_array = (struct player_source **)malloc(nitems * sizeof(struct player_source *));
|
||||||
if (!ps_array)
|
if (!ps_array)
|
||||||
{
|
{
|
||||||
@ -998,16 +1019,17 @@ source_shuffle(struct player_source *head)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ps = head;
|
// Fill array with items in queue (excluding head and tail)
|
||||||
|
ps = head->shuffle_next;
|
||||||
i = 0;
|
i = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ps_array[i] = ps;
|
ps_array[i] = ps;
|
||||||
|
|
||||||
ps = ps->pl_next;
|
ps = ps->shuffle_next;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
while (ps != head);
|
while (ps != tail);
|
||||||
|
|
||||||
shuffle_ptr(&shuffle_rng, (void **)ps_array, nitems);
|
shuffle_ptr(&shuffle_rng, (void **)ps_array, nitems);
|
||||||
|
|
||||||
@ -1022,8 +1044,10 @@ source_shuffle(struct player_source *head)
|
|||||||
ps->shuffle_next = ps_array[i + 1];
|
ps->shuffle_next = ps_array[i + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
ps_array[0]->shuffle_prev = ps_array[nitems - 1];
|
ps_array[0]->shuffle_prev = head;
|
||||||
ps_array[nitems - 1]->shuffle_next = ps_array[0];
|
ps_array[nitems - 1]->shuffle_next = tail;
|
||||||
|
head->shuffle_next = ps_array[0];
|
||||||
|
tail->shuffle_prev = ps_array[nitems - 1];
|
||||||
|
|
||||||
ps = ps_array[0];
|
ps = ps_array[0];
|
||||||
|
|
||||||
@ -1036,14 +1060,27 @@ static void
|
|||||||
source_reshuffle(void)
|
source_reshuffle(void)
|
||||||
{
|
{
|
||||||
struct player_source *ps;
|
struct player_source *ps;
|
||||||
|
struct player_source *head;
|
||||||
|
struct player_source *tail;
|
||||||
|
|
||||||
|
if (cur_streaming)
|
||||||
|
head = cur_streaming;
|
||||||
|
else
|
||||||
|
head = source_head;
|
||||||
|
|
||||||
|
if (repeat == REPEAT_ALL)
|
||||||
|
tail = head;
|
||||||
|
else if (shuffle)
|
||||||
|
tail = shuffle_head;
|
||||||
|
else
|
||||||
|
tail = source_head;
|
||||||
|
|
||||||
|
ps = source_shuffle(head, tail);
|
||||||
|
|
||||||
ps = source_shuffle(source_head);
|
|
||||||
if (!ps)
|
if (!ps)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cur_streaming)
|
if (repeat == REPEAT_ALL)
|
||||||
shuffle_head = cur_streaming;
|
|
||||||
else
|
|
||||||
shuffle_head = ps;
|
shuffle_head = ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3378,9 +3415,6 @@ queue_add(struct player_command *cmd)
|
|||||||
struct player_source *ps_tail;
|
struct player_source *ps_tail;
|
||||||
|
|
||||||
ps = cmd->arg.ps;
|
ps = cmd->arg.ps;
|
||||||
|
|
||||||
ps_shuffle = source_shuffle(ps);
|
|
||||||
if (!ps_shuffle)
|
|
||||||
ps_shuffle = ps;
|
ps_shuffle = ps;
|
||||||
|
|
||||||
if (source_head)
|
if (source_head)
|
||||||
@ -3411,6 +3445,9 @@ queue_add(struct player_command *cmd)
|
|||||||
shuffle_head = ps_shuffle;
|
shuffle_head = ps_shuffle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shuffle)
|
||||||
|
source_reshuffle();
|
||||||
|
|
||||||
if (cur_plid != 0)
|
if (cur_plid != 0)
|
||||||
cur_plid = 0;
|
cur_plid = 0;
|
||||||
|
|
||||||
@ -3425,9 +3462,6 @@ queue_add_next(struct player_command *cmd)
|
|||||||
struct player_source *ps_playing;
|
struct player_source *ps_playing;
|
||||||
|
|
||||||
ps = cmd->arg.ps;
|
ps = cmd->arg.ps;
|
||||||
|
|
||||||
ps_shuffle = source_shuffle(ps);
|
|
||||||
if (!ps_shuffle)
|
|
||||||
ps_shuffle = ps;
|
ps_shuffle = ps;
|
||||||
|
|
||||||
if (source_head && cur_streaming)
|
if (source_head && cur_streaming)
|
||||||
@ -3452,6 +3486,9 @@ queue_add_next(struct player_command *cmd)
|
|||||||
shuffle_head = ps_shuffle;
|
shuffle_head = ps_shuffle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shuffle)
|
||||||
|
source_reshuffle();
|
||||||
|
|
||||||
if (cur_plid != 0)
|
if (cur_plid != 0)
|
||||||
cur_plid = 0;
|
cur_plid = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user