Skip to content

Commit

Permalink
add octave and transpose
Browse files Browse the repository at this point in the history
magnetophon committed Dec 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3c9688a commit 7edd300
Showing 2 changed files with 89 additions and 47 deletions.
60 changes: 40 additions & 20 deletions src/editor.rs
Original file line number Diff line number Diff line change
@@ -293,11 +293,9 @@ fn full_parameters(cx: &mut Context) {
.class("row");
HStack::new(cx, |cx| {
Label::new(cx, "cutoff mode").class("slider-label");
ParamSlider::new(cx, Data::params, |params| {
&params.taps.cutoff_modulation_type
})
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true })
.class("widget");
ParamSlider::new(cx, Data::params, |params| &params.taps.use_note_frequency)
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true })
.class("widget");
})
.class("row");
})
@@ -316,16 +314,40 @@ fn filter_parameters(cx: &mut Context) {
})
.class("column-title-group");
HStack::new(cx, |cx| {
HStack::new(cx, |cx| {
Label::new(cx, "cutoff").class("slider-label");
ParamSlider::new(cx, Data::params, |params| &params.taps.cutoff_main).class("widget");
})
.class("row");
HStack::new(cx, |cx| {
Label::new(cx, "velocity").class("slider-label");
ParamSlider::new(cx, Data::params, |params| &params.taps.cutoff_mod).class("widget");
})
.class("row");
Binding::new(
cx,
Data::params.map(|params| params.taps.use_note_frequency.value()), // Map to get the bool value
|cx, _modulation_type| {
let params = Data::params.get(cx);
if params.taps.use_note_frequency.value() {
HStack::new(cx, |cx| {
Label::new(cx, "octave").class("slider-label");
ParamSlider::new(cx, Data::params, |params| &params.taps.cutoff_octave)
.class("widget");
})
.class("row");
HStack::new(cx, |cx| {
Label::new(cx, "transpose").class("slider-label");
ParamSlider::new(cx, Data::params, |params| &params.taps.cutoff_transpose)
.class("widget");
})
.class("row");
} else {
HStack::new(cx, |cx| {
Label::new(cx, "cutoff").class("slider-label");
ParamSlider::new(cx, Data::params, |params| &params.taps.cutoff_main)
.class("widget");
})
.class("row");
HStack::new(cx, |cx| {
Label::new(cx, "velocity").class("slider-label");
ParamSlider::new(cx, Data::params, |params| &params.taps.cutoff_mod)
.class("widget");
})
.class("row");
}
},
);
})
.class("param-group");

