Add flags to control parameter visibility
For the host and in generic UIs. These aren't wired up to anything yet.
This commit is contained in:
parent
9e3149b931
commit
a1be942d6d
9 changed files with 116 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2133,6 +2133,7 @@ dependencies = [
|
|||
"assert_no_alloc",
|
||||
"atomic_float",
|
||||
"atomic_refcell",
|
||||
"bitflags",
|
||||
"cfg-if 1.0.0",
|
||||
"clap-sys",
|
||||
"crossbeam",
|
||||
|
|
|
@ -46,6 +46,7 @@ nih_plug_derive = { path = "nih_plug_derive" }
|
|||
|
||||
atomic_float = "0.1"
|
||||
atomic_refcell = "0.1"
|
||||
bitflags = "1.3"
|
||||
cfg-if = "1.0"
|
||||
# For CLAP 0.23
|
||||
clap-sys = { git = "https://github.com/glowcoil/clap-sys" }
|
||||
|
|
18
src/param.rs
18
src/param.rs
|
@ -17,6 +17,21 @@ pub use enums::EnumParam;
|
|||
pub use float::FloatParam;
|
||||
pub use integer::IntParam;
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// Flags for controlling a parameter's behavior.
|
||||
#[repr(transparent)]
|
||||
#[derive(Default)]
|
||||
pub struct ParamFlags: u32 {
|
||||
/// 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.
|
||||
const NON_AUTOMATABLE = 1 << 0;
|
||||
/// Don't show this parameter when generating a generic UI for the plugin using one of
|
||||
/// NIH-plug's generic UI widgets.
|
||||
const HIDE_IN_GENERIC_UI = 1 << 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes a single parameter of any type.
|
||||
pub trait Param: Display {
|
||||
/// The plain parameter type.
|
||||
|
@ -112,6 +127,9 @@ pub trait Param: Display {
|
|||
/// will do this for every smoother.
|
||||
fn initialize_block_smoother(&mut self, max_block_size: usize);
|
||||
|
||||
/// Flags to control the parameter's behavior. See [`ParamFlags`].
|
||||
fn flags(&self) -> ParamFlags;
|
||||
|
||||
/// Internal implementation detail for implementing [`Params`][internals::Params]. This should
|
||||
/// not be used directly.
|
||||
fn as_ptr(&self) -> internals::ParamPtr;
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt::Display;
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::internals::ParamPtr;
|
||||
use super::Param;
|
||||
use super::{Param, ParamFlags};
|
||||
|
||||
/// A simple boolean parmaeter.
|
||||
#[repr(C, align(4))]
|
||||
|
@ -14,6 +14,8 @@ pub struct BoolParam {
|
|||
/// The field's default value.
|
||||
pub default: bool,
|
||||
|
||||
/// Flags to control the parameter's behavior. See [`ParamFlags`].
|
||||
pub flags: ParamFlags,
|
||||
/// Optional callback for listening to value changes. The argument passed to this function is
|
||||
/// the parameter's new value. This should not do anything expensive as it may be called
|
||||
/// multiple times in rapid succession, and it can be run from both the GUI and the audio
|
||||
|
@ -36,6 +38,7 @@ impl Default for BoolParam {
|
|||
Self {
|
||||
value: false,
|
||||
default: false,
|
||||
flags: ParamFlags::default(),
|
||||
value_changed: None,
|
||||
name: "",
|
||||
value_to_string: None,
|
||||
|
@ -129,6 +132,10 @@ impl Param for BoolParam {
|
|||
|
||||
fn initialize_block_smoother(&mut self, _max_block_size: usize) {}
|
||||
|
||||
fn flags(&self) -> ParamFlags {
|
||||
self.flags
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> ParamPtr {
|
||||
ParamPtr::BoolParam(self as *const BoolParam as *mut BoolParam)
|
||||
}
|
||||
|
@ -174,4 +181,19 @@ impl BoolParam {
|
|||
self.string_to_value = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
/// Mark the paramter as non-automatable. This means that 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.
|
||||
pub fn non_automatable(mut self) -> Self {
|
||||
self.flags.insert(ParamFlags::NON_AUTOMATABLE);
|
||||
self
|
||||
}
|
||||
|
||||
/// Don't show this parameter when generating a generic UI for the plugin using one of
|
||||
/// NIH-plug's generic UI widgets.
|
||||
pub fn hide_in_generic_ui(mut self) -> Self {
|
||||
self.flags.insert(ParamFlags::HIDE_IN_GENERIC_UI);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
|||
|
||||
use super::internals::ParamPtr;
|
||||
use super::range::IntRange;
|
||||
use super::{IntParam, Param};
|
||||
use super::{IntParam, Param, ParamFlags};
|
||||
|
||||
// Re-export the derive macro
|
||||
pub use nih_plug_derive::Enum;
|
||||
|
@ -159,6 +159,10 @@ impl<T: Enum + PartialEq> Param for EnumParam<T> {
|
|||
self.inner.initialize_block_smoother(max_block_size)
|
||||
}
|
||||
|
||||
fn flags(&self) -> ParamFlags {
|
||||
self.inner.flags()
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> ParamPtr {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
@ -228,6 +232,10 @@ impl Param for EnumParamInner {
|
|||
self.inner.initialize_block_smoother(max_block_size)
|
||||
}
|
||||
|
||||
fn flags(&self) -> ParamFlags {
|
||||
self.inner.flags()
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> ParamPtr {
|
||||
ParamPtr::EnumParam(self as *const EnumParamInner as *mut EnumParamInner)
|
||||
}
|
||||
|
@ -267,6 +275,21 @@ impl<T: Enum + PartialEq + 'static> EnumParam<T> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Mark the paramter as non-automatable. This means that 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.
|
||||
pub fn non_automatable(mut self) -> Self {
|
||||
self.inner.inner = self.inner.inner.non_automatable();
|
||||
self
|
||||
}
|
||||
|
||||
/// Don't show this parameter when generating a generic UI for the plugin using one of
|
||||
/// NIH-plug's generic UI widgets.
|
||||
pub fn hide_in_generic_ui(mut self) -> Self {
|
||||
self.inner.inner = self.inner.inner.hide_in_generic_ui();
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the active enum variant.
|
||||
pub fn value(&self) -> T {
|
||||
self.plain_value()
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
|||
use super::internals::ParamPtr;
|
||||
use super::range::FloatRange;
|
||||
use super::smoothing::{Smoother, SmoothingStyle};
|
||||
use super::Param;
|
||||
use super::{Param, ParamFlags};
|
||||
|
||||
/// A floating point parameter that's stored unnormalized. The range is used for the normalization
|
||||
/// process.
|
||||
|
@ -31,6 +31,8 @@ pub struct FloatParam {
|
|||
/// set by the host.
|
||||
pub smoothed: Smoother<f32>,
|
||||
|
||||
/// Flags to control the parameter's behavior. See [`ParamFlags`].
|
||||
pub flags: ParamFlags,
|
||||
/// Optional callback for listening to value changes. The argument passed to this function is
|
||||
/// the parameter's new **plain** value. This should not do anything expensive as it may be
|
||||
/// called multiple times in rapid succession.
|
||||
|
@ -69,6 +71,7 @@ impl Default for FloatParam {
|
|||
value: 0.0,
|
||||
default: 0.0,
|
||||
smoothed: Smoother::none(),
|
||||
flags: ParamFlags::default(),
|
||||
value_changed: None,
|
||||
range: FloatRange::default(),
|
||||
step_size: None,
|
||||
|
@ -198,6 +201,10 @@ impl Param for FloatParam {
|
|||
self.smoothed.initialize_block_smoother(max_block_size);
|
||||
}
|
||||
|
||||
fn flags(&self) -> ParamFlags {
|
||||
self.flags
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> ParamPtr {
|
||||
ParamPtr::FloatParam(self as *const _ as *mut _)
|
||||
}
|
||||
|
@ -287,6 +294,21 @@ impl FloatParam {
|
|||
self.string_to_value = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
/// Mark the paramter as non-automatable. This means that 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.
|
||||
pub fn non_automatable(mut self) -> Self {
|
||||
self.flags.insert(ParamFlags::NON_AUTOMATABLE);
|
||||
self
|
||||
}
|
||||
|
||||
/// Don't show this parameter when generating a generic UI for the plugin using one of
|
||||
/// NIH-plug's generic UI widgets.
|
||||
pub fn hide_in_generic_ui(mut self) -> Self {
|
||||
self.flags.insert(ParamFlags::HIDE_IN_GENERIC_UI);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Caldculate how many decimals to round to when displaying a floating point value with a specific
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
|||
use super::internals::ParamPtr;
|
||||
use super::range::IntRange;
|
||||
use super::smoothing::{Smoother, SmoothingStyle};
|
||||
use super::Param;
|
||||
use super::{Param, ParamFlags};
|
||||
|
||||
/// A discrete integer parameter that's stored unnormalized. The range is used for the normalization
|
||||
/// process.
|
||||
|
@ -31,6 +31,8 @@ pub struct IntParam {
|
|||
/// set by the host.
|
||||
pub smoothed: Smoother<i32>,
|
||||
|
||||
/// Flags to control the parameter's behavior. See [`ParamFlags`].
|
||||
pub flags: ParamFlags,
|
||||
/// Optional callback for listening to value changes. The argument passed to this function is
|
||||
/// the parameter's new **plain** value. This should not do anything expensive as it may be
|
||||
/// called multiple times in rapid succession.
|
||||
|
@ -65,6 +67,7 @@ impl Default for IntParam {
|
|||
value: 0,
|
||||
default: 0,
|
||||
smoothed: Smoother::none(),
|
||||
flags: ParamFlags::default(),
|
||||
value_changed: None,
|
||||
range: IntRange::default(),
|
||||
name: "",
|
||||
|
@ -162,6 +165,10 @@ impl Param for IntParam {
|
|||
self.smoothed.initialize_block_smoother(max_block_size);
|
||||
}
|
||||
|
||||
fn flags(&self) -> ParamFlags {
|
||||
self.flags
|
||||
}
|
||||
|
||||
fn as_ptr(&self) -> ParamPtr {
|
||||
ParamPtr::IntParam(self as *const _ as *mut _)
|
||||
}
|
||||
|
@ -242,4 +249,19 @@ impl IntParam {
|
|||
self.string_to_value = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
/// Mark the paramter as non-automatable. This means that 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.
|
||||
pub fn non_automatable(mut self) -> Self {
|
||||
self.flags.insert(ParamFlags::NON_AUTOMATABLE);
|
||||
self
|
||||
}
|
||||
|
||||
/// Don't show this parameter when generating a generic UI for the plugin using one of
|
||||
/// NIH-plug's generic UI widgets.
|
||||
pub fn hide_in_generic_ui(mut self) -> Self {
|
||||
self.flags.insert(ParamFlags::HIDE_IN_GENERIC_UI);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::pin::Pin;
|
||||
|
||||
use super::Param;
|
||||
use super::{Param, ParamFlags};
|
||||
|
||||
pub use nih_plug_derive::Params;
|
||||
/// Re-export for use in the [`Params`] proc-macro.
|
||||
|
@ -157,6 +157,7 @@ impl ParamPtr {
|
|||
param_ptr_forward!(pub unsafe fn initialize_block_smoother(&mut self, max_block_size: usize));
|
||||
param_ptr_forward!(pub unsafe fn normalized_value_to_string(&self, normalized: f32, include_unit: bool) -> String);
|
||||
param_ptr_forward!(pub unsafe fn string_to_normalized_value(&self, string: &str) -> Option<f32>);
|
||||
param_ptr_forward!(pub unsafe fn flags(&self) -> ParamFlags);
|
||||
|
||||
// These functions involve casts since the plugin formats only do floating point types, so we
|
||||
// can't generate them with the macro:
|
||||
|
|
|
@ -17,7 +17,7 @@ pub use super::param::enums::{Enum, EnumParam};
|
|||
pub use super::param::internals::{ParamPtr, 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::param::{BoolParam, FloatParam, IntParam, Param, ParamFlags};
|
||||
pub use super::plugin::{
|
||||
BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, Plugin,
|
||||
ProcessStatus, Vst3Plugin,
|
||||
|
|
Loading…
Add table
Reference in a new issue