Register stereo pedals for preset round-trip
Add Octave Splitter and Ping-Pong to PedalRegistry so rigs containing them reconstruct on loadRig — board.add replays the mono→stereo width transition automatically. Document that split-section topology (parallel and stereo) remains outside the captured linear chain, as before. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -12,9 +12,16 @@
|
||||
/// are silently skipped by the loader.
|
||||
///
|
||||
/// To register custom pedal types, extend `builtIn` by building your own dictionary
|
||||
/// and merging it before calling `loadRig`. The built-in registry covers the twelve
|
||||
/// factory pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser,
|
||||
/// Compressor, Mu-Tron, Auto-Wah, Feedback Delay, and Multi-Tap Delay.
|
||||
/// and merging it before calling `loadRig`. The built-in registry covers the factory
|
||||
/// pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser, Compressor,
|
||||
/// Mu-Tron, Auto-Wah, Feedback Delay, Multi-Tap Delay, Octave Splitter, and Ping-Pong.
|
||||
///
|
||||
/// > Note: A saved rig captures each board's *linear* pedal chain only (see `BoardState`).
|
||||
/// > When a registered widener (e.g. Octave Splitter) or stereo-native pedal (e.g.
|
||||
/// > Ping-Pong) appears in that chain it round-trips fully — `board.add(_:)` replays the
|
||||
/// > mono → stereo width transition on load. Parallel sections (`split()`/`merge()`) and
|
||||
/// > stereo split regions (`splitStereo()`) are *not* part of the captured linear chain
|
||||
/// > and are therefore not serialized.
|
||||
public enum PedalRegistry {
|
||||
|
||||
/// Maps each built-in pedal display name to a `@MainActor` no-argument constructor.
|
||||
@@ -36,6 +43,8 @@ public enum PedalRegistry {
|
||||
"Auto-Wah": { AutoWahPedal() },
|
||||
"Feedback Delay": { FeedbackDelayPedal() },
|
||||
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
||||
"Octave Splitter": { OctaveUpSplitterPedal() },
|
||||
"Ping-Pong": { PingPongDelayPedal() },
|
||||
]
|
||||
|
||||
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
||||
|
||||
@@ -43,6 +43,50 @@ struct PresetTests {
|
||||
return (sg, engine, url)
|
||||
}
|
||||
|
||||
// MARK: - Stereo pedal round-trip
|
||||
|
||||
@Test func wideningPedalRigRoundTripsThroughFile() throws {
|
||||
// A linear rig containing a widener + a downstream mono pedal must round-trip:
|
||||
// the registered widener replays the mono → stereo transition on load, and the
|
||||
// downstream pedal auto-stereoizes.
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1, numAudioBuses: 128)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let presetURL: URL = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent(UUID().uuidString + ".json")
|
||||
defer { try? FileManager.default.removeItem(at: presetURL) }
|
||||
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
let octave: OctaveUpSplitterPedal = OctaveUpSplitterPedal()
|
||||
octave.drive = 22.0
|
||||
try board.add(octave)
|
||||
try board.add(DelayPedal())
|
||||
try sg.finalizeBoard(board)
|
||||
#expect(board.width == 2, "Rig should be stereo before saving")
|
||||
|
||||
try sg.saveRig(to: presetURL)
|
||||
try sg.loadRig(from: presetURL)
|
||||
|
||||
// After reload: same topology + restored parameter.
|
||||
guard let loadedBoard: PedalBoard = sg.boards.first else {
|
||||
Issue.record("No board after loadRig")
|
||||
return
|
||||
}
|
||||
#expect(loadedBoard.width == 2, "Widener should re-widen the board on load")
|
||||
#expect(loadedBoard.pedals.count == 2, "Both pedals should be reconstructed")
|
||||
guard let loadedOctave: OctaveUpSplitterPedal =
|
||||
loadedBoard.pedals.first as? OctaveUpSplitterPedal else {
|
||||
Issue.record("Octave Splitter not reconstructed (registry miss?)")
|
||||
return
|
||||
}
|
||||
#expect(loadedOctave.$drive.value == 22.0, "Widener drive should be restored")
|
||||
}
|
||||
|
||||
@Test func pingPongPedalIsRegistered() throws {
|
||||
let pedal: Pedal? = PedalRegistry.makePedal(type: "Ping-Pong")
|
||||
#expect(pedal is PingPongDelayPedal, "Ping-Pong should be registered")
|
||||
}
|
||||
|
||||
// MARK: - In-memory round-trip
|
||||
|
||||
@Test func captureStateRoundTripEquality() throws {
|
||||
|
||||
Reference in New Issue
Block a user