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

47 lines
964 B
Go
Raw Normal View History

2014-12-15 06:37:55 +01:00
/*
* MumbleDJ
* By Matthieu Grieger
* songqueue.go
* Copyright (c) 2014 Matthieu Grieger (MIT License)
*/
package main
2014-12-15 06:37:55 +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.
type SongQueue struct {
queue *Queue
}
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.
func NewSongQueue() *SongQueue {
return &SongQueue{
queue: NewQueue(),
}
}
2014-12-27 19:05:13 +01:00
// 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.")
}
}
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.
func (q *SongQueue) NextSong() *Song {
return q.queue.Poll().(*Song)
}
2014-12-27 19:05:13 +01:00
// Returns the length of the SongQueue.
func (q *SongQueue) Len() int {
return q.queue.Len()
}