euphony_core/time/
beat.rs1use crate::time::{measure::Measure, time_signature::TimeSignature};
2use core::ops::Mul;
3
4new_ratio!(Beat, u64);
5
6impl Beat {
7 pub const EIGHTH: Beat = Beat(1, 8);
8 pub const EIGHTH_TRIPLET: Beat = Beat(1, 3);
10 pub const HALF: Beat = Beat(1, 2);
11 pub const QUARTER: Beat = Beat(1, 4);
12 pub const QUARTER_TRIPLET: Beat = Beat(1, 3);
14 pub const SIXTEENTH: Beat = Beat(1, 16);
15 pub const SIXTY_FOURTH: Beat = Beat(1, 64);
16 pub const THIRTY_SECOND: Beat = Beat(1, 32);
17 pub const WHOLE: Beat = Beat(1, 1);
18}
19
20impl Mul<TimeSignature> for Beat {
21 type Output = Beat;
22
23 fn mul(self, time_signature: TimeSignature) -> Self::Output {
24 (self / time_signature.beat()).into()
25 }
26}
27
28impl core::ops::Div<TimeSignature> for Beat {
29 type Output = Measure;
30
31 fn div(self, time_signature: TimeSignature) -> Self::Output {
32 let beat_count = self / time_signature.beat();
33 (beat_count / time_signature.count()).into()
34 }
35}
36
37#[test]
38fn div_time_signature_test() {
39 assert_eq!(Beat(1, 4) / TimeSignature(4, 4), Measure(1, 4));
40 assert_eq!(Beat(2, 4) / TimeSignature(4, 4), Measure(1, 4) * 2);
41 assert_eq!(Beat(1, 4) / TimeSignature(6, 8), Measure(1, 3));
42 assert_eq!(Beat(5, 4) / TimeSignature(4, 4), Measure(5, 4));
43}