diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-07-21 10:50:07 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-07-21 10:50:07 +0200 |
| commit | 9cb08df11d7446357c5d480d08d256b906d4988e (patch) | |
| tree | 23bfd03aecb715a59892e7bbeb64cb5368771276 /playlist.go | |
| parent | c2ba7e49b2095019f9a7df2d71bb4b42b31a357e (diff) | |
| download | WRMS-9cb08df11d7446357c5d480d08d256b906d4988e.tar.gz WRMS-9cb08df11d7446357c5d480d08d256b906d4988e.zip | |
implement playlist in order traversal
This ensures that the initial reported song array is in order.
Diffstat (limited to 'playlist.go')
| -rw-r--r-- | playlist.go | 13 |
1 files changed, 13 insertions, 0 deletions
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 +} |
