Skip to main content

aether_core/
command.rs

1//! Lock-free command protocol between the control thread and the RT audio thread.
2//!
3//! Commands are sent via an SPSC ring buffer. The RT thread drains up to
4//! MAX_COMMANDS_PER_TICK per callback, bounding mutation cost.
5
6use crate::{arena::NodeId, param::Param};
7use serde::{Deserialize, Serialize};
8
9/// All mutations the control thread can request.
10#[derive(Debug, Clone)]
11pub enum Command {
12    /// Add a new node.
13    AddNode { id: NodeId },
14
15    /// Remove a node and release its buffer.
16    RemoveNode { id: NodeId },
17
18    /// Connect output of `src` to input slot `slot` of `dst`.
19    Connect { src: NodeId, dst: NodeId, slot: usize },
20
21    /// Disconnect input slot `slot` of `dst`.
22    Disconnect { dst: NodeId, slot: usize },
23
24    /// Update a parameter with a new smoothed value.
25    UpdateParam { node: NodeId, param_index: usize, new_param: Param },
26
27    /// Swap the output node.
28    SetOutputNode { id: NodeId },
29
30    /// Mute / unmute all audio output.
31    SetMute { muted: bool },
32
33    /// Remove all nodes and edges — silence the graph.
34    ClearGraph,
35}
36
37/// Serializable graph description for UI ↔ host communication.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct GraphSnapshot {
40    pub nodes: Vec<NodeSnapshot>,
41    pub edges: Vec<EdgeSnapshot>,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct NodeSnapshot {
46    pub id: u32,
47    pub generation: u32,
48    pub node_type: String,
49    pub params: Vec<f32>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct EdgeSnapshot {
54    pub src_id: u32,
55    pub dst_id: u32,
56    pub slot: usize,
57}