diff --git a/nih_plug_derive/src/lib.rs b/nih_plug_derive/src/lib.rs index af190dd2..9b7bf3c7 100644 --- a/nih_plug_derive/src/lib.rs +++ b/nih_plug_derive/src/lib.rs @@ -208,7 +208,7 @@ pub fn derive_params(input: TokenStream) -> TokenStream { self: std::pin::Pin<&Self>, ) -> std::collections::HashMap<&'static str, nih_plug::param::internals::ParamPtr> { // This may not be in scope otherwise - use ::nih_plug::Param; + use ::nih_plug::param::Param; let mut param_map = std::collections::HashMap::new(); #(#param_mapping_insert_tokens)* diff --git a/nih_plug_egui/src/lib.rs b/nih_plug_egui/src/lib.rs index f0eaa306..acb89636 100644 --- a/nih_plug_egui/src/lib.rs +++ b/nih_plug_egui/src/lib.rs @@ -7,7 +7,7 @@ use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy}; use crossbeam::atomic::AtomicCell; use egui::Context; use egui_baseview::EguiWindow; -use nih_plug::{Editor, ParamSetter, ParentWindowHandle}; +use nih_plug::prelude::{Editor, GuiContext, ParamSetter, ParentWindowHandle}; use parking_lot::RwLock; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -88,7 +88,7 @@ where fn spawn( &self, parent: ParentWindowHandle, - context: Arc, + context: Arc, ) -> Box { let update = self.update.clone(); let state = self.user_state.clone(); diff --git a/nih_plug_egui/src/widgets/param_slider.rs b/nih_plug_egui/src/widgets/param_slider.rs index 6c2a7135..d65b25f2 100644 --- a/nih_plug_egui/src/widgets/param_slider.rs +++ b/nih_plug_egui/src/widgets/param_slider.rs @@ -2,7 +2,7 @@ use egui::{vec2, Response, Sense, Stroke, TextStyle, Ui, Vec2, Widget, WidgetTex use lazy_static::lazy_static; use super::util; -use nih_plug::{Param, ParamSetter}; +use nih_plug::prelude::{Param, ParamSetter}; /// When shift+dragging a parameter, one pixel dragged corresponds to this much change in the /// noramlized parameter. diff --git a/plugins/diopser/src/lib.rs b/plugins/diopser/src/lib.rs index aa9bb739..988b8eae 100644 --- a/plugins/diopser/src/lib.rs +++ b/plugins/diopser/src/lib.rs @@ -19,12 +19,7 @@ #[macro_use] extern crate nih_plug; -use nih_plug::{ - formatters, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext, ProcessStatus, - Vst3Plugin, -}; -use nih_plug::{BoolParam, FloatParam, FloatRange, IntParam, IntRange, Params, SmoothingStyle}; -use nih_plug::{Enum, EnumParam}; +use nih_plug::prelude::*; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; diff --git a/plugins/examples/gain-gui/src/lib.rs b/plugins/examples/gain-gui/src/lib.rs index 01ac2eb7..a7565089 100644 --- a/plugins/examples/gain-gui/src/lib.rs +++ b/plugins/examples/gain-gui/src/lib.rs @@ -2,11 +2,7 @@ extern crate nih_plug; use atomic_float::AtomicF32; -use nih_plug::{ - util, Buffer, BufferConfig, BusConfig, ClapPlugin, Editor, Plugin, ProcessContext, - ProcessStatus, Vst3Plugin, -}; -use nih_plug::{FloatParam, FloatRange, IntParam, IntRange, Params, SmoothingStyle}; +use nih_plug::prelude::*; use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState}; use std::pin::Pin; use std::sync::Arc; diff --git a/plugins/examples/gain/src/lib.rs b/plugins/examples/gain/src/lib.rs index a4da36ec..18e63893 100644 --- a/plugins/examples/gain/src/lib.rs +++ b/plugins/examples/gain/src/lib.rs @@ -1,11 +1,7 @@ #[macro_use] extern crate nih_plug; -use nih_plug::{ - formatters, util, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext, - ProcessStatus, Vst3Plugin, -}; -use nih_plug::{BoolParam, FloatParam, FloatRange, Params, Smoother, SmoothingStyle}; +use nih_plug::prelude::*; use parking_lot::RwLock; use std::pin::Pin; use std::sync::Arc; diff --git a/plugins/examples/sine/src/lib.rs b/plugins/examples/sine/src/lib.rs index d5079f4b..3c645bf2 100644 --- a/plugins/examples/sine/src/lib.rs +++ b/plugins/examples/sine/src/lib.rs @@ -1,11 +1,7 @@ #[macro_use] extern crate nih_plug; -use nih_plug::{ - formatters, util, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext, - ProcessStatus, Vst3Plugin, -}; -use nih_plug::{BoolParam, FloatParam, FloatRange, Params, Smoother, SmoothingStyle}; +use nih_plug::prelude::*; use std::f32::consts; use std::pin::Pin; @@ -144,11 +140,11 @@ impl Plugin for Sine { 'midi_events: loop { match next_event { Some(event) if event.timing() == sample_id as u32 => match event { - nih_plug::NoteEvent::NoteOn { note, .. } => { + NoteEvent::NoteOn { note, .. } => { self.midi_note_freq = util::midi_note_to_freq(note); self.midi_note_gain.set_target(self.sample_rate, 1.0); } - nih_plug::NoteEvent::NoteOff { note, .. } => { + NoteEvent::NoteOff { note, .. } => { if self.midi_note_freq == util::midi_note_to_freq(note) { self.midi_note_gain.set_target(self.sample_rate, 0.0); } diff --git a/src/context.rs b/src/context.rs index 2e05c761..983e8a8f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -81,8 +81,8 @@ pub trait GuiContext: Send + Sync + 'static { } /// A convenience helper for setting parameter values. Any changes made here will be broadcasted to -/// the host and reflected in the plugin's [crate::param::internals::Params] object. These functions -/// should only be called from the main thread. +/// the host and reflected in the plugin's [`Params`][crate::param::internals::Params] object. These +/// functions should only be called from the main thread. pub struct ParamSetter<'a> { context: &'a dyn GuiContext, } diff --git a/src/lib.rs b/src/lib.rs index f3726bde..4eb229dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,34 +1,18 @@ -// TODO: Once everything is more fleshed out, document the basic usage of this library and -// restructure these re-exports into a more useful prelude - #![cfg_attr(feature = "simd", feature(portable_simd))] #[macro_use] pub mod debug; +/// Everything you'd need to use NIH-plug. Import this with `use nih_plug::prelude::*;`. +pub mod prelude; + +// These modules have also been re-exported in the prelude. pub mod formatters; pub mod util; -// Re-export our derive macros to make this a bit easier to use -pub use nih_plug_derive::Params; - -// And also re-export anything you'd need to build a plugin -pub use buffer::Buffer; -pub use context::{GuiContext, ParamSetter, ProcessContext}; -pub use param::enums::{Enum, EnumParam}; -pub use param::internals::Params; -pub use param::range::{FloatRange, IntRange}; -pub use param::smoothing::{Smoother, SmoothingStyle}; -pub use param::{BoolParam, FloatParam, IntParam, Param}; -pub use plugin::{ - BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin, - ProcessStatus, Vst3Plugin, -}; - -// The rest is either internal or already re-exported -mod buffer; -mod context; -mod event_loop; +pub mod buffer; +pub mod context; +pub mod event_loop; pub mod param; pub mod plugin; pub mod wrapper; diff --git a/src/param.rs b/src/param.rs index 0c5dc0a3..8d9a7568 100644 --- a/src/param.rs +++ b/src/param.rs @@ -1,4 +1,4 @@ -//! TODO: Document how to use the [Param] trait. Also mention both interfaces: direct initialization +//! TODO: Document how to use the [`Param`] trait. Also mention both interfaces: direct initialization //! + `..Default::default()`, and the builder interface. For the moment, just look at the gain //! example. diff --git a/src/prelude.rs b/src/prelude.rs new file mode 100644 index 00000000..4c164b3a --- /dev/null +++ b/src/prelude.rs @@ -0,0 +1,19 @@ +// Re-export the proc macro +pub use nih_plug_derive::Params; + +pub use super::debug::*; +pub use super::formatters; +pub use super::util; + +pub use super::buffer::Buffer; +pub use super::context::{GuiContext, ParamSetter, ProcessContext}; +// This also includes the derive macro +pub use super::param::enums::{Enum, EnumParam}; +pub use super::param::internals::Params; +pub use super::param::range::{FloatRange, IntRange}; +pub use super::param::smoothing::{Smoother, SmoothingStyle}; +pub use super::param::{BoolParam, FloatParam, IntParam, Param}; +pub use super::plugin::{ + BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin, + ProcessStatus, Vst3Plugin, +}; diff --git a/src/wrapper/clap/context.rs b/src/wrapper/clap/context.rs index 58c5fe38..79cdbd08 100644 --- a/src/wrapper/clap/context.rs +++ b/src/wrapper/clap/context.rs @@ -4,11 +4,10 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use super::wrapper::{OutputParamChange, Task, Wrapper}; -use crate::context::ProcessContext; +use crate::context::{GuiContext, ProcessContext}; use crate::event_loop::EventLoop; use crate::param::internals::ParamPtr; use crate::plugin::{ClapPlugin, NoteEvent}; -use crate::GuiContext; /// A [`GuiContext`] implementation for the wrapper. This is passed to the plugin in /// [`Editor::spawn()`][crate::Editor::spawn()] so it can interact with the rest of the plugin and diff --git a/src/wrapper/clap/factory.rs b/src/wrapper/clap/factory.rs index 6546d8b0..ce18f0ca 100644 --- a/src/wrapper/clap/factory.rs +++ b/src/wrapper/clap/factory.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use super::descriptor::PluginDescriptor; use super::wrapper::Wrapper; -use crate::ClapPlugin; +use crate::plugin::ClapPlugin; /// The plugin's factory. Initialized using a lazy_static from the entry poiunt's `get_factory()` /// function. From this point onwards we don't need to generate code with macros anymore. diff --git a/src/wrapper/state.rs b/src/wrapper/state.rs index 2404fb01..8e3e6199 100644 --- a/src/wrapper/state.rs +++ b/src/wrapper/state.rs @@ -5,9 +5,9 @@ use std::collections::HashMap; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; -use crate::param::internals::ParamPtr; +use crate::param::internals::{ParamPtr, Params}; use crate::param::Param; -use crate::{BufferConfig, Params}; +use crate::plugin::BufferConfig; /// A plain, unnormalized value for a parameter. #[derive(Debug, Serialize, Deserialize)]