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>
This commit is contained in:
@@ -48,7 +48,55 @@ extension Pedal {
|
||||
/// - Parameter state: The state to restore. The `state.type` is not validated
|
||||
/// against `displayName` — the caller is responsible for matching types before
|
||||
/// calling this method.
|
||||
public func applyState(_ state: PedalState) {
|
||||
/// 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
|
||||
)
|
||||
}
|
||||
|
||||
public func applyState(_ rawState: PedalState) {
|
||||
let state: PedalState = Pedal.legacyMigrated(rawState)
|
||||
// Restore the saved identity so the pedal keeps its id across rebuilds; MIDI bindings
|
||||
// address pedals by this id.
|
||||
id = state.id
|
||||
|
||||
@@ -101,6 +101,15 @@ public enum PedalRegistry {
|
||||
"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
|
||||
/// 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
|
||||
/// 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"`).
|
||||
/// - Returns: A freshly allocated `Pedal` subclass instance, or `nil` for unknown types.
|
||||
@MainActor
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user