Commit 076c9a0d authored by Max Kellermann's avatar Max Kellermann

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.
parent 3993176b
...@@ -711,9 +711,10 @@ Whenever possible, ids should be used. ...@@ -711,9 +711,10 @@ Whenever possible, ids should be used.
If the second parameter is given, then the song is inserted at the If the second parameter is given, then the song is inserted at the
specified position. If the parameter starts with ``+`` or ``-``, specified position. If the parameter starts with ``+`` or ``-``,
then it is relative to the current song; e.g. ``+1`` inserts right then it is relative to the current song; e.g. ``+0`` inserts right
after the current song and ``-1`` inserts right before the current after the current song and ``-0`` inserts right before the current
song. (``±0`` is not a legal value.) song (i.e. zero songs between the current song and the newly added
song).
.. _command_clear: .. _command_clear:
......
...@@ -120,8 +120,8 @@ handle_addid(Client &client, Request args, Response &r) ...@@ -120,8 +120,8 @@ handle_addid(Client &client, Request args, Response &r)
const auto queue_length = partition.playlist.queue.GetLength(); const auto queue_length = partition.playlist.queue.GetLength();
const char *const s = args[1]; const char *const s = args[1];
if (*s == '+' || *s == '-') { if (*s == '+') {
/* relative to the current song */ /* after the current song */
const int current = const int current =
partition.playlist.GetCurrentPosition(); partition.playlist.GetCurrentPosition();
...@@ -129,23 +129,23 @@ handle_addid(Client &client, Request args, Response &r) ...@@ -129,23 +129,23 @@ handle_addid(Client &client, Request args, Response &r)
throw ProtocolError(ACK_ERROR_PLAYER_SYNC, throw ProtocolError(ACK_ERROR_PLAYER_SYNC,
"No current song"); "No current song");
to = args.ParseInt(1, -current - 1, assert(unsigned(current) < queue_length);
queue_length - current);
if (to == 0) to = current + 1 +
throw ProtocolError(ACK_ERROR_ARG, ParseCommandArgUnsigned(s + 1,
"Zero is not a legal relative position"); queue_length - current - 1);
} else if (*s == '-') {
/* special case for negative offsets: the /* before the current song */
offset "-1" shall insert the new song right
before the current song (just like "+1" const int current =
inserts right after the current song); partition.playlist.GetCurrentPosition();
computationally, that would be a zero if (current < 0)
offset, but that's not intuitive, so we throw ProtocolError(ACK_ERROR_PLAYER_SYNC,
need to add one here */ "No current song");
if (to < 0)
++to; assert(unsigned(current) < queue_length);
to += current; to = current - ParseCommandArgUnsigned(s + 1, current);
} else } else
/* absolute position */ /* absolute position */
to = args.ParseUnsigned(1, queue_length); to = args.ParseUnsigned(1, queue_length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment