Skip to main content

wavecraft_core/
macros.rs

1//! Declarative macros for Wavecraft DSP processors.
2//!
3//! This module provides the `wavecraft_processor!` macro for creating
4//! named wrappers around built-in DSP processors.
5//!
6//! For the `wavecraft_plugin!` macro that generates nih-plug plugins,
7//! see the `wavecraft-nih_plug` crate.
8
9/// `wavecraft_processor!` — creates a named wrapper around a built-in DSP processor.
10///
11/// This macro generates a newtype struct that wraps a built-in processor type and
12/// delegates the `Processor` trait implementation to the inner type.
13///
14/// # Syntax
15///
16/// ```text
17/// wavecraft_processor!(MyGain => Gain);
18/// ```
19///
20/// # Generated Code
21///
22/// ```text
23/// pub struct MyGain(wavecraft_dsp::builtins::GainDsp);
24///
25/// impl Default for MyGain {
26///     fn default() -> Self {
27///         Self(wavecraft_dsp::builtins::GainDsp::default())
28///     }
29/// }
30///
31/// impl wavecraft_dsp::Processor for MyGain {
32///     type Params = <wavecraft_dsp::builtins::GainDsp as wavecraft_dsp::Processor>::Params;
33///
34///     fn process(&mut self, buffer: &mut [&mut [f32]], transport: &wavecraft_dsp::Transport, params: &Self::Params) {
35///         self.0.process(buffer, transport, params)
36///     }
37/// }
38/// ```
39///
40/// # Built-in Processor Types
41///
42/// - `Gain` → `wavecraft_dsp::builtins::GainDsp`
43/// - `Passthrough` → `wavecraft_dsp::builtins::PassthroughDsp`
44///
45/// # Example
46///
47/// ```rust,no_run
48/// use wavecraft_core::wavecraft_processor;
49/// use wavecraft_dsp::{Processor, Transport};
50///
51/// wavecraft_processor!(InputGain => Gain);
52/// wavecraft_processor!(OutputGain => Gain);
53///
54/// let mut input = InputGain::default();
55/// let mut output = OutputGain::default();
56/// ```
57#[macro_export]
58macro_rules! wavecraft_processor {
59    ($name:ident => Gain) => {
60        #[derive(Default)]
61        pub struct $name($crate::wavecraft_dsp::builtins::GainDsp);
62
63        impl $crate::wavecraft_dsp::Processor for $name {
64            type Params =
65                <$crate::wavecraft_dsp::builtins::GainDsp as $crate::wavecraft_dsp::Processor>::Params;
66
67            fn process(
68                &mut self,
69                buffer: &mut [&mut [f32]],
70                transport: &$crate::wavecraft_dsp::Transport,
71                params: &Self::Params,
72            ) {
73                self.0.process(buffer, transport, params)
74            }
75        }
76    };
77
78    ($name:ident => Passthrough) => {
79        #[derive(Default)]
80        pub struct $name($crate::wavecraft_dsp::builtins::PassthroughDsp);
81
82        impl $crate::wavecraft_dsp::Processor for $name {
83            type Params =
84                <$crate::wavecraft_dsp::builtins::PassthroughDsp as $crate::wavecraft_dsp::Processor>::Params;
85
86            fn process(
87                &mut self,
88                buffer: &mut [&mut [f32]],
89                transport: &$crate::wavecraft_dsp::Transport,
90                params: &Self::Params,
91            ) {
92                self.0.process(buffer, transport, params)
93            }
94        }
95    };
96}