initial project setup

This commit is contained in:
Haze Weathers 2025-09-16 11:49:55 -06:00
commit 963c797594
8 changed files with 4309 additions and 0 deletions

2
.cargo/config Normal file
View file

@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --release --"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

4106
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

16
Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "learner_plug"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib", "lib"]
[dependencies]
atomic_float = "1.1.0"
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" }
parking_lot = "0.12.4"
[workspace]
members = ["xtask"]

173
src/lib.rs Normal file
View 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);

1
xtask/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

7
xtask/Cargo.toml Normal file
View file

@ -0,0 +1,7 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2024"
[dependencies]
nih_plug_xtask = { git = "https://github.com/robbert-vdh/nih-plug.git", version = "0.1.0" }

3
xtask/src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() -> nih_plug_xtask::Result<()> {
nih_plug_xtask::main()
}