Music Software Development

MusicXML basics for programmers

MusicXML represents a score as parts and measures. A note can carry both a duration for timing and a type for its printed appearance. A sequencer can derive these from tick positions, but still needs to choose a spelling such as C sharp or D flat.

A two-beat measure

Put this measure inside a part. Four divisions make one quarter note. A quarter note followed by a quarter rest fills the 2/4 measure.

<measure number="1">
  <attributes>
    <divisions>4</divisions>
    <time><beats>2</beats><beat-type>4</beat-type></time>
  </attributes>
  <note>
    <pitch><step>C</step><alter>1</alter><octave>4</octave></pitch>
    <duration>4</duration><type>quarter</type>
  </note>
  <note>
    <rest/><duration>4</duration><type>quarter</type>
  </note>
</measure>

Convert from ticks

With 480 ticks and four divisions per quarter, divide tick durations by 120. Choose a higher divisions value if your rhythms would yield fractional durations. For a chord, mark each additional simultaneous note with <chord/> so it shares the preceding note’s start.

See the MusicXML reference and compare its measure model with sequencer data structures.