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:
@@ -197,6 +197,49 @@ ctx.remove(synth)
|
||||
ctx.remove(synth, at: sampleTime)
|
||||
```
|
||||
|
||||
### Live parameters
|
||||
|
||||
Change a running synth's `@LiveParam` from the body. Unlike the engine calls above, a `ParameterNode` write goes straight to its lock-free atomic — no main-thread hop — so it runs inline on the routine's own thread; the RT thread picks it up at the next block.
|
||||
|
||||
> `@UIParam` (`UIParamNode`) is **not** a valid target: its value is `@Observable`-tracked and main-thread-only, so it can't be written from the routine's background thread. `ctx.set` / `ctx.ramp` take a `ParameterNode`; update `@UIParam` from the main thread.
|
||||
|
||||
```swift
|
||||
ctx.set(param, to: 8.0) // step: jump to a value
|
||||
try ctx.ramp(param, to: 0.5, seconds: 3) // glide: smooth sweep over 3 s, then continue
|
||||
try ctx.ramp(param, to: 0.5, beats: 2) // same, in beats at the current tempo
|
||||
```
|
||||
|
||||
`ctx.ramp` **blocks** the body for its duration — like `wait` — and lands exactly on the target. It steps the scalar at the 10 ms poll granularity; the `ParameterNode`'s own per-block linear interpolation blends the steps into a continuous glide on the RT thread (no node source is installed, so a later `ctx.set` still takes effect immediately).
|
||||
|
||||
**`param` is the projected node, captured on the main actor first.** The synth is `@MainActor`-isolated, so its `@LiveParam` property and `$`-projection can't be reached from the background body. Capture the (`Sendable`) node once at setup, then drive it from the body — this is the idiomatic Swift-6 shape:
|
||||
|
||||
```swift
|
||||
// runDemo() / setup — @MainActor context
|
||||
let reverbSynth = GVerbTest(sampleRate: sr)
|
||||
let reverbTime = reverbSynth.$reverbTime // ParameterNode — Sendable, captured once
|
||||
|
||||
LyrebirdTask.run(engine: engine) { ctx in // @Sendable body — background thread
|
||||
ctx.add(reverbSynth)
|
||||
try ctx.wait(beats: 2)
|
||||
ctx.set(reverbTime, to: 8.0) // long tail
|
||||
try ctx.ramp(reverbTime, to: 0.5, beats: 2) // then glide down
|
||||
ctx.remove(reverbSynth)
|
||||
}
|
||||
```
|
||||
|
||||
> The background thread is the point: the body is *sequential, blocking* code — `add → wait → set → ramp → remove` reads top-to-bottom like a score — while the audio and the main thread run undisturbed. `wait`/`ramp` sleep this thread, never the RT thread.
|
||||
|
||||
**No-capture alternative.** A synth that is driven mostly from routines can skip `@LiveParam` and expose the node directly as a `nonisolated let ParameterNode`, which *is* reachable from the background with no capture — trading the plain-`Double` value sugar and the `$`-projection:
|
||||
|
||||
```swift
|
||||
@MainActor final class GVerbTest: SynthesizerBase {
|
||||
nonisolated let reverbTime = ParameterNode(3.0)
|
||||
override func build() { output(bus: 0, source: GVerb.Audio(/* … */, reverbTime: reverbTime)) }
|
||||
}
|
||||
// then, straight from the body — no capture line:
|
||||
ctx.set(reverbSynth.reverbTime, to: 8.0)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error handling
|
||||
@@ -226,6 +269,32 @@ Uncaught `LyrebirdRoutineError.stopped` is silently swallowed by the Routine/Tas
|
||||
- Do not call `reset()` from inside the body closure.
|
||||
- Multiple routines run concurrently and independently.
|
||||
|
||||
### Actor isolation
|
||||
|
||||
The body is `@Sendable` and runs off the main thread; `SynthesizerBase` is `@MainActor`. So:
|
||||
|
||||
| To do this from a body | Use | Cost |
|
||||
|---|---|---|
|
||||
| Construct a synth | `ctx.onMain { MySynth(...) }` | Synchronous main hop — absorbed by `wait`'s drift compensation. Keep it short; needs a serviced main thread (see below). |
|
||||
| Add / schedule / remove | `ctx.add` / `ctx.schedule` / `ctx.remove` | Async hop to main (`build()` runs there) |
|
||||
| Change a parameter | `ctx.set(node, to:)` with `$param` captured on main | **None** — lock-free atomic write, inline on the body's thread |
|
||||
|
||||
Direct property writes (`synth.freq = 880`) and projected-node access (`synth.$freq`) are
|
||||
main-isolated and unavailable from a body — capture the node on main first.
|
||||
|
||||
`ctx.onMain` is what lets the *number* and *parameters* of synths depend on the body's own
|
||||
logic, instead of pre-allocating every synth outside the body and capturing it.
|
||||
|
||||
**`ctx.onMain` requires a serviced main thread.** It hops synchronously with no timeout, so it
|
||||
blocks the body forever if nothing drains the main queue. A GUI run loop services it, as does a
|
||||
caller parked on `waitUntilComplete()` / `LyrebirdTask.run` (both pump the main run loop for
|
||||
exactly this reason). The trap: `task.start(engine:)` followed by blocking main on a bare
|
||||
`Thread.sleep` or semaphore — `ctx.add` would silently queue, but `onMain` hangs.
|
||||
|
||||
Full model — what is main-bound and why, pre- vs post-publication, and why
|
||||
`SynthesizerBase.init` cannot simply be made `nonisolated` (a committed regression fixture
|
||||
enforces it) — is in `ARCHITECTURE.md` §9.2.
|
||||
|
||||
---
|
||||
|
||||
## LyrebirdClock
|
||||
|
||||
Reference in New Issue
Block a user