v2.1.0 release: Swift 6.4 modernization

Typed throws across the closed-error-set APIs (OSC, MIDI, engine add/schedule,
bus/config/parameter, and the WAV/RF64/Spectral file codecs — source-compatible
narrowing, new .ioFailure cases), plus internal hardening: NSLock-guarded
scheduling/MIDI state moved to Mutex<State>, and the Spectral/FFT scratch owners
moved to a ~Copyable RTScratchBuffer RAII buffer. No API or behavioral change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-09-24 19:54:59 -07:00
parent 2c20b02e59
commit 844dc4d9cd
42 changed files with 835 additions and 640 deletions
+15
View File
@@ -93,6 +93,21 @@ when Lyrebird's MINOR rolls over.
| `func fillRampedResult(into:from:to:mulAdd:graph:count:)` | ControlGenerator ramp helper |
| `func lastGeneratorSampleOrFloat(_:isGenerator:graph:count:)` | block-constant capture from a generator input |
### Scratch buffers (`Buffers/RTScratchBuffer.swift`)
| Symbol | Signature |
|---|---|
| `struct RTScratchBuffer<Element>: ~Copyable` | single-owner heap scratch buffer; compiler-enforced single free at `deinit`, no ARC |
| `RTScratchBuffer.init(count:)` | allocate + zero-fill (`Element: Numeric`) |
| `RTScratchBuffer.init(count:repeating:)` | allocate + fill with a value |
| `RTScratchBuffer.baseAddress` / `.count` / `subscript` | `@inline(__always)`; `baseAddress` for vDSP / Accelerate / `memcpy` interop |
Replaces the hand-paired `UnsafeMutablePointer.allocate` / `deinitialize` /
`deallocate` in a scratch-owning generator. Store as a `let` assigned in `init`
(never a per-call local) so `deinit` frees off the RT thread. Not for
`[UnsafeMutablePointer]` per-channel arrays (a `~Copyable` type cannot be
`Array`-stored) or capacity-1 scalar boxes used via `.pointee` — leave those raw.
### PRNG (`Generators/Noise/WhiteNoise.swift`)
| Symbol | Signature |
+22
View File
@@ -1014,6 +1014,28 @@ A family of module-level free functions, base classes, and methods exist to elim
> **Out-of-tree extension packages:** these helpers are exposed as `@_spi(LyrebirdExtensions) public`. Add `@_spi(LyrebirdExtensions) import LyrebirdSynth` to any generator implementation file outside the core module. Full surface and stability policy: [extension-sdk.md](extension-sdk.md).
### `RTScratchBuffer<Element>` — single-owner RAII scratch buffer
`Buffers/RTScratchBuffer.swift`. A `~Copyable` heap buffer that replaces the
hand-paired `UnsafeMutablePointer.allocate` / `deinitialize` / `deallocate` a
scratch-owning generator otherwise repeats per buffer. The compiler guarantees it
is freed exactly once at `deinit` (with the right count) and can never be
copy-aliased; it carries no ARC and every accessor is `@inline(__always)`, so a
hot loop compiles to the same code as the raw pointer it replaces.
- `init(count:)` allocates + zero-fills (`Element: Numeric`); `init(count:repeating:)`
fills with any value (e.g. a unity gain table: `RTScratchBuffer(count: n, repeating: 1)`).
- Element access is `buffer[i]` (subscript; the setter is `nonmutating`, so a
`let`-held buffer is still writable — matching the raw pointer). Pass
`buffer.baseAddress` to vDSP / Accelerate / `memcpy`; for an offset use
`buffer.baseAddress + k` / `.baseAddress.advanced(by: k)`.
- **Must be a stored property assigned in `init`** — never a local inside
`process` / `_computeSamples`, which would allocate + free every render call.
- Not for `[UnsafeMutablePointer]`-style per-channel arrays (a `~Copyable` type
cannot be stored in an `Array`) nor for capacity-1 scalar boxes used via
`.pointee`; leave those on raw pointers.
- `@_spi(LyrebirdExtensions) public` — add the SPI import in out-of-tree files.
### `_resolvedInput()` — init-time resolution of `any ValidGeneratorInput`
Protocol requirement on `ValidGeneratorInput`. Default impl returns `self`; `GeneratorInputProvider` overrides to call its `make` closure and return a fresh `any ValidGeneratorInput`. Every Generator `init` that takes `any ValidGeneratorInput` parameters MUST call `_resolvedInput()` on each slot before storing or running `is any Generator` classification.