v2.2.0 release: live-parameter ramp origin primed at synth add

A @UIParam/@LiveParam value assigned after construction but before the first render
is now delivered flat on the first block instead of ramping from the property-
declaration default (fixes e.g. a NoiseGate restored from saved rig state latching
open and ignoring its threshold). Backed by a new internal-facing
LiveParameterValue._primeRampOrigin() (default no-op, source-compatible); live
changes after start still ramp. See RELEASES.md for the full behavior-change note.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-03 12:25:29 -08:00
parent c14efe998a
commit 24ea32e47c
9 changed files with 238 additions and 6 deletions
@@ -82,6 +82,12 @@ at the end of `rebuildGraph()`. The property name (with the leading `_` of prope
backing storage stripped) becomes the parameter key for `updateParameter` and
``LyrebirdMessageContext/set(_:to:on:)``. No `declareParameter` call is needed.
Auto-registration also **primes each parameter's ramp origin** to its current value (before the
RT thread sees the node), so a value assigned between construction and the synth's first render —
for example restoring saved state onto a freshly built synth — is delivered **flat on the first
block**, not as a ramp up from the property-declaration default. Changes made after the synth is
running still ramp as usual.
### Block-rate vs sub-block-rate ramping
When `controlBlockSize == blockSize` (the engine default), the framework calls
@@ -245,7 +245,10 @@ Do not call `engine.remove` from within the RT callback.
- `parameterTable.inputs` is populated by `_autoRegisterLiveParams()` at the end of
`rebuildGraph()` (main thread, before add) and read during `evaluate()` (RT thread,
after add). No concurrent access.
after add). No concurrent access. The same pass also primes each live parameter's ramp
origin to its current value, so a value assigned before the first render (e.g. restored
state) is delivered flat; this write is main-thread-only and precedes the add, so it never
races the RT thread.
- `updateParameter` issues a releasing atomic store on the projected `ParameterNode` /
`UIParamNode`; the RT thread picks up the new value via an acquiring atomic load at the
start of the next (sub-)block — no queue, no dictionary mutation on the RT thread.
@@ -34,6 +34,32 @@ public protocol LiveParameterValue: AnyObject {
/// `UIParamNode` (`@Observable` stored property) satisfy this requirement via their
/// existing public `value` accessor.
var value: Double { get }
/// Moves the interpolation origin (`previousOutputValue`) to the current target value, so the
/// next rendered block is a flat buffer at that value with no ramp.
///
/// `SynthesizerBase` calls this on every live parameter when a synth is (re-)added to the engine
/// — on the main thread, before the RT thread sees the node. Any value assigned to the parameter
/// **before the first render** (e.g. restoring saved state) is therefore delivered flat, while a
/// value changed **after** the synth is running still ramps from the last rendered value.
///
/// Without this, assigning a parameter after construction leaves the ramp origin at the
/// property-declaration default, so the first block ramps default → assigned. For most
/// parameters that is a brief, benign glide; for a decision threshold feeding a `Schmidt`
/// trigger it can latch the trigger into the wrong state.
///
/// - Important: NOT RT-safe — must be called from the control side only, and only while the
/// node is not yet observed by the RT thread. It writes `previousOutputValue` (a plain
/// `Double`) without synchronisation, which is safe because `SynthesizerBase` calls it before
/// the add event is enqueued. A node shared with a synth that is already active must not be
/// primed.
func _primeRampOrigin()
}
public extension LiveParameterValue {
/// Default no-op so external conformers are not source-broken by this requirement. The two
/// in-tree conformers (`ParameterNode`, `UIParamNode`) provide real implementations.
func _primeRampOrigin() {}
}
/// A property wrapper that backs a synthesizer parameter with a `ParameterNode`.
@@ -320,6 +320,12 @@ public final class ParameterNode: GeneratorBase, ControlGenerator, LiveParameter
value = newValue
}
/// `LiveParameterValue` conformance — resets the ramp origin to the current target so the next
/// block is flat (no ramp). See the protocol requirement for when `SynthesizerBase` calls this.
public func _primeRampOrigin() {
previousOutputValue = value
}
// MARK: - Init-time priming
/// Resets both the atomic backing and the ramp origin (`previousOutputValue`) to
@@ -119,6 +119,13 @@ public final class UIParamNode: GeneratorBase, ControlGenerator, LiveParameterVa
update(newValue)
}
/// `LiveParameterValue` conformance — resets the ramp origin to the current target so the next
/// block is flat (no ramp). Delegates to `_node`, which owns the RT interpolation state the
/// render thread reads. See the protocol requirement for when `SynthesizerBase` calls this.
public func _primeRampOrigin() {
_node._primeRampOrigin()
}
// MARK: - Source property (delegates to _node)
/// Generator wired into this parameter slot. When non-nil, the parameter's
@@ -666,9 +666,13 @@ open class SynthesizerBase: Synthesizer {
///
/// **Value survival across re-add.** `parameterTable.inputs` is repopulated by
/// `_autoRegisterLiveParams()` on every call, but each `@LiveParam` / `@UIParam` property
/// wrapper holds its projected node (`ParameterNode` / `UIParamNode`) as a `let` —
/// the same instance is re-registered, so its atomic value and ramp state are preserved
/// across `engine.remove` + `engine.add` cycles.
/// wrapper holds its projected node (`ParameterNode` / `UIParamNode`) as a `let` — the same
/// instance is re-registered, so its **atomic value** is preserved across `engine.remove` +
/// `engine.add` cycles. The **ramp origin** is not preserved: `_autoRegisterLiveParams()`
/// re-primes it to that current value on every add (see
/// ``LiveParameterValue/_primeRampOrigin()``), so the first block after an add is flat at the
/// value in effect — a value assigned between construction (or a remove) and the add is
/// delivered without a ramp, while changes made after the synth is running still ramp.
///
/// - Precondition: the Synthesizer must NOT currently be active in the node tree.
/// Calling this while `evaluate()` may be running on the RT thread is a data race on
@@ -708,7 +712,16 @@ open class SynthesizerBase: Synthesizer {
guard let label: String = child.label else { continue }
let key: String = label.hasPrefix("_") ? String(label.dropFirst()) : label
if let wrapper: any LiveParameterWrapper = child.value as? LiveParameterWrapper {
parameterTable.inputs[key] = wrapper._projectedAsValidInput
let node: any ValidGeneratorInput = wrapper._projectedAsValidInput
parameterTable.inputs[key] = node
// Flatten the ramp origin to the value held right now (before the RT thread first
// sees this node). A value assigned after construction but before the engine
// starts — e.g. restoring saved state — is otherwise delivered as a first-block
// ramp from the property-declaration default, which can latch a downstream
// Schmidt/decision stage into the wrong state. Live changes after start still ramp.
if let primeable: any LiveParameterValue = node as? LiveParameterValue {
primeable._primeRampOrigin()
}
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: MIT
/// The current Lyrebird framework and CLI version.
public let lyrebirdVersion: String = "2.1.1"
public let lyrebirdVersion: String = "2.2.0"
/// The banner printed when the interactive shell or REPL session starts.
public let welcomeBanner: String = """