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
use std::fmt::Display;

use notation_core::prelude::EntryPassMode;
use serde::{Deserialize, Serialize};

use crate::prelude::{Duration, Entry};

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct LyricWord {
    pub text: String,
}
impl Display for LyricWord {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.text)
    }
}
impl From<String> for LyricWord {
    fn from(v: String) -> Self {
        LyricWord { text: v }
    }
}

impl From<&str> for LyricWord {
    fn from(v: &str) -> Self {
        LyricWord::from(String::from(v))
    }
}

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub enum LyricEntry {
    Word(LyricWord, Duration),
}
impl Display for LyricEntry {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            LyricEntry::Word(word, duration) => write!(f, "Word({}, {})", word, duration),
        }
    }
}
impl LyricEntry {
    pub fn duration(&self) -> Duration {
        match self {
            Self::Word(_, duration) => *duration,
        }
    }
    pub fn pass_mode(&self) -> EntryPassMode {
        EntryPassMode::Delayed
    }
}

impl Entry for LyricEntry {
    fn duration(&self) -> Duration {
        self.duration()
    }
    fn pass_mode(&self) -> EntryPassMode {
        self.pass_mode()
    }
}

impl From<(LyricWord, Duration)> for LyricEntry {
    fn from(v: (LyricWord, Duration)) -> Self {
        LyricEntry::Word(v.0, v.1)
    }
}

impl From<(String, Duration)> for LyricEntry {
    fn from(v: (String, Duration)) -> Self {
        LyricEntry::Word(LyricWord::from(v.0), v.1)
    }
}

impl From<(&str, Duration)> for LyricEntry {
    fn from(v: (&str, Duration)) -> Self {
        LyricEntry::Word(LyricWord::from(v.0), v.1)
    }
}