mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
fix(tracker/sequencer): add a way to exit the sequencer loop
This commit is contained in:
parent
d30388a09a
commit
b1ac141ea5
@ -21,7 +21,9 @@ func main() {
|
|||||||
app.Size(unit.Dp(800), unit.Dp(600)),
|
app.Size(unit.Dp(800), unit.Dp(600)),
|
||||||
app.Title("Sointu Tracker"),
|
app.Title("Sointu Tracker"),
|
||||||
)
|
)
|
||||||
if err := tracker.New(plr).Run(w); err != nil {
|
t := tracker.New(plr)
|
||||||
|
defer t.Close()
|
||||||
|
if err := t.Run(w); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ func (t *Tracker) TogglePlay() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sequencerLoop is the main goroutine that handles the playing logic
|
// sequencerLoop is the main goroutine that handles the playing logic
|
||||||
func (t *Tracker) sequencerLoop() {
|
func (t *Tracker) sequencerLoop(closer chan struct{}) {
|
||||||
playing := false
|
playing := false
|
||||||
rowTime := (time.Second * 60) / time.Duration(4*t.song.BPM)
|
rowTime := (time.Second * 60) / time.Duration(4*t.song.BPM)
|
||||||
tick := make(<-chan time.Time)
|
tick := make(<-chan time.Time)
|
||||||
@ -46,6 +46,8 @@ func (t *Tracker) sequencerLoop() {
|
|||||||
atomic.StoreInt32(&t.PlayRow, int32(rowJump))
|
atomic.StoreInt32(&t.PlayRow, int32(rowJump))
|
||||||
case patternJump := <-t.patternJump:
|
case patternJump := <-t.patternJump:
|
||||||
atomic.StoreInt32(&t.PlayPattern, int32(patternJump))
|
atomic.StoreInt32(&t.PlayPattern, int32(patternJump))
|
||||||
|
case <-closer:
|
||||||
|
return
|
||||||
case playState := <-t.setPlaying:
|
case playState := <-t.setPlaying:
|
||||||
playing = playState
|
playing = playState
|
||||||
if playing {
|
if playing {
|
||||||
|
@ -26,6 +26,7 @@ type Tracker struct {
|
|||||||
player audio.Player
|
player audio.Player
|
||||||
synth go4k.Synth
|
synth go4k.Synth
|
||||||
playBuffer []float32
|
playBuffer []float32
|
||||||
|
closer chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracker) LoadSong(song go4k.Song) error {
|
func (t *Tracker) LoadSong(song go4k.Song) error {
|
||||||
@ -42,6 +43,11 @@ func (t *Tracker) LoadSong(song go4k.Song) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tracker) Close() {
|
||||||
|
t.player.Close()
|
||||||
|
t.closer <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
func New(player audio.Player) *Tracker {
|
func New(player audio.Player) *Tracker {
|
||||||
t := &Tracker{
|
t := &Tracker{
|
||||||
QuitButton: new(widget.Clickable),
|
QuitButton: new(widget.Clickable),
|
||||||
@ -51,8 +57,9 @@ func New(player audio.Player) *Tracker {
|
|||||||
rowJump: make(chan int),
|
rowJump: make(chan int),
|
||||||
patternJump: make(chan int),
|
patternJump: make(chan int),
|
||||||
ticked: make(chan struct{}),
|
ticked: make(chan struct{}),
|
||||||
|
closer: make(chan struct{}),
|
||||||
}
|
}
|
||||||
go t.sequencerLoop()
|
go t.sequencerLoop(t.closer)
|
||||||
if err := t.LoadSong(defaultSong); err != nil {
|
if err := t.LoadSong(defaultSong); err != nil {
|
||||||
panic(fmt.Errorf("cannot load default song: %w", err))
|
panic(fmt.Errorf("cannot load default song: %w", err))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user