feat(sointu): update synth instead of recompiling if no commands (units) change

this avoids the nasty clicking resulting from complete reset / recompilation of the synth, which was the previous case
This commit is contained in:
vsariola
2021-01-28 22:35:27 +02:00
parent 61437db0d6
commit 6c97b5e736
4 changed files with 52 additions and 17 deletions

View File

@ -88,11 +88,12 @@ func (s *Sequencer) ReadAudio(buffer []float32) (int, error) {
return totalRendered * 2, fmt.Errorf("despite %v attempts, Sequencer.ReadAudio could not fill the buffer (rowLength was %v, should be >> 0)", SEQUENCER_MAX_READ_TRIES, s.rowLength)
}
// Sets the synth used by the sequencer. This takes ownership of the synth: the
// synth should not be called by anyone else than the sequencer afterwards
func (s *Sequencer) SetSynth(synth sointu.Synth) {
// Updates the patch of the synth
func (s *Sequencer) SetPatch(patch sointu.Patch) {
s.mutex.Lock()
s.synth = synth
if s.synth != nil {
s.synth.Update(patch)
} // TODO: what is s.synth is nil?
s.mutex.Unlock()
}

View File

@ -69,17 +69,11 @@ func (t *Tracker) LoadSong(song sointu.Song) error {
t.songPlayMutex.Lock()
defer t.songPlayMutex.Unlock()
t.song = song
if synth, err := bridge.Synth(song.Patch); err != nil {
fmt.Printf("error loading synth: %v\n", err)
t.synth = nil
} else {
t.synth = synth
}
t.PlayPosition.Clamp(song)
t.Cursor.Clamp(song)
t.SelectionCorner.Clamp(song)
if t.sequencer != nil {
t.sequencer.SetSynth(t.synth)
t.sequencer.SetPatch(song.Patch)
}
return nil
}
@ -213,12 +207,7 @@ func (t *Tracker) AddInstrument() {
Units: units,
})
}
synth, err := bridge.Synth(t.song.Patch)
if err == nil {
t.sequencer.SetSynth(synth)
} else {
fmt.Printf("%v", err)
}
t.sequencer.SetPatch(t.song.Patch)
}
// SetCurrentNote sets the (note) value in current pattern under cursor to iv