Adjustments to queue_move/queue_remove, mostly for consistency

This commit is contained in:
ejurgensen 2014-04-21 21:21:40 +02:00
parent 56e04fe247
commit 8eb6b46ed2
2 changed files with 59 additions and 56 deletions

View File

@ -3398,65 +3398,65 @@ queue_add_next(struct player_command *cmd)
static int static int
queue_move(struct player_command *cmd) queue_move(struct player_command *cmd)
{ {
struct player_source *ps;
struct player_source *ps_src; struct player_source *ps_src;
struct player_source *ps_dst; struct player_source *ps_dst;
int pos_max;
int i; int i;
int pos_max = MAX(cmd->arg.ps_pos[0], cmd->arg.ps_pos[1]); DPRINTF(E_DBG, L_PLAYER, "Moving song from position %d to be the next song after %d\n", cmd->arg.ps_pos[0],
DPRINTF(E_DBG, L_PLAYER, "Move song from position %d to be next song after %d\n", cmd->arg.ps_pos[0],
cmd->arg.ps_pos[1]); cmd->arg.ps_pos[1]);
struct player_source *ps_tmp = cur_playing ? cur_playing : cur_streaming; ps = cur_playing ? cur_playing : cur_streaming;
if (!ps_tmp) if (!ps)
{ {
DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming song not found\n"); DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming song not found\n");
return 0; return -1;
} }
pos_max = MAX(cmd->arg.ps_pos[0], cmd->arg.ps_pos[1]);
ps_src = NULL; ps_src = NULL;
ps_dst = NULL; ps_dst = NULL;
for (i = 0; i <= pos_max; i++) for (i = 0; i <= pos_max; i++)
{ {
if (i == cmd->arg.ps_pos[0]) if (i == cmd->arg.ps_pos[0])
ps_src = ps_tmp; ps_src = ps;
if (i == cmd->arg.ps_pos[1]) if (i == cmd->arg.ps_pos[1])
ps_dst = ps_tmp; ps_dst = ps;
ps_tmp = shuffle ? ps_tmp->shuffle_next : ps_tmp->pl_next; ps = shuffle ? ps->shuffle_next : ps->pl_next;
} }
if (ps_src && ps_dst) if (!ps_src || !ps_dst || (ps_src == ps_dst))
{ {
struct player_source *ps_src_prev; DPRINTF(E_LOG, L_PLAYER, "Invalid source and/or destination for queue_move\n");
struct player_source *ps_src_next; return -1;
struct player_source *ps_dst_next; }
if (shuffle) if (shuffle)
{ {
ps_src_prev = ps_src->shuffle_prev; // Remove ps_src from shuffle queue
ps_src_next = ps_src->shuffle_next; ps_src->shuffle_prev->shuffle_next = ps_src->shuffle_next;
ps_src_prev->shuffle_next = ps_src_next; ps_src->shuffle_next->shuffle_prev = ps_src->shuffle_prev;
ps_src_next->shuffle_prev = ps_src_prev;
ps_dst_next = ps_dst->shuffle_next; // Insert after ps_dst
ps_dst->shuffle_next = ps_src;
ps_src->shuffle_prev = ps_dst; ps_src->shuffle_prev = ps_dst;
ps_dst_next->shuffle_prev = ps_src; ps_src->shuffle_next = ps_dst->shuffle_next;
ps_src->shuffle_next = ps_dst_next; ps_dst->shuffle_next->shuffle_prev = ps_src;
ps_dst->shuffle_next = ps_src;
} }
else else
{ {
ps_src_prev = ps_src->pl_prev; // Remove ps_src from queue
ps_src_next = ps_src->pl_next; ps_src->pl_prev->pl_next = ps_src->pl_next;
ps_src_prev->pl_next = ps_src_next; ps_src->pl_next->pl_prev = ps_src->pl_prev;
ps_src_next->pl_prev = ps_src_prev;
ps_dst_next = ps_dst->pl_next; // Insert after ps_dst
ps_dst->pl_next = ps_src;
ps_src->pl_prev = ps_dst; ps_src->pl_prev = ps_dst;
ps_dst_next->pl_prev = ps_src; ps_src->pl_next = ps_dst->pl_next;
ps_src->pl_next = ps_dst_next; ps_dst->pl_next->pl_prev = ps_src;
} ps_dst->pl_next = ps_src;
} }
return 0; return 0;
@ -3465,36 +3465,39 @@ queue_move(struct player_command *cmd)
static int static int
queue_remove(struct player_command *cmd) queue_remove(struct player_command *cmd)
{ {
struct player_source *ps_src = NULL; struct player_source *ps;
int pos;
int i;
DPRINTF(E_DBG, L_PLAYER, "Remove song from position %d\n", cmd->arg.ps_pos[0]); pos = cmd->arg.ps_pos[0];
struct player_source *ps_tmp = cur_playing ? cur_playing : cur_streaming; DPRINTF(E_DBG, L_PLAYER, "Removing song from position %d\n", pos);
if (!ps_tmp)
if (pos < 1)
{
DPRINTF(E_LOG, L_PLAYER, "Can't remove song, invalid position %d\n", pos);
return -1;
}
ps = cur_playing ? cur_playing : cur_streaming;
if (!ps)
{ {
DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming song not found\n"); DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming song not found\n");
return 0; return -1;
} }
int i = 0; for (i = 0; i <= pos; i++)
for (i = 0; i <= cmd->arg.ps_pos[0]; ++i)
{ {
if (i == cmd->arg.ps_pos[0]) ps = shuffle ? ps->shuffle_next : ps->pl_next;
ps_src = ps_tmp;
ps_tmp = shuffle ? ps_tmp->shuffle_next : ps_tmp->pl_next;
} }
if (ps_src) ps->shuffle_prev->shuffle_next = ps->shuffle_next;
{ ps->shuffle_next->shuffle_prev = ps->shuffle_prev;
ps_src->shuffle_prev->shuffle_next = ps_src->shuffle_next;
ps_src->shuffle_next->shuffle_prev = ps_src->shuffle_prev;
ps_src->pl_prev->pl_next = ps_src->pl_next; ps->pl_prev->pl_next = ps->pl_next;
ps_src->pl_next->pl_prev = ps_src->pl_prev; ps->pl_next->pl_prev = ps->pl_prev;
source_free(ps_src); source_free(ps);
}
return 0; return 0;
} }