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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user