2022-01-26 20:56:02 +11:00
|
|
|
// nih-plug: plugins, but rewritten in Rust
|
|
|
|
// Copyright (C) 2022 Robbert van der Helm
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2022-01-26 21:38:26 +11:00
|
|
|
#[macro_use]
|
|
|
|
extern crate nih_plug;
|
|
|
|
|
2022-01-26 09:02:15 +11:00
|
|
|
use nih_plug::{
|
2022-02-03 01:12:33 +11:00
|
|
|
formatters, util, Buffer, BufferConfig, BusConfig, Plugin, ProcessContext, ProcessStatus,
|
|
|
|
Vst3Plugin,
|
2022-01-26 09:02:15 +11:00
|
|
|
};
|
2022-02-03 07:08:23 +11:00
|
|
|
use nih_plug::{BoolParam, FloatParam, Param, Params, Range, Smoother, SmoothingStyle};
|
2022-02-01 03:16:27 +11:00
|
|
|
use parking_lot::RwLock;
|
2022-01-26 09:02:15 +11:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
|
|
struct Gain {
|
|
|
|
params: Pin<Box<GainParams>>,
|
|
|
|
}
|
2022-01-26 08:18:55 +11:00
|
|
|
|
|
|
|
#[derive(Params)]
|
2022-01-26 09:02:15 +11:00
|
|
|
struct GainParams {
|
2022-01-30 06:40:14 +11:00
|
|
|
#[id = "gain"]
|
2022-01-26 09:02:15 +11:00
|
|
|
pub gain: FloatParam,
|
2022-01-31 02:16:15 +11:00
|
|
|
|
2022-02-01 07:24:26 +11:00
|
|
|
#[id = "as_long_as_this_name_stays_constant"]
|
|
|
|
pub the_field_name_can_change: BoolParam,
|
|
|
|
|
2022-01-31 02:16:15 +11: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-31 03:07:50 +11:00
|
|
|
pub random_data: RwLock<Vec<f32>>,
|
2022-01-26 09:02:15 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Gain {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2022-02-01 05:40:52 +11:00
|
|
|
params: Box::pin(GainParams::default()),
|
2022-01-26 09:02:15 +11:00
|
|
|
}
|
|
|
|
}
|
2022-01-26 08:18:55 +11:00
|
|
|
}
|
|
|
|
|
2022-01-26 09:02:15 +11:00
|
|
|
impl Default for GainParams {
|
2022-01-26 08:18:55 +11:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2022-01-26 09:02:15 +11:00
|
|
|
gain: FloatParam {
|
2022-01-27 01:11:23 +11:00
|
|
|
value: 0.0,
|
2022-02-03 09:00:17 +11:00
|
|
|
smoothed: Smoother::new(SmoothingStyle::Logarithmic(1000.0)),
|
2022-02-01 07:02:47 +11:00
|
|
|
value_changed: None,
|
|
|
|
// 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 a callback like this, where `requires_updates` is an `Arc<AtomicBool>`
|
|
|
|
// that's also stored on the parameters struct:
|
|
|
|
// value_changed: Some(Arc::new(move |_new| { requires_update.store(true, Ordering::Release); })),
|
2022-01-26 08:18:55 +11:00
|
|
|
range: Range::Linear {
|
2022-01-26 09:02:15 +11:00
|
|
|
min: -30.0,
|
2022-01-27 01:11:23 +11:00
|
|
|
max: 30.0,
|
2022-01-26 08:18:55 +11:00
|
|
|
},
|
2022-01-26 09:02:15 +11:00
|
|
|
name: "Gain",
|
|
|
|
unit: " dB",
|
2022-01-29 00:33:29 +11:00
|
|
|
value_to_string: formatters::f32_rounded(2),
|
2022-01-26 08:18:55 +11:00
|
|
|
string_to_value: None,
|
|
|
|
},
|
2022-02-01 07:24:26 +11:00
|
|
|
// For brevity's sake you can also use the default values. Don't forget to set the field
|
|
|
|
// name, default value, and range though.
|
|
|
|
the_field_name_can_change: BoolParam {
|
|
|
|
value: false,
|
|
|
|
name: "Important Value",
|
2022-02-02 06:15:33 +11:00
|
|
|
..Default::default()
|
2022-02-01 07:24:26 +11:00
|
|
|
},
|
2022-01-31 03:07:50 +11:00
|
|
|
random_data: RwLock::new(Vec::new()),
|
2022-01-26 09:02:15 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Plugin for Gain {
|
2022-01-27 04:14:13 +11: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-27 08:20:15 +11:00
|
|
|
const VERSION: &'static str = "0.0.1";
|
2022-01-27 05:49:22 +11:00
|
|
|
|
2022-01-26 09:02:15 +11:00
|
|
|
const DEFAULT_NUM_INPUTS: u32 = 2;
|
|
|
|
const DEFAULT_NUM_OUTPUTS: u32 = 2;
|
|
|
|
|
2022-02-04 11:09:09 +11:00
|
|
|
const ACCEPTS_MIDI: bool = false;
|
|
|
|
|
2022-01-26 09:02:15 +11:00
|
|
|
fn params(&self) -> Pin<&dyn Params> {
|
2022-01-26 21:41:07 +11:00
|
|
|
self.params.as_ref()
|
2022-01-26 09:02:15 +11: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-02 03:09:23 +11:00
|
|
|
fn initialize(
|
|
|
|
&mut self,
|
|
|
|
_bus_config: &BusConfig,
|
|
|
|
_buffer_config: &BufferConfig,
|
2022-02-05 09:03:11 +11:00
|
|
|
_context: &mut impl ProcessContext,
|
2022-02-02 03:09:23 +11:00
|
|
|
) -> bool {
|
2022-01-26 09:02:15 +11: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-05 09:03:11 +11:00
|
|
|
fn process(
|
|
|
|
&mut self,
|
|
|
|
buffer: &mut Buffer,
|
|
|
|
_context: &mut impl ProcessContext,
|
|
|
|
) -> ProcessStatus {
|
2022-02-02 22:29:33 +11:00
|
|
|
for samples in buffer.iter_mut() {
|
2022-02-03 07:08:23 +11:00
|
|
|
// Smoothing is optionally built into the parameters themselves
|
|
|
|
let gain = self.params.gain.smoothed.next();
|
|
|
|
|
2022-02-02 22:29:33 +11:00
|
|
|
for sample in samples {
|
2022-02-03 07:08:23 +11:00
|
|
|
*sample *= util::db_to_gain(gain);
|
2022-01-26 09:02:15 +11:00
|
|
|
}
|
2022-01-26 08:18:55 +11:00
|
|
|
}
|
2022-01-28 07:03:49 +11:00
|
|
|
|
|
|
|
ProcessStatus::Normal
|
2022-01-26 08:18:55 +11:00
|
|
|
}
|
|
|
|
}
|
2022-01-26 22:37:45 +11:00
|
|
|
|
2022-01-28 08:13:13 +11:00
|
|
|
impl Vst3Plugin for Gain {
|
|
|
|
const VST3_CLASS_ID: [u8; 16] = *b"GainMoistestPlug";
|
|
|
|
const VST3_CATEGORIES: &'static str = "Fx|Dynamics";
|
|
|
|
}
|
|
|
|
|
|
|
|
nih_export_vst3!(Gain);
|