From 53aca050d78bcda82bd3f2c22b672df91bba23e6 Mon Sep 17 00:00:00 2001 From: jacksonfu14 Date: Tue, 18 Nov 2025 20:34:56 +0100 Subject: scale staves to fit notes --- morphology-img/src/template.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'morphology-img/src/template.rs') diff --git a/morphology-img/src/template.rs b/morphology-img/src/template.rs index 15a47d5..e552843 100644 --- a/morphology-img/src/template.rs +++ b/morphology-img/src/template.rs @@ -8,7 +8,8 @@ const FORMAT_ILY: &str = include_str!("../static/format.ily"); const ENTRY_ILY: &str = include_str!("../static/entry.ily"); const ELEMENTS_ILY: &str = include_str!("../static/elements.ily"); -const PLACEHOLDER: &str = "%%%"; +const MORPHEME_PLACEHOLDER: &str = "%MORPHEME%"; +const RUNGS_PLACEHOLDER: &str = "%RUNGS%"; /// Returns the template .ly content pub fn get_template() -> &'static str { @@ -30,24 +31,35 @@ pub fn get_elements_ily() -> &'static str { ELEMENTS_ILY } -/// Substitutes the placeholder in the template with the provided markup. +/// Substitutes placeholders in the template with the provided values. /// /// # Arguments -/// - `markup`: The LilyPond markup to substitute into the template +/// - `morpheme`: The LilyPond morpheme markup to substitute +/// - `rungs`: The Scheme list string for staff line positions /// /// # Returns -/// The complete .ly file content with substitution applied +/// The complete .ly file content with substitutions applied /// /// # Errors -/// Returns `RenderError::Template` if the placeholder is not found -pub fn substitute_template(markup: &str) -> Result { +/// Returns `RenderError::Template` if placeholders are not found +pub fn substitute_template(morpheme: &str, rungs: &str) -> Result { let template = get_template(); - if !template.contains(PLACEHOLDER) { + if !template.contains(MORPHEME_PLACEHOLDER) { return Err(RenderError::Template( - "Template does not contain placeholder '%%%'".to_string() + "Template does not contain placeholder '%MORPHEME%'".to_string() )); } - Ok(template.replace(PLACEHOLDER, markup)) + if !template.contains(RUNGS_PLACEHOLDER) { + return Err(RenderError::Template( + "Template does not contain placeholder '%RUNGS%'".to_string() + )); + } + + let result = template + .replace(MORPHEME_PLACEHOLDER, morpheme) + .replace(RUNGS_PLACEHOLDER, rungs); + + Ok(result) } -- cgit v1.2.3