mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-26 21:09:18 -05:00
[player/queue] Add player commands to move queue-items by item-id
This commit is contained in:
parent
43893dff48
commit
1c409846d5
55
src/player.c
55
src/player.c
@ -159,6 +159,14 @@ struct playerqueue_add_param
|
|||||||
int pos;
|
int pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct playerqueue_move_param
|
||||||
|
{
|
||||||
|
uint32_t item_id;
|
||||||
|
int from_pos;
|
||||||
|
int to_pos;
|
||||||
|
int count;
|
||||||
|
};
|
||||||
|
|
||||||
struct icy_artwork
|
struct icy_artwork
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
@ -198,11 +206,11 @@ struct player_command
|
|||||||
enum repeat_mode mode;
|
enum repeat_mode mode;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
int intval;
|
int intval;
|
||||||
int ps_pos[2];
|
|
||||||
struct icy_artwork icy;
|
struct icy_artwork icy;
|
||||||
struct playback_start_param playback_start_param;
|
struct playback_start_param playback_start_param;
|
||||||
struct playerqueue_get_param queue_get_param;
|
struct playerqueue_get_param queue_get_param;
|
||||||
struct playerqueue_add_param queue_add_param;
|
struct playerqueue_add_param queue_add_param;
|
||||||
|
struct playerqueue_move_param queue_move_param;
|
||||||
} arg;
|
} arg;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@ -3405,8 +3413,8 @@ playerqueue_move_bypos(struct player_command *cmd)
|
|||||||
{
|
{
|
||||||
struct player_source *ps_playing;
|
struct player_source *ps_playing;
|
||||||
|
|
||||||
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, "Moving song from position %d to be the next song after %d\n",
|
||||||
cmd->arg.ps_pos[1]);
|
cmd->arg.queue_move_param.from_pos, cmd->arg.queue_move_param.to_pos);
|
||||||
|
|
||||||
ps_playing = source_now_playing();
|
ps_playing = source_now_playing();
|
||||||
|
|
||||||
@ -3416,7 +3424,22 @@ playerqueue_move_bypos(struct player_command *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_move_bypos(queue, ps_playing->item_id, cmd->arg.ps_pos[0], cmd->arg.ps_pos[1], shuffle);
|
queue_move_bypos(queue, ps_playing->item_id, cmd->arg.queue_move_param.from_pos, cmd->arg.queue_move_param.to_pos, shuffle);
|
||||||
|
|
||||||
|
cur_plversion++;
|
||||||
|
|
||||||
|
listener_notify(LISTENER_PLAYLIST);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
playerqueue_move_byitemid(struct player_command *cmd)
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_PLAYER, "Moving song with item-id %d to be the next song after index %d\n",
|
||||||
|
cmd->arg.queue_move_param.item_id, cmd->arg.queue_move_param.to_pos);
|
||||||
|
|
||||||
|
queue_move_byitemid(queue, cmd->arg.queue_move_param.item_id, cmd->arg.queue_move_param.to_pos, 0);
|
||||||
|
|
||||||
cur_plversion++;
|
cur_plversion++;
|
||||||
|
|
||||||
@ -4187,8 +4210,28 @@ player_queue_move_bypos(int pos_from, int pos_to)
|
|||||||
|
|
||||||
cmd.func = playerqueue_move_bypos;
|
cmd.func = playerqueue_move_bypos;
|
||||||
cmd.func_bh = NULL;
|
cmd.func_bh = NULL;
|
||||||
cmd.arg.ps_pos[0] = pos_from;
|
cmd.arg.queue_move_param.from_pos = pos_from;
|
||||||
cmd.arg.ps_pos[1] = pos_to;
|
cmd.arg.queue_move_param.to_pos = pos_to;
|
||||||
|
|
||||||
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
|
command_deinit(&cmd);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
player_queue_move_byitemid(uint32_t item_id, int pos_to)
|
||||||
|
{
|
||||||
|
struct player_command cmd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
command_init(&cmd);
|
||||||
|
|
||||||
|
cmd.func = playerqueue_move_byitemid;
|
||||||
|
cmd.func_bh = NULL;
|
||||||
|
cmd.arg.queue_move_param.item_id = item_id;
|
||||||
|
cmd.arg.queue_move_param.to_pos = pos_to;
|
||||||
|
|
||||||
ret = sync_command(&cmd);
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
|
@ -169,6 +169,9 @@ player_queue_add_next(struct queue_item *items);
|
|||||||
int
|
int
|
||||||
player_queue_move_bypos(int ps_pos_from, int ps_pos_to);
|
player_queue_move_bypos(int ps_pos_from, int ps_pos_to);
|
||||||
|
|
||||||
|
int
|
||||||
|
player_queue_move_byitemid(uint32_t item_id, int pos_to);
|
||||||
|
|
||||||
int
|
int
|
||||||
player_queue_remove_bypos(int pos);
|
player_queue_remove_bypos(int pos);
|
||||||
|
|
||||||
|
82
src/queue.c
82
src/queue.c
@ -725,7 +725,7 @@ queue_move_bypos(struct queue *queue, unsigned int item_id, unsigned int from_po
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the item at the target position
|
// Get the item at the target position
|
||||||
item_next = queueitem_get_bypos(queue, item_id, to_offset, shuffle);
|
item_next = queueitem_get_bypos(queue, item_id, (to_offset + 1), shuffle);
|
||||||
if (!item_next)
|
if (!item_next)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_PLAYER, "Invalid position given to move items\n");
|
DPRINTF(E_LOG, L_PLAYER, "Invalid position given to move items\n");
|
||||||
@ -744,7 +744,7 @@ queue_move_bypos(struct queue *queue, unsigned int item_id, unsigned int from_po
|
|||||||
item->next->prev = item->prev;
|
item->next->prev = item->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert item into the queue befor the item at the target postion
|
// Insert item into the queue before the item at the target postion
|
||||||
if (shuffle)
|
if (shuffle)
|
||||||
{
|
{
|
||||||
item_next->shuffle_prev->shuffle_next = item;
|
item_next->shuffle_prev->shuffle_next = item;
|
||||||
@ -755,11 +755,81 @@ queue_move_bypos(struct queue *queue, unsigned int item_id, unsigned int from_po
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item_next->next->prev = item;
|
item_next->prev->next = item;
|
||||||
item->next = item_next->next;
|
item->prev = item_next->prev;
|
||||||
|
|
||||||
item_next->next = item;
|
item_next->prev = item;
|
||||||
item->prev = item_next;
|
item->next = item_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Moves the item with the given item-id to the index to_pos in the play-queue (shuffle = 0)
|
||||||
|
* or shuffle-queue (shuffle = 1)
|
||||||
|
*
|
||||||
|
* @param queue The queue to move item
|
||||||
|
* @param item_id The item-id of the to be moved
|
||||||
|
* @param to_pos The index to move the item
|
||||||
|
* @param shuffle If 0 the position in the play-queue, 1 the position in the shuffle-queue
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
queue_move_byitemid(struct queue *queue, unsigned int item_id, unsigned int to_pos, char shuffle)
|
||||||
|
{
|
||||||
|
struct queue_item *item;
|
||||||
|
struct queue_item *item_next;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
// Get the item to be moved
|
||||||
|
item = queueitem_get_byitemid(queue, item_id);
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Item with item-id %d does not exist in the queue\n", item_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the index of the item to move is lower than the target index
|
||||||
|
// If that is the case, increment the target position, because the given to_pos
|
||||||
|
// is based on the queue without the moved item.
|
||||||
|
index = queue_index_byitemid(queue, item_id, shuffle);
|
||||||
|
if (index < to_pos)
|
||||||
|
to_pos++;
|
||||||
|
|
||||||
|
// Get the item at the target position
|
||||||
|
item_next = queueitem_get_byindex(queue, to_pos, shuffle);
|
||||||
|
if (!item_next)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_PLAYER, "Invalid position given to move items\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove item from the queue
|
||||||
|
if (shuffle)
|
||||||
|
{
|
||||||
|
item->shuffle_prev->shuffle_next = item->shuffle_next;
|
||||||
|
item->shuffle_next->shuffle_prev = item->shuffle_prev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item->prev->next = item->next;
|
||||||
|
item->next->prev = item->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert item into the queue before the item at the target postion
|
||||||
|
if (shuffle)
|
||||||
|
{
|
||||||
|
item_next->shuffle_prev->shuffle_next = item;
|
||||||
|
item->shuffle_prev = item_next->shuffle_prev;
|
||||||
|
|
||||||
|
item_next->shuffle_prev = item;
|
||||||
|
item->shuffle_next = item_next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item_next->prev->next = item;
|
||||||
|
item->prev = item_next->prev;
|
||||||
|
|
||||||
|
item_next->prev = item;
|
||||||
|
item->next = item_next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,9 @@ queue_add_after(struct queue *queue, struct queue_item *item, unsigned int item_
|
|||||||
void
|
void
|
||||||
queue_move_bypos(struct queue *queue, unsigned int item_id, unsigned int from_pos, unsigned int to_offset, char shuffle);
|
queue_move_bypos(struct queue *queue, unsigned int item_id, unsigned int from_pos, unsigned int to_offset, char shuffle);
|
||||||
|
|
||||||
|
void
|
||||||
|
queue_move_byitemid(struct queue *queue, unsigned int item_id, unsigned int to_pos, char shuffle);
|
||||||
|
|
||||||
void
|
void
|
||||||
queue_remove_byitemid(struct queue *queue, unsigned int item_id);
|
queue_remove_byitemid(struct queue *queue, unsigned int item_id);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user