perf(cab): instantiate only the selected cabinet convolver

The cab selector was a Select over one ConvolutionReverb per CabinetVoice, and
Select evaluates every input each block — so all 8 voices' partitioned-FFT
convolvers ran continuously (7/8 discarded), per CabinetPedal and per amp voice.

Build only the selected voice's convolver. The cab selector is now
rebuildsOnChange: committing a new stop asks the host to rebuild the board
(same mechanism the Neural Amp model loader uses), which re-enters effect()
with the new voice. One convolver runs instead of N; cost moves to a brief
rebuild on cab switch (cabs are set-and-forget).

- PedalSelectorKnob: add rebuildsOnChange flag.
- PedalSelectorKnobView: fire onCommit on drag-end when the stop changed.
- PedalView: wire onCommit → pedalRebuildAction for rebuildsOnChange selectors.
- CabinetVoice.voice(atSelectorValue:): rounded/clamped index → voice.
- CabinetPedal + AmpVoicePedal: single ConvolutionReverb for the selected voice.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-02 20:16:42 -07:00
parent 8a266a33dc
commit 59370ee5dd
8 changed files with 89 additions and 36 deletions
@@ -120,7 +120,8 @@ open class AmpVoicePedal: Pedal {
public override var effectSelectors: [PedalSelectorKnob] {
[
PedalSelectorKnob(label: "Cab", node: $cab, stops: AmpVoicePedal.cabStops),
PedalSelectorKnob(
label: "Cab", node: $cab, stops: AmpVoicePedal.cabStops, rebuildsOnChange: true),
]
}
@@ -128,9 +129,10 @@ open class AmpVoicePedal: Pedal {
/// Preamp → fixed tone stack → power amp → signature shaping → cabinet (voice-selected).
///
/// > Note: the cabinet is a `Select` over one `ConvolutionReverb` per `CabinetVoice`. Per
/// > `Select`'s SC-parity contract every input is evaluated each block, so all cab convolvers
/// > run continuously regardless of the `cab` selection — a bounded, fixed CPU cost.
/// > Note: only the voice named by the live `cab` selector is instantiated, so exactly one
/// > `ConvolutionReverb` runs. The `cab` selector is `rebuildsOnChange`, so switching cabs
/// > rebuilds the board (re-entering `effect(_:)` with the new voice) rather than running every
/// > voice at once.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: The amped, cab-convolved mono output.
@@ -142,13 +144,11 @@ open class AmpVoicePedal: Pedal {
let powerAmp: TriodeStage = TriodeStage(
input: toned, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2)
let shaped: any ValidGeneratorInput = shapeVoice(powerAmp)
let cabinets: [any ValidGeneratorInput] = CabinetVoice.allCases.map { (voice: CabinetVoice) in
ConvolutionReverb.Audio(
input: shaped,
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
mix: cabinetMix
)
}
return Select.Audio(which: $cab, inputs: cabinets)
let voice: CabinetVoice = CabinetVoice.voice(atSelectorValue: cab)
return ConvolutionReverb.Audio(
input: shaped,
ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr),
mix: cabinetMix
)
}
}