diff --git a/CHANGELOG.md b/CHANGELOG.md index 100277a..45dc174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). resized ([#145][i145]) ### Fixed +- When loading an instrument, make sure the total number of voices does not go + over the maximum number allowed by vm, and make sure a loaded instrument has + at least 1 voice - Potential ID collisions when clearing unit or pasteing instruments - Assign new IDs to loaded instruments, and fix ID collisions in case they somehow still appear ([#146][i146]) diff --git a/tracker/files.go b/tracker/files.go index 01af83c..1e8acda 100644 --- a/tracker/files.go +++ b/tracker/files.go @@ -12,6 +12,7 @@ import ( "gopkg.in/yaml.v3" "github.com/vsariola/sointu" + "github.com/vsariola/sointu/vm" ) func (m *Model) ReadSong(r io.ReadCloser) { @@ -171,6 +172,16 @@ success: for len(m.d.Song.Patch) <= m.d.InstrIndex { m.d.Song.Patch = append(m.d.Song.Patch, defaultInstrument.Copy()) } + m.d.Song.Patch[m.d.InstrIndex] = sointu.Instrument{} + numVoices := m.d.Song.Patch.NumVoices() + if numVoices >= vm.MAX_VOICES { + // this really shouldn't happen, as we have already cleared the + // instrument and assuming each instrument has at least 1 voice, it + // should have freed up some voices + m.Alerts().Add(fmt.Sprintf("The patch has already %d voices", vm.MAX_VOICES), Error) + return false + } + instrument.NumVoices = clamp(instrument.NumVoices, 1, 32-numVoices) m.assignUnitIDs(instrument.Units) m.d.Song.Patch[m.d.InstrIndex] = instrument if m.d.Song.Patch[m.d.InstrIndex].Comment != "" {