From 0d4319ed302d0cfd8afb4cc32caf727b23f25805 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 23 Jan 2009 00:10:33 +0100 Subject: [PATCH] playlist: calculate next song before deleting the current one By calling queue_next_order() before playlist.current is invalidated (by the deletion of a song), we get more robust results, and the code becomes a little bit easier. incrPlaylistCurrent() is unused now, and can be removed. --- src/playlist.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/playlist.c b/src/playlist.c index 3b370f9fe..9a6347770 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -89,14 +89,6 @@ void playlistVersionChange(void) idle_add(IDLE_PLAYLIST); } -static void incrPlaylistCurrent(void) -{ - if (playlist.current < 0) - return; - - playlist.current = queue_next_order(&playlist.queue, playlist.current); -} - static void playlist_tag_event(void) { @@ -603,6 +595,11 @@ enum playlist_result deleteFromPlaylist(unsigned song) else return playPlaylistOrderNumber(fd,playlist.current); */ playerWait(); playlist_noGoToNext = 1; + + playlist.current = queue_next_order(&playlist.queue, + playlist.current); + if (playlist.current == (int)songOrder) + playlist.current = -1; } if (!song_in_database(queue_get(&playlist.queue, song))) @@ -614,9 +611,6 @@ enum playlist_result deleteFromPlaylist(unsigned song) if (playlist.current > (int)songOrder) { playlist.current--; - } else if (playlist.current >= (int)queue_length(&playlist.queue)) { - --playlist.current; - incrPlaylistCurrent(); } if (playlist.queued > (int)songOrder) {