Files
ShoeGaze/Sources/LyrebirdShoeGaze/BoardSegment.swift
T
josh e1ec98413d 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>
2026-06-22 09:31:57 -07:00

33 lines
1.3 KiB
Swift

// BoardSegment.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
/// One ordered element of a ``PedalBoard``'s signal chain, used to capture full topology
/// (including parallel and stereo split regions) in signal-flow order.
///
/// `PedalBoard` records these as pedals and split regions are added, so a board can be
/// serialized and rebuilt faithfully rather than as a flat pedal list. Branch pedals live
/// inside their section objects, not as separate segments.
///
/// Public so a UI can walk a board's live structure in signal-flow order (each element carries
/// the live `Pedal` / section object). The index of a segment within `PedalBoard.orderedSegments`
/// matches its index in `captureState().segments`, which is the region index used by the
/// lane-addressed edit API (see ``PedalLane``).
public enum BoardSegment {
/// A single linear pedal in the main chain.
case pedal(Pedal)
/// A parallel section (`split()` → two branches → `merge()`).
case parallel(ParallelSection)
/// A stereo split region (`splitStereo()` → two branches → `collectStereo()`).
case stereoSplit(StereoSplitSection)
/// A `mergeToMono()` collapse — narrows a stereo tail back to mono. Carries no state;
/// recorded so the width transition replays on rebuild.
case mergeToMono
}