From c47a858d15edf1cf9a12e8dcdc16e9c925fe9a1f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 7 Oct 2021 22:19:27 +0200 Subject: [PATCH] command/QueueCommands: move code to RequireCurrentPosition() --- src/command/QueueCommands.cxx | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx index d6c11d61c..d45cdb40a 100644 --- a/src/command/QueueCommands.cxx +++ b/src/command/QueueCommands.cxx @@ -43,6 +43,17 @@ #include +static unsigned +RequireCurrentPosition(const playlist &p) +{ + int position = p.GetCurrentPosition(); + if (position < 0) + throw ProtocolError(ACK_ERROR_PLAYER_SYNC, + "No current song"); + + return position; +} + static void AddUri(Client &client, const LocatedUri &uri) { @@ -123,13 +134,9 @@ handle_addid(Client &client, Request args, Response &r) if (*s == '+') { /* after the current song */ - const int current = - partition.playlist.GetCurrentPosition(); - if (current < 0) - throw ProtocolError(ACK_ERROR_PLAYER_SYNC, - "No current song"); - - assert(unsigned(current) < queue_length); + const unsigned current = + RequireCurrentPosition(partition.playlist); + assert(current < queue_length); to = current + 1 + ParseCommandArgUnsigned(s + 1, @@ -137,13 +144,9 @@ handle_addid(Client &client, Request args, Response &r) } else if (*s == '-') { /* before the current song */ - const int current = - partition.playlist.GetCurrentPosition(); - if (current < 0) - throw ProtocolError(ACK_ERROR_PLAYER_SYNC, - "No current song"); - - assert(unsigned(current) < queue_length); + const unsigned current = + RequireCurrentPosition(partition.playlist); + assert(current < queue_length); to = current - ParseCommandArgUnsigned(s + 1, current); } else