fix(tracker): clamp CurrentInstrument and CurrentUnit when song is loaded

This commit is contained in:
vsariola 2021-02-06 17:12:53 +02:00
parent 207ae5195d
commit 73cbc4314f

View File

@ -82,6 +82,12 @@ func (t *Tracker) LoadSong(song sointu.Song) error {
defer t.songPlayMutex.Unlock() defer t.songPlayMutex.Unlock()
t.song = song t.song = song
t.ClampPositions() t.ClampPositions()
if l := len(t.song.Patch.Instruments); t.CurrentInstrument >= len(t.song.Patch.Instruments) {
t.CurrentInstrument = l - 1
}
if l := len(t.song.Patch.Instruments[t.CurrentInstrument].Units); t.CurrentUnit >= l {
t.CurrentUnit = l - 1
}
if t.sequencer != nil { if t.sequencer != nil {
t.sequencer.SetPatch(song.Patch) t.sequencer.SetPatch(song.Patch)
t.sequencer.SetRowLength(song.SamplesPerRow()) t.sequencer.SetRowLength(song.SamplesPerRow())