initial project setup
This commit is contained in:
commit
963c797594
8 changed files with 4309 additions and 0 deletions
173
src/lib.rs
Normal file
173
src/lib.rs
Normal file
|
@ -0,0 +1,173 @@
|
|||
use nih_plug::{params::persist, prelude::*};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
struct Gain {
|
||||
params: Arc<GainParams>,
|
||||
}
|
||||
|
||||
#[derive(Params)]
|
||||
struct GainParams {
|
||||
#[id = "gain"]
|
||||
pub gain: FloatParam,
|
||||
|
||||
#[persist = "industry_secrets"]
|
||||
pub random: Mutex<Vec<f32>>,
|
||||
|
||||
#[nested(group = "Subparameters")]
|
||||
pub sub_params: SubParams,
|
||||
|
||||
#[nested(array, group = "Array Parameters")]
|
||||
pub array_params: [ArrayParams; 3],
|
||||
}
|
||||
|
||||
#[derive(Params)]
|
||||
struct SubParams {
|
||||
#[id = "thing"]
|
||||
pub nested_parameter: FloatParam,
|
||||
}
|
||||
|
||||
#[derive(Params)]
|
||||
struct ArrayParams {
|
||||
#[id = "noope"]
|
||||
pub nope: FloatParam,
|
||||
}
|
||||
|
||||
impl Default for Gain {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(GainParams::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GainParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
// gain stored as linear gain.
|
||||
gain: FloatParam::new(
|
||||
"Gain",
|
||||
util::db_to_gain(0.0),
|
||||
FloatRange::Skewed {
|
||||
min: -30.0,
|
||||
max: 30.0,
|
||||
// makes range appear as if linear while displaying decibel values
|
||||
factor: FloatRange::gain_skew_factor(-30.0, 30.0),
|
||||
},
|
||||
)
|
||||
// logarithmic smoothing because value is stored as linear
|
||||
.with_smoother(SmoothingStyle::Logarithmic(50.0))
|
||||
.with_unit(" dB")
|
||||
.with_value_to_string(formatters::v2s_f32_gain_to_db(2))
|
||||
.with_string_to_value(formatters::s2v_f32_gain_to_db()),
|
||||
|
||||
// persisted values can be initialized like any other
|
||||
random: Mutex::new(Vec::new()),
|
||||
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::v2s_f32_rounded(2)),
|
||||
},
|
||||
|
||||
array_params: [1, 2, 3].map(|i| ArrayParams {
|
||||
nope: FloatParam::new(
|
||||
format!("Nope {i}"),
|
||||
0.5,
|
||||
FloatRange::Linear { min: 1.0, max: 2.0 },
|
||||
),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for Gain {
|
||||
const NAME: &'static str = "Gain";
|
||||
|
||||
const VENDOR: &'static str = "fogwaves";
|
||||
|
||||
const URL: &'static str = "https://example.com";
|
||||
|
||||
const EMAIL: &'static str = "info@example.com";
|
||||
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[
|
||||
AudioIOLayout {
|
||||
main_input_channels: NonZeroU32::new(2),
|
||||
main_output_channels: NonZeroU32::new(2),
|
||||
|
||||
aux_input_ports: &[],
|
||||
aux_output_ports: &[],
|
||||
|
||||
names: PortNames::const_default(),
|
||||
},
|
||||
AudioIOLayout {
|
||||
main_input_channels: NonZeroU32::new(1),
|
||||
main_output_channels: NonZeroU32::new(1),
|
||||
..AudioIOLayout::const_default()
|
||||
},
|
||||
];
|
||||
|
||||
const SAMPLE_ACCURATE_AUTOMATION: bool = true;
|
||||
|
||||
type SysExMessage = ();
|
||||
|
||||
type BackgroundTask = ();
|
||||
|
||||
fn params(&self) -> Arc<dyn Params> {
|
||||
self.params.clone()
|
||||
}
|
||||
|
||||
fn process(
|
||||
&mut self,
|
||||
buffer: &mut Buffer,
|
||||
_aux: &mut AuxiliaryBuffers,
|
||||
_context: &mut impl ProcessContext<Self>,
|
||||
) -> ProcessStatus {
|
||||
for channel_samples in buffer.iter_samples() {
|
||||
let gain = self.params.gain.smoothed.next();
|
||||
|
||||
for sample in channel_samples {
|
||||
*sample *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
ProcessStatus::Normal
|
||||
}
|
||||
|
||||
fn deactivate(&mut self) {}
|
||||
}
|
||||
|
||||
impl ClapPlugin for Gain {
|
||||
const CLAP_ID: &'static str = "fogwaves.learn_gain";
|
||||
|
||||
const CLAP_DESCRIPTION: Option<&'static str> = Some("A smoothed gain example.");
|
||||
|
||||
const CLAP_MANUAL_URL: Option<&'static str> = Some(Self::URL);
|
||||
|
||||
const CLAP_SUPPORT_URL: Option<&'static str> = None;
|
||||
|
||||
const CLAP_FEATURES: &'static [ClapFeature] = &[
|
||||
ClapFeature::AudioEffect,
|
||||
ClapFeature::Stereo,
|
||||
ClapFeature::Mono,
|
||||
ClapFeature::Utility,
|
||||
];
|
||||
}
|
||||
|
||||
impl Vst3Plugin for Gain {
|
||||
const VST3_CLASS_ID: [u8; 16] = *b"FogwavesGainPlug";
|
||||
|
||||
const VST3_SUBCATEGORIES: &'static [Vst3SubCategory] =
|
||||
&[Vst3SubCategory::Fx, Vst3SubCategory::Tools];
|
||||
}
|
||||
|
||||
nih_export_clap!(Gain);
|
||||
nih_export_vst3!(Gain);
|
Loading…
Add table
Add a link
Reference in a new issue