8 Commits
Author SHA1 Message Date
aneurinandClaude Sonnet 5.5 49fd867283 Add region lookup and structural edits, and reject regions Build can't write
Instrument.Source returns the flattened region and header behind a typed
region. AddRegion, RemoveRegion and MoveRegion edit the document and read
the instrument again, restoring the document if a region would read
differently. NewRegion returns a region with the format's defaults, and
Build refuses a region that can't be read back as it is.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-02 01:19:40 +00:00
aneurinandClaude Sonnet 5.5 535856ba77 Read repeated point spellings in a fixed order and end comments at a carriage return
Two spellings of one curve point, as v064 and v64, now give the same
result each time. A line comment ends at a lone carriage return, as in
sfizz. Header.Set's documentation says an include in the header's range
can override what it sets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-02 00:46:19 +00:00
aneurinandClaude Sonnet 5.5 8134660721 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>
2026-12-01 20:38:57 +00:00
aneurinandClaude Sonnet 5.5 158661eefe 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>
2026-12-01 19:08:00 +00:00
aneurinandClaude Sonnet 5.5 83c905633c Apply changes to a typed region as patches to its own header
Instrument.Patches works out the opcode changes that make region i read as an
updated Region, checking them against the reader, and Instrument.Apply makes
them in the document. Only the changed settings are touched, always in the
region's own header, so unknown opcodes and what other regions inherit stay as
they are. A change the header can't hold is an error and changes nothing.

FlatRegion gains Own, Inherited and Header to trace a region to its source, and
regionLines lists a region's opcodes with the field each sets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-01 18:42:17 +00:00
aneurinandClaude Sonnet 5.5 cc484ac3ef Split instrument.go into model, controls and modulation files
No behaviour change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-01 18:19:11 +00:00
aneurinandClaude Sonnet 5.5 cf54471778 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>
2026-12-01 18:12:16 +00:00
aneurinandClaude Sonnet 5.5 d124690ecf Add lossless SFZ document, flattening, typed model and opcode registry
Parse keeps a file exactly as written, with #define and #include
unexpanded and each include as its own file in a tree. Flatten resolves
directives and header inheritance, and Flat.Instrument reads regions into
the typed model ported from Zampler's internal/sfz. The opcode registry
is generated from the SFZ format's syntax data and drives Lookup, GetAs
and Validate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-01 17:38:10 +00:00