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
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use crate::prelude::ProtoEntry;
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub enum TrackKind {
Unsupported,
Meta,
Chord,
Lyrics,
Vocal,
Guitar,
Synth,
Piano,
Drums,
Bass,
}
impl Display for TrackKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
impl TrackKind {
pub fn from_ident(ident: &str) -> Self {
match ident {
"Meta" => Self::Meta,
"Chord" => Self::Chord,
"Lyrics" => Self::Lyrics,
"Vocal" => Self::Vocal,
"Guitar" => Self::Guitar,
"Synth" => Self::Synth,
"Piano" => Self::Piano,
"Drums" => Self::Drums,
"Bass" => Self::Bass,
_ => {
println!("TrackKind::from_ident() Unsupported ident: {}", ident);
Self::Unsupported
}
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Track {
pub id: String,
pub kind: TrackKind,
pub entries: Vec<ProtoEntry>,
}
impl Track {
pub fn new(id: String, kind: TrackKind, entries: Vec<ProtoEntry>) -> Self {
Self { kind, id, entries }
}
}
impl Display for Track {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"<Track>({} <{}> E:{})",
self.id,
self.kind,
self.entries.len()
)
}
}