💥 Move re-exports to a prelude module
So you can import everything at once, because you're likely going to need at least 90% of it anyways.
This commit is contained in:
parent
f581294d7b
commit
4c0b07c578
|
@ -208,7 +208,7 @@ pub fn derive_params(input: TokenStream) -> TokenStream {
|
||||||
self: std::pin::Pin<&Self>,
|
self: std::pin::Pin<&Self>,
|
||||||
) -> std::collections::HashMap<&'static str, nih_plug::param::internals::ParamPtr> {
|
) -> std::collections::HashMap<&'static str, nih_plug::param::internals::ParamPtr> {
|
||||||
// This may not be in scope otherwise
|
// This may not be in scope otherwise
|
||||||
use ::nih_plug::Param;
|
use ::nih_plug::param::Param;
|
||||||
|
|
||||||
let mut param_map = std::collections::HashMap::new();
|
let mut param_map = std::collections::HashMap::new();
|
||||||
#(#param_mapping_insert_tokens)*
|
#(#param_mapping_insert_tokens)*
|
||||||
|
|
|
@ -7,7 +7,7 @@ use baseview::{Size, WindowHandle, WindowOpenOptions, WindowScalePolicy};
|
||||||
use crossbeam::atomic::AtomicCell;
|
use crossbeam::atomic::AtomicCell;
|
||||||
use egui::Context;
|
use egui::Context;
|
||||||
use egui_baseview::EguiWindow;
|
use egui_baseview::EguiWindow;
|
||||||
use nih_plug::{Editor, ParamSetter, ParentWindowHandle};
|
use nih_plug::prelude::{Editor, GuiContext, ParamSetter, ParentWindowHandle};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -88,7 +88,7 @@ where
|
||||||
fn spawn(
|
fn spawn(
|
||||||
&self,
|
&self,
|
||||||
parent: ParentWindowHandle,
|
parent: ParentWindowHandle,
|
||||||
context: Arc<dyn nih_plug::GuiContext>,
|
context: Arc<dyn GuiContext>,
|
||||||
) -> Box<dyn std::any::Any + Send + Sync> {
|
) -> Box<dyn std::any::Any + Send + Sync> {
|
||||||
let update = self.update.clone();
|
let update = self.update.clone();
|
||||||
let state = self.user_state.clone();
|
let state = self.user_state.clone();
|
||||||
|
|
|
@ -2,7 +2,7 @@ use egui::{vec2, Response, Sense, Stroke, TextStyle, Ui, Vec2, Widget, WidgetTex
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
use super::util;
|
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
|
/// When shift+dragging a parameter, one pixel dragged corresponds to this much change in the
|
||||||
/// noramlized parameter.
|
/// noramlized parameter.
|
||||||
|
|
|
@ -19,12 +19,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate nih_plug;
|
extern crate nih_plug;
|
||||||
|
|
||||||
use nih_plug::{
|
use nih_plug::prelude::*;
|
||||||
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 std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
|
@ -2,11 +2,7 @@
|
||||||
extern crate nih_plug;
|
extern crate nih_plug;
|
||||||
|
|
||||||
use atomic_float::AtomicF32;
|
use atomic_float::AtomicF32;
|
||||||
use nih_plug::{
|
use nih_plug::prelude::*;
|
||||||
util, Buffer, BufferConfig, BusConfig, ClapPlugin, Editor, Plugin, ProcessContext,
|
|
||||||
ProcessStatus, Vst3Plugin,
|
|
||||||
};
|
|
||||||
use nih_plug::{FloatParam, FloatRange, IntParam, IntRange, Params, SmoothingStyle};
|
|
||||||
use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState};
|
use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate nih_plug;
|
extern crate nih_plug;
|
||||||
|
|
||||||
use nih_plug::{
|
use nih_plug::prelude::*;
|
||||||
formatters, util, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext,
|
|
||||||
ProcessStatus, Vst3Plugin,
|
|
||||||
};
|
|
||||||
use nih_plug::{BoolParam, FloatParam, FloatRange, Params, Smoother, SmoothingStyle};
|
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate nih_plug;
|
extern crate nih_plug;
|
||||||
|
|
||||||
use nih_plug::{
|
use nih_plug::prelude::*;
|
||||||
formatters, util, Buffer, BufferConfig, BusConfig, ClapPlugin, Plugin, ProcessContext,
|
|
||||||
ProcessStatus, Vst3Plugin,
|
|
||||||
};
|
|
||||||
use nih_plug::{BoolParam, FloatParam, FloatRange, Params, Smoother, SmoothingStyle};
|
|
||||||
use std::f32::consts;
|
use std::f32::consts;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
|
@ -144,11 +140,11 @@ impl Plugin for Sine {
|
||||||
'midi_events: loop {
|
'midi_events: loop {
|
||||||
match next_event {
|
match next_event {
|
||||||
Some(event) if event.timing() == sample_id as u32 => match 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_freq = util::midi_note_to_freq(note);
|
||||||
self.midi_note_gain.set_target(self.sample_rate, 1.0);
|
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) {
|
if self.midi_note_freq == util::midi_note_to_freq(note) {
|
||||||
self.midi_note_gain.set_target(self.sample_rate, 0.0);
|
self.midi_note_gain.set_target(self.sample_rate, 0.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
/// 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
|
/// the host and reflected in the plugin's [`Params`][crate::param::internals::Params] object. These
|
||||||
/// should only be called from the main thread.
|
/// functions should only be called from the main thread.
|
||||||
pub struct ParamSetter<'a> {
|
pub struct ParamSetter<'a> {
|
||||||
context: &'a dyn GuiContext,
|
context: &'a dyn GuiContext,
|
||||||
}
|
}
|
||||||
|
|
30
src/lib.rs
30
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))]
|
#![cfg_attr(feature = "simd", feature(portable_simd))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod debug;
|
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 formatters;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
// Re-export our derive macros to make this a bit easier to use
|
pub mod buffer;
|
||||||
pub use nih_plug_derive::Params;
|
pub mod context;
|
||||||
|
pub mod event_loop;
|
||||||
// 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 param;
|
pub mod param;
|
||||||
pub mod plugin;
|
pub mod plugin;
|
||||||
pub mod wrapper;
|
pub mod wrapper;
|
||||||
|
|
|
@ -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
|
//! + `..Default::default()`, and the builder interface. For the moment, just look at the gain
|
||||||
//! example.
|
//! example.
|
||||||
|
|
||||||
|
|
19
src/prelude.rs
Normal file
19
src/prelude.rs
Normal file
|
@ -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,
|
||||||
|
};
|
|
@ -4,11 +4,10 @@ use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use super::wrapper::{OutputParamChange, Task, Wrapper};
|
use super::wrapper::{OutputParamChange, Task, Wrapper};
|
||||||
use crate::context::ProcessContext;
|
use crate::context::{GuiContext, ProcessContext};
|
||||||
use crate::event_loop::EventLoop;
|
use crate::event_loop::EventLoop;
|
||||||
use crate::param::internals::ParamPtr;
|
use crate::param::internals::ParamPtr;
|
||||||
use crate::plugin::{ClapPlugin, NoteEvent};
|
use crate::plugin::{ClapPlugin, NoteEvent};
|
||||||
use crate::GuiContext;
|
|
||||||
|
|
||||||
/// A [`GuiContext`] implementation for the wrapper. This is passed to the plugin in
|
/// 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
|
/// [`Editor::spawn()`][crate::Editor::spawn()] so it can interact with the rest of the plugin and
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use super::descriptor::PluginDescriptor;
|
use super::descriptor::PluginDescriptor;
|
||||||
use super::wrapper::Wrapper;
|
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()`
|
/// 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.
|
/// function. From this point onwards we don't need to generate code with macros anymore.
|
||||||
|
|
|
@ -5,9 +5,9 @@ use std::collections::HashMap;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
use crate::param::internals::ParamPtr;
|
use crate::param::internals::{ParamPtr, Params};
|
||||||
use crate::param::Param;
|
use crate::param::Param;
|
||||||
use crate::{BufferConfig, Params};
|
use crate::plugin::BufferConfig;
|
||||||
|
|
||||||
/// A plain, unnormalized value for a parameter.
|
/// A plain, unnormalized value for a parameter.
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|
Loading…
Reference in a new issue