712f049f96
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>
44 lines
1.7 KiB
Swift
44 lines
1.7 KiB
Swift
// PedalBoard+Preset.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
extension PedalBoard {
|
|
|
|
/// Captures the current state of this board's label and full signal-chain topology as a
|
|
/// `BoardState`.
|
|
///
|
|
/// 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 topology and parameters.
|
|
public func captureState() -> BoardState {
|
|
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)
|
|
}
|
|
}
|