From 9cb08df11d7446357c5d480d08d256b906d4988e Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 21 Jul 2023 10:50:07 +0200 Subject: implement playlist in order traversal This ensures that the initial reported song array is in order. --- playlist.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'playlist.go') diff --git a/playlist.go b/playlist.go index becc85e..1fbd344 100644 --- a/playlist.go +++ b/playlist.go @@ -61,3 +61,16 @@ func (pl *Playlist) RemoveSong(s *Song) { heap.Remove(pl, s.index) llog.DDebug("removing song %p in the playlist (%p) -> %v", s, pl, pl) } + +func (pl *Playlist) OrderedList() []*Song { + songs := make([]*Song, 0, pl.Len()) + + cpy := make(Playlist, 0, pl.Len()) + copy(cpy, *pl) + + for cpy.Len() > 0 { + songs = append(songs, heap.Pop(&cpy).(*Song)) + } + + return songs +} -- cgit v1.2.3