euphony_units/time/
timecode.rs1use crate::time::{
2 beat::Beat, measure::Measure, tempo::Tempo, time_signature::TimeSignature, timestamp::Timestamp,
3};
4use core::cmp::Ordering;
5
6#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
7pub struct Timecode {
8 pub(crate) timestamp: Timestamp,
9 pub(crate) tempo: Tempo,
10 pub(crate) time_signature: TimeSignature,
11 pub(crate) measure: Measure,
12 pub(crate) beat: Beat,
13}
14
15impl Timecode {
16 pub fn timestamp(&self) -> Timestamp {
17 self.timestamp
18 }
19
20 pub fn tempo(&self) -> Tempo {
21 self.tempo
22 }
23
24 pub fn time_signature(&self) -> TimeSignature {
25 self.time_signature
26 }
27
28 pub fn measure(&self) -> Measure {
29 self.measure
30 }
31
32 pub fn beat(&self) -> Beat {
33 self.beat
34 }
35}
36
37macro_rules! compare {
38 ($ty:ident, $field:ident) => {
39 impl PartialEq<$ty> for Timecode {
40 fn eq(&self, other: &$ty) -> bool {
41 self.$field.eq(other)
42 }
43 }
44
45 impl PartialOrd<$ty> for Timecode {
46 fn partial_cmp(&self, other: &$ty) -> Option<Ordering> {
47 self.$field.partial_cmp(other)
48 }
49 }
50 };
51}
52
53compare!(Timestamp, timestamp);
54compare!(Tempo, tempo);
55compare!(TimeSignature, time_signature);
56compare!(Measure, measure);
57compare!(Beat, beat);