feat(vm): reuse delaytimes if one has already been used before

This commit is contained in:
vsariola 2021-03-21 10:22:47 +02:00
parent eb61fcb130
commit 452a2f6f04

View File

@ -167,11 +167,28 @@ func Encode(patch sointu.Patch, featureSet FeatureSet) (*BytePatch, error) {
continue // skip encoding delays without any delay lines continue // skip encoding delays without any delay lines
} }
countTrack := count*2 - 1 + unit.Parameters["notetracking"] // 1 means no note tracking and 1 delay, 2 means notetracking with 1 delay, 3 means no note tracking and 2 delays etc. countTrack := count*2 - 1 + unit.Parameters["notetracking"] // 1 means no note tracking and 1 delay, 2 means notetracking with 1 delay, 3 means no note tracking and 2 delays etc.
delStart := len(c.DelayTimes) matchIndex := -1
for _, v := range unit.VarArgs { for i := 0; i <= len(c.DelayTimes)-len(unit.VarArgs); i++ {
c.DelayTimes = append(c.DelayTimes, uint16(v)) match := true
for j, v := range unit.VarArgs {
if uint16(v) != c.DelayTimes[i+j] {
match = false
break
}
}
if match {
matchIndex = i
break
}
}
if matchIndex > -1 {
values = append(values, byte(matchIndex), byte(countTrack))
} else {
values = append(values, byte(len(c.DelayTimes)), byte(countTrack))
for _, v := range unit.VarArgs {
c.DelayTimes = append(c.DelayTimes, uint16(v))
}
} }
values = append(values, byte(delStart), byte(countTrack))
} }
c.Commands = append(c.Commands, byte(opcode+unit.Parameters["stereo"])) c.Commands = append(c.Commands, byte(opcode+unit.Parameters["stereo"]))
c.Values = append(c.Values, values...) c.Values = append(c.Values, values...)