From cd4b85a66b91e51e695e16a7f2e1b322eaff8795 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sat, 14 Feb 2026 20:49:30 +0200 Subject: [PATCH] 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. --- tracker/instrument.go | 15 +++------------ tracker/presets.go | 7 +++---- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/tracker/instrument.go b/tracker/instrument.go index 334ef9c..769fd43 100644 --- a/tracker/instrument.go +++ b/tracker/instrument.go @@ -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 } diff --git a/tracker/presets.go b/tracker/presets.go index 845181c..500f8ef 100644 --- a/tracker/presets.go +++ b/tracker/presets.go @@ -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