fix(amp): clamp cab selector before Int() in isCabinetBypassed

External-review blocker: a huge finite cab value (from a corrupted or
hand-edited rig JSON, restored unclamped via PedalState.selectorValues)
would trap Int(cab.rounded()) at board-build time. Clamp in Double space
first, mirroring CabinetVoice.voice(atSelectorValue:). Regression test
renders infinity / ±1e20 / NaN / out-of-range cab values without trapping.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 21:39:27 -07:00
parent 9daffbbdf3
commit e8b858f1aa
2 changed files with 14 additions and 1 deletions
@@ -350,7 +350,10 @@ open class AmpVoicePedal: Pedal {
/// > low-pass) — expected; a cabinet is what tames the top end.
var isCabinetBypassed: Bool {
guard cab.isFinite else { return false }
return Int(cab.rounded()) >= CabinetVoice.allCases.count
// Clamp in Double space before converting: a huge finite `cab` (from a corrupted/hand-edited
// rig) would otherwise trap `Int(_:)` — same defense as `CabinetVoice.voice(atSelectorValue:)`.
let bounded: Double = Swift.min(Swift.max(cab, 0.0), Double(CabinetVoice.allCases.count))
return Int(bounded.rounded()) >= CabinetVoice.allCases.count
}
/// The per-channel cabinet + output stage: cabinet convolver (or a straight pass at the "None"