This repository has been archived on 2019-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mumbledj/songqueue.go
Matthieu Grieger a90b4671e9 Commented code
2014-12-27 10:05:13 -08:00

47 lines
964 B
Go

/*
* MumbleDJ
* By Matthieu Grieger
* songqueue.go
* Copyright (c) 2014 Matthieu Grieger (MIT License)
*/
package main
import (
"errors"
)
// SongQueue type declaration. Serves as a wrapper around the queue structure defined in queue.go.
type SongQueue struct {
queue *Queue
}
// Initializes a new queue and returns the new SongQueue.
func NewSongQueue() *SongQueue {
return &SongQueue{
queue: NewQueue(),
}
}
// Adds a song to the SongQueue.
func (q *SongQueue) AddSong(s *Song) error {
beforeLen := q.queue.Len()
q.queue.Push(s)
if q.queue.Len() == beforeLen+1 {
return nil
} else {
return errors.New("Could not add Song to the SongQueue.")
}
}
// Moves to the next song in SongQueue. NextSong() pops the first value of the queue, and is stored
// in dj.currentSong.
func (q *SongQueue) NextSong() *Song {
return q.queue.Poll().(*Song)
}
// Returns the length of the SongQueue.
func (q *SongQueue) Len() int {
return q.queue.Len()
}