Skip to main content

sim_lib_music_serial/
audition.rs

1//! Serial audition and export adapters over existing score, lowering, and notation owners.
2
3use sim_lib_music_core::{Score, SmfFile};
4use sim_lib_music_lower::{LowerError, LowerOpts, lower_score, write_smf};
5use thiserror::Error;
6
7use crate::{SerialRealization, SerialRenderOptions, StrictRealizationError, render_serial_score};
8
9/// Error surfaced while routing realized serial music through existing owners.
10#[derive(Debug, Error)]
11pub enum SerialSurfaceError {
12    /// Rendering to the canonical score failed.
13    #[error(transparent)]
14    Realization(#[from] StrictRealizationError),
15    /// MIDI lowering failed in the existing lowering owner.
16    #[error(transparent)]
17    Lower(#[from] LowerError),
18}
19
20/// Renders a serial realization into the existing score surface for audition.
21pub fn render_serial_audition_score(
22    realization: &SerialRealization,
23    options: &SerialRenderOptions,
24) -> Result<Score, SerialSurfaceError> {
25    Ok(render_serial_score(realization, options)?)
26}
27
28/// Lowers a rendered serial score through the existing MIDI owner.
29pub fn lower_serial_score(
30    realization: &SerialRealization,
31    render: &SerialRenderOptions,
32    lower: &LowerOpts,
33) -> Result<SmfFile, SerialSurfaceError> {
34    let score = render_serial_audition_score(realization, render)?;
35    Ok(lower_score(&score, lower)?)
36}
37
38/// Serializes a rendered serial score to SMF bytes through the existing MIDI owner.
39pub fn write_serial_smf(
40    realization: &SerialRealization,
41    render: &SerialRenderOptions,
42    lower: &LowerOpts,
43) -> Result<Vec<u8>, SerialSurfaceError> {
44    let score = render_serial_audition_score(realization, render)?;
45    Ok(write_smf(&score, lower)?)
46}