libdaw/
lib.rs

1pub mod metronome;
2pub mod nodes;
3pub mod notation;
4mod parse;
5pub mod pitch;
6pub mod stream;
7mod sync;
8pub mod time;
9
10use std::fmt::Debug;
11use std::sync::Arc;
12pub use stream::Stream;
13
14pub type Error = Box<dyn std::error::Error + Send + Sync>;
15pub type Result<T> = std::result::Result<T, Error>;
16
17/// An audio node trait, allowing a sample_rate to be set and processing to
18/// be performed. Some things like setters are self, not mut self, because we
19/// need to support Arc<dyn Node> so upcasting works.  This will be fixed when
20/// https://github.com/rust-lang/rust/issues/65991 is fully finished and in
21/// stable rust.  When that happens, the interface will change to &mut self
22/// methods.
23pub trait Node: Debug + Send + Sync {
24    fn process<'a, 'b, 'c>(
25        &'a self,
26        inputs: &'b [Stream],
27        outputs: &'c mut Vec<Stream>,
28    ) -> Result<()>;
29}
30
31/// A node with a settable frequency.
32pub trait FrequencyNode: Node + DynNode {
33    fn get_frequency(&self) -> Result<f64>;
34    fn set_frequency(&self, frequency: f64) -> Result<()>;
35}
36
37/// Dynamic upcasting trait for Node
38pub trait DynNode {
39    fn node(self: Arc<Self>) -> Arc<dyn Node>;
40}
41
42impl<T> DynNode for T
43where
44    T: 'static + Node,
45{
46    fn node(self: Arc<Self>) -> Arc<dyn Node> {
47        self
48    }
49}
50/// Dynamic upcasting trait for FrequencyNode
51pub trait DynFrequencyNode {
52    fn frequency_node(self: Arc<Self>) -> Arc<dyn FrequencyNode>;
53}
54
55impl<T> DynFrequencyNode for T
56where
57    T: 'static + FrequencyNode,
58{
59    fn frequency_node(self: Arc<Self>) -> Arc<dyn FrequencyNode> {
60        self
61    }
62}