[mpd] implement range support for 'delete' command
This commit is contained in:
parent
b007529678
commit
b2d2e9286f
27
src/mpd.c
27
src/mpd.c
|
@ -1696,9 +1696,9 @@ mpd_command_clear(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
static int
|
static int
|
||||||
mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
{
|
{
|
||||||
struct player_status status;
|
int start_pos;
|
||||||
uint32_t start_pos;
|
int end_pos;
|
||||||
int pos;
|
int count;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// If argv[1] is ommited clear the whole queue except the current playing one
|
// If argv[1] is ommited clear the whole queue except the current playing one
|
||||||
|
@ -1709,32 +1709,21 @@ mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If argument argv[1] is present remove only the specified songs
|
// If argument argv[1] is present remove only the specified songs
|
||||||
//TODO support ranges for argv[1]
|
ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos);
|
||||||
ret = safe_atou32(argv[1], &start_pos);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ret = asprintf(errmsg, "Argument doesn't convert to integer: '%s'", argv[1]);
|
ret = asprintf(errmsg, "Argument doesn't convert to integer or range: '%s'", argv[1]);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||||
return ACK_ERROR_ARG;
|
return ACK_ERROR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
player_get_status(&status);
|
count = end_pos - start_pos;
|
||||||
|
|
||||||
pos = start_pos - status.pos_pl;
|
ret = player_queue_remove_byindex(start_pos, count);
|
||||||
|
|
||||||
if (pos < 1)
|
|
||||||
{
|
|
||||||
ret = asprintf(errmsg, "Removing playing or previously played song not supported (song position %d)", pos);
|
|
||||||
if (ret < 0)
|
|
||||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
|
||||||
return ACK_ERROR_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = player_queue_remove_bypos(pos);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
ret = asprintf(errmsg, "Failed to remove song at position '%d'", pos);
|
ret = asprintf(errmsg, "Failed to remove %d songs starting at position %d", count, start_pos);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||||
return ACK_ERROR_UNKNOWN;
|
return ACK_ERROR_UNKNOWN;
|
||||||
|
|
58
src/player.c
58
src/player.c
|
@ -167,6 +167,12 @@ struct playerqueue_move_param
|
||||||
int count;
|
int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct playerqueue_remove_param
|
||||||
|
{
|
||||||
|
int from_pos;
|
||||||
|
int count;
|
||||||
|
};
|
||||||
|
|
||||||
struct icy_artwork
|
struct icy_artwork
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
@ -211,6 +217,7 @@ struct player_command
|
||||||
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;
|
struct playerqueue_move_param queue_move_param;
|
||||||
|
struct playerqueue_remove_param queue_remove_param;
|
||||||
} arg;
|
} arg;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -3490,6 +3497,28 @@ playerqueue_remove_bypos(struct player_command *cmd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
playerqueue_remove_byindex(struct player_command *cmd)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
int count;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pos = cmd->arg.queue_remove_param.from_pos;
|
||||||
|
count = cmd->arg.queue_remove_param.count;
|
||||||
|
|
||||||
|
DPRINTF(E_DBG, L_PLAYER, "Removing %d items starting from position %d\n", count, pos);
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
queue_remove_byindex(queue, pos, 0);
|
||||||
|
|
||||||
|
cur_plversion++;
|
||||||
|
|
||||||
|
listener_notify(LISTENER_PLAYLIST);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
playerqueue_remove_byitemid(struct player_command *cmd)
|
playerqueue_remove_byitemid(struct player_command *cmd)
|
||||||
{
|
{
|
||||||
|
@ -4287,6 +4316,35 @@ player_queue_remove_bypos(int pos)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Removes the media item at the given position from the UpNext-queue
|
||||||
|
*
|
||||||
|
* The UpNext-queue consists of all items of the play-queue (shuffle off) or shuffle-queue
|
||||||
|
* (shuffle on) after the current playing item (starting with position 0).
|
||||||
|
*
|
||||||
|
* @param pos Position in the UpNext-queue (0-based)
|
||||||
|
* @return 0 on success, -1 on failure
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
player_queue_remove_byindex(int pos, int count)
|
||||||
|
{
|
||||||
|
struct player_command cmd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
command_init(&cmd);
|
||||||
|
|
||||||
|
cmd.func = playerqueue_remove_byindex;
|
||||||
|
cmd.func_bh = NULL;
|
||||||
|
cmd.arg.queue_remove_param.from_pos = pos;
|
||||||
|
cmd.arg.queue_remove_param.count = count;
|
||||||
|
|
||||||
|
ret = sync_command(&cmd);
|
||||||
|
|
||||||
|
command_deinit(&cmd);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Removes the item with the given (queueitem) item id from the queue
|
* Removes the item with the given (queueitem) item id from the queue
|
||||||
*
|
*
|
||||||
|
|
|
@ -175,6 +175,9 @@ 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);
|
||||||
|
|
||||||
|
int
|
||||||
|
player_queue_remove_byindex(int pos, int count);
|
||||||
|
|
||||||
int
|
int
|
||||||
player_queue_remove_byitemid(uint32_t id);
|
player_queue_remove_byitemid(uint32_t id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue