// BoutiqueAmpPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Shared base for the boutique high-gain amps (Boutique Lead / Boutique OD) — a footswitchable /// Clean/Lead channel into a master-volume power section, with **Presence** (top-end) and **Depth** /// (low-end resonance) shaping. /// /// The Lead channel cascades a second gain stage (set by `Drive`) via ``preampStage(_:)`` — a /// `rebuildsOnChange` **Channel** switch, so only the selected channel is built. `Master` drives the /// power-amp stage via ``AmpVoicePedal/masterDrive(_:minDrive:maxDrive:)``. Concrete voices override /// ``AmpVoicePedal/toneStackModel`` and gain defaults, and may extend the shaping (e.g. a mid boost). open class BoutiqueAmpPedal: AmpVoicePedal { /// Presence amount in [0, 1] → 0…`presenceMaxGainDb` of top-end lift. @UIParam public var presence: Double = 0.4 /// Depth amount in [0, 1] → 0…`depthMaxGainDb` of low-end resonance lift. @UIParam public var depth: Double = 0.3 /// Master volume in [0, 1] → power-amp drive in [`masterMinDrive`, `masterMaxDrive`]. @UIParam public var master: Double = 0.5 /// Lead-channel preamp gain (the cascaded stage). Range [1, 30]. @UIParam public var drive: Double = 10.0 /// Channel select: `0` = Clean, `1` = Lead (the cascaded gain stage). @UIParam public var channel: Double = 0.0 private let presenceFreqHz: Double = 4500.0 private let presenceMaxGainDb: Double = 8.0 private let presenceSlope: Double = 0.7 private let depthFreqHz: Double = 120.0 private let depthMaxGainDb: Double = 6.0 private let depthSlope: Double = 0.7 private let masterMinDrive: Double = 0.5 private let masterMaxDrive: Double = 5.0 /// Grid bias of the cascaded lead stage — a little asymmetry for even-harmonic grind. let leadBias: Double = 0.15 private let channelThreshold: Double = 0.5 let signatureAmount: ClosedRange = 0.0 ... 1.0 private let driveRange: ClosedRange = 1.0 ... 30.0 let switchOffValue: Double = 0.0 let switchOnValue: Double = 1.0 public override var toneStackModel: ToneStackModel { .marshall } public override var signatureKnobs: [PedalKnob] { [ PedalKnob(label: "Presence", node: $presence, range: signatureAmount), PedalKnob(label: "Depth", node: $depth, range: signatureAmount), PedalKnob(label: "Master", node: $master, range: signatureAmount), PedalKnob(label: "Drive", node: $drive, range: driveRange), ] } public override var effectSwitches: [PedalSwitch] { [ PedalSwitch( label: "Channel", node: $channel, options: [ PedalSwitch.Option(title: "Clean", value: switchOffValue), PedalSwitch.Option(title: "Lead", value: switchOnValue), ], rebuildsOnChange: true ), ] } /// Master drives the power-amp stage. 4× oversampling since it can be driven hard. public override var powerAmpDriveInput: any ValidGeneratorInput { masterDrive($master, minDrive: masterMinDrive, maxDrive: masterMaxDrive) } public override var powerAmpOversample: Int { 4 } /// Wider card for the Presence/Depth/Master/Drive knobs plus the Channel switch. public override var widthUnits: Int { 4 } /// Clean preamp, plus a cascaded lead stage on the Lead channel. `channel` is read at /// board-build time (the switch is `rebuildsOnChange`), so only the selected channel is built. public override func preampStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { let clean: any ValidGeneratorInput = super.preampStage(signal) guard channel >= channelThreshold else { return clean } return TriodeStage(input: clean, drive: $drive, bias: leadBias, oversample: preampOversample) } /// Presence (top-end high-shelf) then Depth (low-end low-shelf), post power amp. public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { let presenceGainDb: LinLin.Audio = LinLin.Audio( $presence, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: presenceMaxGainDb) let presenced: RBJHighShelf.Audio = RBJHighShelf.Audio( input: signal, freq: presenceFreqHz, gain: presenceGainDb, slope: presenceSlope) let depthGainDb: LinLin.Audio = LinLin.Audio( $depth, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: depthMaxGainDb) return RBJLowShelf.Audio( input: presenced, freq: depthFreqHz, gain: depthGainDb, slope: depthSlope) } }