use crate::buffer::Buffer;
use core::fmt;
#[cfg(feature = "node-boxed")]
pub use boxed::{BoxedNode, BoxedNodeSend};
#[cfg(feature = "node-delay")]
pub use delay::Delay;
#[cfg(feature = "node-graph")]
pub use graph::GraphNode;
#[cfg(feature = "node-pass")]
pub use pass::Pass;
#[cfg(feature = "node-sum")]
pub use sum::{Sum, SumBuffers};
#[cfg(feature = "node-boxed")]
mod boxed;
#[cfg(feature = "node-delay")]
mod delay;
#[cfg(feature = "node-graph")]
mod graph;
#[cfg(feature = "node-pass")]
mod pass;
#[cfg(feature = "node-signal")]
mod signal;
#[cfg(feature = "node-sum")]
mod sum;
pub trait Node {
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]);
}
pub struct Input {
buffers_ptr: *const Buffer,
buffers_len: usize,
}
impl Input {
pub(crate) fn new(slice: &[Buffer]) -> Self {
let buffers_ptr = slice.as_ptr();
let buffers_len = slice.len();
Input {
buffers_ptr,
buffers_len,
}
}
pub fn buffers(&self) -> &[Buffer] {
unsafe { std::slice::from_raw_parts(self.buffers_ptr, self.buffers_len) }
}
}
unsafe impl Send for Input {}
impl fmt::Debug for Input {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.buffers(), f)
}
}
impl<'a, T> Node for &'a mut T
where
T: Node,
{
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
(**self).process(inputs, output)
}
}
impl<T> Node for Box<T>
where
T: Node,
{
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
(**self).process(inputs, output)
}
}
impl Node for dyn Fn(&[Input], &mut [Buffer]) {
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
(*self)(inputs, output)
}
}
impl Node for dyn FnMut(&[Input], &mut [Buffer]) {
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
(*self)(inputs, output)
}
}
impl Node for fn(&[Input], &mut [Buffer]) {
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
(*self)(inputs, output)
}
}