fix(amps): recall rebuilds on a rebuildsOnChange switch (channel)
Review blocker: lightweight recall (ShoeGaze.applyState) detected topology change only via Pedal.rebuildSelectorValues (effectSelectors), so a channel switch — the first rebuildsOnChange *switch* — flipped during a scene recall wrote the node value but never rebuilt, leaving the stale channel topology (wrong preamp). - Rename/extend to Pedal.rebuildTopologyValues: folds in effectSwitches flagged rebuildsOnChange alongside the selectors (both NaN-sanitized). Recall call sites in ShoeGaze+Preset updated. - FullertonDrive: rename channel constants to generic switchOff/On (used by the Bright switch too). - Test: applyStateRebuildsBoardWhenChannelSwitchChanges — recall flipping the channel rebuilds the board and applies the recalled channel. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -237,16 +237,21 @@ open class Pedal: SynthesizerBase {
|
|||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current values of every ``effectSelectors`` entry flagged `rebuildsOnChange` — the selectors
|
/// Current values of every ``effectSelectors`` and ``effectSwitches`` entry flagged
|
||||||
/// whose choice changes the graph topology (e.g. a cabinet voice). A lightweight recall compares
|
/// `rebuildsOnChange` — the controls whose choice changes the graph topology (e.g. a cabinet
|
||||||
/// this before/after applying a snapshot to decide whether the board must be rebuilt (a plain
|
/// voice or a clean/drive channel). A lightweight recall compares this before/after applying a
|
||||||
/// node write does not re-enter `effect(_:)`). Empty for pedals with no such selectors.
|
/// snapshot to decide whether the board must be rebuilt (a plain node write does not re-enter
|
||||||
public var rebuildSelectorValues: [Double] {
|
/// `effect(_:)`). Empty for pedals with no such controls.
|
||||||
|
public var rebuildTopologyValues: [Double] {
|
||||||
// Sanitize non-finite to a fixed sentinel: the before/after compare in a recall uses `!=`,
|
// 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.
|
// and `NaN != NaN` would force a spurious rebuild on every recall.
|
||||||
effectSelectors
|
let selectorValues: [Double] = effectSelectors
|
||||||
.filter { $0.rebuildsOnChange }
|
.filter { $0.rebuildsOnChange }
|
||||||
.map { $0.node.value.isFinite ? $0.node.value : 0.0 }
|
.map { $0.node.value.isFinite ? $0.node.value : 0.0 }
|
||||||
|
let switchValues: [Double] = effectSwitches
|
||||||
|
.filter { $0.rebuildsOnChange }
|
||||||
|
.map { $0.node.value.isFinite ? $0.node.value : 0.0 }
|
||||||
|
return selectorValues + switchValues
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ public final class FullertonDriveAmpPedal: AmpVoicePedal {
|
|||||||
|
|
||||||
private let reverbRange: ClosedRange<Double> = 0.0 ... 1.0
|
private let reverbRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
private let driveRange: ClosedRange<Double> = 1.0 ... 30.0
|
private let driveRange: ClosedRange<Double> = 1.0 ... 30.0
|
||||||
private let cleanValue: Double = 0.0
|
private let switchOffValue: Double = 0.0
|
||||||
private let driveValue: Double = 1.0
|
private let switchOnValue: Double = 1.0
|
||||||
|
|
||||||
public override var toneStackModel: ToneStackModel { .fender }
|
public override var toneStackModel: ToneStackModel { .fender }
|
||||||
public override var summaryText: String {
|
public override var summaryText: String {
|
||||||
@@ -59,16 +59,16 @@ public final class FullertonDriveAmpPedal: AmpVoicePedal {
|
|||||||
label: "Bright",
|
label: "Bright",
|
||||||
node: $bright,
|
node: $bright,
|
||||||
options: [
|
options: [
|
||||||
PedalSwitch.Option(title: "Off", value: cleanValue),
|
PedalSwitch.Option(title: "Off", value: switchOffValue),
|
||||||
PedalSwitch.Option(title: "On", value: driveValue),
|
PedalSwitch.Option(title: "On", value: switchOnValue),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
PedalSwitch(
|
PedalSwitch(
|
||||||
label: "Channel",
|
label: "Channel",
|
||||||
node: $channel,
|
node: $channel,
|
||||||
options: [
|
options: [
|
||||||
PedalSwitch.Option(title: "Clean", value: cleanValue),
|
PedalSwitch.Option(title: "Clean", value: switchOffValue),
|
||||||
PedalSwitch.Option(title: "Drive", value: driveValue),
|
PedalSwitch.Option(title: "Drive", value: switchOnValue),
|
||||||
],
|
],
|
||||||
rebuildsOnChange: true
|
rebuildsOnChange: true
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -391,9 +391,9 @@ extension ShoeGaze {
|
|||||||
switch (segment, segmentState) {
|
switch (segment, segmentState) {
|
||||||
case let (.pedal(pedal), .pedal(pedalState)):
|
case let (.pedal(pedal), .pedal(pedalState)):
|
||||||
if pedal.displayName == pedalState.type {
|
if pedal.displayName == pedalState.type {
|
||||||
let before: [Double] = pedal.rebuildSelectorValues
|
let before: [Double] = pedal.rebuildTopologyValues
|
||||||
pedal.applyState(pedalState)
|
pedal.applyState(pedalState)
|
||||||
if pedal.rebuildSelectorValues != before { topologyChanged = true }
|
if pedal.rebuildTopologyValues != before { topologyChanged = true }
|
||||||
}
|
}
|
||||||
|
|
||||||
case let (.parallel(section), .parallel(parallelState)):
|
case let (.parallel(section), .parallel(parallelState)):
|
||||||
@@ -429,9 +429,9 @@ extension ShoeGaze {
|
|||||||
private func applyBranchParams(_ states: [PedalState], to pedals: [Pedal]) -> Bool {
|
private func applyBranchParams(_ states: [PedalState], to pedals: [Pedal]) -> Bool {
|
||||||
var topologyChanged: Bool = false
|
var topologyChanged: Bool = false
|
||||||
for (pedal, pedalState) in zip(pedals, states) where pedal.displayName == pedalState.type {
|
for (pedal, pedalState) in zip(pedals, states) where pedal.displayName == pedalState.type {
|
||||||
let before: [Double] = pedal.rebuildSelectorValues
|
let before: [Double] = pedal.rebuildTopologyValues
|
||||||
pedal.applyState(pedalState)
|
pedal.applyState(pedalState)
|
||||||
if pedal.rebuildSelectorValues != before { topologyChanged = true }
|
if pedal.rebuildTopologyValues != before { topologyChanged = true }
|
||||||
}
|
}
|
||||||
return topologyChanged
|
return topologyChanged
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,6 +329,36 @@ struct PresetTests {
|
|||||||
#expect(sg.boards[0].pedals.first === original, "unchanged cabinet voice should not rebuild")
|
#expect(sg.boards[0].pedals.first === original, "unchanged cabinet voice should not rebuild")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func applyStateRebuildsBoardWhenChannelSwitchChanges() throws {
|
||||||
|
// A rebuildsOnChange *switch* (an amp's Clean/Drive channel) changes graph topology, so a
|
||||||
|
// lightweight recall that flips it must rebuild the board — not just the cab selector case.
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1, numAudioBuses: 128)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
|
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||||
|
let board: PedalBoard = try sg.addBoard()
|
||||||
|
try board.add(FullertonDriveAmpPedal())
|
||||||
|
try sg.finalizeBoard(board)
|
||||||
|
|
||||||
|
guard let original: FullertonDriveAmpPedal = board.pedals.first as? FullertonDriveAmpPedal else {
|
||||||
|
Issue.record("No FullertonDriveAmpPedal in board")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Snapshot on the Drive channel, move the live pedal back to Clean, then recall.
|
||||||
|
original.channel = 1.0
|
||||||
|
let snapshot: ShoeGazeState = sg.captureState()
|
||||||
|
original.channel = 0.0
|
||||||
|
|
||||||
|
sg.applyState(snapshot)
|
||||||
|
|
||||||
|
guard let rebuilt: FullertonDriveAmpPedal = sg.boards[0].pedals.first as? FullertonDriveAmpPedal else {
|
||||||
|
Issue.record("No FullertonDriveAmpPedal after recall")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#expect(rebuilt !== original, "board should rebuild when the channel switch changes")
|
||||||
|
#expect(rebuilt.channel == 1.0, "recalled channel should be applied")
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - In-memory round-trip
|
// MARK: - In-memory round-trip
|
||||||
|
|
||||||
@Test func captureStateRoundTripEquality() throws {
|
@Test func captureStateRoundTripEquality() throws {
|
||||||
|
|||||||
Reference in New Issue
Block a user