1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use crate::lex::command::{Key, NoteKind, ObjId};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Track(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ObjTime {
pub track: Track,
pub numerator: u32,
pub denominator: u32,
}
impl ObjTime {
pub fn new(track: u32, numerator: u32, denominator: u32) -> Self {
if track == 0 {
eprintln!("warning: track 000 detected");
}
assert!(0 < denominator);
assert!(numerator < denominator);
Self {
track: Track(track),
numerator,
denominator,
}
}
}
impl PartialOrd for ObjTime {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for ObjTime {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
let self_time_in_track = self.numerator * other.denominator;
let other_time_in_track = other.numerator * self.denominator;
self.track
.cmp(&other.track)
.then(self_time_in_track.cmp(&other_time_in_track))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Obj {
pub offset: ObjTime,
pub kind: NoteKind,
pub is_player1: bool,
pub key: Key,
pub obj: ObjId,
}
impl PartialOrd for Obj {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Obj {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.offset
.cmp(&other.offset)
.then(self.obj.cmp(&other.obj))
}
}