From ef181668f01b208a19875f42338ab34ed1df7064 Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Fri, 13 Dec 2024 19:29:48 +0100 Subject: [PATCH] panning center -> panning offset --- src/editor.rs | 33 ++++++++++++++------------------- src/lib.rs | 34 ++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index d0618d3..6d33192 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -262,8 +262,8 @@ fn full_parameters(cx: &mut Context) { HStack::new(cx, |cx| { HStack::new(cx, |cx| { - Label::new(cx, "center").class("slider-label"); - ParamSlider::new(cx, Data::params, |params| ¶ms.taps.panning_center) + Label::new(cx, "offset").class("slider-label"); + ParamSlider::new(cx, Data::params, |params| ¶ms.taps.panning_offset) .class("widget"); }) .class("row"); @@ -1063,29 +1063,22 @@ impl DelayGraph { font_color: vg::Color, border_color: vg::Color, ) { - let first_note = params.first_note.load(Ordering::SeqCst); + let first = f32::from(params.first_note.load(Ordering::SeqCst)); let mut center_path = vg::Path::new(); let tap_counter = params.tap_counter.load(Ordering::SeqCst); - let panning_center_value = params.taps.panning_center.value(); + let panning_center = (first + params.taps.panning_offset.value() * 127.0).clamp(0.0, 127.0); let panning_amount = params.taps.panning_amount.value(); - let panning_center = if panning_center_value < 0 { - first_note - } else { - panning_center_value as u8 - }; - let (min_note_value, max_note_value) = { // Initialize min and max with first_note and panning_center - let mut min = first_note.min(panning_center) as u16; - let mut max = first_note.max(panning_center) as u16; - let first = first_note as u16; + let mut min = first.min(panning_center); + let mut max = first.max(panning_center); // Iterate through notes to find min and max for i in 0..tap_counter { - let loaded_note = params.notes[i].load(Ordering::SeqCst) as u16; + let loaded_note = params.notes[i].load(Ordering::SeqCst) as f32; if loaded_note < min { min = loaded_note; } else if loaded_note > max { @@ -1093,11 +1086,11 @@ impl DelayGraph { } } - const ZOOM_NOTES: u16 = 12; - const HALF_ZOOM_NOTES: u16 = (ZOOM_NOTES as f32 * 0.5) as u16; + const ZOOM_NOTES: f32 = 12.0; + const HALF_ZOOM_NOTES: f32 = ZOOM_NOTES * 0.5; let final_min = (first - HALF_ZOOM_NOTES).max(max - ZOOM_NOTES).min(min); let final_max = (first + HALF_ZOOM_NOTES).min(min + ZOOM_NOTES).max(max); - (f32::from(final_min), f32::from(final_max)) + (final_min, final_max) }; let smoothed_min_note_value = Self::gui_smooth( min_note_value, @@ -1142,10 +1135,12 @@ impl DelayGraph { let panning_center_y = bounds.y + panning_center_height; // Draw half a note for the first note at time 0 + + let first = f32::from(params.first_note.load(Ordering::SeqCst)); let normalized_first_note = if range_diff < 0.5 { 0.5 // Put it in the center } else { - 1.0 - ((f32::from(first_note) - min_note_value) / range_diff) + 1.0 - ((first - min_note_value) / range_diff) }; let first_note_height = Self::gui_smooth( @@ -1298,7 +1293,7 @@ impl DelayGraph { canvas.draw_path(¬e_path, &paint); } - if (panning_center_y - first_note_y).abs() > 3.0 { + if (panning_center_y - first_note_y).abs() > 1.0 { let panning_center_x = bounds.x + border_width; center_path.move_to((panning_center_x, panning_center_y + note_half_size)); center_path.line_to((panning_center_x + note_half_size, panning_center_y)); diff --git a/src/lib.rs b/src/lib.rs index 3395683..272e9f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -326,8 +326,8 @@ impl GlobalParams { /// Contains the high and low tap parameters. #[derive(Params)] pub struct TapsParams { - #[id = "panning_center"] - pub panning_center: IntParam, + #[id = "panning_offset"] + pub panning_offset: FloatParam, #[id = "panning_amount"] pub panning_amount: FloatParam, #[id = "note_to_cutoff_amount"] @@ -344,15 +344,22 @@ pub struct TapsParams { impl TapsParams { pub fn new(should_update_filter: Arc) -> Self { Self { - panning_center: IntParam::new( - "panning center", - -1, - IntRange::Linear { min: -1, max: 127 }, + panning_offset: FloatParam::new( + "panning offset", + 0.0, + FloatRange::SymmetricalSkewed { + min: -1.0, + max: 1.0, + factor: FloatRange::skew_factor(-1.8), + center: 0.0, + }, ) - .with_value_to_string(Del2::v2s_i32_note()) - .with_string_to_value(Del2::s2v_i32_note()), + .with_unit(" %") + .with_value_to_string(formatters::v2s_f32_percentage(0)) + .with_string_to_value(formatters::s2v_f32_percentage()), + panning_amount: FloatParam::new( - "panning_amount", + "panning amount", 0.0, FloatRange::SymmetricalSkewed { min: -1.0, @@ -791,11 +798,10 @@ impl Plugin for Del2 { // Write the audio buffer into the delay self.write_into_delay(buffer); - let panning_center = if self.params.taps.panning_center.value() < 0 { - f32::from(self.params.first_note.load(Ordering::SeqCst)) - } else { - self.params.taps.panning_center.value() as f32 - }; + let panning_center = (f32::from(self.params.first_note.load(Ordering::SeqCst)) + + self.params.taps.panning_offset.value() as f32 * 127.0) + .clamp(0.0, 127.0); + let panning_amount = self.params.taps.panning_amount.value(); while block_start < num_samples {