use crate::graph::{Edge, EdgeID, PortIdx};
use firewheel_core::{
channel_config::ChannelCount,
node::{NodeError, NodeID},
};
#[cfg(not(feature = "std"))]
use bevy_platform::prelude::String;
#[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, 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),
#[error("Failed to construct a node's processor: {0}")]
ProcessorConstructionFailed(String),
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum ActivateError {
#[error("Failed to activate Firewheel context: The Firewheel context is already active")]
AlreadyActive,
#[error("Failed to activate Firewheel context: Audio graph failed to compile: {0}")]
GraphCompileError(#[from] CompileGraphError),
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum UpdateError {
#[error("The Firewheel context to processor message channel is full")]
MsgChannelFull,
#[error("The audio graph failed to compile: {0}")]
GraphCompileError(#[from] CompileGraphError),
}
#[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,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum DeactivateError {
#[error("Timed out waiting for the Firewheel context to deactivate")]
TimedOut,
}
#[derive(Debug, thiserror::Error)]
pub enum ModifyGraphError {
#[error("{0}")]
NodeError(NodeError),
#[error("{0}")]
RemoveNodeError(#[from] RemoveNodeError),
#[error("{0}")]
AddEdgeError(#[from] AddEdgeError),
#[error("{0}")]
UpdateError(#[from] UpdateError),
#[error("{0}")]
CompileGraphError(#[from] CompileGraphError),
}
impl From<NodeError> for ModifyGraphError {
fn from(e: NodeError) -> Self {
Self::NodeError(e)
}
}