Recordare Main Navigation Menu Recordare

Using XML for Musical Representation

Michael Good
Recordare

Guest Lecture for Music Representation class (Music 254)
Stanford University
May 17, 2000

Copyright © 2000 Recordare. All rights reserved.


Outline

  • Why another music representation language?
  • Why use XML?
  • XML versions of MIDI and NIFF
  • MusicXML: An updating of MuseData and Humdrum using Internet standards

My Background

  • BS and MS in computer science, MIT
  • Developed Scot language for Music 11 (now Csound) for BS thesis
  • After MS, worked in human-computer interaction for 18 years
  • Started Recordare in January
  • Active choral singer, former trumpeter

Why Another Music Representation Language?

  • 20+ formats described in Beyond MIDI
  • Each commercial music program has its own proprietary format
  • The only commonly used interchange format is MIDI
  • MIDI is good for performance but not sufficient for notation or analysis

HTML and MIDI as Catalysts for Growth

  • HTML and MIDI both hit the "sweet spot" of simplicity and power
  • Powerful enough for real-world information and music
  • Simple enough for lots of people to learn
  • The result: explosive growth in the Web and the electronic music industry

The Limits of HTML and MIDI

  • People want to do more than the formats were designed for
  • Neither format has extensibility designed in
  • HTML is too unstructured for automated electronic commerce
  • MIDI does not represent concepts needed for notation and analysis

The New Standard: XML

  • XML: Extensible Markup Language
  • Like Humdrum, XML provides a syntax for other markup languages
  • Like HTML, XML balances human and computer readability
  • Very wide support within industry, especially for electronic commerce

Why Are People So Excited About XML?

  • Finally, a simple, standard, text-based format for complex structured data
  • If you can represent it hierarchically, you can represent it in XML
  • You can leverage commodity software and existing Web infrastructure
  • Separates semantics, structure, and presentation

More Good Things About XML

  • XSL (Extensible Style Language)
    • Standard data transformation and formatting language
    • In MusicXML, XSLT allows switches between part-based and time-based hierarchies
  • XML documents are in Unicode
  • "Terseness in XML markup is of minimal importance" - W3C

Designing an XML Representation for Music

  • XML by itself is a meta-markup language
  • Domain-specific languages are defined with a Document Type Definition (DTD)
  • Previous attempts at musical DTDs have generally been too simple for real use
  • With a standard DTD in place, musical scores can be exchanged on the Web and between different musical software programs

MusicXML Representation Goals

  • Represent common western musical notation from 17th century onwards
  • Represent popular and classical music
  • Extensible for future support of early music and non-standard modern scores

MusicXML Application Goals

  • Support notation, performance, and analysis applications
  • Sufficient, not optimal, for these applications
  • Support interchange with any musical program with a published data format
  • 100% coverage of MuseData

Why MusicXML Instead of NIFF or SMDL?

  • NIFF and SMDL are both oriented towards machine readability, not human readability
  • NIFF is oriented towards notation; difficult to use for other applications
  • SMDL trades off ease of use with common notation for full generality
  • MusicXML leverages Internet standards

XML Versions of MIDI and NIFF

  • Provide a text representation of these binary formats
  • Used by MusicXML as an intermediate representation for file import and export
  • Why build your own internal data structure when you can just use XML?
  • Examples: Recordare logo (Verdi):

MIDI XML Example

<?xml version="1.0" standalone="yes" ?>
<MIDI>
  <Format>1</Format>
  <Tracks>2</Tracks>
  <TicksPerBeat>24</TicksPerBeat>
  <TimestampType>Delta</TimestampType>
  <Track number="0">
    <SetTempo>
      <Delta>0</Delta>
      <Value>750000</Value>    <!-- MM = 80 -->
    </SetTempo>
    <KeySignature>
      <Delta>0</Delta>
      <Fifths>-1</Fifths>      <!-- One flat -->
      <Mode>0</Mode>
    </KeySignature>
    <EndOfTrack>
      <Delta>192</Delta>
    </EndOfTrack>
  </Track>
  <Track number="1">
    <TrackName>
      <Delta>0</Delta>
      <Value>Mezzo-soprano</Value>
    </TrackName>
    <ProgramChange>
      <Delta>0</Delta>
      <Channel>1</Channel>
      <Number>54</Number>      <!-- GM Voices -->
    </ProgramChange>
    <NoteOn>                   <!-- Initial A -->
      <Delta>0</Delta>
      <Channel>1</Channel>
      <Note>69</Note>
      <Velocity>90</Velocity>
    </NoteOn>
    <NoteOff>
      <Delta>60</Delta>        <!-- Half tied to eighth -->
      <Channel>1</Channel>
      <Note>69</Note>
      <Velocity>90</Velocity>
    </NoteOff>
    <NoteOn>
      <Delta>0</Delta>
      <Channel>1</Channel>
      <Note>65</Note>
      <Velocity>90</Velocity>
    </NoteOn>
    <!-- Rest of notes omitted... -->
    <EndOfTrack>
      <Delta>24</Delta>        <!-- quarter rest -->
    </EndOfTrack>
  </Track>
