3 Commits

Author SHA1 Message Date
josh 9c0122f199 docs(preset): reattach applyState doc above its declaration
The legacy-migration fix spliced private declarations between applyState's
doc comment and the method, so the doc silently reattached to the private
modernHighGainType constant. Move it back above applyState (and note the
legacyMigrated normalization + advanced-knob restore). Caught in re-review.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 21:26:35 -07:00
josh 781577b062 fix(amp): preserve legacy rigs across the Sag/Bias rename + move
Addresses two blocking findings from the external review, both legacy
preset-compat (no RT/protocol issues were found):

- Rename compat: "Fullerton Princeton" → display "Fullerton Ivy League"
  would silently drop the pedal from any rig saved under the old name
  (displayName is the serialization key). Add PedalRegistry.legacyTypeAliases
  resolved in makePedal (self-healing: loads, then re-saves under the new
  name). Regression test asserts the old name still resolves.
- Knob-shift compat: moving Modern High-Gain's Sag off the face shrank its
  effectKnobs by one, so an old 11-value knobValues array would misassign
  Sag→Mix and Mix→Level on load. Add a targeted PedalState migration
  (Pedal.legacyMigrated) that lifts Sag into advancedValues and keeps
  Mix/Level in place. Regression test decodes a hand-built legacy preset
  and asserts correct placement.

Also: drop the not-yet-built "Bias X" from a doc comment; de-brand "Vox"
from the Chime variants test names (ToneStackModel .vox enum refs kept).

643 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 21:20:16 -07:00
josh 1de14fd879 feat(amp): shared power-amp Sag + Bias in an advanced pop-over
Phase 11. Promote Sag from Modern High-Gain to a shared AmpVoicePedal
capability and add a Bias control, both surfaced in a new pedal-card
pop-over rather than on the amp face.

- AmpVoicePedal gains `sag` [0,1] (AmplitudeFollower gain-droop, clamped
  [0.15,1] to prevent phase inversion) and `bias` [0,1] mapped to the
  power-amp TriodeStage grid bias ([-0.25,0.25], neutral 0.5 → 0.0 so
  existing voices are unchanged at defaults). Both applied in
  preCabinetCore; new `applySag(_:)` + `powerAmpBiasInput` helpers.
- Modern High-Gain drops its bespoke sag (now inherited); keeps sag=0.3
  default. Sag moves off its face into the pop-over.
- Pedal gains an `advancedKnobs` surface; PedalView draws a gear button
  (top-right) presenting them in a popover, reusing the existing pattern.
- Advanced knobs round-trip through PedalState (new `advancedValues`,
  backward-compatible decode) and are MIDI-CC-mappable (appended last).

