1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::*;
use alloc::vec::Vec;
pub type Nodes = Vec<Node>;
pub trait Processor: Send {
/// Set the value of the given parameter.
fn set(&mut self, _param: u8, _val: f32) {
// do nothing
}
/// Reset the processor to the initial state.
///
/// This might or might not affect params changed using [`Processor::set`].
/// This is doesn't matter since params are usually `set` by a modulator
/// and when the processor is reset, the modulator is also reset.
/// They can also be changed using [`Node::set`] and the method
/// has a warning about this behavior.
fn reset(&mut self) {
// do nothing
}
/// Get the next frame for the processor.
fn process_children(&mut self, cn: &mut [Node]) -> Option<Frame> {
let mut sum = Frame::zero();
let mut empty = true;
for node in cn.iter_mut() {
let Some(frame) = node.next_frame() else {
continue;
};
sum = sum + frame;
empty = false;
}
if empty {
return None;
}
self.process_frame(sum)
}
fn process_frame(&mut self, f: Frame) -> Option<Frame> {
let left = self.process_sample(f.left)?;
let right = match f.right {
Some(right) => {
let right = self.process_sample(right)?;
Some(right)
}
None => None,
};
Some(Frame { left, right })
}
fn process_sample(&mut self, s: Sample) -> Option<Sample> {
Some(s)
}
}