From Sheet Music to Live Code: The MusicXML Pipeline
April 5, 2026Camel Tech Teammusicxmlstrudeltutorial

From Sheet Music to Live Code: The MusicXML Pipeline

Why MusicXML?

Musicians have decades of sheet music in digital formats. MusicXML is the open standard for exchanging musical notation between applications — Finale, Sibelius, MuseScore, and dozens of other tools can export it. We wanted to bridge the gap between traditional notation and live-coding, letting musicians bring their existing scores into StrudelHub and hear them played back as Strudel patterns.

The constraint we set for ourselves: everything runs in the browser. No server-side processing, no file uploads to our backend, no external conversion services. Your sheet music never leaves your machine.

The 5-Stage Pipeline

Our converter is a pipeline of five pure transformation stages. Each stage takes typed input, produces typed output, and can be tested independently.

Stage 1: Parse

The first stage handles the raw file. MusicXML comes in two flavors:

  • Uncompressed (.xml or .musicxml) — plain XML text
  • Compressed (.mxl) — a ZIP archive containing the XML file plus optional metadata

We use the browser's native DOMParser for XML parsing and JSZip for .mxl decompression. The output is a structured representation of parts, measures, notes, and attributes — extracted from the XML DOM into typed TypeScript objects.

Stage 2: Normalize

Sheet music has a lot of structural complexity that doesn't map directly to Strudel's pattern model. The normalize stage flattens this:

  • Repeats — barline repeats are expanded into the actual sequence of measures
  • Voltas (1st/2nd endings) — each ending is placed at the correct position in the expanded sequence
  • D.C./D.S./Coda navigation — these jump directives are resolved into a linear measure order
  • Voice splitting — measures with multiple voices are split into separate tracks

After normalization, the data is a simple linear sequence of measures per voice — no jumps, no repeats, no structural ambiguity.

Stage 3: Quantize

Strudel works with pattern slots, not traditional note durations. A quarter note in 4/4 time occupies one of four slots. An eighth note occupies half a slot. The quantize stage converts traditional durations into Strudel's slot-based system.

This is where the math gets interesting. MusicXML expresses duration as a fraction of a measure's total divisions. A measure in 4/4 with 24 divisions per quarter note has 96 total divisions. A dotted half note at 72 divisions becomes 3 out of 4 slots. The quantizer maps these fractions to the closest Strudel representation, handling tuplets and irregular time signatures.

Stage 4: Ties

Tied notes — where two notes are connected to create a longer duration — need special handling. A half note tied to a quarter note across a bar line should become a single sustained note, not two separate attacks.

The tie resolution stage merges tied notes both within and across measures. It walks the quantized output, detects tie start/stop markers, and combines the durations. This stage also handles edge cases like ties across repeat boundaries and ties in multi-voice passages.

Stage 5: Emit

The final stage generates Strudel JavaScript code. It takes the quantized, tie-resolved data and produces a valid Strudel program using the arrange() timeline function.

Key decisions in code generation:

  • General MIDI mapping — MusicXML instrument names are mapped to Strudel's GM sound bank. A "Violin" part becomes s("gm_violin"), a "Piano" part becomes s("gm_acoustic_grand_piano").
  • Multi-part arrangement — each voice becomes a stack() entry in the top-level arrange() call, letting all parts play simultaneously.
  • Readable output — the generated code uses meaningful variable names, one pattern per line, and comments marking measure numbers. It's meant to be read and edited, not just executed.

How to Use It

Using the MusicXML converter in StrudelHub is straightforward:

  1. Open any session in the editor
  2. Click the three-dot menu in the toolbar
  3. Select Upload MusicXML
  4. Choose your .xml, .musicxml, or .mxl file

The converted Strudel code replaces the current editor content. Hit Play to hear your sheet music come alive as a Strudel pattern. From there, you can edit the code — change instruments, add effects, modify rhythms — and explore what your score sounds like in the world of live-coding.

Limitations and Trade-offs

No conversion is perfect. Here are the known limitations:

  • Dynamics and expression — MusicXML captures dynamics (pp, ff, crescendo), articulations (staccato, legato), and expression marks. Our converter currently maps note pitches and durations but does not translate dynamic markings into Strudel's gain or velocity controls. This is on our roadmap.
  • Complex tuplets — nested tuplets (triplets within triplets) are quantized to the nearest slot boundary, which may introduce small rhythmic approximations.
  • Percussion notation — unpitched percussion in MusicXML uses a different notation model. We map standard drum kit instruments but custom percussion setups may not convert correctly.
  • Grace notes — these are currently omitted. Strudel has mechanisms for ornaments, but the mapping from MusicXML grace note types to Strudel patterns is non-trivial.

What's Next

We're working on improving the converter in several areas:

  • Dynamics support — mapping MusicXML dynamics to Strudel's .gain() and .velocity() modifiers
  • Lyrics — extracting lyrics from vocal parts and including them as Strudel comments or metadata
  • Round-trip export — converting Strudel patterns back to MusicXML for sharing with traditional notation software

If you have MusicXML files that don't convert well, we'd love to hear about it. The converter is part of our open client-side codebase, and edge cases help us improve the pipeline for everyone.

Read the MusicXML Import documentation for more details, or check out Strudel Basics to learn the language your sheet music will be converted into.