Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Nov 20, 2024
1 parent 39b2092 commit 5209b71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
44 changes: 18 additions & 26 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
}
}),
)
Expand Down Expand Up @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down

0 comments on commit 5209b71

Please sign in to comment.