Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
chore: linting + formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarLiner committed Sep 2, 2024
1 parent bc10077 commit 2ccc492
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 36 deletions.
32 changes: 18 additions & 14 deletions src/dsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ use nih_plug::prelude::{AtomicF32, Enum};
use nih_plug_vizia::vizia::prelude::Data;
use num_traits::{Float, ToPrimitive};
use numeric_literals::replace_float_literals;
use valib::{dsp::blocks::{Series, SwitchAB}, math::{smooth_max, smooth_min}};
use valib::dsp::buffer::{AudioBufferMut, AudioBufferRef};
use valib::dsp::parameter::{HasParameters, ParamId, ParamName, RemoteControlled, SmoothedParam};
use valib::dsp::{blocks::Bypass, BlockAdapter, DSPMeta, DSPProcess, DSPProcessBlock};
use valib::filters::statespace::StateSpace;
use valib::math::smooth_clamp;
use valib::oversample::{Oversample, Oversampled};
use valib::saturators::{bjt, Saturator};
use valib::simd::{
AutoF64x2, AutoSimd, SimdBool, SimdComplexField, SimdPartialOrd, SimdValue,
};
use valib::simd::{SimdComplexField, SimdValue};
use valib::Scalar;
use valib::{
dsp::blocks::{Series, SwitchAB},
math::{smooth_max, smooth_min},
};

use clipping::ClippingStage;

Expand Down Expand Up @@ -56,14 +57,18 @@ impl<T: Scalar> Default for OutputEmitterFollower<T> {

impl<T: Scalar> Saturator<T> for OutputEmitterFollower<T> {
fn saturate(&self, x: T) -> T {
smooth_max(self.t, T::zero(), smooth_min(self.t, x + self.xbias, (x + self.kbias) * self.ksat))
smooth_max(
self.t,
T::zero(),
smooth_min(self.t, x + self.xbias, (x + self.kbias) * self.ksat),
)
}
}

#[derive(Debug, Copy, Clone, PartialEq, Enum, Data)]
pub enum InputLevelMatching {
Instrument,
#[name="Instrument (Hot)"]
#[name = "Instrument (Hot)"]
InstrumentHot,
Line,
Eurorack,
Expand Down Expand Up @@ -173,7 +178,12 @@ impl<T: Scalar> DSPProcess<1, 1> for ToneStage<T> {
let tone = self.tone.next_sample_as();
self.update_state_matrices(self.dt, tone);
let [y] = self.state_space.process(x);
[smooth_clamp(T::from_f64(0.1), y, T::zero(), T::from_f64(9.))]
[smooth_clamp(
T::from_f64(0.1),
y,
T::zero(),
T::from_f64(9.),
)]
}
}

Expand Down Expand Up @@ -340,13 +350,7 @@ where
));
let inner = DspInner::new(samplerate, Bypass::default(), inner, true);
let inner = oversample.with_dsp(base_samplerate, BlockAdapter(inner));
RemoteControlled::new(
base_samplerate,
1e3,
Dsp {
inner,
},
)
RemoteControlled::new(base_samplerate, 1e3, Dsp { inner })
}

