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_processors::GainDsp);
24///
25/// impl Default for MyGain {
26/// fn default() -> Self {
27/// Self(wavecraft_processors::GainDsp::default())
28/// }
29/// }
30///
31/// impl wavecraft_dsp::Processor for MyGain {
32/// type Params = <wavecraft_processors::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_processors::GainDsp`
43/// - `Passthrough` → `wavecraft_processors::PassthroughDsp`
44/// - `Filter` → `wavecraft_processors::UnifiedFilterDsp`
45/// - `Saturator` → `wavecraft_processors::SaturatorDsp`
46///
47/// # Example
48///
49/// ```rust,no_run
50/// use wavecraft_core::wavecraft_processor;
51/// use wavecraft_dsp::{Processor, Transport};
52///
53/// wavecraft_processor!(InputGain => Gain);
54/// wavecraft_processor!(OutputGain => Gain);
55///
56/// let mut input = InputGain::default();
57/// let mut output = OutputGain::default();
58/// ```
59#[macro_export]
60macro_rules! wavecraft_processor {
61 ($name:ident => Gain) => {
62 $crate::wavecraft_processor!($name => $crate::wavecraft_processors::GainDsp);
63 };
64
65 ($name:ident => Passthrough) => {
66 $crate::wavecraft_processor!($name => $crate::wavecraft_processors::PassthroughDsp);
67 };
68
69 ($name:ident => Filter) => {
70 $crate::wavecraft_processor!($name => $crate::wavecraft_processors::UnifiedFilterDsp);
71 };
72
73 ($name:ident => Saturator) => {
74 $crate::wavecraft_processor!($name => $crate::wavecraft_processors::SaturatorDsp);
75 };
76
77 ($name:ident => $inner:path) => {
78 #[derive(Default)]
79 pub struct $name($inner);
80
81 impl $crate::wavecraft_dsp::Processor for $name {
82 type Params = <$inner as $crate::wavecraft_dsp::Processor>::Params;
83
84 fn process(
85 &mut self,
86 buffer: &mut [&mut [f32]],
87 transport: &$crate::wavecraft_dsp::Transport,
88 params: &Self::Params,
89 ) {
90 self.0.process(buffer, transport, params)
91 }
92
93 fn set_sample_rate(&mut self, sample_rate: f32) {
94 self.0.set_sample_rate(sample_rate)
95 }
96
97 fn reset(&mut self) {
98 self.0.reset()
99 }
100 }
101 };
102}