pub struct SignalEngine<T: Transcendental, const BUF_SIZE: usize> { /* private fields */ }Expand description
Real-time safe signal engine for a static signal graph.
Owns the mutable node state and provides:
- Clock boundary —
process_tick: drains commands (with anti-ack) and runspre_process(feedback mix). - Block processing —
process_block: iterates nodes in topological order: for each node, callsprocess_block, thensnapshot_feedback, thenpropagateto downstream nodes via pre-established port connections. - Thread management —
start/stopmanage a cooperative running flag;spawnconsumes the engine and runs it in a dedicated signal thread.
A separate control thread communicates via command/telemetry queues.
§Type Parameters
T— floating-point type (f32orf64)BUF_SIZE— block size (must match the graph)
Implementations§
Source§impl<T: Transcendental, const BUF_SIZE: usize> SignalEngine<T, BUF_SIZE>
impl<T: Transcendental, const BUF_SIZE: usize> SignalEngine<T, BUF_SIZE>
Sourcepub fn new(
nodes: Vec<NodeVariant<T, BUF_SIZE>>,
topo_order: Vec<usize>,
cmd_rx: Option<Receiver<CommandEnum>>,
tel_tx: Option<Sender<Telemetry>>,
) -> Self
pub fn new( nodes: Vec<NodeVariant<T, BUF_SIZE>>, topo_order: Vec<usize>, cmd_rx: Option<Receiver<CommandEnum>>, tel_tx: Option<Sender<Telemetry>>, ) -> Self
Create a new engine from graph parts.
Sourcepub fn process_tick(&mut self, tick: &ClockTick) -> usize
pub fn process_tick(&mut self, tick: &ClockTick) -> usize
Process a clock tick — called from the I/O callback when hardware fires.
Drains pending commands (with anti-ack telemetry on overwrite), then
runs pre_process on all input ports (mixes feedback from previous block),
then applies any pending SetParameter commands to their target nodes.
Returns the number of commands applied this tick.
Sourcepub fn process_block(&mut self, tick: &ClockTick) -> ProcessResult<usize>
pub fn process_block(&mut self, tick: &ClockTick) -> ProcessResult<usize>
Convenience: run a full processing cycle for one block.
Calls process_tick, then iterates nodes in topological order:
process → snapshot_feedback → propagate for each node.
This ensures data flows naturally: Source → propagate → Processor → Sink.
Note: copies port buffers to build input slices for ProcessContext.
Production I/O callbacks should call process_tick and handle data
propagation themselves for zero-copy processing.
Sourcepub fn nodes(&self) -> &[NodeVariant<T, BUF_SIZE>]
pub fn nodes(&self) -> &[NodeVariant<T, BUF_SIZE>]
Access nodes for external processing (I/O layer).
The caller should iterate in topo_order.
Sourcepub fn nodes_mut(&mut self) -> &mut [NodeVariant<T, BUF_SIZE>]
pub fn nodes_mut(&mut self) -> &mut [NodeVariant<T, BUF_SIZE>]
Mutable access to nodes for external processing.
Sourcepub fn topo_order(&self) -> &[usize]
pub fn topo_order(&self) -> &[usize]
Topological order — indices into nodes().
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the engine is running.
Sourcepub fn spawn(self) -> JoinHandle<()>
pub fn spawn(self) -> JoinHandle<()>
Spawn a dedicated signal thread that runs process_block in a loop.
The engine is moved into the thread; communication happens through
command/telemetry queues.
Returns a handle for joining the thread. Signal shutdown by setting
the running flag to false via running_flag.
Sourcepub fn running_flag(&self) -> Arc<AtomicBool>
pub fn running_flag(&self) -> Arc<AtomicBool>
Clone of the running flag, for signaling shutdown from another thread.
Sourcepub fn attach_command_rx(&mut self, rx: Receiver<CommandEnum>)
pub fn attach_command_rx(&mut self, rx: Receiver<CommandEnum>)
Attach a command receiver after construction.
Sourcepub fn attach_telemetry_tx(&mut self, tx: Sender<Telemetry>)
pub fn attach_telemetry_tx(&mut self, tx: Sender<Telemetry>)
Attach a telemetry sender after construction.
Sourcepub fn cmd_slots(&self) -> &[Option<CommandEnum>]
pub fn cmd_slots(&self) -> &[Option<CommandEnum>]
Borrow the command slots (for external processing that needs to check or consume pending commands).
Sourcepub fn cmd_slots_mut(&mut self) -> &mut [Option<CommandEnum>]
pub fn cmd_slots_mut(&mut self) -> &mut [Option<CommandEnum>]
Mutably borrow the command slots.