@@ -471,11 +493,9 @@ fn minimal_parameters(cx: &mut Context) {

HStack::new(cx, |cx| {
Label::new(cx, "cutoff mode").class("slider-label");
ParamSlider::new(cx, Data::params, |params| {
&params.taps.cutoff_modulation_type
})
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true })
.class("widget");
ParamSlider::new(cx, Data::params, |params| &params.taps.use_note_frequency)
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true })
.class("widget");
})
.class("row");
})
76 changes: 49 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -300,8 +300,8 @@ pub struct TapsParams {
pub panning_amount: FloatParam,
#[id = "filter_type"]
pub filter_type: EnumParam<MyLadderMode>,
#[id = "cutoff_modulation_type"]
cutoff_modulation_type: EnumParam<CutoffModulation>,
#[id = "use_note_frequency"]
use_note_frequency: BoolParam,

#[id = "cutoff"]
pub cutoff_main: FloatParam,
@@ -316,6 +316,12 @@ pub struct TapsParams {
pub res_mod: FloatParam,
#[id = "drive mod"]
pub drive_mod: FloatParam,

// for note modulation
#[id = "cutoff_octave"]
pub cutoff_octave: IntParam,
#[id = "cutoff_transpose"]
pub cutoff_transpose: IntParam,
}

impl TapsParams {
@@ -348,21 +354,26 @@ impl TapsParams {
.with_unit(" %")
.with_value_to_string(formatters::v2s_f32_percentage(0))
.with_string_to_value(formatters::s2v_f32_percentage()),
filter_type: EnumParam::new(format!("filter type"), MyLadderMode::lp6()) // Use the passed default value
filter_type: EnumParam::new(format!("filter type"), MyLadderMode::lp6()).with_callback(
Arc::new({
let should_update_filter = should_update_filter.clone();
move |_| should_update_filter.store(true, Ordering::Release)
}),
),

use_note_frequency: BoolParam::new(format!("cutoff mode"), false)
.with_callback(Arc::new({
let should_update_filter = should_update_filter.clone();
move |_| should_update_filter.store(true, Ordering::Release)
}))
.with_value_to_string(Arc::new(|value| {
String::from(if value { "note" } else { "velocity" })
}))
.with_callback(Arc::new({
let should_update_filter = should_update_filter.clone();
move |_| should_update_filter.store(true, Ordering::Release)
})),

cutoff_modulation_type: EnumParam::new(
format!("cutoff mode"),
CutoffModulation::velocity,
) // Use the passed default value
.with_callback(Arc::new({
let should_update_filter = should_update_filter.clone();
move |_| should_update_filter.store(true, Ordering::Release)
})),

cutoff_main: FloatParam::new(
format!("cutoff"),
3_003.0,
@@ -442,6 +453,22 @@ impl TapsParams {
},
)
.with_unit(" dB"),

cutoff_octave: IntParam::new("cutoff octave", 0, IntRange::Linear { min: -4, max: 4 })
.with_callback(Arc::new({
let should_update_filter = should_update_filter.clone();
move |_| should_update_filter.store(true, Ordering::Release)
})),

cutoff_transpose: IntParam::new(
"cutoff transpose",
0,
IntRange::Linear { min: -12, max: 12 },
)
.with_callback(Arc::new({
let should_update_filter = should_update_filter.clone();
move |_| should_update_filter.store(true, Ordering::Release)
})),
}
}
}
@@ -1319,12 +1346,14 @@ impl Del2 {
fn update_filters(&mut self) {
// Extract params once to avoid repeated access
let taps_params = &self.params.taps;
let cutoff_modulation_type = &taps_params.cutoff_modulation_type.value();
let use_note_frequency = &taps_params.use_note_frequency.value();
// let taps_params = &taps_params.velocity_high;

// Pre-compute static values for the iteration
let cutoff_main = taps_params.cutoff_main.value();
let cutoff_mod = taps_params.cutoff_mod.value();
let cutoff_octave = taps_params.cutoff_octave.value();
let cutoff_transpose = taps_params.cutoff_transpose.value();
let res_main = taps_params.res_main.value();
let res_mod = taps_params.res_mod.value();
let filter_type = &self.params.taps.filter_type.value();
@@ -1345,12 +1374,14 @@ impl Del2 {
// cutoff_mod is in octaves, 8.0 octaves gives most of the range.
let velocity_cutoff =
Self::modulate_log(cutoff_main, cutoff_mod * 8.0 * velocity_factor);
let note_cutoff = util::midi_note_to_freq(delay_tap.note);
let note_cutoff = util::f32_midi_note_to_freq(
delay_tap.note as f32 + (cutoff_octave * 12) as f32 + cutoff_transpose as f32,
);

// Fused multiply-add operation
let cutoff = match cutoff_modulation_type {
CutoffModulation::velocity => velocity_cutoff,
CutoffModulation::note => note_cutoff,
let cutoff = if *use_note_frequency {
note_cutoff
} else {
velocity_cutoff
}
.clamp(10.0, 18_000.0);

@@ -1784,15 +1815,6 @@ impl Vst3Plugin for Del2 {
];
}

// the name is used as a parmater value,
// and the others are all lowercase
#[allow(non_camel_case_types)]
#[derive(PartialEq, Enum)]
enum CutoffModulation {
velocity,
note,
}

#[derive(PartialEq, Debug, Clone, Copy)]
pub struct MyLadderMode(LadderMode);

0 comments on commit 7edd300

Please sign in to comment.