2022-03-03 23:23:51 +01:00
|
|
|
use nih_plug::prelude::*;
|
2022-01-31 17:16:27 +01:00
|
|
|
use parking_lot::RwLock;
|
2022-01-25 23:02:15 +01:00
|
|
|
use std::pin::Pin;
|
2022-02-12 17:19:52 +01:00
|
|
|
use std::sync::Arc;
|
2022-01-25 23:02:15 +01:00
|
|
|
|
|
|
|
struct Gain {
|
|
|
|
params: Pin<Box<GainParams>>,
|
|
|
|
}
|
2022-01-25 22:18:55 +01:00
|
|
|
|
|
|
|
#[derive(Params)]
|
2022-01-25 23:02:15 +01:00
|
|
|
struct GainParams {
|
2022-01-29 20:40:14 +01:00
|
|
|
#[id = "gain"]
|
2022-01-25 23:02:15 +01:00
|
|
|
pub gain: FloatParam,
|
2022-01-30 16:16:15 +01:00
|
|
|
|
2022-03-03 20:37:01 +01:00
|
|
|
#[id = "stable"]
|
|
|
|
pub but_field_names_can_change: BoolParam,
|
2022-01-31 21:24:26 +01:00
|
|
|
|
2022-01-30 16:16:15 +01:00
|
|
|
/// This field isn't used in this exampleq, but anything written to the vector would be restored
|
|
|
|
/// together with a preset/state file saved for this plugin. This can be useful for storign
|
|
|
|
/// things like sample data.
|
|
|
|
#[persist = "industry_secrets"]
|
2022-01-30 17:07:50 +01:00
|
|
|
pub random_data: RwLock<Vec<f32>>,
|
2022-03-03 20:37:01 +01:00
|
|
|
|
|
|
|
/// You can also nest parameter structs. This is only for your own organization: they will still
|
|
|
|
/// appear as a flat list to the host.
|
|
|
|
#[nested]
|
|
|
|
pub sub_params: SubParams,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Params)]
|
|
|
|
struct SubParams {
|
|
|
|
#[id = "thing"]
|
|
|
|
pub nested_parameter: FloatParam,
|
2022-01-25 23:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Gain {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2022-01-31 19:40:52 +01:00
|
|
|
params: Box::pin(GainParams::default()),
|
2022-01-25 23:02:15 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-25 22:18:55 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 23:02:15 +01:00
|
|
|
impl Default for GainParams {
|
2022-01-25 22:18:55 +01:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2022-02-12 17:19:52 +01:00
|
|
|
// There are three ways to specify parameters:
|
|
|
|
//
|
|
|
|
// ...either manually specify all fields:
|
2022-01-25 23:02:15 +01:00
|
|
|
gain: FloatParam {
|
2022-01-26 15:11:23 +01:00
|
|
|
value: 0.0,
|
2022-02-06 02:36:31 +01:00
|
|
|
smoothed: Smoother::new(SmoothingStyle::Linear(50.0)),
|
2022-01-31 21:02:47 +01:00
|
|
|
value_changed: None,
|
2022-03-03 19:24:40 +01:00
|
|
|
range: FloatRange::Linear {
|
2022-01-25 23:02:15 +01:00
|
|
|
min: -30.0,
|
2022-01-26 15:11:23 +01:00
|
|
|
max: 30.0,
|
2022-01-25 22:18:55 +01:00
|
|
|
},
|
2022-02-13 16:43:11 +01:00
|
|
|
step_size: Some(0.01),
|
2022-01-25 23:02:15 +01:00
|
|
|
name: "Gain",
|
|
|
|
unit: " dB",
|
2022-02-13 16:43:11 +01:00
|
|
|
// This is actually redundant, because a step size of two decimal places already
|
|
|
|
// causes the parameter to shown rounded
|
2022-02-12 17:19:52 +01:00
|
|
|
value_to_string: Some(formatters::f32_rounded(2)),
|
2022-01-25 22:18:55 +01:00
|
|
|
string_to_value: None,
|
2022-02-12 17:19:52 +01:00
|
|
|
// ...or specify the fields you want to initialize directly and leave the other
|
|
|
|
// fields at their defaults:
|
|
|
|
// // ..Default::default(),
|
2022-01-25 22:18:55 +01:00
|
|
|
},
|
2022-02-12 17:19:52 +01:00
|
|
|
// ...or use the builder interface:
|
2022-03-03 20:37:01 +01:00
|
|
|
but_field_names_can_change: BoolParam::new("Important value", false).with_callback(
|
2022-02-12 17:19:52 +01:00
|
|
|
Arc::new(|_new_value: bool| {
|
|
|
|
// If, for instance, updating this parameter would require other parts of the
|
|
|
|
// plugin's internal state to be updated other values to also be updated, then
|
|
|
|
// you can use this callback to for instance modify an atomic in the plugin.
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
// Persisted fields can be intialized like any other fields, and they'll keep their when
|
|
|
|
// restoring the plugin's state.
|
2022-01-30 17:07:50 +01:00
|
|
|
random_data: RwLock::new(Vec::new()),
|
2022-03-03 20:37:01 +01:00
|
|
|
sub_params: SubParams {
|
|
|
|
nested_parameter: FloatParam::new(
|
|
|
|
"Unused Nested Parameter",
|
|
|
|
0.5,
|
|
|
|
FloatRange::Skewed {
|
|
|
|
min: 2.0,
|
|
|
|
max: 2.4,
|
|
|
|
factor: FloatRange::skew_factor(2.0),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.with_value_to_string(formatters::f32_rounded(2)),
|
|
|
|
},
|
2022-01-25 23:02:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Plugin for Gain {
|
2022-01-26 18:14:13 +01:00
|
|
|
const NAME: &'static str = "Gain";
|
|
|
|
const VENDOR: &'static str = "Moist Plugins GmbH";
|
|
|
|
const URL: &'static str = "https://youtu.be/dQw4w9WgXcQ";
|
|
|
|
const EMAIL: &'static str = "info@example.com";
|
|
|
|
|
2022-01-26 22:20:15 +01:00
|
|
|
const VERSION: &'static str = "0.0.1";
|
2022-01-26 19:49:22 +01:00
|
|
|
|
2022-01-25 23:02:15 +01:00
|
|
|
const DEFAULT_NUM_INPUTS: u32 = 2;
|
|
|
|
const DEFAULT_NUM_OUTPUTS: u32 = 2;
|
|
|
|
|
2022-02-04 01:09:09 +01:00
|
|
|
const ACCEPTS_MIDI: bool = false;
|
|
|
|
|
2022-01-25 23:02:15 +01:00
|
|
|
fn params(&self) -> Pin<&dyn Params> {
|
2022-01-26 11:41:07 +01:00
|
|
|
self.params.as_ref()
|
2022-01-25 23:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn accepts_bus_config(&self, config: &BusConfig) -> bool {
|
|
|
|
// This works with any symmetrical IO layout
|
|
|
|
config.num_input_channels == config.num_output_channels && config.num_input_channels > 0
|
|
|
|
}
|
|
|
|
|
2022-02-01 17:09:23 +01:00
|
|
|
fn initialize(
|
|
|
|
&mut self,
|
|
|
|
_bus_config: &BusConfig,
|
|
|
|
_buffer_config: &BufferConfig,
|
2022-02-04 23:03:11 +01:00
|
|
|
_context: &mut impl ProcessContext,
|
2022-02-01 17:09:23 +01:00
|
|
|
) -> bool {
|
2022-01-25 23:02:15 +01:00
|
|
|
// This plugin doesn't need any special initialization, but if you need to do anything
|
|
|
|
// expensive then this would be the place. State is kept around while when the host
|
|
|
|
// reconfigures the plugin.
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2022-02-04 23:03:11 +01:00
|
|
|
fn process(
|
|
|
|
&mut self,
|
|
|
|
buffer: &mut Buffer,
|
|
|
|
_context: &mut impl ProcessContext,
|
|
|
|
) -> ProcessStatus {
|
2022-03-03 21:38:50 +01:00
|
|
|
for channel_samples in buffer.iter_mut() {
|
2022-02-02 21:08:23 +01:00
|
|
|
// Smoothing is optionally built into the parameters themselves
|
|
|
|
let gain = self.params.gain.smoothed.next();
|
|
|
|
|
2022-03-03 21:38:50 +01:00
|
|
|
for sample in channel_samples {
|
2022-02-02 21:08:23 +01:00
|
|
|
*sample *= util::db_to_gain(gain);
|
2022-01-25 23:02:15 +01:00
|
|
|
}
|
2022-01-25 22:18:55 +01:00
|
|
|
}
|
2022-01-27 21:03:49 +01:00
|
|
|
|
|
|
|
ProcessStatus::Normal
|
2022-01-25 22:18:55 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-26 12:37:45 +01:00
|
|
|
|
2022-02-28 17:04:39 +01:00
|
|
|
impl ClapPlugin for Gain {
|
|
|
|
const CLAP_ID: &'static str = "com.moist-plugins-gmbh.gain";
|
2022-02-28 17:18:11 +01:00
|
|
|
const CLAP_DESCRIPTION: &'static str = "A smoothed gain parameter example plugin";
|
2022-02-28 17:29:53 +01:00
|
|
|
const CLAP_FEATURES: &'static [&'static str] = &["audio_effect", "mono", "stereo", "tool"];
|
2022-02-28 17:18:11 +01:00
|
|
|
const CLAP_MANUAL_URL: &'static str = Self::URL;
|
|
|
|
const CLAP_SUPPORT_URL: &'static str = Self::URL;
|
2022-02-28 17:04:39 +01:00
|
|
|
}
|
2022-02-28 14:45:07 +01:00
|
|
|
|
2022-01-27 22:13:13 +01:00
|
|
|
impl Vst3Plugin for Gain {
|
|
|
|
const VST3_CLASS_ID: [u8; 16] = *b"GainMoistestPlug";
|
|
|
|
const VST3_CATEGORIES: &'static str = "Fx|Dynamics";
|
|
|
|
}
|
|
|
|
|
2022-02-28 14:45:31 +01:00
|
|
|
nih_export_clap!(Gain);
|
2022-01-27 22:13:13 +01:00
|
|
|
nih_export_vst3!(Gain);
|