From 0f79287b04602ce92cb86c056f78d5f70ab71d42 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 17 Oct 2017 19:02:41 +0200 Subject: [PATCH] queue/Playlist: move code to MoveOrderToCurrent() --- src/queue/Playlist.hxx | 12 ++++++++++++ src/queue/PlaylistControl.cxx | 26 +++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx index 32489e354..c04a0913a 100644 --- a/src/queue/Playlist.hxx +++ b/src/queue/Playlist.hxx @@ -356,6 +356,18 @@ public: } void SetConsume(bool new_value); + +private: + /** + * Prepare a manual song change: move the given song to the + * current playback order. This is done to avoid skipping + * upcoming songs in the order list. The newly selected song + * shall be inserted in the order list, and the rest shall be + * played after that as previously planned. + * + * @return the new order number of the given song + */ + unsigned MoveOrderToCurrent(unsigned old_order); }; #endif diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx index 99012aedf..c2284b60c 100644 --- a/src/queue/PlaylistControl.cxx +++ b/src/queue/PlaylistControl.cxx @@ -56,6 +56,24 @@ playlist::Stop(PlayerControl &pc) } } +unsigned +playlist::MoveOrderToCurrent(unsigned old_order) +{ + if (!queue.random) + /* no-op because there is no order list */ + return old_order; + + const unsigned destination_order = playing + ? (unsigned)current + : 0; + + /* swap the new song with the previous "current" one, so + playback continues as planned */ + queue.SwapOrders(old_order, destination_order); + + return destination_order; +} + void playlist::PlayPosition(PlayerControl &pc, int song) { @@ -90,13 +108,7 @@ playlist::PlayPosition(PlayerControl &pc, int song) number, because random mode is enabled */ i = queue.PositionToOrder(song); - if (!playing) - current = 0; - - /* swap the new song with the previous "current" one, - so playback continues as planned */ - queue.SwapOrders(i, current); - i = current; + i = MoveOrderToCurrent(i); } stop_on_error = false;