summaryrefslogtreecommitdiff
path: root/morphology-img/src/pitch.rs
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-14 18:22:21 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-14 18:22:21 +0100
commit6aeb5a91c42446b5ea68ec81dd01079a74787c96 (patch)
tree4de217802fc9701ca1a0dbb08685972885264ee8 /morphology-img/src/pitch.rs
parent30e48fe5083db3f83d68c830fb43c6a7a955a99c (diff)
feature: add morphology rendering module
Diffstat (limited to 'morphology-img/src/pitch.rs')
-rw-r--r--morphology-img/src/pitch.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/morphology-img/src/pitch.rs b/morphology-img/src/pitch.rs
new file mode 100644
index 0000000..dd7d87e
--- /dev/null
+++ b/morphology-img/src/pitch.rs
@@ -0,0 +1,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()
+ }
+}