MuseScoreがエクスポートするMusicXML、NEUTRINOが受け入れてくれる最低限のMusicXML

少し脱線。

f:id:tnantoka:20200305224247p:plain

こういうスコアをエクスポートした場合、以下のような.musicxmlが出力される。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
  <work>
    <work-title>Title</work-title>
    </work>
  <identification>
    <creator type="composer">Composer</creator>
    <encoding>
      <software>MuseScore 3.4.2</software>
      <encoding-date>2020-03-05</encoding-date>
      <supports element="accidental" type="yes"/>
      <supports element="beam" type="yes"/>
      <supports element="print" attribute="new-page" type="yes" value="yes"/>
      <supports element="print" attribute="new-system" type="yes" value="yes"/>
      <supports element="stem" type="yes"/>
      </encoding>
    </identification>
  <defaults>
    <scaling>
      <millimeters>7.05556</millimeters>
      <tenths>40</tenths>
      </scaling>
    <page-layout>
      <page-height>1683.36</page-height>
      <page-width>1190.88</page-width>
      <page-margins type="even">
        <left-margin>56.6929</left-margin>
        <right-margin>56.6929</right-margin>
        <top-margin>56.6929</top-margin>
        <bottom-margin>113.386</bottom-margin>
        </page-margins>
      <page-margins type="odd">
        <left-margin>56.6929</left-margin>
        <right-margin>56.6929</right-margin>
        <top-margin>56.6929</top-margin>
        <bottom-margin>113.386</bottom-margin>
        </page-margins>
      </page-layout>
    <word-font font-family="FreeSerif" font-size="10"/>
    <lyric-font font-family="FreeSerif" font-size="11"/>
    </defaults>
  <credit page="1">
    <credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">Title</credit-words>
    </credit>
  <credit page="1">
    <credit-words default-x="1134.19" default-y="1526.67" justify="right" valign="bottom" font-size="12">Composer</credit-words>
    </credit>
  <part-list>
    <score-part id="P1">
      <part-name>Piano</part-name>
      <part-abbreviation>Pno.</part-abbreviation>
      <score-instrument id="P1-I1">
        <instrument-name>Piano</instrument-name>
        </score-instrument>
      <midi-device id="P1-I1" port="1"></midi-device>
      <midi-instrument id="P1-I1">
        <midi-channel>1</midi-channel>
        <midi-program>1</midi-program>
        <volume>78.7402</volume>
        <pan>0</pan>
        </midi-instrument>
      </score-part>
    </part-list>
  <part id="P1">
    <measure number="1" width="372.34">
      <print>
        <system-layout>
          <system-margins>
            <left-margin>0.00</left-margin>
            <right-margin>0.00</right-margin>
            </system-margins>
          <top-system-distance>170.00</top-system-distance>
          </system-layout>
        </print>
      <attributes>
        <divisions>4</divisions>
        <key>
          <fifths>0</fifths>
          </key>
        <time>
          <beats>4</beats>
          <beat-type>4</beat-type>
          </time>
        </attributes>
      <note default-x="83.07" default-y="-50.00">
        <pitch>
          <step>C</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <voice>1</voice>
        <type>quarter</type>
        <stem>up</stem>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>ど</text>
          </lyric>
        </note>
      <note default-x="154.99" default-y="-45.00">
        <pitch>
          <step>D</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <voice>1</voice>
        <type>quarter</type>
        <stem>up</stem>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>れ</text>
          </lyric>
        </note>
      <note default-x="226.90" default-y="-40.00">
        <pitch>
          <step>E</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <voice>1</voice>
        <type>quarter</type>
        <stem>up</stem>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>み</text>
          </lyric>
        </note>
      <note default-x="298.82" default-y="-35.00">
        <pitch>
          <step>F</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <voice>1</voice>
        <type>quarter</type>
        <stem>up</stem>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>ふぁ</text>
          </lyric>
        </note>
      </measure>
    <measure number="2" width="278.59">
      <note default-x="10.54" default-y="-30.00">
        <pitch>
          <step>G</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <voice>1</voice>
        <type>quarter</type>
        <stem>up</stem>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>ソ</text>
          </lyric>
        </note>
      <note default-x="78.70" default-y="-25.00">
        <pitch>
          <step>A</step>
          <octave>4</octave>
          </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>eighth</type>
        <stem>up</stem>
        <beam number="1">begin</beam>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>ラ</text>
          </lyric>
        </note>
      <note default-x="128.28" default-y="-20.00">
        <pitch>
          <step>B</step>
          <octave>4</octave>
          </pitch>
        <duration>1</duration>
        <voice>1</voice>
        <type>16th</type>
        <stem>up</stem>
        <beam number="1">end</beam>
        <beam number="2">backward hook</beam>
        <lyric number="1" default-x="6.58" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>シ</text>
          </lyric>
        </note>
      <note>
        <rest/>
        <duration>1</duration>
        <voice>1</voice>
        <type>16th</type>
        </note>
      <note default-x="189.88" default-y="-20.00">
        <pitch>
          <step>B</step>
          <octave>4</octave>
          </pitch>
        <duration>8</duration>
        <voice>1</voice>
        <type>half</type>
        <stem>down</stem>
        <lyric number="1" default-x="6.94" default-y="-53.02" relative-y="-30.00">
          <syllabic>single</syllabic>
          <text>ド</text>
          </lyric>
        </note>
      </measure>
    <measure number="3" width="213.28">
      <note>
        <rest/>
        <duration>16</duration>
        <voice>1</voice>
        </note>
      </measure>
    <measure number="4" width="213.28">
      <note>
        <rest/>
        <duration>16</duration>
        <voice>1</voice>
        </note>
      <barline location="right">
        <bar-style>light-heavy</bar-style>
        </barline>
      </measure>
    </part>
  </score-partwise>

