LIBRARY EXAMPLES

Run a small score pipeline.

These examples separate in-memory library calls from CLI file access and browser hosting.

Edit a score in Rust

ScoreEngine validates commands and keeps undo history.

use acorde::core::{Command, ScoreEngine, SetTempoCmd};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut engine = ScoreEngine::new();
    engine.apply(Command::SetTempo(SetTempoCmd { bpm: 144 }))?;
    engine.undo()?;
    println!("{} BPM", engine.score.settings.tempo_bpm);
    Ok(())
}

Render MusicXML to SVG

The CLI owns source and destination files. Save the sample as input.musicxml and run this command from the Acorde repository.

cargo run -p acorde-cli -- render input.musicxml output.svg

Build the WASM binding

Run from the Acorde v1.3.15 checkout and serve the repository root over HTTP.

wasm-pack build crates/wasm --target web
python3 -m http.server 8000

Render in a browser

Save as preview.html in the repository root and open localhost:8000/preview.html.

<!doctype html>
<meta charset="utf-8">
<title>Acorde WASM preview</title>
<img id="score-preview" alt="Rendered MusicXML score">
<script type="module">
  import init, { parse_musicxml_render_svg } from './crates/wasm/pkg/acorde_wasm.js';
  await init();
  const xml = await (await fetch('./tests/fixtures/simple.musicxml')).text();
  const svg = parse_musicxml_render_svg(xml, '{}');
  const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
  const image = document.querySelector('#score-preview');
  image.addEventListener('load', () => URL.revokeObjectURL(url), { once: true });
  image.src = url;
</script>