fix(tracker): ID collisions in ClearUnit and Instruments.unmarshal

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2024-09-07 15:20:12 +03:00
parent 9da6c2216c
commit 74972b5ff4
4 changed files with 20 additions and 4 deletions

View File

@ -269,11 +269,13 @@ func (v *Instruments) unmarshal(data []byte) (from, to int, err error) {
if v.d.Song.Patch.NumVoices()+newInstr.Patch.NumVoices() > vm.MAX_VOICES {
return 0, 0, fmt.Errorf("InstrumentListView.unmarshal: too many voices: %d", v.d.Song.Patch.NumVoices()+newInstr.Patch.NumVoices())
}
patch := append(v.d.Song.Patch, make([]sointu.Instrument, len(newInstr.Patch))...)
v.d.Song.Patch = append(v.d.Song.Patch, make([]sointu.Instrument, len(newInstr.Patch))...)
sel := v.Selected()
copy(patch[sel+len(newInstr.Patch):], patch[sel:])
copy(patch[sel:sel+len(newInstr.Patch)], newInstr.Patch)
v.d.Song.Patch = patch
copy(v.d.Song.Patch[sel+len(newInstr.Patch):], v.d.Song.Patch[sel:])
for i := 0; i < len(newInstr.Patch); i++ {
(*Model)(v).assignUnitIDs(newInstr.Patch[i].Units)
v.d.Song.Patch[sel+i] = newInstr.Patch[i]
}
from = sel
to = sel + len(newInstr.Patch) - 1
return