1use core::error::Error;
2use firewheel_core::{channel_config::ChannelCount, node::NodeID};
3
4use crate::graph::{Edge, EdgeID, PortIdx};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
8pub enum AddEdgeError {
9 #[error("Could not add edge: could not find source node with ID {0:?}")]
11 SrcNodeNotFound(NodeID),
12 #[error("Could not add edge: could not find destination node with ID {0:?}")]
14 DstNodeNotFound(NodeID),
15 #[error("Input port idx {port_idx:?} is out of range on node {node:?} with {num_in_ports:?} input ports")]
17 InPortOutOfRange {
18 node: NodeID,
19 port_idx: PortIdx,
20 num_in_ports: ChannelCount,
21 },
22 #[error("Output port idx {port_idx:?} is out of range on node {node:?} with {num_out_ports:?} output ports")]
24 OutPortOutOfRange {
25 node: NodeID,
26 port_idx: PortIdx,
27 num_out_ports: ChannelCount,
28 },
29 #[error("Could not add edge: cycle was detected")]
31 CycleDetected,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
37pub enum CompileGraphError {
38 #[error("Failed to compile audio graph: a cycle was detected")]
40 CycleDetected,
41 #[error("Failed to compile audio graph: input data contains an edge {0:?} referring to a non-existing node {1:?}")]
43 NodeOnEdgeNotFound(Edge, NodeID),
44 #[error(
46 "Failed to compile audio graph: input data contains multiple nodes with the same ID {0:?}"
47 )]
48 NodeIDNotUnique(NodeID),
49 #[error(
51 "Failed to compile audio graph: input data contains multiple edges with the same ID {0:?}"
52 )]
53 EdgeIDNotUnique(EdgeID),
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
59pub enum StartStreamError<E: Error> {
60 #[error("Audio stream is already running")]
62 AlreadyStarted,
63 #[error("Failed to start audio stream: The old audio stream has not finished stopping yet")]
71 OldStreamNotFinishedStopping,
72 #[error("Failed to start audio stream: Audio graph failed to compile: {0}")]
74 GraphCompileError(#[from] CompileGraphError),
75 #[error("Failed to start audio stream: {0}")]
77 BackendError(E),
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
82pub enum UpdateError<E: Error> {
83 #[error("The Firewheel context to processor message channel is full")]
85 MsgChannelFull,
86 #[error("The audio graph failed to compile: {0}")]
88 GraphCompileError(#[from] CompileGraphError),
89 #[error("The audio stream stopped unexpectedly: {0}")]
92 StreamStoppedUnexpectedly(Option<E>),
93}
94
95#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
97pub enum RemoveNodeError {
98 #[error("Removing the graph in node is not allowed")]
100 CannotRemoveGraphInNode,
101 #[error("Removing the graph out node is not allowed")]
103 CannotRemoveGraphOutNode,
104}