beamer/lib.rs
1//! # Beamer
2//!
3//! Audio Plugin Framework for Rust.
4//!
5//! Beamer is a framework for building audio plugins (AU, VST3).
6//! It provides safe Rust abstractions that work with multiple plugin formats.
7//!
8//! ## Quick Start
9//!
10//! ```rust,ignore
11//! use beamer::prelude::*;
12//!
13//! // Define your plugin
14//! struct MyGain { parameters: MyParameters }
15//!
16//! impl Processor for MyGain {
17//! fn setup(&mut self, _: f64, _: usize) {}
18//! fn process(&mut self, buffer: &mut Buffer, _aux: &mut AuxiliaryBuffers, _context: &ProcessContext) {
19//! // Your DSP here
20//! }
21//! }
22//!
23//! impl Descriptor for MyGain {
24//! type Parameters = MyParameters;
25//! fn parameters(&self) -> &Self::Parameters { &self.parameters }
26//! fn create() -> Self { Self { parameters: MyParameters::new() } }
27//! }
28//!
29//! // Export
30//! static CONFIG: Config = Config::new("MyGain", Category::Effect, "Mfgr", "gain")
31//! .with_vendor("My Company");
32//!
33//! export_plugin!(CONFIG, MyGain);
34//! ```
35
36// Re-export sub-crates
37pub use beamer_core as core;
38
39/// Plugin setup types for declaring host information requirements.
40///
41/// See [`beamer_core::setup`] for documentation and examples.
42pub use beamer_core::setup;
43
44#[cfg(feature = "vst3")]
45pub use beamer_vst3 as vst3_impl;
46
47/// Re-export of vst3 types needed for plugin configuration.
48///
49/// This allows examples and plugins to use `beamer::vst3::Steinberg::TUID`
50/// without adding a direct dependency on the vst3 crate.
51#[cfg(feature = "vst3")]
52pub mod vst3 {
53 pub use ::vst3::Steinberg;
54 pub use ::vst3::Steinberg::TUID;
55}
56
57#[cfg(feature = "au")]
58pub use beamer_au as au_impl;
59
60// Re-export derive macros when feature is enabled
61#[cfg(feature = "derive")]
62pub use beamer_macros::Parameters;
63#[cfg(feature = "derive")]
64pub use beamer_macros::EnumParameter;
65#[cfg(feature = "derive")]
66pub use beamer_macros::HasParameters;
67#[cfg(feature = "derive")]
68pub use beamer_macros::export;
69
70/// Generate plugin entry points for all enabled formats (AU, VST3).
71///
72/// This is the primary export macro for Beamer plugins. It generates the
73/// necessary entry points for whichever plugin formats are enabled via
74/// Cargo features.
75///
76/// # Arguments
77///
78/// * `$config` - A static reference to [`Config`](beamer_core::Config) containing all plugin metadata
79/// * `$plugin` - The plugin type implementing the [`Descriptor`](beamer_core::Descriptor) trait
80/// * `$presets` - (Optional) The presets type implementing [`FactoryPresets`](beamer_core::FactoryPresets)
81///
82/// # Example
83///
84/// ```rust,ignore
85/// use beamer::prelude::*;
86///
87/// pub static CONFIG: Config = Config::new("My Plugin", Category::Effect, "Mfgr", "plgn")
88/// .with_vendor("My Company")
89/// .with_version(env!("CARGO_PKG_VERSION"));
90///
91/// export_plugin!(CONFIG, MyPlugin);
92///
93/// // With presets:
94/// export_plugin!(CONFIG, MyPlugin, MyPresets);
95/// ```
96#[macro_export]
97macro_rules! export_plugin {
98 // With explicit presets type
99 ($config:expr, $plugin:ty, $presets:ty) => {
100 // === AU entry points ===
101 #[cfg(feature = "au")]
102 fn __beamer_au_do_register() {
103 $crate::au_impl::factory::register_factory(
104 || {
105 Box::new($crate::au_impl::AuProcessor::<$plugin, $presets>::new())
106 as Box<dyn $crate::au_impl::AuPluginInstance>
107 },
108 &$config,
109 );
110 }
111
112 #[cfg(feature = "au")]
113 #[used]
114 #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
115 static __BEAMER_AU_INIT: extern "C" fn() = {
116 extern "C" fn __beamer_au_register() {
117 __beamer_au_do_register();
118 }
119 __beamer_au_register
120 };
121
122 #[cfg(feature = "au")]
123 #[doc(hidden)]
124 pub fn __beamer_au_manual_init() {
125 __beamer_au_do_register();
126 }
127
128 // === VST3 entry points ===
129 #[cfg(all(feature = "vst3", target_os = "windows"))]
130 #[no_mangle]
131 extern "system" fn InitDll() -> bool {
132 true
133 }
134
135 #[cfg(all(feature = "vst3", target_os = "windows"))]
136 #[no_mangle]
137 extern "system" fn ExitDll() -> bool {
138 true
139 }
140
141 #[cfg(all(feature = "vst3", target_os = "macos"))]
142 #[no_mangle]
143 extern "system" fn bundleEntry(_bundle_ref: *mut std::ffi::c_void) -> bool {
144 true
145 }
146
147 #[cfg(all(feature = "vst3", target_os = "macos"))]
148 #[no_mangle]
149 extern "system" fn bundleExit() -> bool {
150 true
151 }
152
153 #[cfg(feature = "vst3")]
154 #[no_mangle]
155 extern "system" fn GetPluginFactory() -> *mut std::ffi::c_void {
156 use $crate::vst3_impl::vst3::ComWrapper;
157 use $crate::vst3_impl::Factory;
158
159 let factory = Factory::<$crate::vst3_impl::Vst3Processor<$plugin, $presets>>::new(&$config);
160 let wrapper = ComWrapper::new(factory);
161
162 wrapper
163 .to_com_ptr::<$crate::vst3_impl::vst3::Steinberg::IPluginFactory>()
164 .unwrap()
165 .into_raw() as *mut std::ffi::c_void
166 }
167 };
168
169 // Without presets (default to NoPresets)
170 ($config:expr, $plugin:ty) => {
171 $crate::export_plugin!(
172 $config,
173 $plugin,
174 $crate::core::NoPresets<<$plugin as $crate::core::HasParameters>::Parameters>
175 );
176 };
177}
178
179/// Prelude module for convenient imports.
180///
181/// Import everything you need to build a plugin:
182/// ```rust,ignore
183/// use beamer::prelude::*;
184/// ```
185pub mod prelude {
186 // Core traits and types
187 pub use beamer_core::{
188 // Asset types
189 EmbeddedAsset, EmbeddedAssets,
190 // Buffer types
191 AuxiliaryBuffers, AuxInput, AuxOutput, Buffer,
192 // Bypass handling
193 BypassAction, BypassHandler, BypassState, CrossfadeCurve,
194 // Sample trait for generic f32/f64 processing
195 Sample,
196 // Traits
197 Descriptor, GuiDelegate, HasParameters, Processor,
198 // Plugin setup types (composable)
199 PluginSetup, SampleRate, MaxBufferSize, MainInputChannels, MainOutputChannels,
200 AuxInputCount, AuxOutputCount, ProcessMode,
201 // Bus configuration
202 BusInfo, BusType,
203 // GUI types
204 GuiConstraints, NoGui,
205 // Parameter metadata
206 NoParameters, ParameterFlags, ParameterInfo,
207 // Factory presets
208 FactoryPresets, NoPresets, PresetInfo, PresetValue,
209 // Parameter types
210 BoolParameter, EnumParameter, EnumParameterValue, FloatParameter, IntParameter, Formatter, ParameterRef, Parameters,
211 // MIDI CC configuration (framework manages runtime state)
212 MidiCcConfig,
213 // Parameter smoothing
214 Smoother, SmoothingStyle,
215 // Parameter group system
216 GroupId, GroupInfo, ParameterGroups, ROOT_GROUP_ID,
217 // Range mapping
218 LinearMapper, LogMapper, LogOffsetMapper, PowerMapper, RangeMapper,
219 // Error types
220 PluginError, PluginResult,
221 // Geometry
222 Rect, Size,
223 // MIDI types
224 ChannelPressure, ControlChange, MidiBuffer, MidiChannel, MidiEvent, MidiEventKind,
225 MidiNote, NoteId, NoteOff, NoteOn, PitchBend, PolyPressure, ProgramChange,
226 // Process context and transport
227 FrameRate, ProcessContext, Transport,
228 // FourCharCode
229 FourCharCode,
230 // WebView support
231 WebViewHandler, serde_json,
232 };
233
234 // Plugin configuration
235 pub use beamer_core::{Config, config::Category, config::Subcategory};
236
237 // Unified export macro
238 pub use crate::export_plugin;
239
240 // Derive macros for parameters (when feature enabled)
241 // These share names with the traits/types they implement, which is allowed
242 // because traits and derive macros live in different namespaces.
243 #[cfg(feature = "derive")]
244 pub use beamer_macros::{EnumParameter, HasParameters, Parameters};
245}