fix(tracker): autofix malformed songs with useless params

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-09-22 10:20:52 +03:00
parent 773655ef9c
commit 5c51932f60
3 changed files with 36 additions and 0 deletions

View File

@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
the command line tools. the command line tools.
### Fixed ### Fixed
- If units have useless parameters in their parameter maps, from bugs or from a
malformed yaml file, they are removed and user is warned about it
- Pressing a or 1 when editing note values in hex mode created a note off line - Pressing a or 1 when editing note values in hex mode created a note off line
([#162][i162]) ([#162][i162])
- Warn about plugin sample rate being different from 44100 only after - Warn about plugin sample rate being different from 44100 only after

View File

@ -225,6 +225,7 @@ func (m *Model) change(kind string, t ChangeType, severity ChangeSeverity) func(
} }
if m.changeType&PatchChange != 0 { if m.changeType&PatchChange != 0 {
m.fixIDCollisions() m.fixIDCollisions()
m.fixUnitParams()
m.d.InstrIndex = clamp(m.d.InstrIndex, 0, len(m.d.Song.Patch)-1) m.d.InstrIndex = clamp(m.d.InstrIndex, 0, len(m.d.Song.Patch)-1)
m.d.InstrIndex2 = clamp(m.d.InstrIndex2, 0, len(m.d.Song.Patch)-1) m.d.InstrIndex2 = clamp(m.d.InstrIndex2, 0, len(m.d.Song.Patch)-1)
unitCount := 0 unitCount := 0
@ -481,6 +482,36 @@ func (m *Model) fixIDCollisions() {
} }
} }
var validParameters = map[string](map[string]bool){}
func init() {
for name, unitType := range sointu.UnitTypes {
validParameters[name] = map[string]bool{}
for _, param := range unitType {
validParameters[name][param.Name] = true
}
}
}
func (m *Model) fixUnitParams() {
// loop over all instruments and units and check that unit parameter table
// only has the parameters that are defined in the unit type
fixed := false
for i, instr := range m.d.Song.Patch {
for j, unit := range instr.Units {
for paramName := range unit.Parameters {
if !validParameters[unit.Type][paramName] {
delete(m.d.Song.Patch[i].Units[j].Parameters, paramName)
fixed = true
}
}
}
}
if fixed {
m.Alerts().AddNamed("InvalidUnitParameters", "Some units had invalid parameters, they were removed", Error)
}
}
func (m *Model) updatePatternUseCount() { func (m *Model) updatePatternUseCount() {
for i, track := range m.d.Song.Score.Tracks { for i, track := range m.d.Song.Score.Tracks {
for len(m.cachePatternUseCount) <= i { for len(m.cachePatternUseCount) <= i {

View File

@ -289,6 +289,9 @@ func FuzzModel(f *testing.F) {
if a.Name == "IDCollision" { if a.Name == "IDCollision" {
t.Errorf("Path: %s Model has ID collisions", totalPath) t.Errorf("Path: %s Model has ID collisions", totalPath)
} }
if a.Name == "InvalidUnitParameters" {
t.Errorf("Path: %s Model units with invalid parameters", totalPath)
}
}) })
} }
closeChan <- struct{}{} closeChan <- struct{}{}