Skip to content

Commit

Permalink
Merge pull request #100 from otsob/issue#3
Browse files Browse the repository at this point in the history
Issue #3: Add tests for reading MusicXML with pickup measure
  • Loading branch information
otsob authored May 15, 2019
2 parents 7c010ba + 0020240 commit 882bfd5
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/test/java/org/wmn4j/io/musicxml/MusicXmlReaderDomTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -707,4 +707,47 @@ public void testReadingFileThatDoesNotExistToScoreBuilder() {
// Pass the test, this exception is expected.
}
}

@Test
public void testReadingScoreWithPickupMeasure() {
final MusicXmlReader reader = new MusicXmlReaderDom(true);
try {
Score scoreWithPickup = reader
.readScore(Paths.get(TestHelper.TESTFILE_PATH + MUSICXML_FILE_PATH + "pickup_measure_test.xml"));
assertPickupMeasureReadCorrectly(scoreWithPickup);
} catch (Exception exception) {
fail("Reading score with pickup measure failed with " + exception);
}
}

@Test
public void testReadingScoreBuilderWithPickupMeasure() {
final MusicXmlReader reader = new MusicXmlReaderDom(true);
try {
ScoreBuilder scoreWithPickup = reader
.readScoreBuilder(
Paths.get(TestHelper.TESTFILE_PATH + MUSICXML_FILE_PATH + "pickup_measure_test.xml"));
assertPickupMeasureReadCorrectly(scoreWithPickup.build());
} catch (Exception exception) {
fail("Reading score with pickup measure failed with " + exception);
}
}

private void assertPickupMeasureReadCorrectly(Score score) {
assertEquals(1, score.getPartCount());
Part part = score.getParts().get(0);
assertFalse(part.isMultiStaff());
assertEquals(4, part.getMeasureCount());
assertEquals(3, part.getFullMeasureCount());

assertTrue(part instanceof SingleStaffPart);
Staff staff = ((SingleStaffPart) part).getStaff();
assertTrue(staff.hasPickupMeasure());
assertEquals(4, staff.getMeasureCount());
assertEquals(3, staff.getFullMeasureCount());

Measure pickupMeasure = staff.getMeasure(0);
assertTrue(pickupMeasure.isPickUp());
assertEquals(0, pickupMeasure.getNumber());
}
}
129 changes: 129 additions & 0 deletions src/test/resources/musicxml/pickup_measure_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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.0.0</software>
<encoding-date>2019-05-15</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>
<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.275" default-y="1627.08" justify="center" valign="top" font-size="24">Pickup measure test</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="0" implicit="yes" width="235.29">
<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>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 default-x="79.27" default-y="-25.00">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<note default-x="156.48" default-y="-25.00">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
</measure>
<measure number="1" width="279.38">
<note default-x="10.00" default-y="-25.00">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="2" width="279.38">
<note default-x="10.00" default-y="-25.00">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="3" width="283.11">
<note default-x="10.00" default-y="-25.00">
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>

0 comments on commit 882bfd5

Please sign in to comment.