Skip to main content

rill_core/traits/
active.rs

1use crate::queues::{MpscQueue, SetParameter};
2
3/// Handle passed to an [`ActiveNode`] implementation.
4///
5/// The `nodes` pointer points to the graph's node array cast to `()`.
6/// Concrete implementations cast back to `[NodeVariant<f32, B>]`.
7///
8/// `queue` points to the shared command queue that the audio callback
9/// must drain before each processing cycle.
10pub struct GraphHandle {
11    /// Raw pointer to the graph's node array (cast to `u8`).
12    pub nodes: *mut u8,
13    /// Number of nodes in the graph.
14    pub len: usize,
15    /// Index of the source node in the graph.
16    pub source_idx: usize,
17    /// Sample rate of the audio stream.
18    pub sample_rate: f32,
19    /// Command queue (control → audio thread).
20    pub queue: *const MpscQueue<SetParameter>,
21}
22
23/// A node that drives graph processing.
24///
25/// The implementation receives a [`GraphHandle`] in [`start`](Self::start).
26/// It must drain the command queue at the beginning of every processing
27/// cycle, apply parameters to the graph nodes, then run the signal DAG.
28///
29/// # Safety
30///
31/// The handle is valid only until the corresponding [`stop`](Self::stop)
32/// returns.
33pub trait ActiveNode {
34    /// Start the node with the given graph handle.
35    ///
36    /// Called once before the audio thread begins processing.
37    fn start(&mut self, handle: GraphHandle);
38    /// Stop the node.
39    ///
40    /// Called after the audio thread has stopped.
41    fn stop(&mut self);
42}