mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-15 00:35:55 -04:00
[player] Refactor queue_remove functions
This commit is contained in:
parent
8e1834cdea
commit
f0a6a48599
@ -1865,7 +1865,7 @@ dacp_reply_playqueueedit_remove(struct evhttp_request *req, struct evbuffer *evb
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player_queue_remove(item_index);
|
player_queue_remove_pos_relative(item_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 204 No Content is the canonical reply */
|
/* 204 No Content is the canonical reply */
|
||||||
|
@ -1695,7 +1695,7 @@ mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
|||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = player_queue_remove(pos);
|
ret = player_queue_remove_pos_relative(pos);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ret = asprintf(errmsg, "Failed to remove song at position '%d'", pos);
|
ret = asprintf(errmsg, "Failed to remove song at position '%d'", pos);
|
||||||
@ -1734,7 +1734,7 @@ mpd_command_deleteid(struct evbuffer *evbuf, int argc, char **argv, char **errms
|
|||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = player_queue_removeid(songid);
|
ret = player_queue_remove_queueitemid(songid);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ret = asprintf(errmsg, "Failed to remove song with id '%s'", argv[1]);
|
ret = asprintf(errmsg, "Failed to remove song with id '%s'", argv[1]);
|
||||||
|
189
src/player.c
189
src/player.c
@ -3797,65 +3797,8 @@ queue_move(struct player_command *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
queue_remove(struct player_command *cmd)
|
queue_remove(struct player_source *ps)
|
||||||
{
|
{
|
||||||
struct player_source *ps;
|
|
||||||
struct player_source *ps_current;
|
|
||||||
uint32_t pos;
|
|
||||||
uint32_t id;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (cmd->arg.item_range.type == RANGEARG_ID)
|
|
||||||
{
|
|
||||||
id = cmd->arg.item_range.id;
|
|
||||||
pos = 0;
|
|
||||||
if (id < 1)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Can't remove item, invalid id %d\n", id);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_PLAYER, "Removing item with id %d\n", id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
id = 0;
|
|
||||||
pos = cmd->arg.item_range.start_pos;
|
|
||||||
if (pos < 1)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Can't remove item, invalid position %d\n", pos);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_PLAYER, "Removing item from position %d\n", pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
ps_current = cur_playing ? cur_playing : cur_streaming;
|
|
||||||
if (!ps_current)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming item not found\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
ps = ps_current;
|
|
||||||
while (ps)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
ps = next_ps(ps, shuffle);
|
|
||||||
|
|
||||||
if (ps == ps_current)
|
|
||||||
ps = NULL;
|
|
||||||
else if ((i == pos) || (ps->id == id))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ps)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Can't remove requested item from queue (id %d, pos %d)\n", id, pos);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ps == source_head)
|
if (ps == source_head)
|
||||||
source_head = ps->pl_next;
|
source_head = ps->pl_next;
|
||||||
if (ps == shuffle_head)
|
if (ps == shuffle_head)
|
||||||
@ -3876,6 +3819,106 @@ queue_remove(struct player_command *cmd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
queue_remove_pos_relative(struct player_command *cmd)
|
||||||
|
{
|
||||||
|
struct player_source *ps;
|
||||||
|
struct player_source *ps_current;
|
||||||
|
int pos;
|
||||||
|
int i;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
pos = cmd->arg.intval;
|
||||||
|
if (pos < 1)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Can't remove item, invalid position %d\n", pos);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINTF(E_DBG, L_PLAYER, "Removing item from position %d\n", pos);
|
||||||
|
|
||||||
|
ps_current = cur_playing ? cur_playing : cur_streaming;
|
||||||
|
if (!ps_current)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming item not found\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
ps = ps_current;
|
||||||
|
while (ps)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ps = next_ps(ps, shuffle);
|
||||||
|
|
||||||
|
if (ps == ps_current)
|
||||||
|
ps = NULL;
|
||||||
|
else if (i == pos)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ps)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Can't remove requested item from queue (pos %d)\n", pos);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = queue_remove(ps);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
queue_remove_queueitemid(struct player_command *cmd)
|
||||||
|
{
|
||||||
|
struct player_source *ps;
|
||||||
|
struct player_source *ps_current;
|
||||||
|
uint32_t pos;
|
||||||
|
uint32_t id;
|
||||||
|
int i;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
id = cmd->arg.id;
|
||||||
|
pos = 0;
|
||||||
|
if (id < 1)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Can't remove item, invalid id %d\n", id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINTF(E_DBG, L_PLAYER, "Removing item with id %d\n", id);
|
||||||
|
|
||||||
|
ps_current = cur_playing ? cur_playing : cur_streaming;
|
||||||
|
if (!ps_current)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Current playing/streaming item not found\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
ps = ps_current;
|
||||||
|
while (ps)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ps = next_ps(ps, shuffle);
|
||||||
|
|
||||||
|
if (ps == ps_current)
|
||||||
|
ps = NULL;
|
||||||
|
else if (ps->id == id)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ps)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Can't remove requested item from queue (id %d, pos %d)\n", id, pos);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = queue_remove(ps);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* queue_clear removes all items from the playqueue, playback must be stopped before calling queue_clear
|
* queue_clear removes all items from the playqueue, playback must be stopped before calling queue_clear
|
||||||
*/
|
*/
|
||||||
@ -4569,18 +4612,27 @@ player_queue_move(int ps_pos_from, int ps_pos_to)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Removes the item at the given position from the queue, where the
|
||||||
|
* position is relative to the now playing item and dependent on the
|
||||||
|
* shuffle state of the player.
|
||||||
|
* If shuffle is on, the position determines the position in the shuffle
|
||||||
|
* queue.
|
||||||
|
*
|
||||||
|
* @param pos Position relative to the now playing item and the shuffle state
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
player_queue_remove(int ps_pos_remove)
|
player_queue_remove_pos_relative(int pos)
|
||||||
{
|
{
|
||||||
struct player_command cmd;
|
struct player_command cmd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
command_init(&cmd);
|
command_init(&cmd);
|
||||||
|
|
||||||
cmd.func = queue_remove;
|
cmd.func = queue_remove_pos_relative;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg.item_range.type = RANGEARG_POS;
|
cmd.arg.intval = pos;
|
||||||
cmd.arg.item_range.start_pos = ps_pos_remove;
|
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
@ -4589,18 +4641,23 @@ player_queue_remove(int ps_pos_remove)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Removes the item with the given item id from the queue
|
||||||
|
*
|
||||||
|
* @param id Id of the queue item to remove
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
player_queue_removeid(uint32_t id)
|
player_queue_remove_queueitemid(uint32_t id)
|
||||||
{
|
{
|
||||||
struct player_command cmd;
|
struct player_command cmd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
command_init(&cmd);
|
command_init(&cmd);
|
||||||
|
|
||||||
cmd.func = queue_remove;
|
cmd.func = queue_remove_queueitemid;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg.item_range.type = RANGEARG_ID;
|
cmd.arg.id = id;
|
||||||
cmd.arg.item_range.id = id;
|
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
|
@ -210,10 +210,10 @@ int
|
|||||||
player_queue_move(int ps_pos_from, int ps_pos_to);
|
player_queue_move(int ps_pos_from, int ps_pos_to);
|
||||||
|
|
||||||
int
|
int
|
||||||
player_queue_remove(int ps_pos_remove);
|
player_queue_remove_pos_relative(int pos);
|
||||||
|
|
||||||
int
|
int
|
||||||
player_queue_removeid(uint32_t id);
|
player_queue_remove_queueitemid(uint32_t id);
|
||||||
|
|
||||||
void
|
void
|
||||||
player_queue_clear(void);
|
player_queue_clear(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user