楽譜のデジタル表現 -MusicXML, SMuFL, Dorico-

楽譜をデータとして扱うのに現代で一番普及しているフォーマットがMusicXmlです。
MusicXmlを理解することで、Doricoなどの楽譜作成ソフトやMusic21の設計思想を深く理解できます。
Music21はMusicXmlの構造をそのまま反映したクラス設計になっているので、。

1 MusicXmlの基本構造

MusicXmlはW3Cが仕様を定めていて、ドキュメントはこちらにあります。
MusicXML 4.0
こちらのチュートリアルのHello Worldの例に、少し追記したものを元に見ていきます。

        
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
    "-//Recordare//DTD MusicXML 4.0 Partwise//EN"
    "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
    <work>
        <work-number>Op.1</work-number>
        <work-title>Only C</work-title>
    </work>
    <identification>
        <creator type="composer">J.S.Bach</creator>
    </identification>
    <part-list>
        <score-part id="P1">
        <part-name>Violin</part-name>
        </score-part>
    </part-list>
    <part id="P1">
        <measure number="1">
        <attributes>
            <divisions>1</divisions>
            <key>
            <fifths>0</fifths>
            </key>
            <time>
            <beats>4</beats>
            <beat-type>4</beat-type>
            </time>
            <clef>
            <sign>G</sign>
            <line>2</line>
            </clef>
        </attributes>
        <note>
            <pitch>
            <step>C</step>
            <octave>4</octave>
            </pitch>
            <duration>4</duration>
            <type>whole</type>
        </note>
        </measure>
    </part>
</score-partwise>
            
        
MusicXML 4.0 - Hello World Tutorialを元に作成

1.1 XML宣言とDTD

まず一番最初の

            
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
    "-//Recordare//DTD MusicXML 4.0 Partwise//EN"
    "http://www.musicxml.org/dtds/partwise.dtd">
            
        
という部分はXMLの宣言とDOCTYPE宣言です。
ここは省略しても問題ありませんが、XMLファイルであることを明示するために書いておくのが一般的です。

1.2 ルート要素

次に<score-partwise>要素がルート要素です。
すべての要素はこの<score-partwise>要素の中に含まれます。
<score-partwise>のほかに<score-timewise>というルート要素もありますが、こちらは時間軸に沿った表現をするためのものです。
一般的には<score-partwise>がよく使われます。

1.3 スコアヘッダー

次の部分からがスコアヘッダーの記述です。
この例では次のタグが記述されています。

1.4 楽譜データ

楽譜データの本体は<part>要素の中に記述されます。
<part>要素は複数存在することができ、各パートごとに1つずつ<part>要素が対応します。
<part>要素の中には<measure>要素があり、各小節ごとに1つずつ<measure>要素が対応します。
<measure>要素の中には<note>要素があり、各音符ごとに1つずつ<note>要素が対応します。

2 Doricoによる実際の楽譜データ

実際にDoricoで作成した楽譜データをMusicXmlでエクスポートしたものを見てみましょう。
次の楽譜は、Brahmsの『2つのラプソディ』を弦楽四重奏に編曲したものの、最初の8小節です。

