Skip to content

Commit 713bedc

Browse files
Simpler Math, we don't need to iter at all.
1 parent 07a11e7 commit 713bedc

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

daemon/src/device.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use goxlr_ipc::{
1616
Display, FaderStatus, GoXLRCommand, HardwareStatus, Levels, MicSettings, MixerStatus,
1717
SampleProcessState, Settings,
1818
};
19-
use goxlr_profile_loader::components::echo::EchoStyle;
2019
use goxlr_profile_loader::components::mute::MuteFunction;
2120
use goxlr_types::{
2221
Button, ChannelName, DeviceType, DisplayModeComponents, EffectBankPresets, EffectKey,
@@ -796,16 +795,12 @@ impl<'a> Device<'a> {
796795
return Ok(());
797796
}
798797

799-
let total: Duration = self
800-
.tap_tempo
801-
.iter()
802-
.zip(self.tap_tempo.iter().skip(1))
803-
.map(|(a, b)| b.duration_since(*a))
804-
.sum();
798+
// We know these both exist, so the unwrap is safe
799+
let first = self.tap_tempo.front().unwrap();
800+
let last = self.tap_tempo.back().unwrap();
805801

806-
let total_ms = total.as_millis() as f64;
807-
let avg_ms = total_ms / (self.tap_tempo.len() - 1) as f64;
808-
let bpm = (60_000.0 / avg_ms).clamp(45., 300.) as u16;
802+
let avg_ms = (*last - *first) / ((self.tap_tempo.len() - 1) as u32);
803+
let bpm = (60_000.0 / avg_ms.as_millis() as f64).clamp(45., 300.) as u16;
809804

810805
debug!("BPM Calculated at: {}", bpm);
811806

0 commit comments

Comments
 (0)