use core::error::Error;
use firewheel_core::{channel_config::ChannelCount, node::NodeID};
use crate::graph::{Edge, EdgeID, PortIdx};
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum AddEdgeError {
#[error("Could not add edge: could not find source node with ID {0:?}")]
SrcNodeNotFound(NodeID),
#[error("Could not add edge: could not find destination node with ID {0:?}")]
DstNodeNotFound(NodeID),
#[error("Input port idx {port_idx:?} is out of range on node {node:?} with {num_in_ports:?} input ports")]
InPortOutOfRange {
node: NodeID,
port_idx: PortIdx,
num_in_ports: ChannelCount,
},
#[error("Output port idx {port_idx:?} is out of range on node {node:?} with {num_out_ports:?} output ports")]
OutPortOutOfRange {
node: NodeID,
port_idx: PortIdx,
num_out_ports: ChannelCount,
},
#[error("Could not add edge: cycle was detected")]
CycleDetected,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum CompileGraphError {
#[error("Failed to compile audio graph: a cycle was detected")]
CycleDetected,
#[error("Failed to compile audio graph: input data contains an edge {0:?} referring to a non-existing node {1:?}")]
NodeOnEdgeNotFound(Edge, NodeID),
#[error(
"Failed to compile audio graph: input data contains multiple nodes with the same ID {0:?}"
)]
NodeIDNotUnique(NodeID),
#[error(
"Failed to compile audio graph: input data contains multiple edges with the same ID {0:?}"
)]
EdgeIDNotUnique(EdgeID),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum StartStreamError<E: Error> {
#[error("Audio stream is already running")]
AlreadyStarted,
#[error("Failed to start audio stream: The old audio stream has not finished stopping yet")]
OldStreamNotFinishedStopping,
#[error("Failed to start audio stream: Audio graph failed to compile: {0}")]
GraphCompileError(#[from] CompileGraphError),
#[error("Failed to start audio stream: {0}")]
BackendError(E),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum UpdateError<E: Error> {
#[error("The Firewheel context to processor message channel is full")]
MsgChannelFull,
#[error("The audio graph failed to compile: {0}")]
GraphCompileError(#[from] CompileGraphError),
#[error("The audio stream stopped unexpectedly: {0}")]
StreamStoppedUnexpectedly(Option<E>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum RemoveNodeError {
#[error("Removing the graph in node is not allowed")]
CannotRemoveGraphInNode,
#[error("Removing the graph out node is not allowed")]
CannotRemoveGraphOutNode,
}