-
Notifications
You must be signed in to change notification settings - Fork 0
/
currentsong.go
45 lines (36 loc) · 1.04 KB
/
currentsong.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package mmpd
import "fmt"
type CurrentSong struct {
PreviousSong *PlaylistEntry
CurrentSong *PlaylistEntry
NextSong *PlaylistEntry
}
func NewCurrentSong(status *Status, playlist *Playlist) *CurrentSong {
if playlist == nil {
return nil
}
fmt.Printf("mpd: song=%d songId=%d nextSong=%d nextSongId=%d\n",
status.Song, status.SongId, status.NextSong, status.NextSongId)
currentSong := &CurrentSong{}
playlistLength := len(playlist.Entries)
if status.SongId > 0 {
if status.Song < playlistLength {
if status.Song > 0 {
currentSong.PreviousSong = playlist.Entries[status.Song-1]
}
currentSong.CurrentSong = playlist.Entries[status.Song]
}
}
if status.NextSongId > 0 && status.NextSong < playlistLength {
currentSong.NextSong = playlist.Entries[status.NextSong]
}
return currentSong
}
func (cs *CurrentSong) Equals(other *CurrentSong) bool {
if other == nil {
return false
}
return cs.PreviousSong.Equals(other.PreviousSong) &&
cs.CurrentSong.Equals(other.CurrentSong) &&
cs.NextSong.Equals(other.NextSong)
}