Add board edit API: lane-addressed pedal/region editing

Core support for interactively building and editing a board, all via the
existing capture-BoardState -> mutate -> rebuildBoard path (no RT-graph
surgery):

- PedalLane addresses the main chain or a stereo/parallel branch.
- appendPedal/removePedal/movePedal gain a `lane:` parameter (default
  .main, so existing call sites are unchanged).
- appendStereoSplit/appendParallelSplit/appendMergeToMono/removeSegment
  insert and remove branch regions; split/merge guarded by tail width.
- setInputSource preserves the rig across an input-source change.
- rebuildAllBoards / loadRig(from:Data) / rigData added; loadRig is now
  atomic (teardown-on-failure) so a failed load leaves an empty rig.
- Expose PedalBoard.orderedSegments and BoardSegment publicly so a UI can
  walk live board structure; index aligns with captureState().segments.
- InputSource: Equatable. New errors: unknownPedalType,
  pedalIndexOutOfRange, cannotSplitStereoChain, cannotMergeMonoChain,
  notABranchRegion.

Tests cover append/remove/move on main and branch lanes, region
add/remove, width guards, move-to-end before trailing regions, input
switch, and knob/bypass/branch value persistence through save/load.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 09:31:57 -07:00
parent 0960d4e7c5
commit e1ec98413d
8 changed files with 886 additions and 22 deletions
@@ -48,6 +48,28 @@ public enum ShoeGazeError: Error, LocalizedError, Equatable, Sendable {
/// Narrow the chain with `mergeToMono()` before adding another widener.
case stereoWidthExceeded
/// Thrown by the linear pedal-edit API (`appendPedal(type:to:)`) when `type` is not a
/// known pedal in `PedalRegistry.builtIn`. The associated value is the requested type string.
case unknownPedalType(String)
/// Thrown by `removePedal(at:from:)` / `movePedal(from:to:in:)` when a linear pedal index is
/// negative or `>=` the board's linear pedal count. `index` is the offending index; `count`
/// is the number of linear pedals on the board.
case pedalIndexOutOfRange(index: Int, count: Int)
/// Thrown by `appendStereoSplit(to:)` when the board's tail is already stereo (width 2). A
/// stereo split fans a mono tail into two branches; narrow the chain with a `Merge to Mono`
/// first. (See `PedalBoard.splitStereo()`.)
case cannotSplitStereoChain
/// Thrown by `appendMergeToMono(to:)` when the board's tail is already mono (width 1) — there
/// is no stereo signal to collapse.
case cannotMergeMonoChain
/// Thrown by the lane-addressed edit API when the segment at the given top-level index is not a
/// branch region (stereo split or parallel section). `index` is the offending segment index.
case notABranchRegion(index: Int)
// MARK: - LocalizedError
public var errorDescription: String? {
@@ -64,6 +86,16 @@ public enum ShoeGazeError: Error, LocalizedError, Equatable, Sendable {
return "ShoeGaze: could not open recording file '\(url.lastPathComponent)'."
case .stereoWidthExceeded:
return "PedalBoard: chain is already stereo (width 2); cannot add another widener. Use mergeToMono() first."
case .unknownPedalType(let type):
return "ShoeGaze: '\(type)' is not a known pedal type; cannot add it to the board."
case .pedalIndexOutOfRange(let index, let count):
return "ShoeGaze: pedal index \(index) is out of range; the board has \(count) linear pedal(s)."
case .cannotSplitStereoChain:
return "ShoeGaze: cannot add a stereo split; the chain is already stereo. Merge to mono first."
case .cannotMergeMonoChain:
return "ShoeGaze: the chain is already mono; there is no stereo signal to merge."
case .notABranchRegion(let index):
return "ShoeGaze: segment \(index) is not a branch region (stereo split or parallel section)."
}
}
}