// ShoeGazeError.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Foundation /// Errors thrown by `ShoeGaze` during board and session management. public enum ShoeGazeError: Error, LocalizedError, Equatable, Sendable { /// Thrown by `ShoeGaze.addBoard()` when `inputSource == .liveInput` but the engine /// was created with `numInputChannels == 0`. /// /// Re-create the `SynthesisEngine` with `numInputChannels > 0` before using `.liveInput`. case liveInputRequiresInputChannels /// Thrown when `.liveInput(channel:)` requests a hardware input channel that is /// negative or `>= numInputChannels`. `requested` is the channel asked for; /// `available` is the engine's `numInputChannels`. case inputChannelOutOfRange(requested: Int, available: Int) /// Thrown by `ChainRouter.addToA(_:)` or `addToB(_:)` when called after /// ``ChainRouter/finalize()`` has already been invoked. /// /// Pedals must be added to the router's boards before `finalize()` so the merger /// is placed after the full evaluation tree. Adding pedals after finalization would /// leave them ordered before the merger in the node tree, causing stale-bus reads. case routerAlreadyFinalized /// Thrown by `ShoeGaze.startRecording()` when `recordingFolder` is `nil`. /// /// Set `ShoeGaze.recordingFolder` to a `URL` pointing to the desired output /// directory before calling `startRecording()`. case recordingFolderNotSet /// Thrown by `ShoeGaze.startRecording()` when a `RecordTap`'s `DiskOut.Audio` /// could not open the destination file (e.g. permissions, disk full). /// /// The `URL` identifies the file that could not be created. Any taps that /// were successfully added before the failure are removed and the recording /// session is not started. case recordTapFailedToOpen(URL) /// Thrown by `PedalBoard.add(_:)` when a widener pedal (``PedalChannelKind/widener``) /// is added while the board is already stereo (width 2). The chain width is capped at 2. /// /// Narrow the chain with `mergeToMono()` before adding another widener. case stereoWidthExceeded // MARK: - LocalizedError public var errorDescription: String? { switch self { case .liveInputRequiresInputChannels: return "ShoeGaze: .liveInput requires the engine to be created with numInputChannels > 0." case .inputChannelOutOfRange(let requested, let available): return "ShoeGaze: .liveInput channel \(requested) is out of range; engine has \(available) input channel(s)." case .routerAlreadyFinalized: return "ChainRouter: cannot add pedals after finalize() has been called." case .recordingFolderNotSet: return "ShoeGaze: set recordingFolder before calling startRecording()." case .recordTapFailedToOpen(let url): 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." } } }