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-19 01:28:27 +01:00
|
|
|
queue *Queue
|
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{
|
|
|
|
queue: NewQueue(),
|
|
|
|
}
|
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-19 01:28:27 +01:00
|
|
|
beforeLen := q.queue.Len()
|
|
|
|
q.queue.Push(s)
|
|
|
|
if q.queue.Len() == 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 {
|
|
|
|
return q.queue.Poll().(*Song)
|
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 {
|
|
|
|
return q.queue.Len()
|
2014-12-19 01:28:27 +01:00
|
|
|
}
|