v1.3.0 release: graceful-release fix, quickstart template + demo, documentation accuracy pass

- Fixed: SynthesizerBase subclasses' release/free now dispatch correctly (gated
  synths were hard-freed instead of released).
- New: quickstart project template + LyrebirdQuickstartDemo.
- Docs: every example typechecked or provably illustrative (426->542); ~20
  wrong-API examples fixed; root docs brought under the compile guard.
- Fixed: NRT/Score demo Package.swift build from terminal again.

See RELEASES.md for details.
This commit is contained in:
2026-07-17 14:05:01 -07:00
parent 63d6e0746f
commit 560724d116
149 changed files with 5010 additions and 1029 deletions
+24 -17
View File
@@ -7,8 +7,8 @@ The base unit of signal production in Lyrebird.
```swift
protocol Generator: AnyObject {
var rate: ProcessingRate { get }
func calculatedSamples(graph: SynthGraph, count: Int) -> [[LyrebirdFloat]]
func floatValue(graph: SynthGraph) -> LyrebirdFloat
func calculatedSamples(graph: SynthGraph, count: Int) -> [[Double]]
func floatValue(graph: SynthGraph) -> Double
}
protocol AudioGenerator: Generator {} // rate == .audio
@@ -112,32 +112,39 @@ describe(OscSin.self) // Audio: OscSin.Audio Control: OscSin.Control
## Type Aliases
```swift
typealias LyrebirdFloat = Double
typealias LyrebirdInt = Int
typealias LyrebirdFloatClosureBody = (SynthGraph, Int) -> LyrebirdFloat
typealias ClosureBody = (SynthGraph, Int) -> Double // RT-safe closure signature
```
Samples are plain `Double` and counts plain `Int` — Lyrebird does not wrap them in aliases.
## ValidGeneratorInput Protocol
Enables seamless mixing of constants, generators, parameter keys, and closures as generator inputs. All of the following are valid:
Enables seamless mixing of constants, generators, and closures as generator inputs. All of the following are valid:
```swift
OscSin.Audio(freq: 440.0) // Float literal
OscSin.Audio(freq: someGenerator) // another Generator
OscSin.Audio(freq: "FreqParam") // string parameter key — resolved at runtime
OscSin.Audio(freq: { g, i in ... }) // closure
let someGenerator: OscSin.Control = OscSin.Control(freq: 2.0, mul: 10.0, add: 440.0)
let a: OscSin.Audio = OscSin.Audio(freq: 440.0) // Double literal
let b: OscSin.Audio = OscSin.Audio(freq: 60) // Int literal
let c: OscSin.Audio = OscSin.Audio(freq: someGenerator) // another Generator
let d: OscSin.Audio = OscSin.Audio(freq: Closure { graph, i in Double(i) }) // closure
```
To drive an input from a live parameter, wire a `@LiveParam`'s projected value (`$freq`, a
`ParameterNode`) into the generator. `String` is **not** a `ValidGeneratorInput` — the old
string-parameter-key input was removed when `ParameterNode` / `UIParamNode` became
`ControlGenerator`s.
```swift
protocol ValidGeneratorInput {
func calculatedSamples(graph: SynthGraph, count: Int) -> [[LyrebirdFloat]]
func floatValue(graph: SynthGraph) -> LyrebirdFloat
func intValue(graph: SynthGraph) -> LyrebirdInt
func calculatedSamples(graph: SynthGraph, count: Int) -> [[Double]]
func floatValue(graph: SynthGraph) -> Double
func intValue(graph: SynthGraph) -> Int
func needsInterpolation() -> Bool
func sampleBlock(graph: SynthGraph, count: Int, previousValue: LyrebirdFloat) -> [LyrebirdFloat]
func sampleBlock(graph: SynthGraph, count: Int, previousValue: Double) -> [Double]
}
// Conforming types: Double, Int, String, any Generator, Closure
// Conforming types: Double, Int, any Generator, Closure, GeneratorInputProvider
// Contract: calculatedSamples must always return a non-empty outer array (at least one channel).
```
@@ -199,7 +206,7 @@ mono-izes the generator under arithmetic.
When one or both operands are non-Generator literals (`Double` or `Int`), `BinaryOpGenerator`
uses `floatValue` instead of `calculatedSamples` for that side. This avoids the per-block
`[[LyrebirdFloat](repeating:count:)]` heap allocation that the `Double`/`Int` conformers would
`[[Double](repeating:count:)]` heap allocation that the `Double`/`Int` conformers would
otherwise produce. The classification is performed once in `init` and stored as `lhsIsLiteral`
/ `rhsIsLiteral` — no type-metadata checks on the RT thread.
@@ -251,7 +258,7 @@ is never violated in engine-driven usage. New generators **must** follow this pa
```swift
// Canonical new-generator calculatedSamples skeleton:
public func calculatedSamples(graph: SynthGraph, count: Int) -> [[LyrebirdFloat]] {
public func calculatedSamples(graph: SynthGraph, count: Int) -> [[Double]] {
precondition(count <= _result[0].count,
"count \(count) exceeds pre-allocated buffer. "
+ "Ensure blockSize <= lyrebirdDefaultResultBufferSize.")
+3 -3
View File
@@ -31,8 +31,8 @@ Subclass `SynthesizerBase` and override `build()`. Declare mutable parameters wi
```swift
// Example — your synthesizer, defined by subclassing SynthesizerBase
final class SineTone: SynthesizerBase {
@LiveParam var freq: LyrebirdFloat = 440.0
@LiveParam var amp: LyrebirdFloat = 0.5
@LiveParam var freq: Double = 440.0
@LiveParam var amp: Double = 0.5
override func build() {
let osc = OscSin.Audio(freq: $freq, phase: 0.0)
@@ -234,7 +234,7 @@ Override `release(engine:)` in synthesizers that have an envelope gate:
```swift
final class GatedNote: SynthesizerBase {
@LiveParam var gate: LyrebirdFloat = 1.0
@LiveParam var gate: Double = 1.0
override func build() {
// … gate drives EnvelopeGen …
+48 -3
View File
@@ -31,6 +31,13 @@ public protocol Synthesizer: AnyObject {
Default `evaluate` and `free` are provided by a protocol extension. Default `release` throws `SynthesizerError.noGate` — override it in synthesizers that have a gate input.
`SynthesizerBase` re-declares `release(engine:)` and `free(engine:)` as `open` members mirroring
those defaults. This is deliberate and load-bearing: a protocol-extension default binds
statically at the conformance, so without the class members a subclass's implementation would
be unreachable through an `any Synthesizer` — including `Group.release`'s cascade to its
children, which would then see `.noGate` and hard-free every gated child. Subclass
`SynthesizerBase` and `override`. See `ARCHITECTURE.md` §9.1.
---
## Synthesizer Lifecycle
@@ -41,7 +48,7 @@ Signal the synthesizer to begin releasing (set gate → 0, trigger doneAction en
```swift
final class GatedNote: SynthesizerBase {
@LiveParam var gate: LyrebirdFloat = 1.0
@LiveParam var gate: Double = 1.0
override func build() { /* … gate drives EnvelopeGen … */ }
@@ -102,8 +109,8 @@ Most Synthesizer implementations should subclass `SynthesizerBase` rather than c
```swift
// Example — your synthesizer, defined by subclassing SynthesizerBase
final class SineTone: SynthesizerBase {
@LiveParam var freq: LyrebirdFloat = 440.0
@LiveParam var amp: LyrebirdFloat = 0.5
@LiveParam var freq: Double = 440.0
@LiveParam var amp: Double = 0.5
override func build() {
let osc = OscSin.Audio(freq: $freq, phase: 0.0)
@@ -192,6 +199,44 @@ producing a linearly-interpolated audio-rate buffer ramping to the new value. Th
sized to the engine's control block: one ramp per audio block when `controlBlockSize ==
blockSize` (default), or K ramps per audio block when `controlBlockSize < blockSize`.
### Changing a `@LiveParam` from a Routine / Task
`@LiveParam` values can be driven from a `LyrebirdRoutine` / `LyrebirdTask` body — algorithmic,
sequential, timed control code that runs on a **background thread**. The `ParameterNode`'s value
setter is a releasing atomic store, so a routine/task-body write is safe (a single control-side
producer alongside the RT thread's acquiring load) — the same store as the main-thread setter.
Two facts shape how you access the parameter:
- The synth is `@MainActor`-isolated, so `tone.freq` and `tone.$freq` can't be reached from the
`@Sendable` body (that's a main-actor access from a background thread).
- The projected node `$freq` is a **`ParameterNode`, which is `Sendable`**.
So **capture the projected node on the main actor at setup, then drive it from the body** with
`ctx.set` / `ctx.ramp` (see `docs/tooling/routine-task.md` § Live parameters):
```swift
let tone = SineTone() // @MainActor setup
let freq = tone.$freq // ParameterNode — Sendable, captured once
LyrebirdTask.run(engine: engine) { ctx in // @Sendable body — background thread
ctx.add(tone)
try ctx.wait(beats: 1)
ctx.set(freq, to: 660) // step
try ctx.ramp(freq, to: 220, beats: 2) // glide, blocks for the duration
ctx.remove(tone)
}
```
`ctx.set` / `ctx.ramp` take a **`ParameterNode` only** — `@UIParam`'s `UIParamNode` is `@Observable`
and main-thread-only, so it is not a valid target from a background body; update `@UIParam` from the
main thread.
> No-capture alternative: a synth driven mostly from routines can declare the node directly as
> `nonisolated let freq = ParameterNode(440)` instead of `@LiveParam` — reachable from the body with
> no capture line (`ctx.set(tone.freq, to: 660)`), trading the plain-`Double` value sugar and the
> `$`-projection.
### Auto-registration via Mirror
`SynthesizerBase.rebuildGraph()` walks `Mirror(reflecting: self)` plus the superclass chain
+2 -2
View File
@@ -366,8 +366,8 @@ final class MyOsc: GeneratorBase, AudioGenerator {
Key points:
- `freqIsGenerator` is stored at init, not checked per block.
- The `calculatedSamples` / `floatValue` call is **outside the inner loop** — only the index lookup happens per sample.
- When `freqIsGenerator` is false (literal `Double`/`Int`, `String`, or `Closure`), the scalar path calls `floatValue` once — zero extra allocation. `ConstantGeneratorInput` conforms to `Generator` and therefore takes the audio-rate `calculatedSamples` path; its buffer is pre-allocated so the path is RT-safe.
- String parameter key inputs are classified as non-generator (`String` does not conform to `Generator`), so they always use the block-rate scalar path. This is correct: parameter updates are control-rate by design.
- When `freqIsGenerator` is false (literal `Double`/`Int` or `Closure`), the scalar path calls `floatValue` once — zero extra allocation. `ConstantGeneratorInput` conforms to `Generator` and therefore takes the audio-rate `calculatedSamples` path; its buffer is pre-allocated so the path is RT-safe.
- To drive an input from a live parameter, wire a `@LiveParam`'s projected value (`$name`, a `ParameterNode`) — a `ControlGenerator` — into it. (`String` is not a `ValidGeneratorInput`; the old string-parameter-key input was removed when `ParameterNode` / `UIParamNode` became `ControlGenerator`s.)
### FM synthesis example