31 lines
796 B
Go
31 lines
796 B
Go
|
package sdl
|
||
|
|
||
|
import "errors"
|
||
|
|
||
|
// setPlaying associates a channel no. to the Track playing.
|
||
|
func (e *Engine) setPlaying(channel int, t *Track) {
|
||
|
e.channelMu.Lock()
|
||
|
defer e.channelMu.Unlock()
|
||
|
e.channelsPlaying[channel] = t
|
||
|
}
|
||
|
|
||
|
// unsetPlaying associates a channel no. to the Track playing.
|
||
|
func (e *Engine) unsetPlaying(channel int) error {
|
||
|
e.channelMu.Lock()
|
||
|
defer e.channelMu.Unlock()
|
||
|
if track, ok := e.channelsPlaying[channel]; ok {
|
||
|
track.channel = -1
|
||
|
delete(e.channelsPlaying, channel)
|
||
|
return nil
|
||
|
}
|
||
|
return errors.New("didn't even know channel %d was playing a sound")
|
||
|
}
|
||
|
|
||
|
// isPlaying checks if a sound effect is playing on a channel.
|
||
|
func (e *Engine) isPlaying(channel int) bool {
|
||
|
e.channelMu.RLock()
|
||
|
defer e.channelMu.RUnlock()
|
||
|
_, ok := e.channelsPlaying[channel]
|
||
|
return ok
|
||
|
}
|