multi-plugin structure
This commit is contained in:
parent
fb3ba5d291
commit
ac98cbe6c7
9 changed files with 64 additions and 25 deletions
1
plugins/dfpworm/.gitignore
vendored
Normal file
1
plugins/dfpworm/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
12
plugins/dfpworm/Cargo.toml
Normal file
12
plugins/dfpworm/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "dfpworm"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
atomic_float = "1.1"
|
||||
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", version = "0.0.0", features = ["assert_process_allocs"] }
|
||||
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git", version = "0.0.0" }
|
14
plugins/dfpworm/src/lib.rs
Normal file
14
plugins/dfpworm/src/lib.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
1
plugins/gain/.gitignore
vendored
Normal file
1
plugins/gain/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
12
plugins/gain/Cargo.toml
Normal file
12
plugins/gain/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "gain"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
atomic_float = "1.1"
|
||||
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", version = "0.0.0", features = ["assert_process_allocs"] }
|
||||
nih_plug_vizia = { git = "https://github.com/robbert-vdh/nih-plug.git", version = "0.0.0" }
|
65
plugins/gain/src/editor.rs
Normal file
65
plugins/gain/src/editor.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use atomic_float::AtomicF32;
|
||||
use nih_plug::{editor::Editor, util};
|
||||
use nih_plug_vizia::{
|
||||
ViziaState, ViziaTheming, assets, create_vizia_editor,
|
||||
vizia::prelude::*,
|
||||
widgets::{ParamSlider, PeakMeter, ResizeHandle},
|
||||
};
|
||||
use std::sync::{Arc, atomic::Ordering};
|
||||
|
||||
use crate::GainParams;
|
||||
|
||||
#[derive(Lens)]
|
||||
struct Data {
|
||||
params: Arc<GainParams>,
|
||||
peak_meter: Arc<AtomicF32>,
|
||||
}
|
||||
|
||||
impl Model for Data {}
|
||||
|
||||
pub(crate) fn default_state() -> Arc<ViziaState> {
|
||||
ViziaState::new(|| (200, 150))
|
||||
}
|
||||
|
||||
pub(crate) fn create(
|
||||
params: Arc<GainParams>,
|
||||
peak_meter: Arc<AtomicF32>,
|
||||
editor_state: Arc<ViziaState>,
|
||||
) -> Option<Box<dyn Editor>> {
|
||||
create_vizia_editor(editor_state, ViziaTheming::Custom, move |cx, _| {
|
||||
assets::register_noto_sans_light(cx);
|
||||
assets::register_noto_sans_thin(cx);
|
||||
|
||||
Data {
|
||||
params: params.clone(),
|
||||
peak_meter: peak_meter.clone(),
|
||||
}
|
||||
.build(cx);
|
||||
|
||||
VStack::new(cx, |cx| {
|
||||
Label::new(cx, "Gain GUI")
|
||||
.font_family(vec![FamilyOwned::Name(String::from(assets::NOTO_SANS))])
|
||||
.font_weight(FontWeightKeyword::Thin)
|
||||
.font_size(30.0)
|
||||
.height(Pixels(50.0))
|
||||
.child_top(Stretch(1.0))
|
||||
.child_bottom(Pixels(0.0));
|
||||
|
||||
Label::new(cx, "Gain");
|
||||
ParamSlider::new(cx, Data::params, |params| ¶ms.gain);
|
||||
|
||||
PeakMeter::new(
|
||||
cx,
|
||||
Data::peak_meter
|
||||
.map(|peak_meter| util::gain_to_db(peak_meter.load(Ordering::Relaxed))),
|
||||
Some(Duration::from_millis(600)),
|
||||
)
|
||||
.top(Pixels(10.0));
|
||||
})
|
||||
.row_between(Pixels(0.0))
|
||||
.child_left(Stretch(1.0))
|
||||
.child_right(Stretch(1.0));
|
||||
|
||||
ResizeHandle::new(cx);
|
||||
})
|
||||
}
|
178
plugins/gain/src/lib.rs
Normal file
178
plugins/gain/src/lib.rs
Normal file
|
@ -0,0 +1,178 @@
|
|||
use atomic_float::AtomicF32;
|
||||
use nih_plug::prelude::*;
|
||||
use nih_plug_vizia::ViziaState;
|
||||
use std::sync::{Arc, atomic::Ordering};
|
||||
|
||||
mod editor;
|
||||
|
||||
const PEAK_METER_DECAY_MS: f64 = 150.0;
|
||||
|
||||
pub struct Gain {
|
||||
params: Arc<GainParams>,
|
||||
|
||||
// gotta normalize peak meters response based on sample rate :)
|
||||
peak_meter_decay_weight: f32,
|
||||
// current peak meter value, stored in Arc to share between GUI and processing
|
||||
peak_meter: Arc<AtomicF32>,
|
||||
}
|
||||
|
||||
#[derive(Params)]
|
||||
struct GainParams {
|
||||
#[persist = "editor-state"]
|
||||
editor_state: Arc<ViziaState>,
|
||||
|
||||
#[id = "gain"]
|
||||
pub gain: FloatParam,
|
||||
}
|
||||
|
||||
impl Default for Gain {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(GainParams::default()),
|
||||
|
||||
peak_meter_decay_weight: 1.0,
|
||||
peak_meter: Arc::new(AtomicF32::new(util::MINUS_INFINITY_DB)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GainParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
editor_state: editor::default_state(),
|
||||
|
||||
gain: FloatParam::new(
|
||||
"Gain",
|
||||
util::db_to_gain(0.0),
|
||||
FloatRange::Skewed {
|
||||
min: -30.0,
|
||||
max: 30.0,
|
||||
factor: FloatRange::gain_skew_factor(-30.0, 30.0),
|
||||
},
|
||||
)
|
||||
.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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
..AudioIOLayout::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 editor(&mut self, _async_executor: AsyncExecutor<Self>) -> Option<Box<dyn Editor>> {
|
||||
editor::create(
|
||||
self.params.clone(),
|
||||
self.peak_meter.clone(),
|
||||
self.params.editor_state.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
fn initialize(
|
||||
&mut self,
|
||||
_audio_io_layout: &AudioIOLayout,
|
||||
buffer_config: &BufferConfig,
|
||||
_context: &mut impl InitContext<Self>,
|
||||
) -> bool {
|
||||
self.peak_meter_decay_weight = 0.25f64
|
||||
.powf((buffer_config.sample_rate as f64 * PEAK_METER_DECAY_MS / 1000.0).recip())
|
||||
as f32;
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn process(
|
||||
&mut self,
|
||||
buffer: &mut Buffer,
|
||||
_aux: &mut AuxiliaryBuffers,
|
||||
_context: &mut impl ProcessContext<Self>,
|
||||
) -> ProcessStatus {
|
||||
for channel_samples in buffer.iter_samples() {
|
||||
let mut amplitude = 0.0;
|
||||
let num_samples = channel_samples.len();
|
||||
|
||||
let gain = self.params.gain.smoothed.next();
|
||||
for sample in channel_samples {
|
||||
*sample *= gain;
|
||||
amplitude += *sample;
|
||||
}
|
||||
|
||||
// save resources by only doing GUI calculations when GUI is open
|
||||
if self.params.editor_state.is_open() {
|
||||
amplitude = (amplitude / num_samples as f32).abs();
|
||||
let current_peak_meter = self.peak_meter.load(Ordering::Relaxed);
|
||||
let new_peak_meter = if amplitude > current_peak_meter {
|
||||
amplitude
|
||||
} else {
|
||||
current_peak_meter * self.peak_meter_decay_weight
|
||||
+ amplitude * (1.0 - self.peak_meter_decay_weight)
|
||||
};
|
||||
|
||||
self.peak_meter.store(new_peak_meter, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
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