Skip to content

Commit

Permalink
Merge pull request #37 from ardura/FM_Update
Browse files Browse the repository at this point in the history
Fm update
  • Loading branch information
ardura authored Apr 26, 2024
2 parents 3e83638 + fa68c12 commit 6242f4f
Show file tree
Hide file tree
Showing 11 changed files with 2,250 additions and 409 deletions.
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Actuate"
version = "1.2.5"
version = "1.2.6"
edition = "2021"
authors = ["Ardura <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down Expand Up @@ -33,8 +33,12 @@ lazy_static = "1.4.0"
#nih_plug_egui = { git = "https://github.com/ardura/nih-plug.git", rev = "4d28fb251422bdabfc65641beedb490bdf35c297" }

# My branch - new 2024
nih_plug = { git = "https://github.com/ardura/nih-plug.git", rev = "96d413756faa145dc063fc9ca609d86bc7d2e3e7", features = ["assert_process_allocs"] }
nih_plug_egui = { git = "https://github.com/ardura/nih-plug.git", rev = "96d413756faa145dc063fc9ca609d86bc7d2e3e7" }
#nih_plug = { git = "https://github.com/ardura/nih-plug.git", rev = "96d413756faa145dc063fc9ca609d86bc7d2e3e7", features = ["assert_process_allocs"] }
#nih_plug_egui = { git = "https://github.com/ardura/nih-plug.git", rev = "96d413756faa145dc063fc9ca609d86bc7d2e3e7" }

# Nih plug update
nih_plug = { git = "https://github.com/ardura/nih-plug.git", rev = "fed302db1fcfb374f9af90bb872be0edd3ee0568", features = ["assert_process_allocs"] }
nih_plug_egui = { git = "https://github.com/ardura/nih-plug.git", rev = "fed302db1fcfb374f9af90bb872be0edd3ee0568" }

# Local
#nih_plug = { path = "../../nih-plug", features = ["assert_process_allocs"] }
Expand Down
10 changes: 5 additions & 5 deletions src/CustomWidgets/BeizerButton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'a, P: Param> SliderRegion<'a, P> {
}
},
Rounding::from(4.0),
if self.background_color == Color32::TEMPORARY_COLOR {
if self.background_color == Color32::PLACEHOLDER {
visuals.bg_fill.linear_multiply(0.8)
} else {
self.background_color
Expand All @@ -216,7 +216,7 @@ impl<'a, P: Param> SliderRegion<'a, P> {
ui.painter().rect(
rect,
Rounding::from(4.0),
if self.background_color == Color32::TEMPORARY_COLOR {
if self.background_color == Color32::PLACEHOLDER {
visuals.bg_fill.linear_multiply(0.8)
} else {
self.background_color.linear_multiply(0.8)
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<'a, P: Param> SliderRegion<'a, P> {
Color32::TRANSPARENT,
Stroke::new(
3.0,
if self.line_color == Color32::TEMPORARY_COLOR {
if self.line_color == Color32::PLACEHOLDER {
visuals.fg_stroke.color
} else {
self.line_color
Expand Down Expand Up @@ -312,8 +312,8 @@ impl<'a, P: Param> BeizerButton<'a, P> {
slider_region: SliderRegion::new(
param,
param_setter,
Color32::TEMPORARY_COLOR,
Color32::TEMPORARY_COLOR,
Color32::PLACEHOLDER,
Color32::PLACEHOLDER,
button_layout,
),
scaling_x: x_scaling,
Expand Down
8 changes: 4 additions & 4 deletions src/CustomWidgets/BoolButton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a, P: Param> SliderRegion<'a, P> {
ui.painter().rect(
rect,
0.5,
if self.background_color == Color32::TEMPORARY_COLOR {
if self.background_color == Color32::PLACEHOLDER {
visuals.bg_fill.linear_multiply(0.8)
} else {
self.background_color
Expand All @@ -94,7 +94,7 @@ impl<'a, P: Param> SliderRegion<'a, P> {
Align2::CENTER_CENTER,
self.param.name(),
self.font.clone(),
if self.text_color == Color32::TEMPORARY_COLOR {
if self.text_color == Color32::PLACEHOLDER {
visuals.text_color()
} else {
self.text_color
Expand Down Expand Up @@ -130,8 +130,8 @@ impl<'a, P: Param> BoolButton<'a, P> {
param,
param_setter,
font,
Color32::TEMPORARY_COLOR,
Color32::TEMPORARY_COLOR,
Color32::PLACEHOLDER,
Color32::PLACEHOLDER,
),
scaling_x: x_scaling,
scaling_y: y_scaling,
Expand Down
20 changes: 11 additions & 9 deletions src/CustomWidgets/CustomParamSlider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Needed to make some weird import changes to get this to work...Definitely should find a better way to do this in future...
// Ardura
use std::sync::Arc;

use crate::egui::{vec2, Response, Sense, Stroke, TextStyle, Ui, Vec2, Widget, WidgetText};
use nih_plug::{
prelude::{Param, ParamSetter},
wrapper::clap::lazy_static,
};
use nih_plug_egui::egui::{self, Color32};
use nih_plug_egui::egui::{self, vec2, Color32, Response, Sense, Stroke, TextStyle, Ui, Vec2, Widget, WidgetText};
use nih_plug_egui::widgets::util as nUtil;
use parking_lot::Mutex;

Expand Down Expand Up @@ -67,8 +65,8 @@ impl<'a, P: Param> ParamSlider<'a, P> {
slider_width: None,
// Added in reversed function to have bar drawn other way
reversed: false,
background_set_color: Color32::TEMPORARY_COLOR,
bar_set_color: Color32::TEMPORARY_COLOR,
background_set_color: Color32::PLACEHOLDER,
bar_set_color: Color32::PLACEHOLDER,
left_sided_label: false,
label_width: 50.0,

Expand Down Expand Up @@ -294,13 +292,13 @@ impl<'a, P: Param> ParamSlider<'a, P> {
// Added to reverse filling - Ardura
if self.reversed {
let filled_bg = if response.dragged() {
if self.bar_set_color == Color32::TEMPORARY_COLOR {
if self.bar_set_color == Color32::PLACEHOLDER {
nUtil::add_hsv(ui.visuals().selection.bg_fill, 0.0, -0.1, 0.1)
} else {
nUtil::add_hsv(self.bar_set_color, 0.0, -0.1, 0.1)
}
} else {
if self.bar_set_color == Color32::TEMPORARY_COLOR {
if self.bar_set_color == Color32::PLACEHOLDER {
ui.visuals().selection.bg_fill
} else {
self.bar_set_color
Expand All @@ -317,7 +315,7 @@ impl<'a, P: Param> ParamSlider<'a, P> {
}
}

if self.background_set_color == Color32::TEMPORARY_COLOR {
if self.background_set_color == Color32::PLACEHOLDER {
ui.painter().rect_stroke(
response.rect,
0.0,
Expand Down Expand Up @@ -412,7 +410,11 @@ impl<'a, P: Param> ParamSlider<'a, P> {
.layout()
.align_size_within_rect(text.size(), response.rect.shrink2(padding))
.min;
text.paint_with_visuals(ui.painter(), text_pos, &visuals);
ui.painter().add(egui::epaint::TextShape::new(
text_pos,
text,
visuals.fg_stroke.color,
));
}
//}
}
Expand Down
23 changes: 13 additions & 10 deletions src/CustomWidgets/CustomVerticalSlider.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copy of CustomParamSlider from Canopy Reverb modified further into verticality
// Needed to make some weird import changes to get this to work...Definitely should find a better way to do this in future...
// Ardura
use crate::egui::{vec2, Response, Sense, Stroke, TextStyle, Ui, Vec2, Widget, WidgetText};
use nih_plug::{
prelude::{Param, ParamSetter},
wrapper::clap::lazy_static,
};
use nih_plug_egui::egui;
use nih_plug_egui::egui::{self, vec2, Color32, Response, Sense, Stroke, TextStyle, Ui, Vec2, Widget, WidgetText};
use nih_plug_egui::{
egui::{Color32, Pos2, Rect},
egui::{Pos2, Rect},
widgets::util as nUtil,
};
use parking_lot::Mutex;
Expand Down Expand Up @@ -65,8 +64,8 @@ impl<'a, P: Param> ParamSlider<'a, P> {
slider_height: None,
// Added in reversed function to have bar drawn other way
reversed: false,
background_set_color: Color32::TEMPORARY_COLOR,
bar_set_color: Color32::TEMPORARY_COLOR,
background_set_color: Color32::PLACEHOLDER,
bar_set_color: Color32::PLACEHOLDER,
use_padding: false,

// I removed this because it was causing errors on plugin load somehow in FL
Expand Down Expand Up @@ -258,7 +257,7 @@ impl<'a, P: Param> ParamSlider<'a, P> {
if ui.is_rect_visible(response.rect) {
// Also flipped these orders for vertical
if self.reversed {
if self.background_set_color == Color32::TEMPORARY_COLOR {
if self.background_set_color == Color32::PLACEHOLDER {
// We'll do a flat widget with background -> filled foreground -> slight border
ui.painter().rect_filled(
response.rect,
Expand Down Expand Up @@ -301,13 +300,13 @@ impl<'a, P: Param> ParamSlider<'a, P> {
// Vertical has this flipped to make sense vs the horizontal bar
if self.reversed {
let filled_bg = if response.dragged() {
if self.bar_set_color == Color32::TEMPORARY_COLOR {
if self.bar_set_color == Color32::PLACEHOLDER {
nUtil::add_hsv(ui.visuals().selection.bg_fill, 0.0, -0.1, 0.1)
} else {
nUtil::add_hsv(self.bar_set_color, 0.0, -0.1, 0.1)
}
} else {
if self.bar_set_color == Color32::TEMPORARY_COLOR {
if self.bar_set_color == Color32::PLACEHOLDER {
ui.visuals().selection.bg_fill
} else {
self.bar_set_color
Expand All @@ -324,7 +323,7 @@ impl<'a, P: Param> ParamSlider<'a, P> {
}
}

if self.background_set_color == Color32::TEMPORARY_COLOR {
if self.background_set_color == Color32::PLACEHOLDER {
ui.painter().rect_stroke(
response.rect,
4.0,
Expand Down Expand Up @@ -410,7 +409,11 @@ impl<'a, P: Param> ParamSlider<'a, P> {
.layout()
.align_size_within_rect(text.size(), response.rect.shrink2(padding))
.min;
text.paint_with_visuals(ui.painter(), text_pos, &visuals);
ui.painter().add(egui::epaint::TextShape::new(
text_pos,
text,
visuals.fg_stroke.color,
));
}
//}
}
Expand Down
11 changes: 4 additions & 7 deletions src/CustomWidgets/ui_knob.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Ardura 2023 - ui_knob.rs - egui + nih-plug parameter widget with customization
// Ardura 2024 update - ui_knob.rs - egui + nih-plug parameter widget with customization
// this ui_knob.rs is built off a2aaron's knob base as part of nyasynth and Robbert's ParamSlider code
// https://github.com/a2aaron/nyasynth/blob/canon/src/ui_knob.rs

// This is the older style of ui_knob code for older nih_plug + egui with some updates added in
// If you want the latest, egui version for nih-plug check Interleaf's version!
// https://github.com/ardura/Interleaf/blob/main/src/ui_knob.rs

use std::{
f32::consts::TAU,
ops::{Add, Mul, Sub},
Expand Down Expand Up @@ -158,6 +154,7 @@ impl<'a, P: Param> SliderRegion<'a, P> {
}
if response.drag_released() {
self.param_setter.end_set_parameter(self.param);
Self::set_drag_amount_memory(ui, 0.0);
}
self.normalized_value()
}
Expand Down Expand Up @@ -232,7 +229,7 @@ impl<'a, P: Param> ArcKnob<'a, P> {
padding: 10.0,
show_label: true,
swap_label_and_value: true,
text_color_override: Color32::TEMPORARY_COLOR,
text_color_override: Color32::PLACEHOLDER,
readable_box: false,
layout: layout,
arc_start: match layout {
Expand Down Expand Up @@ -834,7 +831,7 @@ impl<'a, P: Param> Widget for ArcKnob<'a, P> {

let text_color: Color32;
// Setting text color
if self.text_color_override != Color32::TEMPORARY_COLOR {
if self.text_color_override != Color32::PLACEHOLDER {
text_color = self.text_color_override;
} else {
text_color = self.line_color;
Expand Down
1 change: 1 addition & 0 deletions src/audio_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use std::{collections::VecDeque, f32::consts::SQRT_2, path::PathBuf, sync::Arc};

// Audio module files
pub(crate) mod Oscillator;
pub(crate) mod frequency_modulation;
use self::Oscillator::{DeterministicWhiteNoiseGenerator, OscState, RetriggerStyle, SmoothStyle};
#[allow(unused_imports)]
use crate::{
Expand Down
27 changes: 27 additions & 0 deletions src/audio_module/frequency_modulation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::f32::consts::{PI};

pub fn frequency_modulation(modulating_sample: f32, carrier_sample: f32, modulation_index: f32) -> f32 {
if modulation_index == 0.0 {
return carrier_sample;
}
let phase_change = modulation_index * modulating_sample;
let modulated_signal = (2.0 * PI * carrier_sample + phase_change).cos();

let compensation_factor = 1.0 / (modulation_index*0.5 + 2.0);
let compensated_signal = modulated_signal * compensation_factor;

compensated_signal
}

pub fn double_modulation(modulating_sample: f32, carrier_sample: f32, modulation_index: f32) -> f32 {
let first_fm_sample = frequency_modulation(modulating_sample, carrier_sample, modulation_index);
let second_fm_sample = frequency_modulation(first_fm_sample, carrier_sample, modulation_index);
second_fm_sample
}

pub fn triple_modulation(modulating_sample: f32, carrier_sample: f32, modulation_index: f32) -> f32 {
let first_fm_sample = frequency_modulation(modulating_sample, carrier_sample, modulation_index);
let second_fm_sample = frequency_modulation(first_fm_sample, carrier_sample, modulation_index);
let third_fm_sample = frequency_modulation(second_fm_sample, carrier_sample, modulation_index);
third_fm_sample
}
36 changes: 36 additions & 0 deletions src/fx/abass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@

use nih_plug::util;

// My updated 2024 Algorithm used in Subhoofer
pub fn a_bass_saturation(signal: f32, harmonic_strength: f32) -> f32 {
let mut output = custom_sincos_saturation(
signal,
harmonic_strength * 31.422043,
harmonic_strength * 189.29568,
harmonic_strength * 25.0,
harmonic_strength * 26.197401
);
let h_l = (output * 2.0) - output.powf(2.0);
output += h_l * 0.0070118904;

// I used -9.0 here instead of Subhoofer's value because Actuate signal often runs hotter/louder
chebyshev_tape(output, 0.0093) * util::db_to_gain(-9.0)
}

fn custom_sincos_saturation(signal: f32, harmonic_strength1: f32, harmonic_strength2: f32, harmonic_strength3: f32, harmonic_strength4: f32) -> f32 {
let mut summed: f32 = 0.0;

let harmonic_component: f32 = harmonic_strength1 * (signal * 1.0).cos() - signal;
summed += harmonic_component;

let harmonic_component: f32 = harmonic_strength2 * (signal * 2.0).sin() - signal;
summed += harmonic_component;

let harmonic_component: f32 = harmonic_strength3 * (signal * 3.0).cos() - signal;
summed += harmonic_component;

let harmonic_component2: f32 = harmonic_strength4 * (signal * 4.0).sin() - signal;
summed += harmonic_component2;

summed
}

/* Older Subhoofer Algorithm
// Subhoofer's default harmonic_strength was 0.0011 and hardness 0.04
pub fn a_bass_saturation(signal: f32, harmonic_strength: f32) -> f32 {
let num_harmonics: usize = 4;
Expand Down Expand Up @@ -38,6 +73,7 @@ pub fn a_bass_saturation(signal: f32, harmonic_strength: f32) -> f32 {
0.0
}
}
*/

// Modified function from Duro Console for different behavior - hoof hardness
fn chebyshev_tape(sample: f32, drive: f32) -> f32 {
Expand Down
Loading

0 comments on commit 6242f4f

Please sign in to comment.