pub struct Port<T, const BUF_SIZE: usize>where
T: Transcendental,{
pub id: PortId,
pub name: String,
pub direction: PortDirection,
pub action: Option<Box<dyn Algorithm<T>>>,
pub pending_command: Option<T>,
pub buffer: Buffer<T, BUF_SIZE>,
pub feedback_buffer: Option<Buffer<T, BUF_SIZE>>,
pub downstream: Vec<(usize, usize)>,
pub feedback_downstream: Vec<(usize, usize)>,
}Expand description
A port on a node.
Each port has an owned Buffer<T, BUF_SIZE> for its data and an optional
Action that defines per-port processing. Output ports typically have
an action; input ports may have one for preprocessing.
Ports can optionally participate in feedback edges:
- On an output port in a feedback edge,
feedback_bufferstores the previous block’s output, snapshotted after DSP viasnapshot_feedback(). - On an input port in a feedback edge,
feedback_bufferholds the delayed feedback value that gets mixed intobufferbypre_process(). downstreamlists audio connections from this output port to input ports of other nodes, populated at build time by the graph builder.
Fields§
§id: PortIdPort identifier
name: StringPort name
direction: PortDirectionPort direction (input/output)
action: Option<Box<dyn Algorithm<T>>>Per-port processing algorithm (None for simple input ports)
pending_command: Option<T>Pending command value from the control path, delivered to the
algorithm via Algorithm::apply_command() before the next
process() call. When there is no algorithm, this value is
written directly into the buffer.
buffer: Buffer<T, BUF_SIZE>Owned audio buffer
feedback_buffer: Option<Buffer<T, BUF_SIZE>>Delayed feedback state (None if not on a feedback edge). On output ports: snapshotted from buffer after DSP for next block. On input ports: receives the delayed feedback from the source output, mixed into buffer by pre_process().
downstream: Vec<(usize, usize)>Downstream audio connections: (target_node_index, target_port_index). Set at build time by GraphBuilder; immutable during processing.
feedback_downstream: Vec<(usize, usize)>Feedback edge targets from this output port: (target_node_index, target_port_index). Populated at build time by GraphBuilder; the delayed feedback buffer is written to these input ports by a processing driver.
Implementations§
Source§impl<T, const BUF_SIZE: usize> Port<T, BUF_SIZE>where
T: Transcendental,
impl<T, const BUF_SIZE: usize> Port<T, BUF_SIZE>where
T: Transcendental,
Sourcepub fn output(node_id: NodeId, index: u16, name: &str) -> Port<T, BUF_SIZE>
pub fn output(node_id: NodeId, index: u16, name: &str) -> Port<T, BUF_SIZE>
Create a new audio output port
Sourcepub fn output_with_action(
node_id: NodeId,
index: u16,
name: &str,
action: Box<dyn Algorithm<T>>,
) -> Port<T, BUF_SIZE>
pub fn output_with_action( node_id: NodeId, index: u16, name: &str, action: Box<dyn Algorithm<T>>, ) -> Port<T, BUF_SIZE>
Create a new audio output port with an algorithm
Sourcepub fn input(node_id: NodeId, index: u16, name: &str) -> Port<T, BUF_SIZE>
pub fn input(node_id: NodeId, index: u16, name: &str) -> Port<T, BUF_SIZE>
Create a new audio input port
Sourcepub fn control_output(
node_id: NodeId,
index: u16,
name: &str,
) -> Port<T, BUF_SIZE>
pub fn control_output( node_id: NodeId, index: u16, name: &str, ) -> Port<T, BUF_SIZE>
Create a new control output port
Sourcepub fn control_output_with_action(
node_id: NodeId,
index: u16,
name: &str,
action: Box<dyn Algorithm<T>>,
) -> Port<T, BUF_SIZE>
pub fn control_output_with_action( node_id: NodeId, index: u16, name: &str, action: Box<dyn Algorithm<T>>, ) -> Port<T, BUF_SIZE>
Create a new control output port with an algorithm
Sourcepub fn control_input(
node_id: NodeId,
index: u16,
name: &str,
) -> Port<T, BUF_SIZE>
pub fn control_input( node_id: NodeId, index: u16, name: &str, ) -> Port<T, BUF_SIZE>
Create a new control input port
Sourcepub fn buffer_mut(&mut self) -> &mut Buffer<T, BUF_SIZE>
pub fn buffer_mut(&mut self) -> &mut Buffer<T, BUF_SIZE>
Get a mutable reference to the buffer
Sourcepub fn pre_process(&mut self, _tick: &ClockTick)
pub fn pre_process(&mut self, _tick: &ClockTick)
Pre-process this port before node DSP.
For input ports on a feedback edge, mixes the delayed feedback
(from feedback_buffer) into the current buffer.
No-op when feedback_buffer is None.
tick is the current clock tick, available for future
sample-accurate or time-varying port-level processing.
Sourcepub fn snapshot_feedback(&mut self)
pub fn snapshot_feedback(&mut self)
Snapshot the buffer into feedback_buffer after node DSP.
For output ports on a feedback edge, saves the current buffer
so it can be used as delayed feedback in the next block.
No-op when feedback_buffer is None.
Sourcepub fn propagate(
&self,
_tick: &ClockTick,
nodes: &mut [NodeVariant<T, BUF_SIZE>],
)
pub fn propagate( &self, _tick: &ClockTick, nodes: &mut [NodeVariant<T, BUF_SIZE>], )
Propagate this port’s buffer to all downstream input ports.
Iterates over downstream and copies buffer into each target
input port’s buffer. The caller must ensure no aliasing between
this port’s node and any target node (guaranteed by DAG topology).
tick is the current clock tick, available for future
sample-accurate or time-varying port-level propagation.
Sourcepub fn run_action(
&mut self,
input: Option<&[T; BUF_SIZE]>,
ctx: &ActionContext<'_>,
) -> Result<(), ProcessError>
pub fn run_action( &mut self, input: Option<&[T; BUF_SIZE]>, ctx: &ActionContext<'_>, ) -> Result<(), ProcessError>
Run the port’s algorithm.
Delivers any pending command via Algorithm::apply_command(), then
calls Algorithm::process() with the input and output slices.
When no algorithm is attached, the pending command value (if any)
is written directly into the buffer; otherwise input is passed
through or zero-filled.