</MIDI>

NIFF XML Example

<?xml version="1.0" standalone="yes" ?>
<NIFF>
  <SetupSection>
    <!-- Skip these next 3 for here... -->
    <ChunkLengthTable />
    <NiffInformation />
    <FontDescriptions list="yes" />
    <StringTable>
      <String Offset="0">Mezzo-soprano</String>
      <String Offset="14">M.</String>
    </StringTable>
    <Parts list="yes">
      <PartDescription>
        <PartID>0</PartID>
        <PartName>0</PartName>
        <PartAbbreviation>14</PartAbbreviation>
        <Staves>1</Staves>
        <MidiChannel>0</MidiChannel>
        <MidiCable>-1</MidiCable>
        <Transpose>0</Transpose>
      </PartDescription>
    </Parts>
  </SetupSection>
  <DataSection>
    <Page list="yes">
      <PageHeader />    <!-- Skip headers here -->
      <System list="yes">
        <SystemHeader />
        <Staff list="yes">
          <StaffHeader />
          <TimeSlice type="2">
            <StartTime Numerator="0" 
                Denominator="1" />
          </TimeSlice>
          <Clef Shape="1" StaffStep="2" 
                OctaveNumber="0" />
          <KeySignature StandardCode="8" />
          <Stem>
            <LogicalPlacement Horizontal="0"
                Vertical="1" Proximity="0" />
          </Stem>
          <Slur>
            <NumberOfNodes>2</NumberOfNodes>
            <ID>0</ID>
          </Slur>
          <Notehead Shape="3" StaffStep="3">
            <Duration Numerator="1" Denominator="2" />
            <PartID>0</PartID>
          </Notehead>
          <Tie>
            <NumberOfNodes>2</NumberOfNodes>
            <ID>0</ID>
          </Tie>
          <!-- Rest of notes omitted... -->
        </Staff>
      </System>
    </Page>
  </DataSection>
</NIFF>

MusicXML Example (May 2000 version)

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE score-partwise SYSTEM "musicxml-p.dtd">
<score-partwise>
  <movement id="M1">
    <part-list>
      <score-part id="M1-P1">
        <part-name>Mezzo-soprano</part-name>
        <part-abbreviation>M.</part-abbreviation>
      </score-part>
    </part-list>
    <part id="M1-P1">
      <measure number="1">
        <attributes>
           <key>
             <fifths>-1</fifths>
          </key>
          <divisions>2</divisions>
          <staves>1</staves>
          <clef>
            <sign>G</sign>
            <line>2</line>
          </clef>
        </attributes>
        <note>
          <pitch>
            <step>A</step>
            <octave>4</octave>
          </pitch>
          <duration>4</duration>
          <tie />
          <type>half</type>
          <stem>up</stem>
          <notations>
            <slur type="start" number="1"/>
            <tied/>
          </notations>
        </note>
        <!-- Notes omitted until last B-flat -->
        <note>
          <pitch>
            <step>B</step>
            <alter>-1</alter>
            <octave>4</octave>
          </pitch>
          <duration>1</duration>
          <type>eighth</type>
          <stem>up</stem>
          <beam number="1">end</beam>
        </note>
      </measure>
      <measure number="2">
        <!-- Notes omitted until last rest -->
        <note>
          <rest />
          <duration>2</duration>
        </note>
      </measure>
    </part>
  </movement>
</score-partwise>

MusicXML Converter Status as of May 17, 2000

  • Proof of concept that MusicXML supports performance, notation, and analysis formats
  • Reads MuseData and NIFF files
  • Writes Standard MIDI Files
  • Future directions: Support Humdrum and commercial formats

