Files
ShoeGaze/Sources/LyrebirdShoeGaze/Presets/PedalLane.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

38 lines
1.3 KiB
Swift

// PedalLane.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
/// Addresses where a linear pedal edit applies: the board's main chain, or one branch of a
/// split region (stereo split or parallel section).
///
/// `region` is the index of the region's segment within the board's top-level segment list
/// (`board.captureState().segments`). For a `.stereoSplit` segment, `.left`/`.right` map to its
/// left/right branches; for a `.parallel` segment they map to branch A/B.
public enum PedalLane: Equatable, Sendable {
/// The board's top-level linear chain (the `.pedal` segments).
case main
/// The left branch (stereo) / branch A (parallel) of the region segment at `region`.
case left(region: Int)
/// The right branch (stereo) / branch B (parallel) of the region segment at `region`.
case right(region: Int)
/// The region segment index this lane targets, or `nil` for ``main``.
public var regionIndex: Int? {
switch self {
case .main: return nil
case .left(let region), .right(let region): return region
}
}
/// `true` for the left / A branch; `false` for the right / B branch. `false` for ``main``.
public var isLeftBranch: Bool {
if case .left = self { return true }
return false
}
}