Check the text of structural edits and refuse stale instruments
AddRegion, RemoveRegion and MoveRegion now refuse an edit whose written text would read differently from the nodes, as when a comment that never ends takes in the text after it, and an instrument whose regions were changed other than by Apply. Build refuses an unknown trigger and an empty random range. Add tests for edits across files, defines, skipped regions and edge cases, a random-sequence test and FuzzRegionEdits. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"path"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -72,6 +73,12 @@ func NewRegion(sample string) Region {
|
||||
return r
|
||||
}
|
||||
|
||||
// triggers returns the values that trigger can have.
|
||||
func triggers() []string {
|
||||
info, _ := Lookup("trigger")
|
||||
return info.Options
|
||||
}
|
||||
|
||||
// checkRegion returns an error saying why a region can't be written as it is:
|
||||
// the opcodes for it would be empty, or would be read as something else, or
|
||||
// would never match a note.
|
||||
@@ -81,10 +88,14 @@ func checkRegion(r Region) error {
|
||||
return errors.New("the sample is empty")
|
||||
case r.Trigger == "":
|
||||
return errors.New("the trigger is empty")
|
||||
case !slices.Contains(triggers(), r.Trigger):
|
||||
return fmt.Errorf("the trigger %q isn't one of %s", r.Trigger, strings.Join(triggers(), ", "))
|
||||
case r.OffMode != "fast" && r.OffMode != "time" && r.OffMode != "normal":
|
||||
return fmt.Errorf("the off mode %q isn't fast, time or normal", r.OffMode)
|
||||
case r.SequenceLength < 1 || r.SequencePosition < 1:
|
||||
return errors.New("the sequence length and position start at 1")
|
||||
case r.HighRandom <= r.LowRandom:
|
||||
return errors.New("the random range is empty, so the region never plays")
|
||||
case r.HighKey < r.LowKey:
|
||||
return errors.New("the highest key is below the lowest")
|
||||
case r.HighVelocity < r.LowVelocity:
|
||||
|
||||
Reference in New Issue
Block a user