Skip to content

Commit

Permalink
make const NO_GUI_SMOOTHING
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Nov 22, 2024
1 parent edb7e2a commit c51d89a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use nih_plug_vizia::{
use crate::{
format_time, util, AtomicBoolArray, AtomicByteArray, AtomicF32, AtomicF32Array,
AtomicUsizeArray, Del2Params, LastPlayedNotes, CLEAR_TAPS, LEARNING, LOCK_TAPS, MUTE_IN,
MUTE_OUT, NO_LEARNED_NOTE, NUM_TAPS,
MUTE_OUT, NO_GUI_SMOOTHING, NO_LEARNED_NOTE, NUM_TAPS,
};

#[allow(unused_imports)]
Expand Down Expand Up @@ -586,7 +586,7 @@ impl DelayGraph {
}

/// Smoothly updates the value stored within an `f32` based on a target value.
/// If the current value is `f32::MAX`, it initializes with the target value.
/// If the current value is `NO_GUI_SMOOTHING`, it initializes with the target value.
fn gui_smooth(target_value: f32, atomic_value: &AtomicF32, gui_decay_weight: f32) -> f32 {
// Define the threshold relative to the target value
let threshold = 0.001 * target_value.abs();
Expand All @@ -600,7 +600,7 @@ impl DelayGraph {
}

// Check if initial condition is met and initialize with the target value if so
if current_value >= f32::MAX - 1.0 {
if current_value >= NO_GUI_SMOOTHING - 1.0 {
atomic_value.store(target_value, Ordering::SeqCst);
return target_value;
}
Expand Down
23 changes: 14 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const MUTE_OUT: usize = 1;
const CLEAR_TAPS: usize = 2;
const LOCK_TAPS: usize = 3;
const MAX_HAAS_MS: f32 = 5.0;
const NO_GUI_SMOOTHING: f32 = f32::MAX;

struct Del2 {
params: Arc<Del2Params>,
Expand Down Expand Up @@ -650,9 +651,11 @@ impl Plugin for Del2 {

// don't smooth the gui for the new taps
for i in (self.params.old_nr_taps.load(Ordering::SeqCst) + 1)..tap_counter {
self.params.previous_note_heights[i].store(f32::MAX, Ordering::SeqCst);
self.params.previous_pan_foreground_lengths[i].store(f32::MAX, Ordering::SeqCst);
self.params.previous_pan_background_lengths[i].store(f32::MAX, Ordering::SeqCst);
self.params.previous_note_heights[i].store(NO_GUI_SMOOTHING, Ordering::SeqCst);
self.params.previous_pan_foreground_lengths[i]
.store(NO_GUI_SMOOTHING, Ordering::SeqCst);
self.params.previous_pan_background_lengths[i]
.store(NO_GUI_SMOOTHING, Ordering::SeqCst);
}
}

Expand Down Expand Up @@ -1058,17 +1061,19 @@ impl Del2 {

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

self.start_release_for_all_delay_taps();
Expand Down

0 comments on commit c51d89a

Please sign in to comment.