From 73cbc4314f7dff692e910d74c20d665141f15225 Mon Sep 17 00:00:00 2001 From: vsariola <5684185+vsariola@users.noreply.github.com> Date: Sat, 6 Feb 2021 17:12:53 +0200 Subject: [PATCH] fix(tracker): clamp CurrentInstrument and CurrentUnit when song is loaded --- tracker/tracker.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tracker/tracker.go b/tracker/tracker.go index 09291c8..b57e0e6 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -82,6 +82,12 @@ func (t *Tracker) LoadSong(song sointu.Song) error { defer t.songPlayMutex.Unlock() t.song = song 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 { t.sequencer.SetPatch(song.Patch) t.sequencer.SetRowLength(song.SamplesPerRow())