summaryrefslogtreecommitdiff
path: root/morphology-img/src/pitch.rs
blob: dd7d87ea2bbe2a8f885c58abab99c9b6c6ebe07c (plain)
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
/// Represents a LilyPond absolute pitch name (e.g., "c'", "bes,", "fis")
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LilyPondPitch(String);

impl LilyPondPitch {
    pub fn new(s: impl Into<String>) -> Self {
        Self(s.into())
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }
}

/// Represents a complete LilyPond note with duration (e.g., "c'4")
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LilyPondNote(String);

impl LilyPondNote {
    pub fn new(pitch: LilyPondPitch, duration: Duration) -> Self {
        Self(format!("{}{}", pitch.as_str(), duration.as_str()))
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }
}

/// Represents a note duration in LilyPond (e.g., "4", "8", "2")
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Duration(u8);

impl Duration {
    pub const QUARTER: Duration = Duration(4);

    pub fn new(value: u8) -> Self {
        Self(value)
    }

    pub fn as_str(&self) -> String {
        self.0.to_string()
    }
}