diff --git a/dasp_graph/src/buffer.rs b/dasp_graph/src/buffer.rs index aed0a7b6..588c113e 100644 --- a/dasp_graph/src/buffer.rs +++ b/dasp_graph/src/buffer.rs @@ -3,17 +3,14 @@ use core::ops::{Deref, DerefMut}; /// The fixed-size buffer used for processing the graph. #[derive(Clone)] -pub struct Buffer { - data: [f32; Self::LEN], +pub struct Buffer { + data: [f32; N], } -impl Buffer { - /// The fixed length of the **Buffer** type. - pub const LEN: usize = 64; +impl Buffer { + pub const LEN: usize = N; /// A silent **Buffer**. - pub const SILENT: Self = Buffer { - data: [0.0; Self::LEN], - }; + pub const SILENT: Self = Buffer { data: [0.0; N] }; /// Short-hand for writing silence to the whole buffer. pub fn silence(&mut self) { @@ -21,38 +18,38 @@ impl Buffer { } } -impl Default for Buffer { +impl Default for Buffer { fn default() -> Self { Self::SILENT } } -impl From<[f32; Self::LEN]> for Buffer { - fn from(data: [f32; Self::LEN]) -> Self { +impl From<[f32; N]> for Buffer { + fn from(data: [f32; N]) -> Self { Buffer { data } } } -impl fmt::Debug for Buffer { +impl fmt::Debug for Buffer { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self.data[..], f) } } -impl PartialEq for Buffer { +impl PartialEq for Buffer { fn eq(&self, other: &Self) -> bool { &self[..] == &other[..] } } -impl Deref for Buffer { +impl Deref for Buffer { type Target = [f32]; fn deref(&self) -> &Self::Target { &self.data[..] } } -impl DerefMut for Buffer { +impl DerefMut for Buffer { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.data[..] } diff --git a/dasp_graph/src/lib.rs b/dasp_graph/src/lib.rs index 2dcb145e..925d884b 100644 --- a/dasp_graph/src/lib.rs +++ b/dasp_graph/src/lib.rs @@ -152,16 +152,16 @@ pub mod node; /// use petgraph; /// # /// # // The node type. (Hint: Use existing node impls by enabling their associated features). -/// # struct MyNode; +/// # struct MyNode; /// /// // Chose a type of graph for audio processing. -/// type Graph = petgraph::graph::DiGraph, (), u32>; +/// type Graph = petgraph::graph::DiGraph, 128>, (), u32>; /// // Create a short-hand for our processor type. -/// type Processor = dasp_graph::Processor; +/// type Processor = dasp_graph::Processor; /// # -/// # impl Node for MyNode { +/// # impl Node for MyNode { /// # // ... -/// # fn process(&mut self, _inputs: &[Input], _output: &mut [Buffer]) { +/// # fn process(&mut self, _inputs: &[Input], _output: &mut [Buffer]) { /// # } /// # } /// @@ -173,37 +173,37 @@ pub mod node; /// let mut p = Processor::with_capacity(max_nodes); /// /// // Add some nodes and edges... -/// # let n_id = g.add_node(NodeData::new1(MyNode)); +/// # let n_id = g.add_node(NodeData::new1(MyNode::<128>)); /// /// // Process all nodes within the graph that output to the node at `n_id`. /// p.process(&mut g, n_id); /// } /// ``` -pub struct Processor +pub struct Processor where G: Visitable, { // State related to the traversal of the audio graph starting from the output node. dfs_post_order: DfsPostOrder, // Solely for collecting the inputs of a node in order to apply its `Node::process` method. - inputs: Vec, + inputs: Vec>, } /// For use as the node weight within a dasp graph. Contains the node and its buffers. /// /// For a graph to be compatible with a graph **Processor**, its node weights must be of type /// `NodeData`, where `T` is some type that implements the `Node` trait. -pub struct NodeData { +pub struct NodeData { /// The buffers to which the `node` writes audio data during a call to its `process` method. /// /// Generally, each buffer stored within `buffers` corresponds to a unique audio channel. E.g. /// a node processing mono data would store one buffer, a node processing stereo data would /// store two, and so on. - pub buffers: Vec, + pub buffers: Vec>, pub node: T, } -impl Processor +impl Processor where G: Visitable, { @@ -242,17 +242,17 @@ where /// **Panics** if there is no node for the given index. pub fn process(&mut self, graph: &mut G, node: G::NodeId) where - G: Data> + DataMapMut, + G: Data> + DataMapMut, for<'a> &'a G: GraphBase + IntoNeighborsDirected, - T: Node, + T: Node, { process(self, graph, node) } } -impl NodeData { +impl NodeData { /// Construct a new **NodeData** from an instance of its node type and buffers. - pub fn new(node: T, buffers: Vec) -> Self { + pub fn new(node: T, buffers: Vec>) -> Self { NodeData { node, buffers } } @@ -268,11 +268,11 @@ impl NodeData { } #[cfg(feature = "node-boxed")] -impl NodeData { +impl NodeData, N> { /// The same as **new**, but boxes the given node data before storing it. - pub fn boxed(node: T, buffers: Vec) -> Self + pub fn boxed(node: T, buffers: Vec>) -> Self where - T: 'static + Node, + T: 'static + Node, { NodeData::new(BoxedNode(Box::new(node)), buffers) } @@ -280,7 +280,7 @@ impl NodeData { /// The same as **new1**, but boxes the given node data before storing it. pub fn boxed1(node: T) -> Self where - T: 'static + Node, + T: 'static + Node, { Self::boxed(node, vec![Buffer::SILENT]) } @@ -288,7 +288,7 @@ impl NodeData { /// The same as **new2**, but boxes the given node data before storing it. pub fn boxed2(node: T) -> Self where - T: 'static + Node, + T: 'static + Node, { Self::boxed(node, vec![Buffer::SILENT, Buffer::SILENT]) } @@ -310,17 +310,20 @@ impl NodeData { /// type `NodeData` where `T` implements the `Node` trait. /// /// **Panics** if there is no node for the given index. -pub fn process(processor: &mut Processor, graph: &mut G, node: G::NodeId) -where - G: Data> + DataMapMut + Visitable, +pub fn process( + processor: &mut Processor, + graph: &mut G, + node: G::NodeId, +) where + G: Data> + DataMapMut + Visitable, for<'a> &'a G: GraphBase + IntoNeighborsDirected, - T: Node, + T: Node, { const NO_NODE: &str = "no node exists for the given index"; processor.dfs_post_order.reset(Reversed(&*graph)); processor.dfs_post_order.move_to(node); while let Some(n) = processor.dfs_post_order.next(Reversed(&*graph)) { - let data: *mut NodeData = graph.node_weight_mut(n).expect(NO_NODE) as *mut _; + let data: *mut NodeData = graph.node_weight_mut(n).expect(NO_NODE) as *mut _; processor.inputs.clear(); for in_n in (&*graph).neighbors_directed(n, Incoming) { // Skip edges that connect the node to itself to avoid aliasing `node`. diff --git a/dasp_graph/src/node/boxed.rs b/dasp_graph/src/node/boxed.rs index 7501d555..b5e8116f 100644 --- a/dasp_graph/src/node/boxed.rs +++ b/dasp_graph/src/node/boxed.rs @@ -6,7 +6,7 @@ use core::ops::{Deref, DerefMut}; /// /// Provides the necessary `Sized` implementation to allow for compatibility with the graph process /// function. -pub struct BoxedNode(pub Box); +pub struct BoxedNode(pub Box>); /// A wrapper around a `Box`. /// @@ -16,107 +16,107 @@ pub struct BoxedNode(pub Box); /// Useful when the ability to send nodes from one thread to another is required. E.g. this is /// common when initialising nodes or the audio graph itself on one thread before sending them to /// the audio thread. -pub struct BoxedNodeSend(pub Box); +pub struct BoxedNodeSend(pub Box + Send>); -impl BoxedNode { +impl BoxedNode { /// Create a new `BoxedNode` around the given `node`. /// /// This is short-hand for `BoxedNode::from(Box::new(node))`. pub fn new(node: T) -> Self where - T: 'static + Node, + T: 'static + Node, { Self::from(Box::new(node)) } } -impl BoxedNodeSend { +impl BoxedNodeSend { /// Create a new `BoxedNode` around the given `node`. /// /// This is short-hand for `BoxedNode::from(Box::new(node))`. pub fn new(node: T) -> Self where - T: 'static + Node + Send, + T: 'static + Node + Send, { Self::from(Box::new(node)) } } -impl Node for BoxedNode { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { +impl Node for BoxedNode { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { self.0.process(inputs, output) } } -impl Node for BoxedNodeSend { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { +impl Node for BoxedNodeSend { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { self.0.process(inputs, output) } } -impl From> for BoxedNode +impl From> for BoxedNode where - T: 'static + Node, + T: 'static + Node, { fn from(n: Box) -> Self { - BoxedNode(n as Box) + BoxedNode(n as Box>) } } -impl From> for BoxedNodeSend +impl From> for BoxedNodeSend where - T: 'static + Node + Send, + T: 'static + Node + Send, { fn from(n: Box) -> Self { - BoxedNodeSend(n as Box) + BoxedNodeSend(n as Box + Send>) } } -impl Into> for BoxedNode { - fn into(self) -> Box { +impl Into>> for BoxedNode { + fn into(self) -> Box> { self.0 } } -impl Into> for BoxedNodeSend { - fn into(self) -> Box { +impl Into + Send>> for BoxedNodeSend { + fn into(self) -> Box + Send> { self.0 } } -impl fmt::Debug for BoxedNode { +impl fmt::Debug for BoxedNode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("BoxedNode").finish() } } -impl fmt::Debug for BoxedNodeSend { +impl fmt::Debug for BoxedNodeSend { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("BoxedNodeSend").finish() } } -impl Deref for BoxedNode { - type Target = Box; +impl Deref for BoxedNode { + type Target = Box>; fn deref(&self) -> &Self::Target { &self.0 } } -impl Deref for BoxedNodeSend { - type Target = Box; +impl Deref for BoxedNodeSend { + type Target = Box + Send>; fn deref(&self) -> &Self::Target { &self.0 } } -impl DerefMut for BoxedNode { +impl DerefMut for BoxedNode { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } -impl DerefMut for BoxedNodeSend { +impl DerefMut for BoxedNodeSend { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } diff --git a/dasp_graph/src/node/delay.rs b/dasp_graph/src/node/delay.rs index 8e18d6b4..3ce276d5 100644 --- a/dasp_graph/src/node/delay.rs +++ b/dasp_graph/src/node/delay.rs @@ -9,11 +9,11 @@ use dasp_ring_buffer as ring_buffer; #[derive(Clone, Debug, PartialEq)] pub struct Delay(pub Vec>); -impl Node for Delay +impl Node for Delay where S: ring_buffer::SliceMut, { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { // Retrieve the single input, ignore any others. let input = match inputs.get(0) { Some(input) => input, diff --git a/dasp_graph/src/node/graph.rs b/dasp_graph/src/node/graph.rs index e4b61017..3847346a 100644 --- a/dasp_graph/src/node/graph.rs +++ b/dasp_graph/src/node/graph.rs @@ -7,24 +7,24 @@ use core::marker::PhantomData; use petgraph::data::DataMapMut; use petgraph::visit::{Data, GraphBase, IntoNeighborsDirected, Visitable}; -pub struct GraphNode +pub struct GraphNode where G: Visitable, { - pub processor: Processor, + pub processor: Processor, pub graph: G, pub input_nodes: Vec, pub output_node: G::NodeId, pub node_type: PhantomData, } -impl Node for GraphNode +impl Node for GraphNode where - G: Data> + DataMapMut + Visitable, + G: Data> + DataMapMut + Visitable, for<'a> &'a G: GraphBase + IntoNeighborsDirected, - T: Node, + T: Node, { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { let GraphNode { ref mut processor, ref mut graph, diff --git a/dasp_graph/src/node/mod.rs b/dasp_graph/src/node/mod.rs index 953f6406..3a4cd529 100644 --- a/dasp_graph/src/node/mod.rs +++ b/dasp_graph/src/node/mod.rs @@ -46,12 +46,12 @@ mod sum; /// use dasp_graph::{Buffer, Input, Node}; /// /// // Our new `Node` type. -/// pub struct Sum; +/// pub struct Sum; /// /// // Implement the `Node` trait for our new type. /// # #[cfg(feature = "dasp_slice")] -/// impl Node for Sum { -/// fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { +/// impl Node for Sum { +/// fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { /// // Fill the output with silence. /// for out_buffer in output.iter_mut() { /// out_buffer.silence(); @@ -68,7 +68,7 @@ mod sum; /// } /// } /// ``` -pub trait Node { +pub trait Node { /// Process some audio given a list of the node's `inputs` and write the result to the `output` /// buffers. /// @@ -82,7 +82,7 @@ pub trait Node { /// /// This `process` method is called by the [`Processor`](../struct.Processor.html) as it /// traverses the graph during audio rendering. - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]); + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]); } /// A reference to another node that is an input to the current node. @@ -90,14 +90,14 @@ pub trait Node { /// *TODO: It may be useful to provide some information that can uniquely identify the input node. /// This could be useful to allow to distinguish between side-chained and regular inputs for /// example.* -pub struct Input { - buffers_ptr: *const Buffer, +pub struct Input { + buffers_ptr: *const Buffer, buffers_len: usize, } -impl Input { +impl Input { // Constructor solely for use within the graph `process` function. - pub(crate) fn new(slice: &[Buffer]) -> Self { + pub(crate) fn new(slice: &[Buffer]) -> Self { let buffers_ptr = slice.as_ptr(); let buffers_len = slice.len(); Input { @@ -107,7 +107,7 @@ impl Input { } /// A reference to the buffers of the input node. - pub fn buffers(&self) -> &[Buffer] { + pub fn buffers(&self) -> &[Buffer] { // As we know that an `Input` can only be constructed during a call to the graph `process` // function, we can be sure that our slice is still valid as long as the input itself is // alive. @@ -118,46 +118,46 @@ impl Input { // Inputs can only be created by the `dasp_graph::process` implementation and only ever live as // long as the lifetime of the call to the function. Thus, it's safe to implement this so that // `Send` closures can be stored within the graph and sent between threads. -unsafe impl Send for Input {} +unsafe impl Send for Input {} -impl fmt::Debug 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 +impl<'a, T, const N: usize> Node for &'a mut T where - T: Node, + T: Node, { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { (**self).process(inputs, output) } } -impl Node for Box +impl Node for Box where - T: Node, + T: Node, { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { + 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]) { +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]) { +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]) { +impl Node for fn(&[Input], &mut [Buffer]) { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { (*self)(inputs, output) } } diff --git a/dasp_graph/src/node/pass.rs b/dasp_graph/src/node/pass.rs index 8872719a..477cac6c 100644 --- a/dasp_graph/src/node/pass.rs +++ b/dasp_graph/src/node/pass.rs @@ -10,8 +10,8 @@ use crate::{Buffer, Input, Node}; #[derive(Clone, Debug, PartialEq)] pub struct Pass; -impl Node for Pass { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { +impl Node for Pass { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { let input = match inputs.get(0) { None => return, Some(input) => input, diff --git a/dasp_graph/src/node/signal.rs b/dasp_graph/src/node/signal.rs index cd8285bc..ff427686 100644 --- a/dasp_graph/src/node/signal.rs +++ b/dasp_graph/src/node/signal.rs @@ -2,13 +2,13 @@ use crate::{Buffer, Input, Node}; use dasp_frame::Frame; use dasp_signal::Signal; -impl Node for dyn Signal +impl Node for dyn Signal where F: Frame, { - fn process(&mut self, _inputs: &[Input], output: &mut [Buffer]) { + fn process(&mut self, _inputs: &[Input], output: &mut [Buffer]) { let channels = std::cmp::min(F::CHANNELS, output.len()); - for ix in 0..Buffer::LEN { + for ix in 0..N { let frame = self.next(); for ch in 0..channels { // Safe, as we verify the number of channels at the beginning of the function. diff --git a/dasp_graph/src/node/sum.rs b/dasp_graph/src/node/sum.rs index 9a078d40..0912c970 100644 --- a/dasp_graph/src/node/sum.rs +++ b/dasp_graph/src/node/sum.rs @@ -22,8 +22,8 @@ pub struct Sum; #[derive(Clone, Debug, PartialEq)] pub struct SumBuffers; -impl Node for Sum { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { +impl Node for Sum { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { // Fill the output with silence. for out_buffer in output.iter_mut() { out_buffer.silence(); @@ -40,8 +40,8 @@ impl Node for Sum { } } -impl Node for SumBuffers { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { +impl Node for SumBuffers { + fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { // Get the first output buffer. let mut out_buffers = output.iter_mut(); let out_buffer_first = match out_buffers.next() { diff --git a/dasp_graph/tests/graph_send.rs b/dasp_graph/tests/graph_send.rs index 8bde1188..3459bb7f 100644 --- a/dasp_graph/tests/graph_send.rs +++ b/dasp_graph/tests/graph_send.rs @@ -11,8 +11,8 @@ use petgraph::visit::GraphBase; #[test] #[should_panic] fn test_graph_send() { - type Graph = petgraph::Graph, (), petgraph::Directed, u32>; - type Processor = dasp_graph::Processor; + type Graph = petgraph::Graph, 128>, (), petgraph::Directed, u32>; + type Processor = dasp_graph::Processor; let mut g: Graph = unimplemented!(); let mut p: Processor = unimplemented!(); let n: ::NodeId = unimplemented!(); diff --git a/dasp_graph/tests/graph_types.rs b/dasp_graph/tests/graph_types.rs index a7b0212d..242e0758 100644 --- a/dasp_graph/tests/graph_types.rs +++ b/dasp_graph/tests/graph_types.rs @@ -11,8 +11,8 @@ use petgraph::visit::GraphBase; #[test] #[should_panic] fn test_graph() { - type Graph = petgraph::Graph, (), petgraph::Directed, u32>; - type Processor = dasp_graph::Processor; + type Graph = petgraph::Graph, 128>, (), petgraph::Directed, u32>; + type Processor = dasp_graph::Processor; let mut g: Graph = unimplemented!(); let mut p: Processor = unimplemented!(); let n: ::NodeId = unimplemented!(); @@ -22,9 +22,13 @@ fn test_graph() { #[test] #[should_panic] fn test_stable_graph() { - type Graph = - petgraph::stable_graph::StableGraph, (), petgraph::Directed, u32>; - type Processor = dasp_graph::Processor; + type Graph = petgraph::stable_graph::StableGraph< + NodeData, 128>, + (), + petgraph::Directed, + u32, + >; + type Processor = dasp_graph::Processor; let mut g: Graph = unimplemented!(); let mut p: Processor = unimplemented!(); let n: ::NodeId = unimplemented!(); diff --git a/dasp_graph/tests/sum.rs b/dasp_graph/tests/sum.rs index 4c27a69f..0e3f9b9c 100644 --- a/dasp_graph/tests/sum.rs +++ b/dasp_graph/tests/sum.rs @@ -2,10 +2,10 @@ use dasp_graph::{node, Buffer, Input, Node, NodeData}; -type BoxedNode = dasp_graph::BoxedNode; +type BoxedNode = dasp_graph::BoxedNode<128>; // A simple source node that just writes `0.1` to the output. We'll use this to test the sum node. -fn src_node(_inputs: &[Input], output: &mut [Buffer]) { +fn src_node(_inputs: &[Input<128>], output: &mut [Buffer<128>]) { for o in output { o.iter_mut().for_each(|s| *s = 0.1); } @@ -14,8 +14,8 @@ fn src_node(_inputs: &[Input], output: &mut [Buffer]) { #[test] fn test_sum() { // The type of graph to use for this test. - type Graph = petgraph::Graph, (), petgraph::Directed, u32>; - type Processor = dasp_graph::Processor; + type Graph = petgraph::Graph, (), petgraph::Directed, u32>; + type Processor = dasp_graph::Processor; // Create a graph and a processor. let max_nodes = 6; @@ -24,7 +24,7 @@ fn test_sum() { let mut p = Processor::with_capacity(max_nodes); // Create and add the nodes to the graph. - let src_node_ptr = src_node as fn(&[Input], &mut [Buffer]); + let src_node_ptr = src_node as fn(&[Input<128>], &mut [Buffer<128>]); let src_a = g.add_node(NodeData::new1(BoxedNode::new(src_node_ptr))); let src_b = g.add_node(NodeData::new1(BoxedNode::new(src_node_ptr))); let sum = g.add_node(NodeData::new1(BoxedNode::new(node::Sum))); @@ -37,7 +37,7 @@ fn test_sum() { p.process(&mut g, sum); // Check that `sum` actually contains the sum. - let expected = Buffer::from([0.2; Buffer::LEN]); + let expected = Buffer::from([0.2; 128]); assert_eq!(&g[sum].buffers[..], &[expected][..]); // Plug in some more sources. @@ -50,15 +50,15 @@ fn test_sum() { // Check that the result is consistent. p.process(&mut g, sum); - let expected = Buffer::from([0.5; Buffer::LEN]); + let expected = Buffer::from([0.5; 128]); assert_eq!(&g[sum].buffers[..], &[expected][..]); } #[test] fn test_sum2() { // The type of graph to use for this test. - type Graph = petgraph::Graph, (), petgraph::Directed, u32>; - type Processor = dasp_graph::Processor; + type Graph = petgraph::Graph, (), petgraph::Directed, u32>; + type Processor = dasp_graph::Processor; // Create a graph and a processor. let mut g = Graph::new(); @@ -66,7 +66,7 @@ fn test_sum2() { // Create a small tree where we first sum a and b, then sum the result with c. // This time, using two buffers (channels) per node. - let src_node_ptr = src_node as fn(&[Input], &mut [Buffer]); + let src_node_ptr = src_node as fn(&[Input<128>], &mut [Buffer<128>]); let src_a = g.add_node(NodeData::new2(BoxedNode::new(src_node_ptr))); let src_b = g.add_node(NodeData::new2(BoxedNode::new(src_node_ptr))); let src_c = g.add_node(NodeData::new2(BoxedNode::new(src_node_ptr))); @@ -81,10 +81,10 @@ fn test_sum2() { p.process(&mut g, sum_ab_c); // sum_a_b should be 0.2. - let expected = vec![Buffer::from([0.2; Buffer::LEN]); 2]; + let expected = vec![Buffer::from([0.2; 128]); 2]; assert_eq!(&g[sum_a_b].buffers[..], &expected[..]); // sum_ab_c should be 0.3. - let expected = vec![Buffer::from([0.3; Buffer::LEN]); 2]; + let expected = vec![Buffer::from([0.3; 128]); 2]; assert_eq!(&g[sum_ab_c].buffers[..], &expected[..]); } @@ -92,12 +92,12 @@ fn test_sum2() { fn test_sum_unboxed() { // Prove to ourselves we also support unboxed node types with a custom node type. enum TestNode { - SourceFnPtr(fn(&[Input], &mut [Buffer])), + SourceFnPtr(fn(&[Input<128>], &mut [Buffer<128>])), Sum(node::Sum), } - impl Node for TestNode { - fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { + impl Node<128> for TestNode { + fn process(&mut self, inputs: &[Input<128>], output: &mut [Buffer<128>]) { match *self { TestNode::SourceFnPtr(ref mut f) => (*f)(inputs, output), TestNode::Sum(ref mut sum) => sum.process(inputs, output), @@ -106,8 +106,8 @@ fn test_sum_unboxed() { } // The type of graph to use for this test. - type Graph = petgraph::Graph, (), petgraph::Directed, u32>; - type Processor = dasp_graph::Processor; + type Graph = petgraph::Graph, (), petgraph::Directed, u32>; + type Processor = dasp_graph::Processor; // Create a graph and a processor. let mut g = Graph::new(); @@ -127,6 +127,6 @@ fn test_sum_unboxed() { p.process(&mut g, sum); // Check that `sum` actually contains the sum. - let expected = Buffer::from([0.2; Buffer::LEN]); + let expected = Buffer::from([0.2; 128]); assert_eq!(&g[sum].buffers[..], &[expected][..]); }