Skip to content

Commit

Permalink
smooth the pan gui
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Nov 16, 2024
1 parent ed01245 commit 83c58e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
29 changes: 19 additions & 10 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ impl DelayGraph {
}

/// Smoothly updates the value stored within an AtomicF32 based on a target value.
/// If the current value is zero, it initializes with the target value.
/// If the current value is f32::MIN, it initializes with the target value.
fn gui_smooth(target_value: f32, atomic_value: &AtomicF32) -> f32 {
// Check if current value is zero and initialize if necessary
if atomic_value.load(Ordering::SeqCst) == 0.0 {
// Check if current value is f32::MIN and initialize if necessary
if atomic_value.load(Ordering::SeqCst) == f32::MIN {
atomic_value.store(target_value, Ordering::SeqCst);
}

Expand Down Expand Up @@ -835,12 +835,21 @@ impl DelayGraph {
let pan_value = params.pans[i].load(std::sync::atomic::Ordering::SeqCst);
let line_length = 50.0;
if pan_value.abs() > 1.0 / line_length {
let pan_foreground_length = pan_value * line_length;
let pan_background_length = if pan_value < 0.0 {
let target_pan_foreground_length = pan_value * line_length;
let target_pan_background_length = if pan_value < 0.0 {
-line_length
} else {
line_length
};

let pan_foreground_length = Self::gui_smooth(
target_pan_foreground_length,
&params.previous_pan_foreground_lengths[i],
);
let pan_background_length = Self::gui_smooth(
target_pan_background_length,
&params.previous_pan_background_lengths[i],
);
pan_path.move_to(diamond_center_x, diamond_center_y);
pan_path.line_to(
(diamond_center_x + pan_background_length)
Expand All @@ -863,11 +872,6 @@ impl DelayGraph {
&vg::Paint::color(border_color).with_line_width(line_width),
);

canvas.stroke_path(
&pan_amount_path,
&vg::Paint::color(font_color).with_line_width(line_width),
);

// Draw the diamond for panning center before the first note
canvas.stroke_path(
&center_path,
Expand All @@ -879,6 +883,11 @@ impl DelayGraph {
&vg::Paint::color(color).with_line_width(line_width),
);

canvas.stroke_path(
&pan_amount_path,
&vg::Paint::color(font_color).with_line_width(line_width),
);

// FIXME:
// cover up, probably needed due to https://github.com/vizia/vizia/issues/401
if first_note != NO_LEARNED_NOTE {
Expand Down
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ pub struct Del2Params {
previous_note_heights: AtomicF32Array,
previous_first_note_height: Arc<AtomicF32>,
previous_panning_center_height: Arc<AtomicF32>,
previous_pan_foreground_lengths: AtomicF32Array,
previous_pan_background_lengths: AtomicF32Array,

/// A voice's gain. This can be polyphonically modulated.
#[id = "gain"]
Expand Down Expand Up @@ -537,6 +539,12 @@ impl Del2Params {
})),
previous_first_note_height: Arc::new(AtomicF32::new(0.0)),
previous_panning_center_height: Arc::new(AtomicF32::new(0.0)),
previous_pan_foreground_lengths: AtomicF32Array(array_init::array_init(|_| {
Arc::new(AtomicF32::new(0.0))
})),
previous_pan_background_lengths: AtomicF32Array(array_init::array_init(|_| {
Arc::new(AtomicF32::new(0.0))
})),

gain: FloatParam::new(
"Gain",
Expand Down Expand Up @@ -1252,15 +1260,17 @@ impl Del2 {

self.params
.previous_time_scaling_factor
.store(0.0, Ordering::SeqCst);
.store(f32::MIN, Ordering::SeqCst);
self.params
.previous_first_note_height
.store(0.0, Ordering::SeqCst);
.store(f32::MIN, Ordering::SeqCst);
self.params
.previous_panning_center_height
.store(0.0, Ordering::SeqCst);
.store(f32::MIN, Ordering::SeqCst);
for i in 0..NUM_TAPS {
self.params.previous_note_heights[i].store(0.0, Ordering::SeqCst);
self.params.previous_note_heights[i].store(f32::MIN, Ordering::SeqCst);
self.params.previous_pan_foreground_lengths[i].store(f32::MIN, Ordering::SeqCst);
self.params.previous_pan_background_lengths[i].store(f32::MIN, Ordering::SeqCst);
}

self.start_release_for_all_delay_taps(self.sample_rate);
Expand Down

0 comments on commit 83c58e7

Please sign in to comment.