Skip to main content

rill_core/traits/
bridge.rs

1//! Bridge backend trait for duplex execution boundaries.
2//!
3//! A bridge node splits the signal graph into left (recording) and right (playback)
4//! sub-graphs. It maintains internal state across callbacks. Feedback is handled
5//! externally via `feedback_read`/`feedback_write` annotations on graph nodes —
6//! the bridge itself does not manage feedback.
7
8use crate::math::Transcendental;
9use crate::traits::ProcessResult;
10
11/// A graph node that serves as a duplex boundary between recording and playback chains.
12///
13/// # Execution model
14///
15/// Each tick is split into five phases:
16/// 1. ReadFeedback — mix feedback buffers into node inputs
17/// 2. process_left — execute left sub-graph + bridge.process_left(inputs)
18/// 3. process_right — bridge.process_right(outputs) + execute right sub-graph
19/// 4. WriteFeedback — capture node outputs into feedback buffers
20/// 5. Shadow copy — swap read/write feedback buffers
21pub trait BridgeAlgorithm<T: Transcendental>: Send + Sync {
22    /// Number of signal input channels.
23    fn num_inputs(&self) -> usize;
24    /// Number of signal output channels.
25    fn num_outputs(&self) -> usize;
26
27    /// Input callback: write into bridge state.
28    fn process_left(&mut self, inputs: &[&[T]]) -> ProcessResult<()>;
29
30    /// Output callback: read from bridge state.
31    fn process_right(&mut self, outputs: &mut [&mut [T]]) -> ProcessResult<()>;
32
33    /// Reset internal state.
34    fn reset(&mut self);
35}