From 142fb307bd99ffd33e7cb909a1632adfa14ae470 Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Mon, 18 Nov 2024 11:03:58 +0100 Subject: [PATCH] rename current_tap -> tap_counter --- src/editor.rs | 36 ++++++++++++++++++------------------ src/lib.rs | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index be8f1df..769bd88 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -410,8 +410,8 @@ impl DelayGraph { Label::new( cx, params.map(move |params| { - let current_tap_value = params.current_tap.load(Ordering::SeqCst); - match current_tap_value { + let tap_counter = params.tap_counter.load(Ordering::SeqCst); + match tap_counter { // 0 => "tap a rhythm!".to_string(), 0 => String::new(), 1 => "1 tap".to_string(), @@ -430,21 +430,21 @@ impl DelayGraph { outline_width: f32, ) -> f32 { // Load atomic values once - let current_tap_value = params.current_tap.load(Ordering::SeqCst); + let tap_counter = params.tap_counter.load(Ordering::SeqCst); let current_time_value = params.current_time.load(Ordering::SeqCst); let max_tap_samples = params.max_tap_samples.load(Ordering::SeqCst); // Calculate max delay time if necessary - let max_delay_time = if current_tap_value > 0 { - params.delay_times[current_tap_value - 1].load(Ordering::SeqCst) + let max_delay_time = if tap_counter > 0 { + params.delay_times[tap_counter - 1].load(Ordering::SeqCst) } else { 0 }; - let zoom_tap_samples = if current_time_value == max_delay_time && current_tap_value == 1 { + let zoom_tap_samples = if current_time_value == max_delay_time && tap_counter == 1 { // one delay tap, put it in the middle max_delay_time as f32 - } else if current_tap_value == NUM_TAPS || current_time_value == max_delay_time { + } else if tap_counter == NUM_TAPS || current_time_value == max_delay_time { // time out, zoom in but leave a margin 0.16 * max_delay_time as f32 } else { @@ -536,9 +536,9 @@ impl DelayGraph { ) { let mut path = vg::Path::new(); - let current_tap_value = params.current_tap.load(Ordering::SeqCst); + let tap_counter = params.tap_counter.load(Ordering::SeqCst); - for i in 0..current_tap_value { + for i in 0..tap_counter { let delay_time_value = params.delay_times[i].load(Ordering::SeqCst) as f32; let x_offset = delay_time_value.mul_add(time_scaling_factor, border_width * 0.5); @@ -572,15 +572,15 @@ impl DelayGraph { border_width: f32, ) { // Load the values once - let current_tap = params.current_tap.load(Ordering::SeqCst); - if current_tap == NUM_TAPS { + let tap_counter = params.tap_counter.load(Ordering::SeqCst); + if tap_counter == NUM_TAPS { return; }; let current_time = params.current_time.load(Ordering::SeqCst); // Determine the max delay time - let max_delay_time = if current_tap > 0 { - params.delay_times[current_tap - 1].load(Ordering::SeqCst) + let max_delay_time = if tap_counter > 0 { + params.delay_times[tap_counter - 1].load(Ordering::SeqCst) } else { 0 }; @@ -614,9 +614,9 @@ impl DelayGraph { time_scaling_factor: f32, border_width: f32, ) { - let current_tap = params.current_tap.load(Ordering::SeqCst); + let tap_counter = params.tap_counter.load(Ordering::SeqCst); - for i in 0..current_tap { + for i in 0..tap_counter { let delay_time = params.delay_times[i].load(Ordering::SeqCst) as f32; let x_offset = delay_time.mul_add(time_scaling_factor, border_width * 0.5); @@ -699,7 +699,7 @@ impl DelayGraph { let mut pan_background_path = vg::Path::new(); let mut pan_foreground_path = vg::Path::new(); - let current_tap = params.current_tap.load(Ordering::SeqCst); + let tap_counter = params.tap_counter.load(Ordering::SeqCst); let first_note = params.first_note.load(Ordering::SeqCst); let first_panning_center_value = params.taps.panning_center.value(); @@ -715,7 +715,7 @@ impl DelayGraph { let mut max = first_note.max(panning_center); // Iterate through notes to find min and max - for i in 0..current_tap { + for i in 0..tap_counter { let loaded_note = params.notes[i].load(Ordering::SeqCst); if loaded_note < min { min = loaded_note; @@ -803,7 +803,7 @@ impl DelayGraph { note_path.close(); } - for i in 0..current_tap { + for i in 0..tap_counter { let delay_time = params.delay_times[i].load(Ordering::SeqCst) as f32; let x_offset = delay_time.mul_add(time_scaling_factor, border_width * 0.5); diff --git a/src/lib.rs b/src/lib.rs index cf149df..1b74df3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,8 +145,8 @@ pub struct Del2Params { pans: AtomicF32Array, #[persist = "notes"] notes: AtomicU8Array, - #[persist = "current-tap"] - current_tap: Arc, + #[persist = "tap-counter"] + tap_counter: Arc, current_time: Arc, max_tap_samples: Arc, #[persist = "first-note"] @@ -522,7 +522,7 @@ impl Del2Params { learned_notes: ArcAtomicByteArray(learned_notes), enabled_actions: ArcAtomicBoolArray(enabled_actions), - current_tap: Arc::new(AtomicUsize::new(0)), + tap_counter: Arc::new(AtomicUsize::new(0)), delay_times: AtomicU32Array(array_init::array_init(|_| Arc::new(AtomicU32::new(0)))), velocities: AtomicF32Array(array_init::array_init(|_| Arc::new(AtomicF32::new(0.0)))), pans: AtomicF32Array(array_init::array_init(|_| Arc::new(AtomicF32::new(0.0)))), @@ -636,7 +636,7 @@ impl Plugin for Del2 { } self.delay_taps.fill(None); - for tap_index in 0..self.params.current_tap.load(Ordering::SeqCst) { + for tap_index in 0..self.params.tap_counter.load(Ordering::SeqCst) { self.load_and_configure_tap(self.sample_rate, 0, tap_index); } @@ -670,7 +670,7 @@ impl Plugin for Del2 { self.write_into_delay(buffer); while block_start < num_samples { - let old_nr_taps = self.params.current_tap.load(Ordering::SeqCst); + let old_nr_taps = self.params.tap_counter.load(Ordering::SeqCst); // First of all, handle all note events that happen at the start of the block, and cut // the block short if another event happens before the end of it. @@ -687,9 +687,9 @@ impl Plugin for Del2 { .. } => { self.store_note_on_in_delay_data(timing, note, velocity); - if self.params.current_tap.load(Ordering::SeqCst) > old_nr_taps { + if self.params.tap_counter.load(Ordering::SeqCst) > old_nr_taps { let tap_index = - self.params.current_tap.load(Ordering::SeqCst) - 1; + self.params.tap_counter.load(Ordering::SeqCst) - 1; self.load_and_configure_tap( sample_rate, // timing, @@ -724,7 +724,7 @@ impl Plugin for Del2 { .compare_exchange(true, false, Ordering::SeqCst, Ordering::SeqCst) .is_ok() { - for tap in 0..self.params.current_tap.load(Ordering::SeqCst) { + for tap in 0..self.params.tap_counter.load(Ordering::SeqCst) { self.update_filter(tap); } } @@ -919,8 +919,8 @@ impl Del2 { fn store_note_on_in_delay_data(&mut self, timing: u32, note: u8, velocity: f32) { // Load values that are used multiple times at the start - let mut current_tap = self.params.current_tap.load(Ordering::SeqCst); - let is_tap_slot_available = current_tap < NUM_TAPS; + let mut tap_counter = self.params.tap_counter.load(Ordering::SeqCst); + let is_tap_slot_available = tap_counter < NUM_TAPS; let is_delay_note = !self.learned_notes.contains(note); let is_learning = self.is_learning.load(Ordering::SeqCst); let taps_unlocked = !self.enabled_actions.load(LOCK_TAPS); @@ -985,23 +985,23 @@ impl Del2 { && velocity > 0.0 { // Update tap information with timing and velocity - if current_tap > 0 { + if tap_counter > 0 { let previous_delay = - self.params.delay_times[current_tap - 1].load(Ordering::SeqCst); - self.params.delay_times[current_tap].store( + self.params.delay_times[tap_counter - 1].load(Ordering::SeqCst); + self.params.delay_times[tap_counter].store( self.samples_since_last_event + previous_delay, Ordering::SeqCst, ); } else { - self.params.delay_times[current_tap] + self.params.delay_times[tap_counter] .store(self.samples_since_last_event, Ordering::SeqCst); } - self.params.velocities[current_tap].store(velocity, Ordering::SeqCst); - self.params.notes[current_tap].store(note, Ordering::SeqCst); + self.params.velocities[tap_counter].store(velocity, Ordering::SeqCst); + self.params.notes[tap_counter].store(note, Ordering::SeqCst); - current_tap += 1; - self.params.current_tap.store(current_tap, Ordering::SeqCst); - if current_tap == NUM_TAPS { + tap_counter += 1; + self.params.tap_counter.store(tap_counter, Ordering::SeqCst); + if tap_counter == NUM_TAPS { self.counting_state = CountingState::TimeOut; self.timing_last_event = 0; self.samples_since_last_event = 0; @@ -1055,7 +1055,7 @@ impl Del2 { fn clear_taps(&mut self, timing: u32, restart: bool) { self.enabled_actions.store(LOCK_TAPS, false); - self.params.current_tap.store(0, Ordering::SeqCst); + self.params.tap_counter.store(0, Ordering::SeqCst); self.params .previous_time_scaling_factor @@ -1092,12 +1092,12 @@ impl Del2 { self.no_more_events(buffer_samples as u32); // Cache the current tap value to reduce atomic loads - let current_tap = self.params.current_tap.load(Ordering::SeqCst); + let tap_counter = self.params.tap_counter.load(Ordering::SeqCst); let samples_since_last_event = self.samples_since_last_event; // Cache to a local variable // Calculate the current time based on whether there are taps - let current_time = if current_tap > 0 { - let last_delay_time = self.params.delay_times[current_tap - 1].load(Ordering::SeqCst); + let current_time = if tap_counter > 0 { + let last_delay_time = self.params.delay_times[tap_counter - 1].load(Ordering::SeqCst); last_delay_time + samples_since_last_event } else { samples_since_last_event @@ -1128,7 +1128,7 @@ impl Del2 { self.timing_last_event = 0; self.samples_since_last_event = 0; - if self.params.current_tap.load(Ordering::SeqCst) == 0 { + if self.params.tap_counter.load(Ordering::SeqCst) == 0 { self.params .first_note .store(NO_LEARNED_NOTE, Ordering::SeqCst);