command/QueueCommands: offset relative "addid" positions by one
Now, "+0" means "right after the current song" and "-0" means "right before the current song". Mnemonic: there are zero songs between the current song and the newly added song.
This commit is contained in:
parent
3993176b76
commit
076c9a0dd9
@ -711,9 +711,10 @@ Whenever possible, ids should be used.
|
||||
|
||||
If the second parameter is given, then the song is inserted at the
|
||||
specified position. If the parameter starts with ``+`` or ``-``,
|
||||
then it is relative to the current song; e.g. ``+1`` inserts right
|
||||
after the current song and ``-1`` inserts right before the current
|
||||
song. (``±0`` is not a legal value.)
|
||||
then it is relative to the current song; e.g. ``+0`` inserts right
|
||||
after the current song and ``-0`` inserts right before the current
|
||||
song (i.e. zero songs between the current song and the newly added
|
||||
song).
|
||||
|
||||
.. _command_clear:
|
||||
|
||||
|
@ -120,8 +120,8 @@ handle_addid(Client &client, Request args, Response &r)
|
||||
const auto queue_length = partition.playlist.queue.GetLength();
|
||||
|
||||
const char *const s = args[1];
|
||||
if (*s == '+' || *s == '-') {
|
||||
/* relative to the current song */
|
||||
if (*s == '+') {
|
||||
/* after the current song */
|
||||
|
||||
const int current =
|
||||
partition.playlist.GetCurrentPosition();
|
||||
@ -129,23 +129,23 @@ handle_addid(Client &client, Request args, Response &r)
|
||||
throw ProtocolError(ACK_ERROR_PLAYER_SYNC,
|
||||
"No current song");
|
||||
|
||||
to = args.ParseInt(1, -current - 1,
|
||||
queue_length - current);
|
||||
if (to == 0)
|
||||
throw ProtocolError(ACK_ERROR_ARG,
|
||||
"Zero is not a legal relative position");
|
||||
assert(unsigned(current) < queue_length);
|
||||
|
||||
/* special case for negative offsets: the
|
||||
offset "-1" shall insert the new song right
|
||||
before the current song (just like "+1"
|
||||
inserts right after the current song);
|
||||
computationally, that would be a zero
|
||||
offset, but that's not intuitive, so we
|
||||
need to add one here */
|
||||
if (to < 0)
|
||||
++to;
|
||||
to = current + 1 +
|
||||
ParseCommandArgUnsigned(s + 1,
|
||||
queue_length - current - 1);
|
||||
} else if (*s == '-') {
|
||||
/* before the current song */
|
||||
|
||||
to += current;
|
||||
const int current =
|
||||
partition.playlist.GetCurrentPosition();
|
||||
if (current < 0)
|
||||
throw ProtocolError(ACK_ERROR_PLAYER_SYNC,
|
||||
"No current song");
|
||||
|
||||
assert(unsigned(current) < queue_length);
|
||||
|
||||
to = current - ParseCommandArgUnsigned(s + 1, current);
|
||||
} else
|
||||
/* absolute position */
|
||||
to = args.ParseUnsigned(1, queue_length);
|
||||
|
Loading…
Reference in New Issue
Block a user