Rewrite the code comments for consistent tone and accuracy

Comments only: the tokens of every Go file are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 19:08:00 +00:00
co-authored by Claude Sonnet 5.5
parent 41f752e1c1
commit 158661eefe
27 changed files with 716 additions and 437 deletions
+26
View File
@@ -42,6 +42,7 @@ func parseText(t *testing.T, text string) *Instrument {
return parseFiles(t, map[string]string{"main.sfz": text}).Flatten().Instrument()
}
// near reports whether two numbers are equal to within a rounding error.
func near(a, b float64) bool { return math.Abs(a-b) < 1e-9 }
// TestVariableNames checks that a variable's name ends at the shortest
@@ -59,6 +60,8 @@ func TestVariableNames(t *testing.T) {
}
}
// TestFlatten checks that Flatten reads includes, variables and comments as
// the format says.
func TestFlatten(t *testing.T) {
doc := parseFiles(t, map[string]string{
"main.sfz": "#define $DIR Data // the folder\n" +
@@ -101,6 +104,8 @@ func TestVariableOpcodes(t *testing.T) {
}
}
// TestParseErrors checks the errors that Parse returns for includes that
// loop, nest too deeply or can't be read.
func TestParseErrors(t *testing.T) {
// An include loop and an include nested too deeply are refused (spec:
// "recursion must be avoided"; sfizz limits the depth).
@@ -140,6 +145,8 @@ func TestParseErrors(t *testing.T) {
}
}
// TestIncludes checks that Includes lists the files that a file includes
// itself.
func TestIncludes(t *testing.T) {
// A file's includes are listed once each, in order, with its own
// variables substituted, backslashes read as slashes and paths cleaned.
@@ -161,6 +168,8 @@ func TestIncludes(t *testing.T) {
}
}
// TestInheritance checks which opcodes a region takes from the headers above
// it.
func TestInheritance(t *testing.T) {
inst := parseText(t, `
<control> default_path=One/
@@ -220,6 +229,7 @@ func TestInheritance(t *testing.T) {
}
}
// TestDefaults checks the values of a region that sets nothing.
func TestDefaults(t *testing.T) {
r := parseText(t, "<region> sample=a.wav").Regions[0]
// Spec: lovel 1, hivel 127, pitch_keycenter 60, pitch_keytrack 100,
@@ -237,6 +247,8 @@ func TestDefaults(t *testing.T) {
}
}
// TestKeysAndNotes checks how keys, note names and the offsets of the control
// header set a region's keys.
func TestKeysAndNotes(t *testing.T) {
inst := parseText(t, `
<control> note_offset=1 octave_offset=-1
@@ -279,6 +291,8 @@ func TestKeysAndNotes(t *testing.T) {
}
}
// TestControllers checks how modulation by controllers, and the conditions on
// them, are read.
func TestControllers(t *testing.T) {
inst := parseText(t, `
<control> set_cc7=127 set_hdcc20=0.25 set_cc64=0 label_cc20=Mic mix
@@ -373,6 +387,8 @@ func TestControllers(t *testing.T) {
}
}
// TestVariantsAndChokes checks how round robins, random variants and choke
// groups are read.
func TestVariantsAndChokes(t *testing.T) {
inst := parseText(t, `
<region> sample=plain.wav
@@ -411,6 +427,7 @@ func TestVariantsAndChokes(t *testing.T) {
}
}
// TestStartingControllers checks the starting values of the controllers.
func TestStartingControllers(t *testing.T) {
// Without set_cc, volume starts at 100, pan in the middle and expression
// at full (sfizz); other controllers start at 0 (sfizz). The controllers
@@ -428,6 +445,7 @@ func TestStartingControllers(t *testing.T) {
}
}
// TestControllerConditions checks how the ranges of locc and hicc are read.
func TestControllerConditions(t *testing.T) {
// locc and hicc include both ends, and hiccN includes all of value N
// (sfizz), so a controller at 0.5, which is 63.5 of 127, is within hicc63
@@ -472,6 +490,8 @@ func TestControllerConditions(t *testing.T) {
}
}
// TestKeyswitches checks the keyswitches that regions need, and the range of
// keys that they make.
func TestKeyswitches(t *testing.T) {
// Every region is kept with the keyswitches it needs, and the first
// articulation is the one down at the start unless sw_default says
@@ -515,6 +535,8 @@ func TestKeyswitches(t *testing.T) {
}
}
// TestModulationsAndBend checks how a region's stereo width, pitch bend and
// modulation of its settings are read.
func TestModulationsAndBend(t *testing.T) {
inst := parseText(t, `
<region> sample=a.wav width=50 width_oncc3=-25 gain_oncc4=3 pitch_oncc5=100 bend_up=1200 bend_down=-100 bend_step=100
@@ -543,6 +565,8 @@ func TestModulationsAndBend(t *testing.T) {
}
}
// TestOtherOpcodes checks how the other opcodes the typed model reads are
// read, and that those it doesn't are counted.
func TestOtherOpcodes(t *testing.T) {
inst := parseText(t, `
<region> sample=a.wav tune=-20 transpose=1 pitch_keytrack=0 offset=100 amp_veltrack=40 group_volume=-3
@@ -562,6 +586,8 @@ trigger=release rt_decay=6 loop_mode=loop_continuous loopstart=10 loop_end=20 am
}
}
// TestSplendid checks the typed instrument that the Splendid Grand Piano
// fixture makes.
func TestSplendid(t *testing.T) {
doc, err := ParseFile(os.DirFS(filepath.Join("testdata", "splendid")), "Splendid Grand Piano.sfz")
if err != nil {