この楽譜をMusicXmlでエクスポートしたものが次のコードです。
およそ2800行ほどあり、抜粋して掲載します。

        
<?xml version="2.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 4.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
  <work>
    <work-title>Zewi Rhapsodien</work-title>
  </work>
  <movement-title>1</movement-title>
  <identification>
    <creator type="composer">Johannes Brahms</creator>
    <encoding>
      <software>Dorico 5.1.51.2153</software>
      <encoding-date>2026-01-03</encoding-date>
      <supports type="yes" element="print" attribute="new-system" value="yes"/>
      <supports type="yes" element="print" attribute="new-page" value="yes"/>
      <supports type="yes" element="accidental"/>
      <supports type="yes" element="beam"/>
      <supports type="yes" element="stem"/>
    </encoding>
  </identification>
  <defaults>
    <scaling>
      <millimeters>6.99911</millimeters>
      <tenths>40</tenths>
    </scaling>
    <page-layout>
      <page-height>1695.56</page-height>
      <page-width>1197.58</page-width>
      <page-margins type="both">
        <left-margin>84.6774</left-margin>
        <right-margin>84.6774</right-margin>
        <top-margin>84.6774</top-margin>
        <bottom-margin>84.6774</bottom-margin>
      </page-margins>
    </page-layout>
    <music-font font-family="Bravura" font-size="19.84"/>
    <word-font font-family="Academico" font-size="9.92"/>
  </defaults>
  <credit page="1">
    <credit-type>title</credit-type>
    <credit-words font-family="Academico" font-size="20" justify="center" valign="middle" default-x="593.75" default-y="1562.5" xml:space="preserve">Zewi Rhapsodien</credit-words>
  </credit>
  <credit page="1">
    <credit-type>composer</credit-type>
    <credit-words font-family="Academico" font-size="10" justify="right" valign="middle" default-x="1103.75" default-y="1502.5" xml:space="preserve">Johannes Brahms</credit-words>
  </credit>
  <part-list>
    <score-part id="P1">
      <part-name>Violin 1</part-name>
      <part-name-display>
        <display-text>Violin 1</display-text>
      </part-name-display>
      <part-abbreviation print-object="no">Vln 1</part-abbreviation>
      <part-abbreviation-display print-object="no">
        <display-text/>
      </part-abbreviation-display>
      <score-instrument id="instrument-1">
        <instrument-name>Violin 1</instrument-name>
        <instrument-sound>strings.violin</instrument-sound>
      </score-instrument>
    </score-part>
  </part-list>
  <part id="P1">
    <measure number="1">
      <print>
        <system-layout>
          <system-margins>
            <left-margin>131.25</left-margin>
            <right-margin>0</right-margin>
          </system-margins>
          <top-system-distance>201.875</top-system-distance>
        </system-layout>
      </print>
      <attributes>
        <divisions>12</divisions>
        <key number="1">
          <fifths>2</fifths>
          <mode>minor</mode>
        </key>
        <time symbol="cut">
          <beats>2</beats>
          <beat-type>2</beat-type>
        </time>
        <staves>1</staves>
        <clef number="1">
          <sign>G</sign>
          <line>2</line>
        </clef>
      </attributes>
      <direction placement="below">
        <direction-type>
          <dynamics default-y="-70">
            <f/>
          </dynamics>
        </direction-type>
        <staff>1</staff>
      </direction>
      <note>
        <pitch>
          <step>F</step>
          <alter>1</alter>
          <octave>5</octave>
        </pitch>
        <duration>18</duration>
        <voice>1</voice>
        <type>quarter</type>
        <dot/>
        <stem>down</stem>
        <staff>1</staff>
        <notations>
          <articulations>
            <accent placement="above"/>
          </articulations>
        </notations>
      </note>
      <note>
        <pitch>
          <step>C</step>
          <alter>1</alter>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>16th</type>
        <time-modification>
          <actual-notes>3</actual-notes>
          <normal-notes>2</normal-notes>
          <normal-type>16th</normal-type>
        </time-modification>
        <stem>down</stem>
        <staff>1</staff>
        <beam number="1">begin</beam>
        <beam number="2">begin</beam>
        <notations>
          <tuplet type="start" bracket="no" number="1">
            <tuplet-actual>
              <tuplet-number>3</tuplet-number>
              <tuplet-type>16th</tuplet-type>
            </tuplet-actual>
            <tuplet-normal>
              <tuplet-number>2</tuplet-number>
              <tuplet-type>16th</tuplet-type>
            </tuplet-normal>
          </tuplet>
        </notations>
        <notations>
          <slur type="start" number="1" orientation="over"/>
        </notations>
      </note>
      <note>
        <pitch>
          <step>D</step>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>16th</type>
        <time-modification>
          <actual-notes>3</actual-notes>
          <normal-notes>2</normal-notes>
          <normal-type>16th</normal-type>
        </time-modification>
        <stem>down</stem>
        <staff>1</staff>
        <beam number="1">continue</beam>
        <beam number="2">continue</beam>
      </note>
      <note>
        <pitch>
          <step>E</step>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>16th</type>
        <time-modification>
          <actual-notes>3</actual-notes>
          <normal-notes>2</normal-notes>
          <normal-type>16th</normal-type>
        </time-modification>
        <stem>down</stem>
        <staff>1</staff>
        <beam number="1">end</beam>
        <beam number="2">end</beam>
        <notations>
          <tuplet type="stop" bracket="no" number="1"/>
        </notations>
        <notations>
          <slur type="stop" number="1" orientation="over"/>
        </notations>
      </note>
      <note>
        <pitch>
          <step>D</step>
          <octave>5</octave>
        </pitch>
        <duration>18</duration>
        <voice>1</voice>
        <type>quarter</type>
        <dot/>
        <stem>down</stem>
        <staff>1</staff>
        <notations>
          <slur type="start" number="1" orientation="over"/>
        </notations>
      </note>
      <note>
        <pitch>
          <step>C</step>
          <alter>1</alter>
          <octave>5</octave>
        </pitch>
        <duration>6</duration>
        <voice>1</voice>
        <type>eighth</type>
        <stem>down</stem>
        <staff>1</staff>
        <notations>
          <slur type="stop" number="1" orientation="over"/>
        </notations>
      </note>
    </measure>
  </part>

</score-partwise>