長い…。自分で書くのはとても無理。

ただ、かなりの情報がMuseScoreの編集のためにあるもののはずで、NEUTRINOに渡すものはもっとシンプルでいいはず。

ということで色々削ってみた結果、以下のXMLでも行けた。 (仕様上必須のとかも削っちゃってるかもしれないけど、実験なのでよしとする)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
  <part>
    <measure>
      <attributes>
        <divisions>4</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>
        <lyric>
          <text>ど</text>
          </lyric>
        </note>
      <note>
        <pitch>
          <step>D</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <lyric>
          <text>れ</text>
          </lyric>
        </note>
      <note>
        <pitch>
          <step>E</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <lyric>
          <text>み</text>
          </lyric>
        </note>
      <note>
        <pitch>
          <step>F</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <lyric>
          <text>ふぁ</text>
          </lyric>
        </note>
      </measure>
    <measure>
      <note>
        <pitch>
          <step>G</step>
          <octave>4</octave>
          </pitch>
        <duration>4</duration>
        <lyric>
          <text>ソ</text>
          </lyric>
        </note>
      <note>
        <pitch>
          <step>A</step>
          <octave>4</octave>
          </pitch>
        <duration>2</duration>
        <lyric>
          <text>ラ</text>
          </lyric>
        </note>
      <note>
        <pitch>
          <step>B</step>
          <octave>4</octave>
          </pitch>
        <duration>1</duration>
        <lyric>
          <text>シ</text>
          </lyric>
        </note>
      <note>
        <rest/>
        <duration>1</duration>
        </note>
      <note>
        <pitch>
          <step>B</step>
          <octave>4</octave>
          </pitch>
        <duration>8</duration>
        <lyric>
          <text>ド</text>
          </lyric>
        </note>
      </measure>
    <measure>
      <note>
        <rest/>
        <duration>16</duration>
        </note>
      </measure>
    <measure>
      <note>
        <rest/>
        <duration>16</duration>
        </note>
      </measure>
    </part>
  </score-partwise>

これなら自分でXMLを生成するのも無理ではないか?と思える長さにはなった。