fix(tracker): keep instrument properties when loading a preset

Also when loading an instrument from the disk. We only load units,
instrument name and comment. MIDI and the number of voices are kept.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2026-02-14 20:49:30 +02:00
parent 942da94982
commit cd4b85a66b
2 changed files with 6 additions and 16 deletions

View File

@ -470,18 +470,9 @@ 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
(*Model)(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)
(*Model)(m).assignUnitIDs(instrument.Units)
instrument.MIDI = m.d.Song.Patch[m.d.InstrIndex].MIDI // keep the MIDI config of the current instrument
m.d.Song.Patch[m.d.InstrIndex] = instrument
m.d.Song.Patch[m.d.InstrIndex].Name = instrument.Name // only copy the relevant fields to preserve the user defined values e.g. NumVoices and MIDI configuration
m.d.Song.Patch[m.d.InstrIndex].Comment = instrument.Comment
m.d.Song.Patch[m.d.InstrIndex].Units = instrument.Units
return true
}

View File

@ -12,7 +12,6 @@ import (
"strings"
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/vm"
"gopkg.in/yaml.v3"
)
@ -165,10 +164,10 @@ func (m *presetResultList) SetSelected(i int) {
m.d.Song.Patch = append(m.d.Song.Patch, defaultInstrument.Copy())
}
newInstr := m.presetData.cache.results[i].instr.Copy()
newInstr.NumVoices = clamp(m.d.Song.Patch[m.d.InstrIndex].NumVoices, 1, vm.MAX_VOICES)
(*Model)(m).assignUnitIDs(newInstr.Units)
newInstr.MIDI = m.d.Song.Patch[m.d.InstrIndex].MIDI // keep the MIDI config of the current instrument
m.d.Song.Patch[m.d.InstrIndex] = newInstr
m.d.Song.Patch[m.d.InstrIndex].Name = newInstr.Name // only copy the relevant fields to preserve the user defined values e.g. NumVoices and MIDI configuration
m.d.Song.Patch[m.d.InstrIndex].Comment = newInstr.Comment
m.d.Song.Patch[m.d.InstrIndex].Units = newInstr.Units
}
// SearchResult returns the search result at the given index in the search