XML Parsing |
||||||
NavigationNext - Previous TOC
|
Here is a sample of a music XML file :
<measure number="1">
<attributes>
<divisions>24</divisions>
<key>
<fifths>-3</fifths>
<mode>major</mode>
</key>
<time>
<beats>3</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<words font-weight="bold" relative-x="-40">Andantino</words>
</direction-type>
<sound tempo="60"/>
</direction>
<note>
<rest/>
<duration>72</duration>
<voice>1</voice>
</note>
We see that the measure has time attributes
i.e : we have a mesure 3/4 in which each beat is divided into 24 divisions.
Then in the measure 1 there is a rest.
The measure last 72, since 3*24 = 72, it last the whole measure. In the program we call this quantity TotalDivisions.
We notice that the type of the rest had not been specified so the program will have to determine that it is a whole. At first we always specify the type of the note, but it is not standard music XML
then let's go ahead :
<measure number="2"> <direction placement="above"> <direction-type> <words font-style="italic" relative-x="-12">dolce</words> </direction-type> </direction> <note> <pitch> <step>G</step> <octave>4</octave> </pitch> <duration>24</duration> <voice>1</voice> <type>quarter</type> <stem>up</stem> <notations/> <lyric number="1"> <syllabic>single</syllabic> <text>Dans</text> </lyric> </note> <direction placement="above"> <direction-type> <wedge type="crescendo" spread="0" relative-y="5"/> </direction-type> <offset>-8</offset> </direction> <note> <pitch> <step>C</step> <octave>5</octave> </pitch> <duration>24</duration> <voice>1</voice> <type>quarter</type> <stem>down</stem> <lyric number="1"> <syllabic>single</syllabic> <text>un</text> </lyric> </note> <note> <pitch> <step>D</step> <octave>5</octave> </pitch> <duration>24</duration> <voice>1</voice> <type>quarter</type> <stem>down</stem> <lyric number="1"> <syllabic>begin</syllabic> <text>som</text> </lyric> </note> <direction> <direction-type> <wedge type="stop" spread="11"/> </direction-type> <offset>-11</offset> </direction> </measure>
We build one by one all the measures. To know the time position of a note we only need to know its position in the measure section. The computation of the start time is done by iterating on the current position and the lasting of the inserted note. We take the last position of the note and add its lasting.
There are some exeptions to this when the note we are appending is part of a chord. See chords
G in measure 2 is
position 0 lasting 24
We note 2:0 its position
and C
position 24 lasting 24
we note 2:24 its position
D
position 48 lasting 24
we note 2:48 its position
Now let us consider the first measure of the MozarVielSample
<measure number="1"> <note> <pitch> <step>D</step> <octave>5</octave> </pitch> <duration>2</duration> <voice>1</voice> <type>eighth</type> <stem>up</stem> <staff>1</staff> <beam number="1">begin</beam> <notations> <slur type="start" number="1"/> </notations> </note> <note> <pitch> <step>B</step> <octave>4</octave> </pitch> <duration>2</duration> <voice>1</voice> <type>eighth</type> <stem>up</stem> <staff>1</staff> <beam number="1">continue</beam> </note> <note> <pitch> <step>C</step> <octave>5</octave> </pitch> <duration>2</duration> <voice>1</voice> <type>eighth</type> <stem>up</stem> <staff>1</staff> <beam number="1">continue</beam> </note> <note> <pitch> <step>E</step> <octave>5</octave> </pitch> <duration>2</duration> <voice>1</voice> <type>eighth</type> <stem>up</stem> <staff>1</staff> <beam number="1">end</beam> <notations> <slur type="stop" number="1"/> </notations> </note> <backup> <duration>8</duration> </backup> <note> <pitch> <step>G</step> <octave>4</octave> </pitch> <duration>8</duration> <voice>2</voice> <type>half</type> <stem>down</stem> <staff>1</staff> </note> <backup> <duration>8</duration> </backup> <note> <pitch> <step>B</step> <octave>3</octave> </pitch> <duration>2</duration> <voice>5</voice> <type>eighth</type> <stem>down</stem> <staff>2</staff> <beam number="1">begin</beam> <notations> <slur type="start" number="1"/> </notations> </note> <note> <pitch> <step>G</step> <octave>3</octave> </pitch> <duration>2</duration> <voice>5</voice> <type>eighth</type> <stem>down</stem> <staff>2</staff> <beam number="1">continue</beam> </note> <note> <pitch> <step>A</step> <octave>3</octave> </pitch> <duration>2</duration> <voice>5</voice> <type>eighth</type> <stem>down</stem> <staff>2</staff> <beam number="1">continue</beam> </note> <note> <pitch> <step>C</step> <octave>4</octave> </pitch> <duration>2</duration> <voice>5</voice> <type>eighth</type> <stem>down</stem> <staff>2</staff> <beam number="1">end</beam> <notations> <slur type="stop" number="1"/> </notations> </note> </measure>