2014-12-15 06:37:55 +01:00
|
|
|
/*
|
|
|
|
* MumbleDJ
|
|
|
|
* By Matthieu Grieger
|
|
|
|
* songqueue.go
|
|
|
|
* Copyright (c) 2014 Matthieu Grieger (MIT License)
|
|
|
|
*/
|
|
|
|
|
2014-12-16 01:41:58 +01:00
|
|
|
package main
|
2014-12-15 06:37:55 +01:00
|
|
|
|
2014-12-27 09:25:49 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2014-12-27 19:05:13 +01:00
|
|
|
// SongQueue type declaration. Serves as a wrapper around the queue structure defined in queue.go.
|
2014-12-16 01:41:58 +01:00
|
|
|
type SongQueue struct {
|
2014-12-31 23:36:53 +01:00
|
|
|
queue []*Song
|
2014-12-16 01:41:58 +01:00
|
|
|
}
|
2014-12-15 06:37:55 +01:00
|
|
|
|
2014-12-27 19:05:13 +01:00
|
|
|
// Initializes a new queue and returns the new SongQueue.
|
2014-12-16 01:41:58 +01:00
|
|
|
func NewSongQueue() *SongQueue {
|
2014-12-19 01:28:27 +01:00
|
|
|
return &SongQueue{
|
2014-12-31 23:36:53 +01:00
|
|
|
queue: make([]*Song, 0),
|
2014-12-19 01:28:27 +01:00
|
|
|
}
|
2014-12-16 01:41:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 19:05:13 +01:00
|
|
|
// Adds a song to the SongQueue.
|
2014-12-27 09:25:49 +01:00
|
|
|
func (q *SongQueue) AddSong(s *Song) error {
|
2014-12-31 23:36:53 +01:00
|
|
|
beforeLen := len(q.queue)
|
|
|
|
q.queue = append(q.queue, s)
|
|
|
|
if len(q.queue) == beforeLen+1 {
|
2014-12-27 09:25:49 +01:00
|
|
|
return nil
|
2014-12-19 01:28:27 +01:00
|
|
|
} else {
|
2014-12-27 09:25:49 +01:00
|
|
|
return errors.New("Could not add Song to the SongQueue.")
|
2014-12-19 01:28:27 +01:00
|
|
|
}
|
2014-12-16 01:41:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 19:05:13 +01:00
|
|
|
// Moves to the next song in SongQueue. NextSong() pops the first value of the queue, and is stored
|
|
|
|
// in dj.currentSong.
|
2014-12-19 01:28:27 +01:00
|
|
|
func (q *SongQueue) NextSong() *Song {
|
2014-12-31 23:36:53 +01:00
|
|
|
s, queue := q.queue[0], q.queue[1:]
|
|
|
|
q.queue = queue
|
|
|
|
return s
|
2014-12-16 01:41:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 19:05:13 +01:00
|
|
|
// Returns the length of the SongQueue.
|
2014-12-27 09:25:49 +01:00
|
|
|
func (q *SongQueue) Len() int {
|
2014-12-31 23:36:53 +01:00
|
|
|
return len(q.queue)
|
2014-12-19 01:28:27 +01:00
|
|
|
}
|