feat(tracker): hook up audio to tracker, we have liftoff

audio still a bit crackly; should probably decouple actual row ticking and rendering of audio (but how does that work with tempo ops?)

sequencer goroutine is a bit weird, too, should rethink
This commit is contained in:
Matias Lahti
2020-11-08 04:17:21 +02:00
parent 175bbb7743
commit 5e45e4f1f4
8 changed files with 146 additions and 5 deletions

View File

@ -1,8 +1,11 @@
package tracker
import (
"fmt"
"gioui.org/widget"
"github.com/vsariola/sointu/go4k"
"github.com/vsariola/sointu/go4k/audio"
"github.com/vsariola/sointu/go4k/bridge"
)
type Tracker struct {
@ -11,14 +14,47 @@ type Tracker struct {
CursorRow int
CursorColumn int
DisplayPattern int
PlayPattern int32
PlayRow int32
ActiveTrack int
CurrentOctave byte
Playing bool
ticked chan struct{}
setPlaying chan bool
rowJump chan int
patternJump chan int
player audio.Player
synth go4k.Synth
playBuffer []float32
}
func New() *Tracker {
return &Tracker{
func (t *Tracker) LoadSong(song go4k.Song) error {
if err := song.Validate(); err != nil {
return fmt.Errorf("invalid song: %w", err)
}
t.song = song
if synth, err := bridge.Synth(song.Patch); err != nil {
fmt.Println("error loading synth: %v", err)
t.synth = nil
} else {
t.synth = synth
}
return nil
}
func New(player audio.Player) *Tracker {
t := &Tracker{
QuitButton: new(widget.Clickable),
CurrentOctave: 4,
song: defaultSong,
player: player,
setPlaying: make(chan bool),
rowJump: make(chan int),
patternJump: make(chan int),
ticked: make(chan struct{}),
}
go t.sequencerLoop()
if err := t.LoadSong(defaultSong); err != nil {
panic(fmt.Errorf("cannot load default song: %w", err))
}
return t
}