Converter screen shot

How Much Bigger Are The MusicXML Files?

  • XML compresses very well
  • Zip compresses MusicXML about 30x
  • Comparison with MuseData for first movement of Haydn's Symphony #104:
    • Uncompressed (11 score files)
      • MuseData 319K, MusicXML 2.19M (7x)
    • Compressed (.zip)
      • MuseData 35K, MusicXML 69K (2x)

XML Document Type Definitions (DTDs)

  • XML is a meta-markup language
  • A DTD defines the specific markup language or tag set
  • Documents without DTDs can be well-formed XML, but not validated XML
  • Standardization thus becomes a DTD design issue

MusicXML DTD Sample: note

<!-- Internal entities to simplify note definitions -->
<!ENTITY % full-note "(chord?, (pitch | rest))">
<!ENTITY % voice-track "(footnote?, level?, track?)">

<!-- Definition of the note element -->
<!ELEMENT note ((((cue | grace), %full-note;) |
               (%full-note;, duration, tie?)),
               %voice-track;, type?, dot*,
               accidental?, time-modification?,
               stem?, staff?, beam*, notations*, 
               text*)>

MusicXML DTD Sample: pitch and slur

<!ELEMENT pitch (step, alter?, octave)>
<!ELEMENT step (#PCDATA)>
<!ELEMENT alter (#PCDATA)>
<!ELEMENT octave (#PCDATA)>

<!-- Slur is an empty element with attributes -->
<!ENTITY % beam-level "(1 | 2 | 3 | 4 | 5 | 6)">
<!ENTITY % start-stop "(start | stop)">
<!ELEMENT slur EMPTY>
<!ATTLIST slur type %start-stop; #REQUIRED>
<!ATTLIST slur number %beam-level; "1">

Working With XML

  • Two main XML programming models
    • Tree-based like DOM (W3C Document Object Model)
    • Event-based like SAX (Simple API for XML)
  • Accessible from many programming languages (Java, C++, Visual Basic)
  • Tools available from multiple vendors
  • My examples use DOM and Visual Basic

Analysis Examples

  • Two examples adapted from Humdrum problem list:
    • Do Bach's pieces really have 90% of the notes in one of two durations?
    • Is pitch correlated with duration?
  • Show duration distribution on bar chart
  • Show correlation analysis on scatterplot

Durations in Bach BWV 6, 2nd Movement

Bar chart showing 16th notes at 52 percent and eighth notes at 35 percent

Correlations in Mozart Quartet #7, 1st Movement

Scatterplot showing no correlation between pitch and duration

Distribution Analysis Code

Set oNodes = oRoot.selectNodes("//note | //divisions")
Do
  Set oNote = oNodes.NextNode
  If oNote Is Nothing Then Exit Do
  If oNote.tagName = "divisions" Then
    nMultiplier = nDivisions \ CLng(oNote.Text)
  Else
    Set oTmp = oNote.selectSingleNode("duration")
    If Not oTmp Is Nothing Then  ' Exclude grace and cue notes
      nDuration = CLng(oTmp.Text) * nMultiplier
      nCounts(nDuration) = nCounts(nDuration) + 1
    End If
  End If
Loop

Correlation Analysis Code

  ' Code structure is same as for distribution analysis.
  ' The Else clause for handling notes changes:
  Else
      Set oDuration = oNote.SelectSingleNode("duration")
      Set oPitch = oNote.SelectSingleNode("pitch")
      If (Not oDuration Is Nothing) And _
         (Not oPitch Is Nothing) Then  ' No rests either
        nDuration = CLng(oDuration.Text) * nMultiplier
        nPitch = MidiNote(oPitch)      ' Separate function
        oWorksheet.Cells(i, 1) = nDuration
        oWorksheet.Cells(i, 2) = nPitch
      End If
  End If

Future Directions for MusicXML

  • Test, debug, and iterate with more music, formats, and applications
  • More general release once internally debugged

Summary

  • XML is the Internet standard for representing complex structured data
  • Representing music in XML is a natural way to publish musical scores, not just recordings, on the Internet
  • Standard music DTD must be well-designed from musical, human, and computer perspectives

Acknowledgments


Home - Music - Software - MusicXML - Events - Search - Store - About Us

Copyright © 2000 Recordare. All rights reserved.