io.musicxml.writer

writer

MusicXML out: one Score of an OmkGraph becomes a <score-partwise> document.

The inverse of reader, rule by rule (_plans/musicxml.md §5 and §6); in short:

  • the parts are written in their STACKS_ABOVE order: a Part with a Stint over a line is one staff, a Part performing a LineGroup is one staff per line in the group’s stack order, and a LineGroup whose lines are each performed by a PercussionPart is one staff of a drum kit;
  • a line’s DivisionEvents are its bar lines, and between them (or on a line without them) the MeterEvent in force puts one every meter, which is exactly what OmkGraph.remove_derivable_divisions takes away, so a graph stripped of derivable bar lines writes the same document as the full one;
  • a branched line is another voice on its parent’s staff, except a single event branched with no displacement from a chord it fits, which is written back into that chord as <chord/> notes;
  • pitches are written as written: a Stint.transposition is added back to the stored sounding pitches and becomes <transpose>;
  • ties, slurs, hairpins, pedals and other spanners become start/stop pairs, markings become <notations> or <direction>s through tables, lyric syllables become <lyric>s numbered by their verse, and a chord line pinned to a part becomes that part’s <harmony>s;
  • what the reader kept in node.meta["musicxml"] (voice and measure numbers, hidden notes, tuplet brackets, part ids and instruments) is written back.

The writer refuses (UnexportableError) only when no document can be written. Everything else it cannot write – an event of unknown or clock-time duration and the rest of its line, an annotation, a line no part performs – raises an OmkWarning naming what was left out.

Attributes

Name Description
DOCTYPE
SOFTWARE
XML_LANG
ORIGIN
MAX_NUMBER
NEVER

Functions

Name Description
write Writes score (the graph’s only Score when None) as MusicXML 4.0,
to_bytes The uncompressed document write writes, as bytes.
document The <score-partwise> element write serializes.