Add metronome

This commit is contained in:
Skyler Lehmkuhl
2026-03-19 01:16:26 -04:00
parent 84a1a98452
commit c938ea44b0
4 changed files with 84 additions and 21 deletions
+8 -16
View File
@@ -90,8 +90,9 @@ impl Metronome {
self.last_beat = -1; // Reset beat tracking when disabled
self.click_position = 0; // Stop any playing click
} else {
// When enabling, don't trigger a click until the next beat
self.click_position = usize::MAX; // Set to max to prevent immediate click
// Reset beat tracking so the next beat boundary (including beat 0) fires a click
self.last_beat = -1;
self.click_position = self.high_click.len(); // Idle (past end, nothing playing)
}
}
@@ -130,20 +131,11 @@ impl Metronome {
if current_beat != self.last_beat && current_beat >= 0 {
self.last_beat = current_beat;
// Only trigger a click if we're not in the "just enabled" state
if self.click_position != usize::MAX {
// Determine which click to play
// Beat 1 of each measure gets the accent (high click)
let beat_in_measure = (current_beat as u32 % self.time_signature_numerator) as usize;
let is_first_beat = beat_in_measure == 0;
// Start playing the appropriate click
self.playing_high_click = is_first_beat;
self.click_position = 0; // Start from beginning of click
} else {
// We just got enabled - reset position but don't play yet
self.click_position = self.high_click.len(); // Set past end so no click plays
}
// Determine which click to play.
// Beat 0 of each measure gets the accent (high click).
let beat_in_measure = (current_beat as u32 % self.time_signature_numerator) as usize;
self.playing_high_click = beat_in_measure == 0;
self.click_position = 0; // Start from beginning of click
}
// Continue playing click sample if we're currently in one