fix(tracker): when reassigning unit IDs, update send targets. fixes instrument loading

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-05-12 21:53:30 +03:00
parent cd700ed954
commit 9efddd673d

View File

@ -1267,9 +1267,13 @@ func (m *Model) freeUnitIDs(units []sointu.Unit) {
}
func (m *Model) assignUnitIDs(units []sointu.Unit) {
rewrites := map[int]int{}
for i := range units {
if units[i].ID == 0 || m.usedIDs[units[i].ID] {
if id := units[i].ID; id == 0 || m.usedIDs[id] {
m.maxID++
if id > 0 {
rewrites[id] = m.maxID
}
units[i].ID = m.maxID
}
m.usedIDs[units[i].ID] = true
@ -1277,6 +1281,13 @@ func (m *Model) assignUnitIDs(units []sointu.Unit) {
m.maxID = units[i].ID
}
}
for i, u := range units {
if target, ok := u.Parameters["target"]; u.Type == "send" && ok {
if newId, ok := rewrites[target]; ok {
units[i].Parameters["target"] = newId
}
}
}
}
func (m *Model) computePatternUseCounts() {