Serialize split-region topology in presets
Replace the flat per-board pedal list with an ordered [BoardSegmentState] (pedal | parallel | stereoSplit | mergeToMono) so parallel and stereo split regions — branch pedal chains plus SplitMode/StereoRoute — round-trip through saveRig/loadRig and rebuildBoard. - PedalBoard.orderedSegments tracks chain structure (add/split/splitStereo/ mergeToMono); captureState() walks it; rebuildSegments() replays it. - BoardState backward-compatible: decodes legacy flat `pedals` arrays; computed `pedals` exposes the linear subset; throws on a file missing both keys. BoardSegmentState wire discriminators documented. - applyState (lightweight recall) extended to branch pedals + routing modes. - Unknown pedal types skipped on load, including inside branches. - Tests: parallel / stereo / mergeToMono file round-trips, legacy decode, unknown-pedal-in-branch, branch-param recall. Suite 116/116; demo builds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -6,14 +6,38 @@
|
||||
|
||||
extension PedalBoard {
|
||||
|
||||
/// Captures the current state of this board's label and pedal chain as a `BoardState`.
|
||||
/// Captures the current state of this board's label and full signal-chain topology as a
|
||||
/// `BoardState`.
|
||||
///
|
||||
/// Each pedal's `displayName`, knob values, and bypass flag are snapshotted in
|
||||
/// signal-flow order. The engine graph is not modified; this is a read-only operation.
|
||||
/// Walks the board's ordered segments, snapshotting each linear pedal and each split
|
||||
/// region (parallel and stereo) in signal-flow order — including branch pedal chains and
|
||||
/// the section's routing mode. The engine graph is not modified; this is read-only.
|
||||
///
|
||||
/// - Returns: A `BoardState` reflecting the board's current label and pedal parameters.
|
||||
/// - Returns: A `BoardState` reflecting the board's current topology and parameters.
|
||||
public func captureState() -> BoardState {
|
||||
let pedalStates: [PedalState] = pedals.map { $0.captureState() }
|
||||
return BoardState(label: label, pedals: pedalStates)
|
||||
let segmentStates: [BoardSegmentState] = orderedSegments.map { segment in
|
||||
switch segment {
|
||||
case .pedal(let pedal):
|
||||
return BoardSegmentState.pedal(pedal.captureState())
|
||||
|
||||
case .parallel(let section):
|
||||
return BoardSegmentState.parallel(ParallelSectionState(
|
||||
branchA: section.branchA.pedals.map { $0.captureState() },
|
||||
branchB: section.branchB.pedals.map { $0.captureState() },
|
||||
mode: section.splitter.mode
|
||||
))
|
||||
|
||||
case .stereoSplit(let section):
|
||||
return BoardSegmentState.stereoSplit(StereoSplitState(
|
||||
left: section.left.pedals.map { $0.captureState() },
|
||||
right: section.right.pedals.map { $0.captureState() },
|
||||
route: section.route
|
||||
))
|
||||
|
||||
case .mergeToMono:
|
||||
return BoardSegmentState.mergeToMono
|
||||
}
|
||||
}
|
||||
return BoardState(label: label, segments: segmentStates)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user