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:
@@ -121,6 +121,10 @@ public final class PedalBoard {
|
||||
/// All branch chains owned by the board (for teardown).
|
||||
private var branchChains: [BranchChain] = []
|
||||
|
||||
/// Ordered signal-chain segments (pedals + split regions) in signal-flow order. Used to
|
||||
/// capture full board topology for serialization. Maintained by `add`/`split`/`splitStereo`.
|
||||
private(set) var orderedSegments: [BoardSegment] = []
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a pedalboard that allocates its head bus and prepares for pedal insertion.
|
||||
@@ -227,6 +231,7 @@ public final class PedalBoard {
|
||||
}
|
||||
|
||||
pedals.append(pedal)
|
||||
orderedSegments.append(.pedal(pedal))
|
||||
}
|
||||
|
||||
/// Returns the right tail bus, enforcing the `width == 2 ⟺ outputBusRight != nil` invariant.
|
||||
@@ -289,6 +294,7 @@ public final class PedalBoard {
|
||||
try insertNode(merger, after: nil)
|
||||
routingNodes.append(merger)
|
||||
advanceTail(left: monoBus, right: nil, width: 1)
|
||||
orderedSegments.append(.mergeToMono)
|
||||
}
|
||||
|
||||
// MARK: - Stereo split
|
||||
@@ -355,6 +361,7 @@ public final class PedalBoard {
|
||||
dryTapBus: dryTapBus
|
||||
)
|
||||
stereoSplitSections.append(section)
|
||||
orderedSegments.append(.stereoSplit(section))
|
||||
return section
|
||||
}
|
||||
|
||||
@@ -458,7 +465,14 @@ public final class PedalBoard {
|
||||
branchChains.append(chainA)
|
||||
branchChains.append(chainB)
|
||||
|
||||
return ParallelSection(splitter: splitter, branchA: chainA, branchB: chainB, sharedTail: tail)
|
||||
let section: ParallelSection = ParallelSection(
|
||||
splitter: splitter,
|
||||
branchA: chainA,
|
||||
branchB: chainB,
|
||||
sharedTail: tail
|
||||
)
|
||||
orderedSegments.append(.parallel(section))
|
||||
return section
|
||||
}
|
||||
|
||||
/// Combines the two branches of a ``ParallelSection`` back into the main board chain.
|
||||
@@ -547,6 +561,8 @@ public final class PedalBoard {
|
||||
branchChains.removeAll()
|
||||
|
||||
lastNode = nil
|
||||
orderedSegments.removeAll()
|
||||
stereoSplitSections.removeAll()
|
||||
|
||||
// Step 4: Release board-owned buses (head bus and main-chain inter-node buses).
|
||||
for bus: AudioBus in allocatedBuses {
|
||||
|
||||
Reference in New Issue
Block a user