Bound parsing work and fix writer, lexer and keyswitch bugs
- Count variable expansions against MaxBytes and stop substituting past it, so nested #defines can't grow exponentially. Read at most MaxBytes from a reader. - Lex in linear time: end an opcode value at the next line break with the same regexp, and merge text nodes by slicing. Cap variable names at 128 bytes. - Read a byte order mark as space so a directive after it is recognised. - Refuse in WriteFiles an include path that is absolute or leaves the folder, and report include.outside and sample.outside from Validate. - Give a lone sw_lokey or sw_hikey a one-key range. - Sum controller modulations in a fixed order so Instrument is deterministic. - Stop samplePrefix looping on a sample at the root. - Validate without lexing plain opcodes again, and cache registry lookups. - Add regression tests and FuzzWrite, FuzzEdit and FuzzBuild. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+33
-15
@@ -350,8 +350,11 @@ func keyswitchRange(regions []Opcodes) *KeyswitchRange {
|
||||
if r == nil {
|
||||
r = &KeyswitchRange{Low: 127, High: 0}
|
||||
}
|
||||
if lowOK && highOK {
|
||||
keys = append(keys, low+shift, high+shift)
|
||||
if lowOK {
|
||||
keys = append(keys, low+shift)
|
||||
}
|
||||
if highOK {
|
||||
keys = append(keys, high+shift)
|
||||
}
|
||||
for _, k := range keys {
|
||||
r.Low, r.High = min(r.Low, k), max(r.High, k)
|
||||
@@ -872,18 +875,39 @@ func (e evaluator) modulations(ops Opcodes, only ...string) []Modulation {
|
||||
// form targetccN, shaped by target_curveccN at the controller's value.
|
||||
func (e evaluator) modulation(ops Opcodes, target string, cc func(int) float64, from int) float64 {
|
||||
total := 0.0
|
||||
for _, m := range modulators(ops, target, from) {
|
||||
total += m.depth * e.shape(ops, target, m.controller, cc(m.controller))
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
// modulatorOpcode is a controller modulation of a target in a region's
|
||||
// opcodes.
|
||||
type modulatorOpcode struct {
|
||||
name string
|
||||
controller int
|
||||
depth float64
|
||||
}
|
||||
|
||||
// modulators returns the controller modulations of a target from the
|
||||
// controller given up, whose depths are numbers, ordered by controller and then
|
||||
// by name. The order makes sums of them, which floating-point addition makes
|
||||
// depend on it, the same each time.
|
||||
func modulators(ops Opcodes, target string, from int) []modulatorOpcode {
|
||||
var out []modulatorOpcode
|
||||
for name, v := range ops {
|
||||
n, ok := modulator(name, target)
|
||||
if !ok || n < from {
|
||||
continue
|
||||
}
|
||||
depth, ok := parseNumber(v)
|
||||
if !ok {
|
||||
continue
|
||||
if depth, ok := parseNumber(v); ok {
|
||||
out = append(out, modulatorOpcode{name, n, depth})
|
||||
}
|
||||
total += depth * e.shape(ops, target, n, cc(n))
|
||||
}
|
||||
return total
|
||||
slices.SortFunc(out, func(a, b modulatorOpcode) int {
|
||||
return cmp.Or(cmp.Compare(a.controller, b.controller), cmp.Compare(a.name, b.name))
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
// amplitude returns the region's amplitude as a factor: amplitude and the
|
||||
@@ -896,14 +920,8 @@ func (e evaluator) amplitude(ops Opcodes, cc func(int) float64) float64 {
|
||||
a *= v / 100
|
||||
}
|
||||
}
|
||||
for name, v := range ops {
|
||||
n, ok := modulator(name, "amplitude")
|
||||
if !ok || n < extendedOnly {
|
||||
continue
|
||||
}
|
||||
if depth, ok := parseNumber(v); ok {
|
||||
a *= depth / 100 * e.shape(ops, "amplitude", n, cc(n))
|
||||
}
|
||||
for _, m := range modulators(ops, "amplitude", extendedOnly) {
|
||||
a *= m.depth / 100 * e.shape(ops, "amplitude", m.controller, cc(m.controller))
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user