e1ec98413d
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>
53 lines
2.1 KiB
Swift
53 lines
2.1 KiB
Swift
// InputSource.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
|
|
/// Selects how the pedalboard's head bus is fed with audio.
|
|
///
|
|
/// - `.testLoop`: A synthesized test tone (`TestLoopSource`) writes to the head bus.
|
|
/// Suitable for testing the pedalboard with no hardware connected.
|
|
/// - `.liveInput(channel:)`: A hardware input channel feeds the head bus. `channel` is
|
|
/// the zero-based hardware input channel index (`0` = first input). It maps to engine
|
|
/// audio-bus index `numOutputChannels + channel` (hardware input buses follow the
|
|
/// output buses). Requires the engine to be created with `numInputChannels > channel`.
|
|
public enum InputSource: Equatable {
|
|
/// Synthesized test signal — no hardware required.
|
|
case testLoop
|
|
/// Live hardware input from the given zero-based input channel. The engine must be
|
|
/// created with `numInputChannels > channel`.
|
|
case liveInput(channel: Int)
|
|
}
|
|
|
|
/// Validates a `.liveInput` channel against the engine and returns the engine audio-bus
|
|
/// index of that hardware input channel.
|
|
///
|
|
/// Hardware input buses occupy indices `numOutputChannels ..< (numOutputChannels +
|
|
/// numInputChannels)`, so input channel `channel` lives at `numOutputChannels + channel`.
|
|
///
|
|
/// - Parameters:
|
|
/// - channel: Zero-based hardware input channel index.
|
|
/// - engine: The engine whose bus layout is queried.
|
|
/// - Returns: The audio-bus index to read the requested input channel from.
|
|
/// - Throws:
|
|
/// - `ShoeGazeError.liveInputRequiresInputChannels` if the engine has no input channels.
|
|
/// - `ShoeGazeError.inputChannelOutOfRange` if `channel` is negative or `>= numInputChannels`.
|
|
internal func liveInputBusIndex(
|
|
channel: Int,
|
|
engine: SynthesisEngine
|
|
) throws -> Int {
|
|
guard engine.numInputChannels > 0 else {
|
|
throw ShoeGazeError.liveInputRequiresInputChannels
|
|
}
|
|
guard channel >= 0, channel < engine.numInputChannels else {
|
|
throw ShoeGazeError.inputChannelOutOfRange(
|
|
requested: channel,
|
|
available: engine.numInputChannels
|
|
)
|
|
}
|
|
return engine.numOutputChannels + channel
|
|
}
|