2022-04-12 01:38:20 +10:00
|
|
|
//! NIH-plug can handle floating point, integer, boolean, and enum parameters. Parameters are
|
|
|
|
//! managed by creating a struct deriving the [`Params`][internals::Params] trait containing fields
|
2022-04-25 02:34:40 +10:00
|
|
|
//! for those parameter types, and then returning a reference to that object from your
|
2022-04-12 01:38:20 +10:00
|
|
|
//! [`Plugin::params()`][crate::prelude::Plugin::params()] method. See the `Params` trait for more
|
|
|
|
//! information.
|
2022-01-31 03:16:12 +11:00
|
|
|
|
2022-01-25 12:17:30 +11:00
|
|
|
use std::fmt::Display;
|
2022-01-25 06:59:46 +11:00
|
|
|
|
2022-02-15 00:19:46 +11:00
|
|
|
// Parameter types
|
2022-02-15 00:27:40 +11:00
|
|
|
mod boolean;
|
2022-02-15 00:35:57 +11:00
|
|
|
pub mod enums;
|
2022-03-04 05:24:40 +11:00
|
|
|
mod float;
|
|
|
|
mod integer;
|
2022-02-02 07:06:13 +11:00
|
|
|
|
2022-02-02 07:01:28 +11:00
|
|
|
pub mod internals;
|
2022-02-02 07:06:13 +11:00
|
|
|
pub mod range;
|
2022-02-03 07:08:23 +11:00
|
|
|
pub mod smoothing;
|
2022-02-02 07:01:28 +11:00
|
|
|
|
2022-02-15 00:27:40 +11:00
|
|
|
pub use boolean::BoolParam;
|
2022-02-15 00:35:57 +11:00
|
|
|
pub use enums::EnumParam;
|
2022-03-04 05:24:40 +11:00
|
|
|
pub use float::FloatParam;
|
|
|
|
pub use integer::IntParam;
|
2022-02-14 12:04:17 +11:00
|
|
|
|
2022-03-23 23:02:54 +11:00
|
|
|
bitflags::bitflags! {
|
|
|
|
/// Flags for controlling a parameter's behavior.
|
|
|
|
#[repr(transparent)]
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct ParamFlags: u32 {
|
2022-03-24 03:36:58 +11:00
|
|
|
/// When applied to a [`BoolParam`], this will cause the parameter to be linked to the
|
|
|
|
/// host's bypass control. Only a single parameter can be marked as a bypass parameter. If
|
|
|
|
/// you don't have a bypass parameter, then NIH-plug will add one for you. You will need to
|
|
|
|
/// implement this yourself if your plugin introduces latency.
|
|
|
|
const BYPASS = 1 << 0;
|
2022-03-23 23:02:54 +11:00
|
|
|
/// The parameter cannot be automated from the host. Setting this flag also prevents it from
|
|
|
|
/// showing up in the host's own generic UI for this plugin. The parameter can still be
|
|
|
|
/// changed from the plugin's editor GUI.
|
2022-03-24 03:36:58 +11:00
|
|
|
const NON_AUTOMATABLE = 1 << 1;
|
2022-03-23 23:02:54 +11:00
|
|
|
/// Don't show this parameter when generating a generic UI for the plugin using one of
|
|
|
|
/// NIH-plug's generic UI widgets.
|
2022-03-24 03:36:58 +11:00
|
|
|
const HIDE_IN_GENERIC_UI = 1 << 2;
|
2022-03-23 23:02:54 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 00:40:18 +10:00
|
|
|
/// Describes a single parameter of any type. Most parameter implementations also have a field
|
|
|
|
/// called `value` that and a field called `smoothed`. The former stores the latest unsmoothed
|
|
|
|
/// value, and the latter can be used to access the smoother. These two fields should be used in DSP
|
|
|
|
/// code to either get the parameter's current (smoothed) value. In UI code the getters from this
|
|
|
|
/// trait should be used instead.
|
2022-02-10 05:45:16 +11:00
|
|
|
pub trait Param: Display {
|
2022-02-02 07:02:58 +11:00
|
|
|
/// The plain parameter type.
|
2022-03-06 05:50:12 +11:00
|
|
|
type Plain: PartialEq;
|
2022-02-02 07:02:58 +11:00
|
|
|
|
2022-03-03 23:55:54 +11:00
|
|
|
/// Get the human readable name for this parameter.
|
2022-04-12 07:27:36 +10:00
|
|
|
fn name(&self) -> &str;
|
2022-03-03 23:55:54 +11:00
|
|
|
|
|
|
|
/// Get the unit label for this parameter, if any.
|
|
|
|
fn unit(&self) -> &'static str;
|
|
|
|
|
2022-03-20 02:09:31 +11:00
|
|
|
/// Get the unnormalized value for this parameter.
|
|
|
|
fn plain_value(&self) -> Self::Plain;
|
|
|
|
|
|
|
|
/// Get the normalized `[0, 1]` value for this parameter.
|
2022-05-02 00:32:01 +10:00
|
|
|
#[inline]
|
2022-03-21 23:15:17 +11:00
|
|
|
fn normalized_value(&self) -> f32 {
|
|
|
|
self.preview_normalized(self.plain_value())
|
|
|
|
}
|
2022-03-20 02:09:31 +11:00
|
|
|
|
2022-03-21 22:49:59 +11:00
|
|
|
/// Get the unnormalized default value for this parameter.
|
|
|
|
fn default_plain_value(&self) -> Self::Plain;
|
|
|
|
|
|
|
|
/// Get the normalized `[0, 1]` default value for this parameter.
|
2022-05-02 00:32:01 +10:00
|
|
|
#[inline]
|
2022-03-21 22:49:59 +11:00
|
|
|
fn default_normalized_value(&self) -> f32 {
|
|
|
|
self.preview_normalized(self.default_plain_value())
|
|
|
|
}
|
|
|
|
|
2022-03-20 02:06:20 +11:00
|
|
|
/// Get the number of steps for this paramter, if it is discrete. Used for the host's generic
|
|
|
|
/// UI.
|
2022-03-03 23:55:54 +11:00
|
|
|
fn step_count(&self) -> Option<usize>;
|
|
|
|
|
2022-04-27 03:39:03 +10:00
|
|
|
/// Returns the previous step from a specific value for this parameter. This can be the same as
|
2022-03-20 02:06:20 +11:00
|
|
|
/// `from` if the value is at the start of its range. This is mainly used for scroll wheel
|
|
|
|
/// interaction in plugin GUIs. When the parameter is not discrete then a step should cover one
|
|
|
|
/// hundredth of the normalized range instead.
|
|
|
|
fn previous_step(&self, from: Self::Plain) -> Self::Plain;
|
|
|
|
|
2022-04-27 03:39:03 +10:00
|
|
|
/// Returns the next step from a specific value for this parameter. This can be the same as
|
2022-03-20 02:06:20 +11:00
|
|
|
/// `from` if the value is at the end of its range. This is mainly used for scroll wheel
|
|
|
|
/// interaction in plugin GUIs. When the parameter is not discrete then a step should cover one
|
|
|
|
/// hundredth of the normalized range instead.
|
|
|
|
fn next_step(&self, from: Self::Plain) -> Self::Plain;
|
|
|
|
|
2022-03-20 02:12:10 +11:00
|
|
|
/// The same as [`previous_step()`][Self::previous_step()], but for normalized values. This is
|
|
|
|
/// mostly useful for GUI widgets.
|
2022-03-20 05:24:08 +11:00
|
|
|
fn previous_normalized_step(&self, from: f32) -> f32 {
|
2022-03-20 02:12:10 +11:00
|
|
|
self.preview_normalized(self.previous_step(self.preview_plain(from)))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The same as [`next_step()`][Self::next_step()], but for normalized values. This is mostly
|
|
|
|
/// useful for GUI widgets.
|
2022-03-20 05:24:08 +11:00
|
|
|
fn next_normalized_step(&self, from: f32) -> f32 {
|
2022-03-20 02:12:10 +11:00
|
|
|
self.preview_normalized(self.next_step(self.preview_plain(from)))
|
|
|
|
}
|
|
|
|
|
2022-02-14 03:52:54 +11:00
|
|
|
/// Set this parameter based on a plain, unnormalized value. This does **not** snap to step
|
2022-03-04 09:05:01 +11:00
|
|
|
/// sizes for continuous parameters (i.e. [`FloatParam`]).
|
2022-02-03 07:26:34 +11:00
|
|
|
///
|
|
|
|
/// This does **not** update the smoother.
|
2022-02-02 07:02:58 +11:00
|
|
|
fn set_plain_value(&mut self, plain: Self::Plain);
|
|
|
|
|
2022-02-14 03:52:54 +11:00
|
|
|
/// Set this parameter based on a normalized value. This **does** snap to step sizes for
|
2022-03-04 09:05:01 +11:00
|
|
|
/// continuous parameters (i.e. [`FloatParam`]).
|
2022-02-03 07:26:34 +11:00
|
|
|
///
|
|
|
|
/// This does **not** update the smoother.
|
2022-03-21 23:17:28 +11:00
|
|
|
fn set_normalized_value(&mut self, normalized: f32) {
|
|
|
|
self.set_plain_value(self.preview_plain(normalized))
|
|
|
|
}
|
2022-02-02 07:02:58 +11:00
|
|
|
|
|
|
|
/// Get the string representation for a normalized value. Used as part of the wrappers. Most
|
|
|
|
/// plugin formats already have support for units, in which case it shouldn't be part of this
|
|
|
|
/// string or some DAWs may show duplicate units.
|
|
|
|
fn normalized_value_to_string(&self, normalized: f32, include_unit: bool) -> String;
|
|
|
|
|
|
|
|
/// Get the string representation for a normalized value. Used as part of the wrappers.
|
|
|
|
fn string_to_normalized_value(&self, string: &str) -> Option<f32>;
|
|
|
|
|
2022-02-06 03:31:45 +11:00
|
|
|
/// Get the normalized value for a plain, unnormalized value, as a float. Used as part of the
|
|
|
|
/// wrappers.
|
|
|
|
fn preview_normalized(&self, plain: Self::Plain) -> f32;
|
|
|
|
|
|
|
|
/// Get the plain, unnormalized value for a normalized value, as a float. Used as part of the
|
2022-03-04 09:05:01 +11:00
|
|
|
/// wrappers. This **does** snap to step sizes for continuous parameters (i.e. [`FloatParam`]).
|
2022-02-06 03:31:45 +11:00
|
|
|
fn preview_plain(&self, normalized: f32) -> Self::Plain;
|
|
|
|
|
2022-03-02 02:53:18 +11:00
|
|
|
/// Update the smoother state to point to the current value. Also used when initializing and
|
|
|
|
/// restoring a plugin so everything is in sync. In that case the smoother should completely
|
|
|
|
/// reset to the current value.
|
|
|
|
fn update_smoother(&mut self, sample_rate: f32, reset: bool);
|
|
|
|
|
2022-03-04 09:05:01 +11:00
|
|
|
/// Allocate memory for block-based smoothing. The
|
2022-03-04 09:30:29 +11:00
|
|
|
/// [`Plugin::initialize_block_smoothers()`][crate::prelude::Plugin::initialize_block_smoothers()] method
|
2022-03-04 09:05:01 +11:00
|
|
|
/// will do this for every smoother.
|
2022-03-02 03:07:03 +11:00
|
|
|
fn initialize_block_smoother(&mut self, max_block_size: usize);
|
|
|
|
|
2022-03-23 23:02:54 +11:00
|
|
|
/// Flags to control the parameter's behavior. See [`ParamFlags`].
|
|
|
|
fn flags(&self) -> ParamFlags;
|
|
|
|
|
2022-03-04 09:05:01 +11:00
|
|
|
/// Internal implementation detail for implementing [`Params`][internals::Params]. This should
|
|
|
|
/// not be used directly.
|
2022-02-02 07:02:58 +11:00
|
|
|
fn as_ptr(&self) -> internals::ParamPtr;
|
|
|
|
}
|