summaryrefslogtreecommitdiff
path: root/morphology-img/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'morphology-img/src/lib.rs')
-rw-r--r--morphology-img/src/lib.rs58
1 files changed, 57 insertions, 1 deletions
diff --git a/morphology-img/src/lib.rs b/morphology-img/src/lib.rs
index 3ba78f2..8e82f91 100644
--- a/morphology-img/src/lib.rs
+++ b/morphology-img/src/lib.rs
@@ -34,6 +34,25 @@ pub use error::RenderError;
pub use note::sequence_to_markup;
use std::path::PathBuf;
+use std::sync::Arc;
+
+/// Type alias for progress callback function.
+///
+/// The callback receives:
+/// - `current`: The number of sequences processed so far (1-indexed)
+/// - `total`: The total number of sequences to process
+///
+/// # Examples
+///
+/// ```no_run
+/// use morphology_img::ProgressCallback;
+/// use std::sync::Arc;
+///
+/// let callback: ProgressCallback = Arc::new(|current, total| {
+/// println!("Progress: {}/{}", current, total);
+/// });
+/// ```
+pub type ProgressCallback = Arc<dyn Fn(usize, usize) + Send + Sync>;
/// Configuration for rendering sequences to SVGs.
///
@@ -53,7 +72,7 @@ use std::path::PathBuf;
/// .keep_temp_files(true)
/// .lilypond_binary("/usr/local/bin/lilypond");
/// ```
-#[derive(Debug, Clone)]
+#[derive(Clone)]
pub struct RenderConfig {
/// Directory where SVG files should be created
pub output_dir: PathBuf,
@@ -63,6 +82,20 @@ pub struct RenderConfig {
/// Path to the LilyPond binary (default: "lilypond")
pub lilypond_binary: PathBuf,
+
+ /// Optional callback for progress reporting during batch rendering
+ pub progress_callback: Option<ProgressCallback>,
+}
+
+impl std::fmt::Debug for RenderConfig {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("RenderConfig")
+ .field("output_dir", &self.output_dir)
+ .field("keep_temp_files", &self.keep_temp_files)
+ .field("lilypond_binary", &self.lilypond_binary)
+ .field("progress_callback", &self.progress_callback.as_ref().map(|_| "<callback>"))
+ .finish()
+ }
}
impl Default for RenderConfig {
@@ -71,6 +104,7 @@ impl Default for RenderConfig {
output_dir: PathBuf::from("output"),
keep_temp_files: false,
lilypond_binary: PathBuf::from("lilypond"),
+ progress_callback: None,
}
}
}
@@ -136,6 +170,27 @@ impl RenderConfig {
self.lilypond_binary = path.into();
self
}
+
+ /// Sets a progress callback for batch rendering.
+ ///
+ /// The callback will be called after each sequence is rendered, allowing
+ /// you to track progress for large batches.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use morphology_img::RenderConfig;
+ /// use std::sync::Arc;
+ ///
+ /// let config = RenderConfig::new("output")
+ /// .progress_callback(Arc::new(|current, total| {
+ /// println!("Rendered {}/{} sequences", current, total);
+ /// }));
+ /// ```
+ pub fn progress_callback(mut self, callback: ProgressCallback) -> Self {
+ self.progress_callback = Some(callback);
+ self
+ }
}
/// Renders multiple sequences to SVG files.
@@ -217,6 +272,7 @@ pub fn render_sequences(
&ly_files,
&config.output_dir,
&config.lilypond_binary,
+ config.progress_callback.as_ref(),
)?;
// Handle temp directory cleanup