De-branding (review nits): "Vox" removed from the Chime family's
user-visible summaries + docs; "Fullerton Princeton" renamed to display
"Fullerton Ivy League". Palette horizontal picker second row now shows
Routing before the Amp Model group.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-03 21:08:23 -07:00
19 changed files with 375 additions and 90 deletions
+21 -5
View File
@@ -237,6 +237,17 @@ open class Pedal: SynthesizerBase {
[] []
} }
/// Secondary "advanced" knobs that read best tucked behind a pop-over rather than on the pedal
/// face — deep-cut controls a player reaches for occasionally, not while performing (e.g. an
/// amp's power-amp Sag / Bias / Bias X). When non-empty the pedal card shows a small button that
/// presents these in a popover; when empty no button is drawn. Defaults to empty.
///
/// These are ordinary live `@UIParam` knobs — they round-trip through `PedalState` and are not
/// topology controls (no `rebuildsOnChange`).
open var advancedKnobs: [PedalKnob] {
[]
}
/// Current values of every ``effectSelectors`` and ``effectSwitches`` entry flagged /// Current values of every ``effectSelectors`` and ``effectSwitches`` entry flagged
/// `rebuildsOnChange` — the controls whose choice changes the graph topology (e.g. a cabinet /// `rebuildsOnChange` — the controls whose choice changes the graph topology (e.g. a cabinet
/// voice or a clean/drive channel). A lightweight recall compares this before/after applying a /// voice or a clean/drive channel). A lightweight recall compares this before/after applying a
@@ -283,11 +294,13 @@ open class Pedal: SynthesizerBase {
} }
/// Every continuous control on this pedal that a MIDI Control Change can drive — the pedal's /// Every continuous control on this pedal that a MIDI Control Change can drive — the pedal's
/// knobs (effect knobs + Mix + Level) followed by its vertical-fader sliders. Discrete controls /// knobs (effect knobs + Mix + Level), then its vertical-fader sliders, then its advanced
/// (switches, stepped selectors) are excluded; they suit Program Change toggles, not CC sweeps. /// (pop-over) knobs. Discrete controls (switches, stepped selectors) are excluded; they suit
/// Program Change toggles, not CC sweeps.
/// ///
/// Ordering is stable — knobs first, then sliders — so a persisted CC binding addressed by index /// Ordering is stable — knobs, then sliders, then advanced knobs (appended last so existing
/// keeps resolving to the same control across launches. Used by MIDI mapping. /// index-addressed CC bindings keep resolving to the same control across launches). Used by MIDI
/// mapping.
public var ccMappableControls: [PedalControl] { public var ccMappableControls: [PedalControl] {
let knobControls: [PedalControl] = knobs.map { let knobControls: [PedalControl] = knobs.map {
PedalControl(label: $0.label, node: $0.node, range: $0.range) PedalControl(label: $0.label, node: $0.node, range: $0.range)
@@ -295,7 +308,10 @@ open class Pedal: SynthesizerBase {
let sliderControls: [PedalControl] = effectSliders.map { let sliderControls: [PedalControl] = effectSliders.map {
PedalControl(label: $0.label, node: $0.node, range: $0.range) PedalControl(label: $0.label, node: $0.node, range: $0.range)
} }
return knobControls + sliderControls let advancedControls: [PedalControl] = advancedKnobs.map {
PedalControl(label: $0.label, node: $0.node, range: $0.range)
}
return knobControls + sliderControls + advancedControls
} }
// MARK: - Tempo sync // MARK: - Tempo sync
+1 -1
View File
@@ -66,7 +66,7 @@ public extension PedalType {
static let chimeBaby = PedalType("Chime Baby") static let chimeBaby = PedalType("Chime Baby")
static let fullertonReverb = PedalType("Fullerton Reverb") static let fullertonReverb = PedalType("Fullerton Reverb")
static let fullertonDeluxe = PedalType("Fullerton Deluxe") static let fullertonDeluxe = PedalType("Fullerton Deluxe")
static let fullertonPrinceton = PedalType("Fullerton Princeton") static let fullertonPrinceton = PedalType("Fullerton Ivy League")
static let fullertonDrive = PedalType("Fullerton Drive") static let fullertonDrive = PedalType("Fullerton Drive")
static let jazzClean = PedalType("Jazz Clean") static let jazzClean = PedalType("Jazz Clean")
static let chimeTopBoost = PedalType("Chime Top Boost") static let chimeTopBoost = PedalType("Chime Top Boost")
@@ -48,6 +48,14 @@ open class AmpVoicePedal: Pedal {
@UIParam public var treble: Double = 0.6 @UIParam public var treble: Double = 0.6
/// Selected cabinet voice as an index into `CabinetVoice.allCases`. /// Selected cabinet voice as an index into `CabinetVoice.allCases`.
@UIParam public var cab: Double = 0.0 @UIParam public var cab: Double = 0.0
/// Power-amp **Sag** in `[0, 1]`: `0` = stiff (no droop), `1` = heavy power-supply sag/bloom.
/// Surfaced in the advanced pop-over, not on the pedal face. See ``applySag(_:)``.
@UIParam public var sag: Double = 0.0
/// Power-amp **Bias** in `[0, 1]`, mapped to the power-amp `TriodeStage` grid bias. `0.5` = the
/// neutral (symmetric) operating point; lower = colder (tighter, more odd harmonics), higher =
/// hotter (warmer, more even harmonics). Surfaced in the advanced pop-over. See
/// ``powerAmpBiasInput``.
@UIParam public var bias: Double = 0.5
// MARK: - Subclass configuration // MARK: - Subclass configuration
@@ -153,6 +161,31 @@ open class AmpVoicePedal: Pedal {
/// power stage of the standard voices). /// power stage of the standard voices).
open var powerAmpOversample: Int { 2 } open var powerAmpOversample: Int { 2 }
/// Grid bias fed to the power-amp `TriodeStage`, from the live `Bias` knob: `[0, 1]` mapped to
/// `[coldPowerAmpBias, hotPowerAmpBias]`. The neutral `bias = 0.5` maps to `0.0`, so the default
/// leaves the power-amp stage symmetric (unchanged from the old fixed bias).
var powerAmpBiasInput: any ValidGeneratorInput {
LinLin.Audio($bias, inLo: 0.0, inHi: 1.0, outLo: coldPowerAmpBias, outHi: hotPowerAmpBias)
}
/// Applies power-supply **Sag**: an `AmplitudeFollower` on `signal` reduces gain as it gets loud
/// (droop) and recovers slowly (bloom). `Sag` scales the depth; at `sag = 0` the droop is `0` and
/// the gain is a constant `1.0` (an identity multiply), so a sag-less amp is unchanged.
///
/// The droop gain is clamped to `[sagGainFloor, 1]`: the envelope tracks a post-power-amp,
/// post-`shapeVoice` signal that can exceed 1 (Presence/Depth shelves), so an unclamped
/// `1 − sag·env` would go negative and phase-invert loud content instead of attenuating it.
///
/// - Parameter signal: The post-`shapeVoice` signal to apply sag to.
/// - Returns: The sagged signal.
func applySag(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
in: signal, attackTime: sagAttackSeconds, releaseTime: sagReleaseSeconds)
let sagGain: any ValidGeneratorInput = Clip.Audio(
1.0 - ($sag * envelope), lo: sagGainFloor, hi: 1.0)
return signal * sagGain
}
// MARK: - Constants // MARK: - Constants
private static let defaultMix: Double = 1.0 private static let defaultMix: Double = 1.0
@@ -166,9 +199,22 @@ open class AmpVoicePedal: Pedal {
/// Generic `PedalSwitch` off / on values, shared by every amp that publishes switches. /// Generic `PedalSwitch` off / on values, shared by every amp that publishes switches.
let switchOffValue: Double = 0.0 let switchOffValue: Double = 0.0
let switchOnValue: Double = 1.0 let switchOnValue: Double = 1.0
/// Fixed power-amp stage drive/bias (gentler than the preamp). /// Fixed power-amp stage drive (gentler than the preamp).
private let powerAmpDrive: Double = 1.5 private let powerAmpDrive: Double = 1.5
private let powerAmpBias: Double = 0.0 /// Power-amp grid bias at `bias = 0` (coldest) and `bias = 1` (hottest). Symmetric about `0`, so
/// the neutral `bias = 0.5` maps to `0.0` — the old fixed power-amp bias — leaving every amp's
/// default tone unchanged. Modest magnitude so the control colours the harmonics without
/// drastically re-voicing the amp.
private let coldPowerAmpBias: Double = -0.25
private let hotPowerAmpBias: Double = 0.25
/// Sag envelope-follower attack — moderately fast (the supply starts drooping under load).
private let sagAttackSeconds: Double = 0.02
/// Sag envelope-follower release — slow, so the sag lingers and blooms back (supply recovery).
private let sagReleaseSeconds: Double = 0.30
/// Lowest the sag gain can droop to (~-16 dB). Bounds sag depth and — crucially — keeps the gain
/// strictly positive: the envelope tracks a post-shelf signal that can exceed 1, so an unclamped
/// `1 − sag·env` would go negative and phase-invert loud content instead of drooping.
private let sagGainFloor: Double = 0.15
private let cabinetMix: Double = 1.0 private let cabinetMix: Double = 1.0
/// Output soft-limit drive. `1.0` gives unit small-signal gain (clean playing untouched) with a /// Output soft-limit drive. `1.0` gives unit small-signal gain (clean playing untouched) with a
/// hard `tanh` asymptote at ±1 — models output-transformer / speaker compression and keeps the /// hard `tanh` asymptote at ±1 — models output-transformer / speaker compression and keeps the
@@ -243,6 +289,16 @@ open class AmpVoicePedal: Pedal {
] ]
} }
/// Power-amp deep-cut controls, tucked behind the pedal card's advanced pop-over: **Sag**
/// (power-supply droop/bloom) and **Bias** (power-amp grid-bias operating point). Neither is a
/// topology control — both are live nodes that round-trip through the rig save format.
public override var advancedKnobs: [PedalKnob] {
[
PedalKnob(label: "Sag", node: $sag, range: signatureRange),
PedalKnob(label: "Bias", node: $bias, range: toneRange),
]
}
// MARK: - Effect // MARK: - Effect
/// Preamp → fixed tone stack → power amp → signature shaping → cabinet → output soft-limit. /// Preamp → fixed tone stack → power amp → signature shaping → cabinet → output soft-limit.
@@ -277,8 +333,8 @@ open class AmpVoicePedal: Pedal {
input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel) input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel)
let processed: any ValidGeneratorInput = onboardEffects(toned) let processed: any ValidGeneratorInput = onboardEffects(toned)
let powerAmp: TriodeStage = TriodeStage( let powerAmp: TriodeStage = TriodeStage(
input: processed, drive: powerAmpDriveInput, bias: powerAmpBias, oversample: powerAmpOversample) input: processed, drive: powerAmpDriveInput, bias: powerAmpBiasInput, oversample: powerAmpOversample)
return shapeVoice(powerAmp) return applySag(shapeVoice(powerAmp))
} }
/// The per-channel cabinet + output stage: the selected `CabinetVoice` convolver → `tanh` /// The per-channel cabinet + output stage: the selected `CabinetVoice` convolver → `tanh`
@@ -10,8 +10,8 @@ import LyrebirdUI
/// Chimey/jangly amp (bell-like top boost) with a **Cut** control that rolls off the high end as /// Chimey/jangly amp (bell-like top boost) with a **Cut** control that rolls off the high end as
/// it's turned up — the classic top-boost "Cut" behavior. /// it's turned up — the classic top-boost "Cut" behavior.
/// ///
/// A ``AmpVoicePedal`` fixed to the chime tone stack. The base of the Vox-voiced family — the /// A ``AmpVoicePedal`` fixed to the chime tone stack. The base of the chime-voiced family — the
/// AC-style variants (Chime 15 / Chime Normal / Chime Baby) subclass it and differ by gain, cab, /// EL84-combo variants (Chime 15 / Chime Normal / Chime Baby) subclass it and differ by gain, cab,
/// and tone defaults (and, for the smaller combos, an earlier power-amp breakup). /// and tone defaults (and, for the smaller combos, an earlier power-amp breakup).
open class ChimeAmpPedal: AmpVoicePedal { open class ChimeAmpPedal: AmpVoicePedal {
@@ -7,7 +7,7 @@
import LyrebirdSynth import LyrebirdSynth
import LyrebirdUI import LyrebirdUI
/// Vox-voiced **practice combo** — the tiny AC4/AC10-style amp: low headroom, a small boxy /// Chime-family **practice combo** — the tiny, low-power amp: low headroom, a small boxy
/// speaker, and the earliest breakup of the chime family. /// speaker, and the earliest breakup of the chime family.
/// ///
/// A ``ChimeAmpPedal`` (Cut voice) driven hardest into the power stage, with the small lo-fi cab. /// A ``ChimeAmpPedal`` (Cut voice) driven hardest into the power stage, with the small lo-fi cab.
@@ -17,7 +17,7 @@ public final class ChimeBabyAmpPedal: ChimeAmpPedal {
private let babyPowerDrive: Double = 2.5 private let babyPowerDrive: Double = 2.5
public override var summaryText: String { public override var summaryText: String {
"Vox practice combo — tiny, boxy, earliest-breakup chime with a Cut control." "Chime-style practice combo — tiny, boxy, earliest-breakup chime with a Cut control."
} }
/// Driven hardest of the chime family, so 4× oversampling for anti-alias headroom. /// Driven hardest of the chime family, so 4× oversampling for anti-alias headroom.
@@ -7,7 +7,7 @@
import LyrebirdSynth import LyrebirdSynth
import LyrebirdUI import LyrebirdUI
/// Vox-voiced **1×12 EL84 combo** — the lower-powered, earlier-breakup sibling of the AC top-boost /// Chime-family **1×12 EL84 combo** — the lower-powered, earlier-breakup sibling of the top-boost
/// voice. Chimey but grittier: the small power section saturates sooner. /// voice. Chimey but grittier: the small power section saturates sooner.
/// ///
/// A ``ChimeAmpPedal`` (Cut voice) with a higher fixed power-amp drive and a bright cab. /// A ``ChimeAmpPedal`` (Cut voice) with a higher fixed power-amp drive and a bright cab.
@@ -17,7 +17,7 @@ public final class ChimeFifteenAmpPedal: ChimeAmpPedal {
private let fifteenPowerDrive: Double = 2.0 private let fifteenPowerDrive: Double = 2.0
public override var summaryText: String { public override var summaryText: String {
"Vox 1×12 EL84 combo — chimey but earlier-breakup, with a Cut control." "Chime-style 1×12 EL84 combo — chimey but earlier-breakup, with a Cut control."
} }
/// Driven harder than the base, so 4× oversampling for anti-alias headroom. /// Driven harder than the base, so 4× oversampling for anti-alias headroom.
@@ -7,15 +7,15 @@
import LyrebirdSynth import LyrebirdSynth
import LyrebirdUI import LyrebirdUI
/// Vox-voiced **Normal channel** — the AC30's non-top-boost side: warmer and rounder than the /// Chime-family **Normal channel** — the big combo's non-top-boost side: warmer and rounder than
/// bright top-boost voice, with the same high clean headroom. /// the bright top-boost voice, with the same high clean headroom.
/// ///
/// A ``ChimeAmpPedal`` (Cut voice) voiced darker (lower treble default, a touch more Cut) to stand /// A ``ChimeAmpPedal`` (Cut voice) voiced darker (lower treble default, a touch more Cut) to stand
/// in for the plainer Normal-channel EQ. /// in for the plainer Normal-channel EQ.
public final class ChimeNormalAmpPedal: ChimeAmpPedal { public final class ChimeNormalAmpPedal: ChimeAmpPedal {
public override var summaryText: String { public override var summaryText: String {
"Vox Normal channel — warm, round, high-headroom chime with a Cut control." "Chime Normal channel — warm, round, high-headroom chime with a Cut control."
} }
/// Creates a Chime Normal amp. /// Creates a Chime Normal amp.
@@ -26,13 +26,13 @@ public final class FullertonPrincetonAmpPedal: FullertonReverbAmpPedal {
public override var powerAmpOversample: Int { 4 } public override var powerAmpOversample: Int { 4 }
public override var powerAmpDriveInput: any ValidGeneratorInput { princetonPowerDrive } public override var powerAmpDriveInput: any ValidGeneratorInput { princetonPowerDrive }
/// Creates a Fullerton Princeton amp. /// Creates a Fullerton Ivy League amp.
/// ///
/// - Parameters: /// - Parameters:
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`. /// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
public init(inputBus: Int = 0, outputBus: Int = 0) { public init(inputBus: Int = 0, outputBus: Int = 0) {
super.init(name: "Fullerton Princeton", inputBus: inputBus, outputBus: outputBus) super.init(name: "Fullerton Ivy League", inputBus: inputBus, outputBus: outputBus)
gain = 5.0 // hotter still — the small combo grits up soonest gain = 5.0 // hotter still — the small combo grits up soonest
bass = 0.4 // least low end of the trio bass = 0.4 // least low end of the trio
treble = 0.55 // a shade darker treble = 0.55 // a shade darker
@@ -17,36 +17,21 @@ import LyrebirdUI
/// tube-rectified amp. **Tight** high-passes the input to tighten the low end for fast riffing. /// tube-rectified amp. **Tight** high-passes the input to tighten the low end for fast riffing.
public final class ModernHighGainAmpPedal: BoutiqueAmpPedal { public final class ModernHighGainAmpPedal: BoutiqueAmpPedal {
/// Sag amount in [0, 1]: `0` = stiff (no droop), `1` = heavy power-supply sag/bloom.
@UIParam public var sag: Double = 0.3
/// Tight switch: `0` = full low end, `1` = low-cut engaged (tight riffing). /// Tight switch: `0` = full low end, `1` = low-cut engaged (tight riffing).
@UIParam public var tight: Double = 0.0 @UIParam public var tight: Double = 0.0
/// Sag envelope-follower attack — moderately fast (the supply starts drooping under load).
private let sagAttackSeconds: Double = 0.02
/// Sag envelope-follower release — slow, so the sag lingers and blooms back (supply recovery).
private let sagReleaseSeconds: Double = 0.30
/// Tight low-cut: high-pass corner is ~20 Hz (loose, no cut) or `tightFreqHz` (tight). /// Tight low-cut: high-pass corner is ~20 Hz (loose, no cut) or `tightFreqHz` (tight).
private let tightLooseFreqHz: Double = 20.0 private let tightLooseFreqHz: Double = 20.0
/// Tight-switch-on high-pass corner in Hz. /// Tight-switch-on high-pass corner in Hz.
private let tightFreqHz: Double = 120.0 private let tightFreqHz: Double = 120.0
/// Tight high-pass Q (Butterworth). /// Tight high-pass Q (Butterworth).
private let tightQ: Double = 0.707 private let tightQ: Double = 0.707
/// Lowest the sag gain can droop to (~-16 dB — the deepest droop before the tone reads as
/// obviously gated rather than sagging). Bounds sag depth and — crucially — keeps the gain
/// strictly positive: the envelope tracks a post-shelf signal that can exceed 1, so an unclamped
/// `1 − sag·env` would go negative and phase-invert loud content instead of drooping.
private let sagGainFloor: Double = 0.15
public override var toneStackModel: ToneStackModel { .mesa } public override var toneStackModel: ToneStackModel { .mesa }
public override var summaryText: String { public override var summaryText: String {
"Modern high-gain rectifier — scooped Mesa lead with Sag (power-supply bloom) and a Tight switch." "Modern high-gain rectifier — scooped Mesa lead with Sag (power-supply bloom) and a Tight switch."
} }
public override var signatureKnobs: [PedalKnob] {
super.signatureKnobs + [PedalKnob(label: "Sag", node: $sag, range: signatureRange)]
}
public override var effectSwitches: [PedalSwitch] { public override var effectSwitches: [PedalSwitch] {
super.effectSwitches + [ super.effectSwitches + [
PedalSwitch( PedalSwitch(
@@ -70,6 +55,7 @@ public final class ModernHighGainAmpPedal: BoutiqueAmpPedal {
gain = 7.0 gain = 7.0
drive = 18.0 // hottest lead of the lineup drive = 18.0 // hottest lead of the lineup
cab = 1.0 // British 4×12 — tight, aggressive cab = 1.0 // British 4×12 — tight, aggressive
sag = 0.3 // rectifier bloom on by default (shared power-amp Sag from AmpVoicePedal)
} }
/// Tight switch: a pre-preamp high-pass whose corner switches between ~20 Hz (loose, negligible /// Tight switch: a pre-preamp high-pass whose corner switches between ~20 Hz (loose, negligible
@@ -79,18 +65,4 @@ public final class ModernHighGainAmpPedal: BoutiqueAmpPedal {
$tight, inLo: 0.0, inHi: 1.0, outLo: tightLooseFreqHz, outHi: tightFreqHz) $tight, inLo: 0.0, inHi: 1.0, outLo: tightLooseFreqHz, outHi: tightFreqHz)
return RBJHighPass.Audio(input: signal, freq: cutoff, q: tightQ) return RBJHighPass.Audio(input: signal, freq: cutoff, q: tightQ)
} }
/// Base Presence/Depth shaping, then power-supply Sag: an envelope follower reduces gain as the
/// signal gets loud (droop) and recovers slowly (bloom). `Sag` scales the depth; `0` = stiff.
public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let shaped: any ValidGeneratorInput = super.shapeVoice(signal)
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
in: shaped, attackTime: sagAttackSeconds, releaseTime: sagReleaseSeconds)
// Gain droops toward `sagGainFloor` as the envelope rises. The Presence/Depth shelves can
// push the envelope above 1, so clamp to `[sagGainFloor, 1]` — an unclamped `1 − sag·env`
// would go negative and phase-invert loud content instead of attenuating it.
let sagGain: any ValidGeneratorInput = Clip.Audio(
1.0 - ($sag * envelope), lo: sagGainFloor, hi: 1.0)
return shaped * sagGain
}
} }
@@ -20,6 +20,7 @@ extension Pedal {
let switchValues: [Double] = effectSwitches.map { $0.node.value } let switchValues: [Double] = effectSwitches.map { $0.node.value }
let sliderValues: [Double] = effectSliders.map { $0.node.value } let sliderValues: [Double] = effectSliders.map { $0.node.value }
let selectorValues: [Double] = effectSelectors.map { $0.node.value } let selectorValues: [Double] = effectSelectors.map { $0.node.value }
let advancedValues: [Double] = advancedKnobs.map { $0.node.value }
return PedalState( return PedalState(
id: id, id: id,
type: displayName, type: displayName,
@@ -27,26 +28,74 @@ extension Pedal {
switchValues: switchValues, switchValues: switchValues,
sliderValues: sliderValues, sliderValues: sliderValues,
selectorValues: selectorValues, selectorValues: selectorValues,
advancedValues: advancedValues,
bypass: bypass, bypass: bypass,
tempoSync: tempoSync.isEmpty ? nil : tempoSync, tempoSync: tempoSync.isEmpty ? nil : tempoSync,
resourcePath: resourcePath resourcePath: resourcePath
) )
} }
/// Modern High-Gain's display name — the one shipped amp whose `Sag` control started life as a
/// face knob and later moved to the advanced pop-over. Used to detect its legacy `PedalState`
/// layout in ``legacyMigrated(_:)``.
private static let modernHighGainType: String = "Modern High-Gain"
/// A legacy Modern High-Gain `PedalState` has 11 `knobValues`: `Gain, Bass, Mid, Treble,
/// Presence, Depth, Master, Drive, Sag, Mix, Level`.
private static let modernHighGainLegacyKnobCount: Int = 11
/// Index of `Sag` in that legacy `knobValues` array (the 9th knob).
private static let modernHighGainLegacySagIndex: Int = 8
/// Normalizes a `PedalState` saved under a superseded on-disk layout to the current shape, so old
/// rigs load without corruption.
///
/// Currently one case: **Modern High-Gain** shipped `Sag` as its 9th face knob (`knobValues`
/// index 8, ahead of the trailing `Mix`/`Level`); `Sag` has since moved to the advanced pop-over,
/// so it is no longer in `knobValues`. Because `knobValues` is a flat positional array, loading a
/// legacy preset against the current 10-knob shape would misassign the old `Sag` onto `Mix` and
/// the old `Mix` onto `Level`. Detected by the legacy shape (11 `knobValues`, empty
/// `advancedValues`) and rewritten: `Sag` is lifted out of `knobValues` into `advancedValues`,
/// leaving `Gain…Drive, Mix, Level` in order. `Bias` (the second advanced knob) had no legacy
/// value, so it stays at its default.
///
/// - Parameter state: The decoded state, possibly in a legacy layout.
/// - Returns: The state in the current layout, or `state` unchanged when no migration applies.
private static func legacyMigrated(_ state: PedalState) -> PedalState {
guard state.type == modernHighGainType,
state.advancedValues.isEmpty,
state.knobValues.count == modernHighGainLegacyKnobCount else {
return state
}
let sag: Double = state.knobValues[modernHighGainLegacySagIndex]
var knobValues: [Double] = state.knobValues
knobValues.remove(at: modernHighGainLegacySagIndex)
return PedalState(
id: state.id,
type: state.type,
knobValues: knobValues,
switchValues: state.switchValues,
sliderValues: state.sliderValues,
selectorValues: state.selectorValues,
advancedValues: [sag],
bypass: state.bypass,
tempoSync: state.tempoSync,
resourcePath: state.resourcePath
)
}
/// Applies a previously captured `PedalState` to this pedal's parameters. /// Applies a previously captured `PedalState` to this pedal's parameters.
/// ///
/// For each (knob, value) pair in `zip(knobs, state.knobValues)`, the knob's /// The incoming state is first normalized by ``legacyMigrated(_:)`` for older on-disk layouts.
/// `UIParamNode` is updated via `node.update(_:)`; switch positions are restored the /// For each (knob, value) pair in `zip(knobs, state.knobValues)`, the knob's `UIParamNode` is
/// same way from `zip(effectSwitches, state.switchValues)`. If either array has fewer /// updated via `node.update(_:)`; switch, slider, selector, and advanced-knob positions are
/// entries than its controls, the trailing controls retain their current values; extra /// restored the same way. If either array has fewer entries than its controls, the trailing
/// values are ignored. The `bypass` parameter is always applied regardless of any /// controls retain their current values; extra values are ignored. The `bypass` parameter is
/// count mismatch. Presets saved before switches existed carry an empty /// always applied regardless of any count mismatch. Presets saved before a given control existed
/// `switchValues`, leaving switch positions at their defaults. /// carry an empty array for it, leaving those controls at their defaults.
/// ///
/// - Parameter state: The state to restore. The `state.type` is not validated /// - Parameter rawState: The state to restore. The `state.type` is not validated against
/// against `displayName` — the caller is responsible for matching types before /// `displayName` — the caller is responsible for matching types before calling this method.
/// calling this method. public func applyState(_ rawState: PedalState) {
public func applyState(_ state: PedalState) { let state: PedalState = Pedal.legacyMigrated(rawState)
// Restore the saved identity so the pedal keeps its id across rebuilds; MIDI bindings // Restore the saved identity so the pedal keeps its id across rebuilds; MIDI bindings
// address pedals by this id. // address pedals by this id.
id = state.id id = state.id
@@ -62,6 +111,9 @@ extension Pedal {
for (selector, value) in zip(effectSelectors, state.selectorValues) { for (selector, value) in zip(effectSelectors, state.selectorValues) {
selector.node.update(value) selector.node.update(value)
} }
for (advancedKnob, value) in zip(advancedKnobs, state.advancedValues) {
advancedKnob.node.update(value)
}
bypass = state.bypass bypass = state.bypass
// Restore tempo-sync state. The synced values themselves are recomputed from the rig's // Restore tempo-sync state. The synced values themselves are recomputed from the rig's
// tempo by `ShoeGaze` after the rebuild, so no clock is required here. // tempo by `ShoeGaze` after the rebuild, so no clock is required here.
@@ -53,7 +53,7 @@ public enum PedalRegistry {
"Chime Baby": { ChimeBabyAmpPedal() }, "Chime Baby": { ChimeBabyAmpPedal() },
"Fullerton Reverb": { FullertonReverbAmpPedal() }, "Fullerton Reverb": { FullertonReverbAmpPedal() },
"Fullerton Deluxe": { FullertonDeluxeAmpPedal() }, "Fullerton Deluxe": { FullertonDeluxeAmpPedal() },
"Fullerton Princeton": { FullertonPrincetonAmpPedal() }, "Fullerton Ivy League": { FullertonPrincetonAmpPedal() },
"Fullerton Drive": { FullertonDriveAmpPedal() }, "Fullerton Drive": { FullertonDriveAmpPedal() },
"Jazz Clean": { JazzCleanAmpPedal() }, "Jazz Clean": { JazzCleanAmpPedal() },
"Chime Top Boost": { ChimeTopBoostAmpPedal() }, "Chime Top Boost": { ChimeTopBoostAmpPedal() },
@@ -101,6 +101,15 @@ public enum PedalRegistry {
"Looper": { LooperPedal() }, "Looper": { LooperPedal() },
] ]
/// Maps a pedal `displayName` that has since been renamed to its current registry key, so rigs
/// saved under the old name still load (the `displayName` **is** the serialization key — see
/// ``BoardSegmentState`` — so a bare rename would silently drop the pedal on load). A loaded
/// pedal takes the new name and re-saves under it, so this is self-healing. Extend when renaming
/// any shipped pedal's `displayName`.
static let legacyTypeAliases: [String: String] = [
"Fullerton Princeton": "Fullerton Ivy League",
]
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type /// Returns a new `Pedal` instance for the given type string, or `nil` if the type
/// is not in the built-in registry. /// is not in the built-in registry.
/// ///
@@ -108,11 +117,15 @@ public enum PedalRegistry {
/// the caller is responsible for routing it via `board.add(_:)` before the engine /// the caller is responsible for routing it via `board.add(_:)` before the engine
/// processes any audio. /// processes any audio.
/// ///
/// A ``legacyTypeAliases`` entry is resolved first, so a rig saved under a pedal's old
/// `displayName` still reconstructs the renamed pedal.
///
/// - Parameter type: The `displayName` of the pedal (e.g. `"Overdrive"`, `"Delay"`). /// - Parameter type: The `displayName` of the pedal (e.g. `"Overdrive"`, `"Delay"`).
/// - Returns: A freshly allocated `Pedal` subclass instance, or `nil` for unknown types. /// - Returns: A freshly allocated `Pedal` subclass instance, or `nil` for unknown types.
@MainActor @MainActor
public static func makePedal(type: String) -> Pedal? { public static func makePedal(type: String) -> Pedal? {
guard let constructor: @MainActor () -> Pedal = builtIn[type] else { return nil } let resolvedType: String = legacyTypeAliases[type] ?? type
guard let constructor: @MainActor () -> Pedal = builtIn[resolvedType] else { return nil }
return constructor() return constructor()
} }
@@ -42,6 +42,10 @@ public struct PedalState: Codable, Equatable {
/// no selectors. Absent in presets saved before selectors existed — decodes to `[]`. /// no selectors. Absent in presets saved before selectors existed — decodes to `[]`.
public let selectorValues: [Double] public let selectorValues: [Double]
/// Advanced (pop-over) knob values in the same order as `Pedal.advancedKnobs`. Empty for pedals
/// with no advanced knobs. Absent in presets saved before advanced knobs existed — decodes to `[]`.
public let advancedValues: [Double]
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed. /// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
public let bypass: Double public let bypass: Double
@@ -62,6 +66,7 @@ public struct PedalState: Codable, Equatable {
/// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty. /// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty.
/// - sliderValues: Current slider values in `Pedal.effectSliders` order. Defaults to empty. /// - sliderValues: Current slider values in `Pedal.effectSliders` order. Defaults to empty.
/// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty. /// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty.
/// - advancedValues: Current advanced-knob values in `Pedal.advancedKnobs` order. Defaults to empty.
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed). /// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
/// - tempoSync: Tempo-sync state per syncable parameter, or `nil` for none. Defaults to `nil`. /// - tempoSync: Tempo-sync state per syncable parameter, or `nil` for none. Defaults to `nil`.
/// - resourcePath: Path to an external resource the pedal references (e.g. a neural-amp /// - resourcePath: Path to an external resource the pedal references (e.g. a neural-amp
@@ -73,6 +78,7 @@ public struct PedalState: Codable, Equatable {
switchValues: [Double] = [], switchValues: [Double] = [],
sliderValues: [Double] = [], sliderValues: [Double] = [],
selectorValues: [Double] = [], selectorValues: [Double] = [],
advancedValues: [Double] = [],
bypass: Double, bypass: Double,
tempoSync: [String: TempoSync]? = nil, tempoSync: [String: TempoSync]? = nil,
resourcePath: String? = nil resourcePath: String? = nil
@@ -83,6 +89,7 @@ public struct PedalState: Codable, Equatable {
self.switchValues = switchValues self.switchValues = switchValues
self.sliderValues = sliderValues self.sliderValues = sliderValues
self.selectorValues = selectorValues self.selectorValues = selectorValues
self.advancedValues = advancedValues
self.bypass = bypass self.bypass = bypass
self.tempoSync = tempoSync self.tempoSync = tempoSync
self.resourcePath = resourcePath self.resourcePath = resourcePath
@@ -95,13 +102,14 @@ public struct PedalState: Codable, Equatable {
case switchValues case switchValues
case sliderValues case sliderValues
case selectorValues case selectorValues
case advancedValues
case bypass case bypass
case tempoSync case tempoSync
case resourcePath case resourcePath
} }
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` / /// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` /
/// `selectorValues` / `tempoSync` existed by defaulting the missing keys. /// `selectorValues` / `advancedValues` / `tempoSync` existed by defaulting the missing keys.
public init(from decoder: any Decoder) throws { public init(from decoder: any Decoder) throws {
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self) let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID() self.id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
@@ -110,6 +118,7 @@ public struct PedalState: Codable, Equatable {
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? [] self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
self.sliderValues = try container.decodeIfPresent([Double].self, forKey: .sliderValues) ?? [] self.sliderValues = try container.decodeIfPresent([Double].self, forKey: .sliderValues) ?? []
self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? [] self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? []
self.advancedValues = try container.decodeIfPresent([Double].self, forKey: .advancedValues) ?? []
self.bypass = try container.decode(Double.self, forKey: .bypass) self.bypass = try container.decode(Double.self, forKey: .bypass)
self.tempoSync = try container.decodeIfPresent([String: TempoSync].self, forKey: .tempoSync) self.tempoSync = try container.decodeIfPresent([String: TempoSync].self, forKey: .tempoSync)
self.resourcePath = try container.decodeIfPresent(String.self, forKey: .resourcePath) self.resourcePath = try container.decodeIfPresent(String.self, forKey: .resourcePath)
@@ -44,7 +44,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
} }
private static let mapping: [String: PedalCategory] = [ private static let mapping: [String: PedalCategory] = [
"California": .amp, "British": .amp, "British Plexi": .amp, "British JTM": .amp, "British Bluesbreaker": .amp, "British Master": .amp, "British Dual": .amp, "Boutique Lead": .amp, "Boutique OD": .amp, "Cali Hi-Gain": .amp, "Command": .amp, "Citrus": .amp, "Sixties Combo": .amp, "Magna Vibrato": .amp, "Anaheim": .amp, "Modern High-Gain": .amp, "Chime": .amp, "Chime 15": .amp, "Chime Normal": .amp, "Chime Baby": .amp, "Fullerton Reverb": .amp, "Fullerton Deluxe": .amp, "Fullerton Princeton": .amp, "Fullerton Drive": .amp, "Jazz Clean": .amp, "Chime Top Boost": .amp, "Neural Amp": .amp, "California": .amp, "British": .amp, "British Plexi": .amp, "British JTM": .amp, "British Bluesbreaker": .amp, "British Master": .amp, "British Dual": .amp, "Boutique Lead": .amp, "Boutique OD": .amp, "Cali Hi-Gain": .amp, "Command": .amp, "Citrus": .amp, "Sixties Combo": .amp, "Magna Vibrato": .amp, "Anaheim": .amp, "Modern High-Gain": .amp, "Chime": .amp, "Chime 15": .amp, "Chime Normal": .amp, "Chime Baby": .amp, "Fullerton Reverb": .amp, "Fullerton Deluxe": .amp, "Fullerton Ivy League": .amp, "Fullerton Drive": .amp, "Jazz Clean": .amp, "Chime Top Boost": .amp, "Neural Amp": .amp,
"Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
"Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics, "Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics,
"Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter, "Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter,
@@ -54,7 +54,7 @@ public struct PedalPaletteView: View {
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is /// Preferred display order for the built-in pedals. Any registered pedal not listed here is
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal. /// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
private static let preferredOrder: [String] = [ private static let preferredOrder: [String] = [
"California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "British Master", "British Dual", "Boutique Lead", "Boutique OD", "Cali Hi-Gain", "Command", "Citrus", "Sixties Combo", "Magna Vibrato", "Anaheim", "Modern High-Gain", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Princeton", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", "California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "British Master", "British Dual", "Boutique Lead", "Boutique OD", "Cali Hi-Gain", "Command", "Citrus", "Sixties Combo", "Magna Vibrato", "Anaheim", "Modern High-Gain", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Ivy League", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
"Volume", "Volume",
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary", "Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary",
"Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator", "Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator",
@@ -183,6 +183,12 @@ public struct PedalPaletteView: View {
/// Full-width column for a left sidebar. /// Full-width column for a left sidebar.
private var verticalBody: some View { private var verticalBody: some View {
VStack(alignment: .leading, spacing: PedalPaletteView.sectionSpacing) { VStack(alignment: .leading, spacing: PedalPaletteView.sectionSpacing) {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
sectionTitle("ROUTING")
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
routingCard(title: option.title, caption: option.caption, action: option.action)
}
}
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) { VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
HStack { HStack {
sectionTitle("PEDALS") sectionTitle("PEDALS")
@@ -193,13 +199,6 @@ public struct PedalPaletteView: View {
pedalRow(name) pedalRow(name)
} }
} }
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
sectionTitle("ROUTING")
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
routingCard(title: option.title, caption: option.caption, action: option.action)
}
}
} }
} }
@@ -225,6 +224,14 @@ public struct PedalPaletteView: View {
} }
} }
HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) { HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
sectionTitle("ROUTING")
HStack(alignment: .top, spacing: PedalPaletteView.rowSpacing) {
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
routingCard(title: option.title, caption: option.caption, action: option.action)
}
}
}
if let amps: (category: PedalCategory, names: [String]) = ampGroup { if let amps: (category: PedalCategory, names: [String]) = ampGroup {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) { VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
categoryLabel(amps.category) categoryLabel(amps.category)
@@ -235,14 +242,6 @@ public struct PedalPaletteView: View {
} }
} }
} }
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
sectionTitle("ROUTING")
HStack(alignment: .top, spacing: PedalPaletteView.rowSpacing) {
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
routingCard(title: option.title, caption: option.caption, action: option.action)
}
}
}
} }
} }
} }
+65 -5
View File
@@ -34,15 +34,15 @@ private func enclosureColor(for displayName: String) -> Color {
case "Anaheim": return Color(red: 0.24, green: 0.30, blue: 0.32) // hybrid slate case "Anaheim": return Color(red: 0.24, green: 0.30, blue: 0.32) // hybrid slate
case "Modern High-Gain": return Color(red: 0.12, green: 0.12, blue: 0.14) // recto black case "Modern High-Gain": return Color(red: 0.12, green: 0.12, blue: 0.14) // recto black
case "Chime": return Color(red: 0.16, green: 0.24, blue: 0.22) // vintage green case "Chime": return Color(red: 0.16, green: 0.24, blue: 0.22) // vintage green
case "Chime 15": return Color(red: 0.18, green: 0.28, blue: 0.22) // brighter vox green case "Chime 15": return Color(red: 0.18, green: 0.28, blue: 0.22) // brighter chime green
case "Chime Normal": return Color(red: 0.20, green: 0.26, blue: 0.20) // warm vox green case "Chime Normal": return Color(red: 0.20, green: 0.26, blue: 0.20) // warm chime green
case "Chime Baby": return Color(red: 0.22, green: 0.30, blue: 0.24) // pale vox green case "Chime Baby": return Color(red: 0.22, green: 0.30, blue: 0.24) // pale chime green
case "Fullerton Reverb": return Color(red: 0.15, green: 0.22, blue: 0.30) // blackface panel case "Fullerton Reverb": return Color(red: 0.15, green: 0.22, blue: 0.30) // blackface panel
case "Fullerton Deluxe": return Color(red: 0.17, green: 0.20, blue: 0.26) // blackface, warmer case "Fullerton Deluxe": return Color(red: 0.17, green: 0.20, blue: 0.26) // blackface, warmer
case "Fullerton Princeton": return Color(red: 0.19, green: 0.19, blue: 0.23) // small blackface case "Fullerton Ivy League": return Color(red: 0.19, green: 0.19, blue: 0.23) // small blackface
case "Fullerton Drive": return Color(red: 0.22, green: 0.18, blue: 0.24) // two-channel combo case "Fullerton Drive": return Color(red: 0.22, green: 0.18, blue: 0.24) // two-channel combo
case "Jazz Clean": return Color(red: 0.14, green: 0.30, blue: 0.34) // solid-state silver-teal case "Jazz Clean": return Color(red: 0.14, green: 0.30, blue: 0.34) // solid-state silver-teal
case "Chime Top Boost": return Color(red: 0.20, green: 0.32, blue: 0.20) // vox-green tolex case "Chime Top Boost": return Color(red: 0.20, green: 0.32, blue: 0.20) // chime-green tolex
case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
@@ -470,6 +470,14 @@ public struct PedalView: View {
/// Insets placing the ⓘ info button just under the top-left corner screw. /// Insets placing the ⓘ info button just under the top-left corner screw.
private static let infoButtonLeading: CGFloat = 5 private static let infoButtonLeading: CGFloat = 5
private static let infoButtonTop: CGFloat = 20 private static let infoButtonTop: CGFloat = 20
/// Insets placing the advanced (gear) button just under the top-right corner screw, mirroring
/// the info button.
private static let advancedButtonTrailing: CGFloat = 5
private static let advancedButtonTop: CGFloat = 20
/// Layout of the advanced-controls pop-over: knobs per row and the inter-knob gap.
private static let advancedPopoverColumns: Int = 2
private static let advancedPopoverSpacing: CGFloat = 14
private static let advancedPopoverPadding: CGFloat = 16
private static let outerBorderLineWidth: CGFloat = 1.5 private static let outerBorderLineWidth: CGFloat = 1.5
private static let innerHighlightLineWidth: CGFloat = 1 private static let innerHighlightLineWidth: CGFloat = 1
private static let innerHighlightPadding: CGFloat = 1 private static let innerHighlightPadding: CGFloat = 1
@@ -482,6 +490,9 @@ public struct PedalView: View {
/// Presentation flag for the pedal info panel (description + control ranges). /// Presentation flag for the pedal info panel (description + control ranges).
@State private var showInfo: Bool = false @State private var showInfo: Bool = false
/// Presentation flag for the advanced-controls pop-over (amp Sag / Bias).
@State private var showAdvanced: Bool = false
/// Presentation flag for the Neural Amp model-file importer. /// Presentation flag for the Neural Amp model-file importer.
@State private var showModelImporter: Bool = false @State private var showModelImporter: Bool = false
@@ -559,6 +570,15 @@ public struct PedalView: View {
.padding(.leading, PedalView.infoButtonLeading) .padding(.leading, PedalView.infoButtonLeading)
.padding(.top, PedalView.infoButtonTop) .padding(.top, PedalView.infoButtonTop)
} }
// Advanced (gear) button, tucked under the top-right corner screw — only for pedals that
// publish advanced knobs (e.g. an amp's Sag / Bias).
.overlay(alignment: .topTrailing) {
if !pedal.advancedKnobs.isEmpty {
advancedButton
.padding(.trailing, PedalView.advancedButtonTrailing)
.padding(.top, PedalView.advancedButtonTop)
}
}
.shadow( .shadow(
color: Color.black.opacity(PedalView.shadowOpacity), color: Color.black.opacity(PedalView.shadowOpacity),
radius: PedalView.shadowRadius, radius: PedalView.shadowRadius,
@@ -731,6 +751,46 @@ public struct PedalView: View {
.help("About this pedal") .help("About this pedal")
} }
/// Advanced-controls (gear) button tucked under the top-right corner screw. Presents
/// ``advancedPanel`` — the pedal's ``Pedal/advancedKnobs`` — in a popover. Only drawn when the
/// pedal publishes advanced knobs (the caller gates on `advancedKnobs.isEmpty`).
private var advancedButton: some View {
Button {
showAdvanced = true
} label: {
Image(systemName: "slider.horizontal.3")
.font(.system(size: PedalView.fontSizeNamePlate))
.foregroundStyle(Color.white.opacity(PedalView.infoButtonOpacity))
}
.buttonStyle(.plain)
.help("Advanced controls")
.popover(isPresented: $showAdvanced) {
advancedPanel
.presentationCompactAdaptation(.popover)
}
}
/// Grid of the pedal's ``Pedal/advancedKnobs`` shown in the advanced popover, laid out in rows of
/// ``advancedPopoverColumns``. Plain `ParameterKnob`s — these are live, non-topology controls.
private var advancedPanel: some View {
let knobs: [PedalKnob] = pedal.advancedKnobs
let columns: Int = PedalView.advancedPopoverColumns
let rows: [[PedalKnob]] = stride(from: 0, to: knobs.count, by: columns).map { startIndex in
Array(knobs[startIndex ..< min(startIndex + columns, knobs.count)])
}
return VStack(spacing: PedalView.advancedPopoverSpacing) {
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
HStack(alignment: .top, spacing: PedalView.advancedPopoverSpacing) {
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { knobPair in
ParameterKnob(knobPair.element.label, node: knobPair.element.node, range: knobPair.element.range)
.foregroundStyle(Color.white)
}
}
}
}
.padding(PedalView.advancedPopoverPadding)
}
/// Grid of the effect knobs, in rows of up to `knobColumnCount`. /// Grid of the effect knobs, in rows of up to `knobColumnCount`.
/// ///
/// The trailing `Mix` and `Level` knobs (the last two entries of `pedal.knobs`) are /// The trailing `Mix` and `Level` knobs (the last two entries of `pedal.knobs`) are
@@ -183,6 +183,82 @@ struct AmpVoicePedalTests {
#expect(windowedSSD(open, dark) > 0, "Chime Cut had no effect") #expect(windowedSSD(open, dark) > 0, "Chime Cut had no effect")
} }
// MARK: - Power-amp Sag / Bias (shared)
@Test func sagChangesOutput() throws {
for voice in voices {
let stiff: [Float] = try render(voice.make) { $0.gain = 20.0; $0.sag = 0.0 }
let saggy: [Float] = try render(voice.make) { $0.gain = 20.0; $0.sag = 1.0 }
#expect(windowedSSD(stiff, saggy) > 0, "\(voice.name) Sag had no effect")
}
}
@Test func sagStaysWithinCeilingWithoutPhaseInversion() throws {
// Sag is a gain droop; it must attenuate loud content, never phase-invert it. The envelope
// tracks a post-power-amp signal that can exceed 1, so the droop gain is clamped positive.
// Assert the sagged output correlates positively with the stiff one (not an inverted copy)
// and never breaches the ±1 ceiling.
let ceilingEpsilon: Double = 1.0e-4
for voice in voices {
let cfg: (AmpVoicePedal) -> Void = { (p: AmpVoicePedal) in
p.gain = 25.0; p.bass = 1.0; p.treble = 1.0
}
let stiff: [Float] = try render(voice.make) { cfg($0); $0.sag = 0.0 }
let saggy: [Float] = try render(voice.make) { cfg($0); $0.sag = 1.0 }
let peak: Double = saggy.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.0 + ceilingEpsilon, "\(voice.name) sagged peak \(peak) exceeds ±1")
let skip: Int = 4096, window: Int = 4096
guard stiff.count >= skip + window, saggy.count >= skip + window else {
Issue.record("\(voice.name) render too short"); continue
}
let dotProduct: Double = zip(stiff[skip..<(skip + window)], saggy[skip..<(skip + window)])
.reduce(0.0) { acc, pair in acc + Double(pair.0) * Double(pair.1) }
#expect(dotProduct > 0, "\(voice.name) Sag phase-inverted the signal (dot \(dotProduct) < 0)")
}
}
@Test func biasChangesWaveshape() throws {
// Bias shifts the power-amp tanh operating point → changes the even/odd harmonic mix (a
// waveshape change), not merely the level. RMS-normalize so a pure level difference collapses.
for voice in voices {
let cold: [Float] = try render(voice.make) { $0.gain = 22.0; $0.bias = 0.0 }
let hot: [Float] = try render(voice.make) { $0.gain = 22.0; $0.bias = 1.0 }
#expect(hasNonSilentOutput(cold) && hasNonSilentOutput(hot))
#expect(rmsNormalizedSSD(cold, hot) > 1.0e-4, "\(voice.name) Bias changed level but not waveshape")
}
}
@Test func neutralBiasAndZeroSagAreIdentityDefault() throws {
// The shipped defaults are sag = 0 and bias = 0.5 (neutral). Setting them explicitly to those
// values must be bit-for-bit identical to leaving them at their defaults — proof the new
// controls don't perturb any existing amp's voice at their neutral position.
for voice in voices {
let byDefault: [Float] = try render(voice.make)
let explicit: [Float] = try render(voice.make) { $0.sag = 0.0; $0.bias = 0.5 }
#expect(windowedSSD(byDefault, explicit) == 0, "\(voice.name) neutral Sag/Bias is not identity")
}
}
@Test func advancedKnobsExposeSagAndBias() throws {
for voice in voices {
let pedal: AmpVoicePedal = voice.make()
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias"], "\(voice.name) advanced knobs")
// Sag/Bias are pop-over-only — they must NOT also appear on the pedal face.
let faceLabels: [String] = pedal.effectKnobs.map { $0.label }
#expect(!faceLabels.contains("Sag") && !faceLabels.contains("Bias"),
"\(voice.name) leaked Sag/Bias onto the pedal face")
}
}
@Test func sagBiasRoundTripThroughState() throws {
let pedal: CaliforniaAmpPedal = CaliforniaAmpPedal()
pedal.sag = 0.7
pedal.bias = 0.2
let restored: CaliforniaAmpPedal = CaliforniaAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.sag == 0.7 && restored.bias == 0.2, "Sag/Bias did not round-trip through state")
}
// MARK: - Chrome / config // MARK: - Chrome / config
@Test func exposesControls() throws { @Test func exposesControls() throws {
@@ -11,7 +11,7 @@ import LyrebirdUI
@testable import LyrebirdShoeGaze @testable import LyrebirdShoeGaze
@MainActor @MainActor
@Suite("Chime Vox variants") @Suite("Chime variants")
struct ChimeVariantsTests { struct ChimeVariantsTests {
private let sampleRate: Double = 48000.0 private let sampleRate: Double = 48000.0
@@ -71,7 +71,7 @@ struct ChimeVariantsTests {
} }
} }
@Test func inheritCutSurfaceAndVoxStack() throws { @Test func inheritCutSurfaceAndChimeStack() throws {
for v: (name: String, make: () -> ChimeAmpPedal) in variants { for v: (name: String, make: () -> ChimeAmpPedal) in variants {
let pedal: ChimeAmpPedal = v.make() let pedal: ChimeAmpPedal = v.make()
#expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Cut"], "\(v.name) knobs") #expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Cut"], "\(v.name) knobs")
@@ -51,7 +51,7 @@ struct FullertonVariantsTests {
private let variants: [(name: String, make: () -> FullertonReverbAmpPedal)] = [ private let variants: [(name: String, make: () -> FullertonReverbAmpPedal)] = [
("Fullerton Deluxe", { FullertonDeluxeAmpPedal() }), ("Fullerton Deluxe", { FullertonDeluxeAmpPedal() }),
("Fullerton Princeton", { FullertonPrincetonAmpPedal() }), ("Fullerton Ivy League", { FullertonPrincetonAmpPedal() }),
] ]
@Test func bothBuildNonSilentFinite() throws { @Test func bothBuildNonSilentFinite() throws {
@@ -122,6 +122,13 @@ struct FullertonVariantsTests {
@Test func registeredInBuiltInRegistry() throws { @Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Fullerton Deluxe") is FullertonDeluxeAmpPedal) #expect(PedalRegistry.makePedal(type: "Fullerton Deluxe") is FullertonDeluxeAmpPedal)
#expect(PedalRegistry.makePedal(type: "Fullerton Ivy League") is FullertonPrincetonAmpPedal)
}
@Test func legacyPrincetonNameStillResolves() throws {
// The pedal's display name was "Fullerton Princeton" when first shipped; rigs saved then key
// on that string. The legacy alias must still reconstruct the (renamed) pedal so it isn't
// silently dropped on load.
#expect(PedalRegistry.makePedal(type: "Fullerton Princeton") is FullertonPrincetonAmpPedal) #expect(PedalRegistry.makePedal(type: "Fullerton Princeton") is FullertonPrincetonAmpPedal)
} }
} }
@@ -98,11 +98,14 @@ struct ModernHighGainAmpPedalTests {
@Test func exposesControlSurface() throws { @Test func exposesControlSurface() throws {
let pedal: ModernHighGainAmpPedal = ModernHighGainAmpPedal() let pedal: ModernHighGainAmpPedal = ModernHighGainAmpPedal()
// Sag now lives in the shared advanced pop-over (with Bias), not on the pedal face.
#expect(pedal.effectKnobs.map { $0.label } #expect(pedal.effectKnobs.map { $0.label }
== ["Gain", "Bass", "Mid", "Treble", "Presence", "Depth", "Master", "Drive", "Sag"]) == ["Gain", "Bass", "Mid", "Treble", "Presence", "Depth", "Master", "Drive"])
#expect(pedal.advancedKnobs.map { $0.label } == ["Sag", "Bias"])
#expect(pedal.effectSwitches.map { $0.label } == ["Channel", "Tight"]) #expect(pedal.effectSwitches.map { $0.label } == ["Channel", "Tight"])
#expect(pedal.widthUnits == 4) #expect(pedal.widthUnits == 4)
#expect(pedal.toneStackModel == .mesa) #expect(pedal.toneStackModel == .mesa)
#expect(pedal.sag == 0.3, "Modern High-Gain keeps rectifier sag on by default")
} }
@Test func controlsRoundTripThroughState() throws { @Test func controlsRoundTripThroughState() throws {
@@ -118,4 +121,26 @@ struct ModernHighGainAmpPedalTests {
@Test func registeredInBuiltInRegistry() throws { @Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Modern High-Gain") is ModernHighGainAmpPedal) #expect(PedalRegistry.makePedal(type: "Modern High-Gain") is ModernHighGainAmpPedal)
} }
@Test func legacyPresetWithSagOnFaceMigratesWithoutShiftingMixLevel() throws {
// A rig saved when Sag was the 9th face knob has 11 knobValues (Gain…Drive, Sag, Mix, Level)
// and no advancedValues. Sag has since moved to the advanced pop-over, so the current shape
// has 10 knobValues (Gain…Drive, Mix, Level) + 2 advancedValues (Sag, Bias). Loading the
// legacy preset must lift Sag into advancedValues and keep Mix/Level in place — never shift
// the old Sag onto Mix or the old Mix onto Level.
let legacy: PedalState = PedalState(
id: UUID(),
type: "Modern High-Gain",
knobValues: [10.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 15.0, 0.7, 0.8, 0.9],
bypass: 0.0
)
let pedal: ModernHighGainAmpPedal = ModernHighGainAmpPedal()
pedal.applyState(legacy)
let restored: PedalState = pedal.captureState()
// Gain…Drive, then Mix (0.8), Level (0.9) — the old Sag (0.7) is gone from knobValues.
#expect(restored.knobValues == [10.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 15.0, 0.8, 0.9],
"legacy Sag shifted Mix/Level: \(restored.knobValues)")
// Sag lifted into advanced slot 0; Bias had no legacy value → default 0.5.
#expect(restored.advancedValues == [0.7, 0.5], "Sag/Bias advanced values wrong: \(restored.advancedValues)")
}
} }