aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-09-30 23:10:15 +0200
committerMax Kellermann <max@duempel.org>2009-09-30 23:10:15 +0200
commit0478a8e2880a26f9993c5adeb10f29acc11deb72 (patch)
treea00f8b0289c148d337951b1cfa8ecb95515f0880
parent1039d572513589b2383b51ae08577bd9135c7b3b (diff)
downloadmpd-0478a8e2880a26f9993c5adeb10f29acc11deb72.tar.gz
mpd-0478a8e2880a26f9993c5adeb10f29acc11deb72.tar.xz
mpd-0478a8e2880a26f9993c5adeb10f29acc11deb72.zip
playlist_edit: moved code to playlist_delete_internal()
-rw-r--r--src/playlist_edit.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/playlist_edit.c b/src/playlist_edit.c
index 7b390aa17..6b15f56cb 100644
--- a/src/playlist_edit.c
+++ b/src/playlist_edit.c
@@ -208,16 +208,13 @@ playlist_swap_songs_id(struct playlist *playlist, unsigned id1, unsigned id2)
return playlist_swap_songs(playlist, song1, song2);
}
-enum playlist_result
-playlist_delete(struct playlist *playlist, unsigned song)
+static void
+playlist_delete_internal(struct playlist *playlist, unsigned song,
+ const struct song **queued_p)
{
- const struct song *queued;
unsigned songOrder;
- if (song >= queue_length(&playlist->queue))
- return PLAYLIST_RESULT_BAD_RANGE;
-
- queued = playlist_get_queued_song(playlist);
+ assert(song < queue_length(&playlist->queue));
songOrder = queue_position_to_order(&playlist->queue, song);
@@ -244,7 +241,7 @@ playlist_delete(struct playlist *playlist, unsigned song)
completely */
playlist_stop(playlist);
- queued = NULL;
+ *queued_p = NULL;
} else if (playlist->current == (int)songOrder)
/* there's a "current song" but we're not playing
currently - clear "current" */
@@ -257,14 +254,26 @@ playlist_delete(struct playlist *playlist, unsigned song)
queue_delete(&playlist->queue, song);
- playlist_increment_version(playlist);
-
/* update the "current" and "queued" variables */
if (playlist->current > (int)songOrder) {
playlist->current--;
}
+}
+
+enum playlist_result
+playlist_delete(struct playlist *playlist, unsigned song)
+{
+ const struct song *queued;
+ if (song >= queue_length(&playlist->queue))
+ return PLAYLIST_RESULT_BAD_RANGE;
+
+ queued = playlist_get_queued_song(playlist);
+
+ playlist_delete_internal(playlist, song, &queued);
+
+ playlist_increment_version(playlist);
playlist_update_queued_song(playlist, queued);
return PLAYLIST_RESULT_SUCCESS;