Files
ShoeGaze/Sources/LyrebirdShoeGaze/ShoeGazeError.swift
T
2026-06-21 12:25:18 -07:00

62 lines
2.7 KiB
Swift

// 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)
// 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)'."
}
}
}