From 5209b71b22217ed663d9d19672b8f768a0d6d283 Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Wed, 20 Nov 2024 09:57:56 +0100 Subject: [PATCH] clippy fix --- src/editor.rs | 44 ++++++++++++++++++-------------------------- src/lib.rs | 10 +++++----- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 4e18506..06e7bc4 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -444,7 +444,7 @@ impl DelayGraph { if tempo >= 0.0 && time_sig_numerator > 0 { // Only proceed if tempo and time signature are valid (non-negative) - let seconds_per_beat = 60.0 / tempo as f32; + let seconds_per_beat = 60.0 / tempo; let seconds_per_measure = seconds_per_beat * time_sig_numerator as f32; let full_bars = (seconds / seconds_per_measure).floor() as i32; @@ -453,33 +453,30 @@ impl DelayGraph { (remaining_seconds / seconds_per_beat).round() as i32; if full_bars > 1 { - format!("{} bars", full_bars) + format!("{full_bars} bars") } else if full_bars > 0 { - format!("{} bar", full_bars) + format!("{full_bars} bar") } else if additional_beats > 1 { - format!("{} beats", additional_beats) + format!("{additional_beats} beats") } else if additional_beats > 0 { - format!("{} beat", additional_beats) + format!("{additional_beats} beat") } else { return String::new(); } - } else { - if seconds < 0.001 { - String::new() - } else if seconds < 1.0 { - // Calculate the number of digits after the decimal to maintain a total of three digits - let ms = seconds * 1000.0; - let digits_after_decimal = (TOTAL_DIGITS - - ms.trunc().to_string().len()) + } else if seconds < 0.001 { + String::new() + } else if seconds < 1.0 { + // Calculate the number of digits after the decimal to maintain a total of three digits + let ms = seconds * 1000.0; + let digits_after_decimal = (TOTAL_DIGITS - ms.trunc().to_string().len()) .max(0) .min(TOTAL_DIGITS - 1); // Ensure it's between 0 and 2 - format!("{ms:.digits_after_decimal$} ms") - } else { - // Same logic for seconds - let digits_after_decimal = - (TOTAL_DIGITS - seconds.trunc().to_string().len()).max(0); - format!("{seconds:.digits_after_decimal$} s") - } + format!("{ms:.digits_after_decimal$} ms") + } else { + // Same logic for seconds + let digits_after_decimal = + (TOTAL_DIGITS - seconds.trunc().to_string().len()).max(0); + format!("{seconds:.digits_after_decimal$} s") } }), ) @@ -1155,12 +1152,7 @@ impl ActionTrigger { .as_nanos() as u64; // Calculate the learning time duration - let learning_duration_nanos = if now_nanos < learning_start_time_nanos { - // Time went backwards - 0 - } else { - now_nanos - learning_start_time_nanos - }; + let learning_duration_nanos = now_nanos.saturating_sub(learning_start_time_nanos); if learning_duration_nanos > MAX_LEARNING_NANOS { self.stop_learning(); } diff --git a/src/lib.rs b/src/lib.rs index 01325ce..fccc085 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -623,7 +623,7 @@ impl Plugin for Del2 { } fn reset(&mut self) { - for delay_tap in self.delay_taps.iter_mut() { + for delay_tap in &mut self.delay_taps { delay_tap.ladders.s = [f32x4::splat(0.); 4]; } @@ -1196,7 +1196,7 @@ impl Del2 { } fn initialize_filter_parameters(&mut self) { - for delay_tap in self.delay_taps.iter_mut() { + for delay_tap in &mut self.delay_taps { let filter_params = unsafe { Arc::get_mut_unchecked(&mut delay_tap.filter_params) }; filter_params.set_sample_rate(self.params.sample_rate.load(Ordering::SeqCst)); } @@ -1346,7 +1346,7 @@ impl Del2 { let mut found_oldest = None; let mut oldest_id = u64::MAX; - for delay_tap in self.delay_taps.iter_mut() { + for delay_tap in &mut self.delay_taps { if delay_tap.is_alive { // Recycle an old tap if `delay_time` and `note` match if delay_tap.delay_time == delay_time && delay_tap.note == note { @@ -1392,7 +1392,7 @@ impl Del2 { /// Start the release process for all delay taps by changing their amplitude envelope. fn start_release_for_all_delay_taps(&mut self) { - for delay_tap in self.delay_taps.iter_mut() { + for delay_tap in &mut self.delay_taps { delay_tap.releasing = true; delay_tap.amp_envelope.style = SmoothingStyle::Linear(self.params.global.release_ms.value()); @@ -1406,7 +1406,7 @@ impl Del2 { fn set_mute_for_all_delay_taps(&mut self) { let is_playing_mute_out = self.is_playing_action(MUTE_OUT); - for delay_tap in self.delay_taps.iter_mut() { + for delay_tap in &mut self.delay_taps { let is_toggle = self.params.global.mute_is_toggle.value(); let mute_in_delayed = delay_tap.mute_in_delayed[0]; let mute_out = self.enabled_actions.load(MUTE_OUT);