rack/
lib.rs

1//! # Rack - Audio Plugin Hosting for Rust
2//!
3//! Rack is a modern Rust library for hosting audio plugins in your applications.
4//! It provides a clean, safe API for discovering, loading, and processing audio
5//! through VST3, AudioUnit, CLAP, and other plugin formats.
6//!
7//! ## Quick Start
8//!
9//! ```rust,no_run
10//! use rack::prelude::*;
11//!
12//! # fn main() -> rack::Result<()> {
13//! // Scan for plugins
14//! let scanner = Scanner::new()?;
15//! let plugins = scanner.scan()?;
16//!
17//! println!("Found {} plugins", plugins.len());
18//!
19//! // Load a plugin
20//! let mut plugin = scanner.load(&plugins[0])?;
21//! plugin.initialize(48000.0, 512)?;
22//!
23//! // Process audio (planar format - one buffer per channel)
24//! let left_in = vec![0.0f32; 512];
25//! let right_in = vec![0.0f32; 512];
26//! let mut left_out = vec![0.0f32; 512];
27//! let mut right_out = vec![0.0f32; 512];
28//!
29//! plugin.process(
30//!     &[&left_in, &right_in],
31//!     &mut [&mut left_out, &mut right_out],
32//!     512
33//! )?;
34//! # Ok(())
35//! # }
36//! ```
37//!
38//! ## Features
39//!
40//! - **AudioUnit support** (macOS, iOS) - built-in
41//! - **VST3 support** (Windows, macOS, Linux) - built-in
42//! - **CLAP support** - coming soon
43//! - **cpal integration** - optional, enable with `cpal` feature
44//!
45//! ## Platform Support
46//!
47//! - **macOS**: AudioUnit (default) and VST3
48//! - **iOS**: AudioUnit only (VST3 not available on mobile)
49//! - **Windows**: VST3 (default)
50//! - **Linux**: VST3 (default)
51//!
52//! AudioUnit provides the best integration on Apple platforms (native GUI support).
53//! VST3 is the default on Windows and Linux, and also available on macOS.
54
55pub mod error;
56pub mod midi;
57pub mod plugin_info;
58pub mod traits;
59
60pub use error::{Error, Result};
61pub use midi::{MidiEvent, MidiEventKind};
62pub use plugin_info::{ParameterInfo, PluginInfo, PluginType, PresetInfo};
63pub use traits::{PluginInstance, PluginScanner};
64
65// Platform-specific implementations
66// AudioUnit is available on both macOS and iOS
67#[cfg(target_vendor = "apple")]
68pub mod au;
69
70// VST3 is available on desktop platforms (Windows, macOS, Linux) when the SDK is present
71// Explicitly disabled on mobile platforms (iOS, tvOS, watchOS, visionOS)
72// The "vst3_sdk" cfg is set by build.rs when the VST3 SDK is found
73#[cfg(all(
74    vst3_sdk,
75    not(target_os = "ios"),
76    not(target_os = "tvos"),
77    not(target_os = "watchos"),
78    not(target_os = "visionos")
79))]
80pub mod vst3;
81
82// Re-export the default scanner and plugin types for the platform
83// On Apple platforms, default to AudioUnit (better integration, GUI support)
84#[cfg(target_vendor = "apple")]
85pub use au::{AudioUnitGui, AudioUnitPlugin as Plugin, AudioUnitScanner as Scanner};
86
87// On non-Apple desktop platforms, default to VST3 (if available)
88#[cfg(all(
89    vst3_sdk,
90    not(target_vendor = "apple"),
91    not(target_os = "ios"),
92    not(target_os = "tvos"),
93    not(target_os = "watchos"),
94    not(target_os = "visionos")
95))]
96pub use vst3::{Vst3Plugin as Plugin, Vst3Scanner as Scanner};
97
98/// Prelude module for convenient imports
99pub mod prelude {
100    pub use crate::{
101        Error, MidiEvent, MidiEventKind, ParameterInfo, PluginInfo, PluginInstance,
102        PluginScanner, PluginType, PresetInfo, Result,
103    };
104
105    // Platform-specific exports
106    #[cfg(target_vendor = "apple")]
107    pub use crate::{AudioUnitGui, Plugin, Scanner};
108
109    // VST3 exports (only when SDK is available)
110    #[cfg(all(
111        vst3_sdk,
112        not(target_vendor = "apple"),
113        not(target_os = "ios"),
114        not(target_os = "tvos"),
115        not(target_os = "watchos"),
116        not(target_os = "visionos")
117    ))]
118    pub use crate::{Plugin, Scanner};
119}