pub fn get_led_display(&self) -> Arc<AtomicF32> {
Expand Down
12 changes: 5 additions & 7 deletions src/dsp/clipping.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use crate::params::MAX_AGE;
use crate::{util::Rms, TARGET_SAMPLERATE};
use nih_plug::prelude::AtomicF32;
use nih_plug::util::db_to_gain_fast;
use num_traits::{Float, ToPrimitive};
use std::sync::{atomic::Ordering, Arc};
use numeric_literals::replace_float_literals;
use valib::math::{smooth_clamp, smooth_max, smooth_min};
use std::sync::{atomic::Ordering, Arc};
use valib::math::smooth_clamp;
use valib::saturators::clippers::DiodeClipper;
use valib::saturators::{Saturator, Slew};
use valib::simd::{SimdComplexField, SimdValue};
use valib::util::lerp;
use valib::wdf::dsl::*;
use valib::{
dsp::{DSPMeta, DSPProcess},
Expand Down Expand Up @@ -40,7 +38,7 @@ impl<T: Scalar> CrossoverDistortion<T> {

#[replace_float_literals(T::from_f64(literal))]
fn drift_from_age(age: T) -> T {
2.96e-3 * age.simd_powf(1./3.)
2.96e-3 * age.simd_powf(1. / 3.)
}
}

Expand Down Expand Up @@ -240,8 +238,7 @@ impl<T: Scalar<Element: Float>> ClippingStage<T> {

pub fn set_age(&mut self, age: T) {
self.crossover.set_age(age);
self.out_slew.max_diff =
component_matching_slew_rate(self.samplerate, age);
self.out_slew.max_diff = component_matching_slew_rate(self.samplerate, age);
}

pub fn set_dist(&mut self, amt: T) {
Expand Down Expand Up @@ -307,6 +304,7 @@ mod tests {
use super::*;
use valib::dsp::buffer::{AudioBufferMut, AudioBufferRef};
use valib::dsp::{BlockAdapter, DSPProcessBlock};
use valib::util::lerp;

#[test]
fn crossover_dc_sweep() {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/components/knob.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::f32::consts::{FRAC_PI_2, TAU};

use nih_plug::{nih_error, nih_log, prelude::Param};
use nih_plug_vizia::vizia::vg::{ImageFlags, ImageId};
use nih_plug_vizia::{
vizia::{prelude::*, vg},
widgets::param_base::ParamWidgetBase,
};
use nih_plug_vizia::vizia::vg::{ImageFlags, ImageId};

enum KnobEvents {
SetValueNormalized(f32),
Expand Down
2 changes: 1 addition & 1 deletion src/editor/components/led.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::sync::Arc;

use nih_plug::prelude::AtomicF32;
use nih_plug_vizia::vizia::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub(super) mod knob;
pub(super) mod led;
pub(super) mod led;
9 changes: 5 additions & 4 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;
use std::sync::atomic::Ordering;
use components::led::Led;
use nih_plug::prelude::*;
use nih_plug_vizia::vizia::prelude::*;
use nih_plug_vizia::vizia::views::{Knob, VStack};
use nih_plug_vizia::widgets::param_base::ParamWidgetBase;
use nih_plug_vizia::{create_vizia_editor, ViziaState, ViziaTheming};
use std::sync::atomic::Ordering;
use std::sync::Arc;

use crate::params::Ts404Params;

Expand Down Expand Up @@ -49,7 +49,8 @@ pub(crate) fn create(
})
.class("small");
Binding::new(cx, AppData::drive_led, |cx, drive| {
let display = drive.map(|x| format!("LED brightness: {}", x.load(Ordering::Relaxed)));
let display =
drive.map(|x| format!("LED brightness: {}", x.load(Ordering::Relaxed)));
Label::new(cx, display);
});
})
Expand Down Expand Up @@ -128,7 +129,7 @@ fn labelled_node_enum<E: 'static + PartialEq + ToString + Data + Enum>(
let name = param.map(|param| param.value().to_string());
let num_values = E::variants().len();
EnumData {
names: E::variants().into_iter().map(|s| s.to_string()).collect(),
names: E::variants().iter().map(|s| s.to_string()).collect(),
}
.build(cx);

Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::mpsc::{channel, Sender};
use std::sync::Arc;

use nih_plug::prelude::*;
use valib::contrib::nih_plug::{process_buffer_simd64, BindToParameter};
use valib::contrib::nih_plug::process_buffer_simd64;
use valib::dsp::parameter::RemoteControlled;
use valib::dsp::DSPMeta;
use valib::simd::{AutoF32x2, AutoF64x2};
Expand Down Expand Up @@ -100,8 +99,10 @@ impl Plugin for Ts404 {
self.dsp.inner.set_led_display(&drive_led);

let dsp = &self.dsp;
dsp.proxy
.set_parameter(DspParams::InputMode, self.params.input_mode.value().to_index() as _);
dsp.proxy.set_parameter(
DspParams::InputMode,
self.params.input_mode.value().to_index() as _,
);
dsp.proxy
.set_parameter(DspParams::Distortion, self.params.dist.value());
dsp.proxy
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ use ts404::Ts404;
fn main() {
profiling::register_thread!("Main thread");
nih_export_standalone::<Ts404>();
}
}
4 changes: 1 addition & 3 deletions src/params.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::dsp::{DspParams, InputLevelMatching};
use nih_plug::formatters;
use nih_plug::params::{BoolParam, EnumParam, FloatParam, Params};
use nih_plug::prelude::{AtomicF32, FloatRange};
use nih_plug::util::{gain_to_db, MINUS_INFINITY_DB, MINUS_INFINITY_GAIN};
use nih_plug::prelude::FloatRange;
use nih_plug_vizia::ViziaState;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::Arc;
use valib::contrib::nih_plug::BindToParameter;
use valib::dsp::parameter::RemoteControl;
Expand Down

0 comments on commit 2ccc492

Please sign in to comment.