From e1ed4e348c60963205f2c0a5fca850da355e994d Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Sun, 2 Aug 2026 20:36:21 -0700 Subject: [PATCH] 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 --- Sources/LyrebirdShoeGaze/Pedal.swift | 6 +++++- Sources/LyrebirdShoeGaze/Presets/ShoeGaze+Preset.swift | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/Pedal.swift b/Sources/LyrebirdShoeGaze/Pedal.swift index 29c24e9..b060e53 100644 --- a/Sources/LyrebirdShoeGaze/Pedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedal.swift @@ -242,7 +242,11 @@ open class Pedal: SynthesizerBase { /// 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. 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 diff --git a/Sources/LyrebirdShoeGaze/Presets/ShoeGaze+Preset.swift b/Sources/LyrebirdShoeGaze/Presets/ShoeGaze+Preset.swift index 981ca60..95965ea 100644 --- a/Sources/LyrebirdShoeGaze/Presets/ShoeGaze+Preset.swift +++ b/Sources/LyrebirdShoeGaze/Presets/ShoeGaze+Preset.swift @@ -334,8 +334,8 @@ extension ShoeGaze { // MARK: - Lightweight recall - /// Applies parameter values from `state` to the current rig topology without - /// rebuilding the engine graph. + /// Applies parameter values from `state` to the current rig topology, rebuilding only the + /// boards where a graph-topology selector changed. /// /// This is a lightweight "recall settings" path intended for topologically identical /// rigs (same board count, same segment order, same pedal types). Boards, segments, and @@ -345,6 +345,12 @@ extension ShoeGaze { /// is thrown and remaining /// 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. /// /// - Parameter state: The `ShoeGazeState` whose parameter values should be applied.