diff options
| author | jacksonfu14 <jackson@fashionunited.com> | 2025-11-14 18:22:21 +0100 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2025-11-14 18:22:21 +0100 |
| commit | 6aeb5a91c42446b5ea68ec81dd01079a74787c96 (patch) | |
| tree | 4de217802fc9701ca1a0dbb08685972885264ee8 /morphology-img/src | |
| parent | 30e48fe5083db3f83d68c830fb43c6a7a955a99c (diff) | |
feature: add morphology rendering module
Diffstat (limited to 'morphology-img/src')
| -rw-r--r-- | morphology-img/src/error.rs | 19 | ||||
| -rw-r--r-- | morphology-img/src/file_gen.rs | 1 | ||||
| -rw-r--r-- | morphology-img/src/lib.rs | 9 | ||||
| -rw-r--r-- | morphology-img/src/pitch.rs | 43 | ||||
| -rw-r--r-- | morphology-img/src/render.rs | 1 | ||||
| -rw-r--r-- | morphology-img/src/template.rs | 1 |
6 files changed, 74 insertions, 0 deletions
diff --git a/morphology-img/src/error.rs b/morphology-img/src/error.rs new file mode 100644 index 0000000..cee092d --- /dev/null +++ b/morphology-img/src/error.rs @@ -0,0 +1,19 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum RenderError { + #[error("LilyPond not found: {0}")] + LilyPondNotFound(String), + + #[error("LilyPond execution failed: {0}")] + LilyPondExecution(String), + + #[error("Template error: {0}")] + Template(String), + + #[error("File I/O error: {0}")] + FileIO(#[from] std::io::Error), + + #[error("Invalid sequence: {0}")] + InvalidSequence(String), +} diff --git a/morphology-img/src/file_gen.rs b/morphology-img/src/file_gen.rs new file mode 100644 index 0000000..c429719 --- /dev/null +++ b/morphology-img/src/file_gen.rs @@ -0,0 +1 @@ +// .ly file generation and temp directory management diff --git a/morphology-img/src/lib.rs b/morphology-img/src/lib.rs new file mode 100644 index 0000000..28dfc58 --- /dev/null +++ b/morphology-img/src/lib.rs @@ -0,0 +1,9 @@ +pub mod error; +pub mod pitch; +pub mod template; +pub mod file_gen; +pub mod render; + +// Re-export key types +pub use error::RenderError; +pub use pitch::{LilyPondPitch, LilyPondNote, Duration}; 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() + } +} diff --git a/morphology-img/src/render.rs b/morphology-img/src/render.rs new file mode 100644 index 0000000..cd5b293 --- /dev/null +++ b/morphology-img/src/render.rs @@ -0,0 +1 @@ +// LilyPond CLI invocation for SVG generation diff --git a/morphology-img/src/template.rs b/morphology-img/src/template.rs new file mode 100644 index 0000000..afa091b --- /dev/null +++ b/morphology-img/src/template.rs @@ -0,0 +1 @@ +// Template handling and substitution |