Fix the differences from the spec and sfizz that a conformance review found
Read opcodes under their other names. The registry lists the other names an opcode has, and the typed model now reads each under its own name: amp_release for ampeg_release, offby, bendup, tune_keytrack and the rest. Apply treats an old name as belonging to the same field, so it doesn't leave one behind. Cut a #define's value at the first space, as ARIA and sfizz do, so that two defines can share a line. Before, the first define took the rest of the line, and a kit that writes "#define $lo 1 #define $hi 25" lost its velocity layers. Ignore opcodes before any header when flattening, as sfizz does, and report them as a warning. Included files that hold only opcodes are not affected. Read the limits of a controller the same way each time. A region that sets lohdccN and inherits loccN took whichever the map gave first, so Apply's change could read back as the old limits. The hdcc opcodes now win. Accept -1 for lokey, hikey and key, which SFZ v2 allows, and don't report a region with a hikey of -1 as an inverted range. Cut numbers that don't fit to what a setting can hold, so offset=1e30 doesn't turn negative, and ignore a controller number or octave that overflows. Read polyphony=legato_high, legato_last and legato_low as a limit of 1. Put a new #define after a byte order mark. Mark in the tests where each expected value comes from, correct the tags that the spec doesn't support, and add tests for each of these. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+17
-12
@@ -95,11 +95,11 @@ func TestFlatten(t *testing.T) {
|
||||
// headers, and for part of an opcode's name.
|
||||
func TestVariableOpcodes(t *testing.T) {
|
||||
doc := parseFiles(t, map[string]string{
|
||||
"main.sfz": "#define $RANGE lokey=36 hikey=40\n#define $CC 70\n#define $HEAD <region>\n" +
|
||||
"main.sfz": "#define $RANGE lokey=36\n#define $CC 70\n#define $HEAD <region>\n" +
|
||||
"$HEAD sample=a.wav $RANGE locc$CC=5\n",
|
||||
})
|
||||
ops := doc.Flatten().Regions[0].Opcodes
|
||||
if ops["lokey"] != "36" || ops["hikey"] != "40" || ops["locc70"] != "5" || ops["sample"] != "a.wav" {
|
||||
if ops["lokey"] != "36" || ops["locc70"] != "5" || ops["sample"] != "a.wav" {
|
||||
t.Errorf("%v", ops)
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func TestInheritance(t *testing.T) {
|
||||
got[r.Sample] = r
|
||||
}
|
||||
// A region has the opcodes of the headers above it, its own winning
|
||||
// (spec); a new <group> starts without the last group's opcodes (choice:
|
||||
// (spec); a new <group> starts without the last group's opcodes (sfizz;
|
||||
// the spec doesn't say); and default_path is the one set before the
|
||||
// region.
|
||||
if r := got["One/a b.wav"]; r.Tune != 7 || r.LowVelocity != 64 || r.Pan != 10 {
|
||||
@@ -203,8 +203,8 @@ func TestInheritance(t *testing.T) {
|
||||
if r := got["Two/d.wav"]; r.Tune != 0 || r.LowVelocity != 1 || r.HighVelocity != 90 || r.Pan != 10 {
|
||||
t.Errorf("third region %+v", r)
|
||||
}
|
||||
// A <master> clears the group, and a <global> clears everything (choice:
|
||||
// the spec says a global applies until the next one).
|
||||
// A <master> clears the group, and a <global> clears the master and the
|
||||
// group (sfizz; the spec says a global applies until the next one).
|
||||
if r := got["Two/e.wav"]; r.HighVelocity != 127 || r.Pan != -20 {
|
||||
t.Errorf("fourth region %+v", r)
|
||||
}
|
||||
@@ -215,11 +215,15 @@ func TestInheritance(t *testing.T) {
|
||||
t.Errorf("unread %v", inst.Unread)
|
||||
}
|
||||
|
||||
// Opcodes before any header apply to every region (choice: the spec
|
||||
// doesn't say).
|
||||
if r := parseText(t, "volume=-1\n<region> sample=a.wav").Regions[0]; r.Volume != -1 {
|
||||
// Opcodes before any header belong to no region (sfizz; the spec doesn't
|
||||
// say). The document keeps them, and Validate reports them.
|
||||
if r := parseText(t, "volume=-1\ndefault_path=X/\n<region> sample=a.wav").Regions[0]; r.Volume != 0 || r.Sample != "a.wav" {
|
||||
t.Errorf("opcode before any header %+v", r)
|
||||
}
|
||||
doc := parseFiles(t, map[string]string{"main.sfz": "volume=-1\n<region> sample=a.wav"})
|
||||
if p := doc.Validate(); len(p) != 1 || p[0].Code != "opcode.no-header" || p[0].Severity != SeverityWarning || doc.String() != "volume=-1\n<region> sample=a.wav" {
|
||||
t.Errorf("problems %v, text %q", p, doc.String())
|
||||
}
|
||||
|
||||
// A new <control> resets default_path but keeps the other control
|
||||
// settings (spec, describing ARIA; Cakewalk keeps it).
|
||||
@@ -320,7 +324,8 @@ func TestControllers(t *testing.T) {
|
||||
}
|
||||
|
||||
// Modulation by a controller is kept as it is, to be applied as notes
|
||||
// play: the setting has only its own value (spec: _onccN adds), with
|
||||
// play: the setting has only its own value (choice: the spec doesn't say how _onccN
|
||||
// combines with it, and its tune_onccN example reads as adding), with
|
||||
// pan's curve 1 and the others' straight one, in the settings' own
|
||||
// units, and the depth of an amplitude as a percentage.
|
||||
r := got["natural.wav"]
|
||||
@@ -416,8 +421,8 @@ func TestVariantsAndChokes(t *testing.T) {
|
||||
if r := got["zero.wav"]; r.SequenceLength != 1 || r.SequencePosition != 1 || r.LowRandom != 0 || r.HighRandom != 1 {
|
||||
t.Errorf("out of range %+v", r)
|
||||
}
|
||||
// polyphony_group is v2's name for group (spec), and off_by may name group
|
||||
// 0 (spec).
|
||||
// polyphony_group is ARIA's alias of group (spec), and an off_by of group
|
||||
// 0 is kept for the host to read, as the spec says some players ignore it.
|
||||
if r := got["v2.wav"]; r.Group != 7 || r.OffBy == nil || *r.OffBy != 0 {
|
||||
t.Errorf("polyphony_group %+v", r)
|
||||
}
|
||||
@@ -616,7 +621,7 @@ func TestSplendid(t *testing.T) {
|
||||
}
|
||||
|
||||
// The lowest region that always plays: its own release plus 0.7 s from the
|
||||
// Release control at 0.35 × 2 (spec: _onccN adds), and a hold and decay
|
||||
// Release control at 0.35 × 2 (choice: _onccN adds), and a hold and decay
|
||||
// shortened by its key. Its level comes from the volume control at 100
|
||||
// through curve 4, x² (sfizz), multiplied (sfizz), which is kept to be
|
||||
// applied as notes play.
|
||||
|
||||
Reference in New Issue
Block a user