fix(cab): NaN-safe selector compare; correct applyState doc contract
Re-review follow-ups: - rebuildSelectorValues sanitizes non-finite node values to a sentinel so the before/after recall compare (uses !=) can't be forced true by NaN != NaN, which would trigger a needless rebuild on every recall. - ShoeGaze.applyState doc no longer claims "without rebuilding the engine graph": it now documents that a board is rebuilt (with the one-block-glitch caveat) when a rebuildsOnChange selector value differs from the live rig. Iteration-during-mutation in applyState confirmed safe: zip over the stored [PedalBoard] array snapshots it (COW), and PedalBoard is a final class, so rebuildBoard mutating self.boards mid-loop does not disturb the iteration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -242,7 +242,11 @@ open class Pedal: SynthesizerBase {
|
|||||||
/// this before/after applying a snapshot to decide whether the board must be rebuilt (a plain
|
/// this before/after applying a snapshot to decide whether the board must be rebuilt (a plain
|
||||||
/// node write does not re-enter `effect(_:)`). Empty for pedals with no such selectors.
|
/// node write does not re-enter `effect(_:)`). Empty for pedals with no such selectors.
|
||||||
public var rebuildSelectorValues: [Double] {
|
public var rebuildSelectorValues: [Double] {
|
||||||
effectSelectors.filter { $0.rebuildsOnChange }.map { $0.node.value }
|
// Sanitize non-finite to a fixed sentinel: the before/after compare in a recall uses `!=`,
|
||||||
|
// and `NaN != NaN` would force a spurious rebuild on every recall.
|
||||||
|
effectSelectors
|
||||||
|
.filter { $0.rebuildsOnChange }
|
||||||
|
.map { $0.node.value.isFinite ? $0.node.value : 0.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Effect-specific transport controls, rendered as a row directly below the knobs — above
|
/// Effect-specific transport controls, rendered as a row directly below the knobs — above
|
||||||
|
|||||||
@@ -334,8 +334,8 @@ extension ShoeGaze {
|
|||||||
|
|
||||||
// MARK: - Lightweight recall
|
// MARK: - Lightweight recall
|
||||||
|
|
||||||
/// Applies parameter values from `state` to the current rig topology without
|
/// Applies parameter values from `state` to the current rig topology, rebuilding only the
|
||||||
/// rebuilding the engine graph.
|
/// boards where a graph-topology selector changed.
|
||||||
///
|
///
|
||||||
/// This is a lightweight "recall settings" path intended for topologically identical
|
/// This is a lightweight "recall settings" path intended for topologically identical
|
||||||
/// rigs (same board count, same segment order, same pedal types). Boards, segments, and
|
/// rigs (same board count, same segment order, same pedal types). Boards, segments, and
|
||||||
@@ -345,6 +345,12 @@ extension ShoeGaze {
|
|||||||
/// is thrown and remaining
|
/// is thrown and remaining
|
||||||
/// entries continue to be processed.
|
/// entries continue to be processed.
|
||||||
///
|
///
|
||||||
|
/// Most parameters apply live with no graph change. The exception is a `rebuildsOnChange`
|
||||||
|
/// selector (e.g. a cabinet voice, which picks which convolver is instantiated): if such a
|
||||||
|
/// selector's value differs from the live rig, that board is rebuilt via `rebuildBoard(_:from:)`
|
||||||
|
/// so the new selection takes effect — which carries the same at-most-one-block glitch as any
|
||||||
|
/// rebuild on a running engine. Boards without such a selector stay fully live.
|
||||||
|
///
|
||||||
/// Use `loadRig(from:)` when you need a full topology rebuild.
|
/// Use `loadRig(from:)` when you need a full topology rebuild.
|
||||||
///
|
///
|
||||||
/// - Parameter state: The `ShoeGazeState` whose parameter values should be applied.
|
/// - Parameter state: The `ShoeGazeState` whose parameter values should be applied.
|
||||||
|
|||||||
Reference in New Issue
Block a user