Search in sources :

Example 1 with MxlPart

use of com.xenoage.zong.musicxml.types.partwise.MxlPart in project Zong by Xenoage.

the class MxlScorePartwise method read.

@NonNull
public static MxlScorePartwise read(XmlReader reader, ErrorHandler errorHandler) {
    // attributes
    String version = notNull(reader.getAttribute("version"), defaultVersion);
    // elements
    MxlScoreHeader scoreHeader = new MxlScoreHeader();
    List<MxlPart> parts = alist();
    while (reader.openNextChildElement()) {
        if (reader.getElementName().equals(MxlPart.elemName))
            parts.add(MxlPart.read(reader));
        else
            scoreHeader.readElement(reader, errorHandler);
        reader.closeElement();
    }
    scoreHeader.check(reader);
    if (parts.size() < 1)
        throw reader.dataException("no parts found");
    return new MxlScorePartwise(scoreHeader, parts, version);
}
Also used : MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlScoreHeader(com.xenoage.zong.musicxml.types.groups.MxlScoreHeader) NonNull(com.xenoage.utils.annotations.NonNull)

Example 2 with MxlPart

use of com.xenoage.zong.musicxml.types.partwise.MxlPart in project Zong by Xenoage.

the class Test02a method test.

@ToDo("multirests are not supported yet")
@Test
public void test() {
    MxlPart part = getFirstPart();
    int iDuration = 0;
    // from MusicXML file
    int divisions = 64;
    for (int iM = 0; iM < part.getMeasures().size(); iM++) {
        MxlMeasure measure = part.getMeasures().get(iM);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Note) {
                // check type and duration
                MxlNormalNote note = (MxlNormalNote) ((MxlNote) data).getContent();
                assertEquals(MxlFullNoteContentType.Rest, note.getFullNote().getContent().getFullNoteContentType());
                assertEquals("rest " + iDuration, expectedDurations[iDuration++], Companion.fr(note.getDuration(), divisions * 4));
            }
        }
    }
    assertEquals("not all rests found", expectedDurations.length, iDuration);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 3 with MxlPart

use of com.xenoage.zong.musicxml.types.partwise.MxlPart in project Zong by Xenoage.

the class Test03a method test.

@ToDo("multiple-rest not yet supported")
@Test
public void test() {
    MxlPart part = getFirstPart();
    int iDuration = 0;
    // from MusicXML file
    int divisions = 64;
    for (int iM = 0; iM < part.getMeasures().size(); iM++) {
        MxlMeasure measure = part.getMeasures().get(iM);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Note) {
                // check type and duration
                MxlNormalNote note = (MxlNormalNote) ((MxlNote) data).getContent();
                assertEquals(MxlFullNoteContentType.Pitch, note.getFullNote().getContent().getFullNoteContentType());
                assertEquals("note " + iDuration, expectedDurations[iDuration++], Companion.fr(note.getDuration(), divisions * 4));
            }
        }
    }
    assertEquals("not all notes found", expectedDurations.length, iDuration);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 4 with MxlPart

use of com.xenoage.zong.musicxml.types.partwise.MxlPart in project Zong by Xenoage.

the class Test11a method test.

@Test
public void test() {
    MxlPart part = getFirstPart();
    int iTime = 0;
    for (int i = 0; i < part.getMeasures().size(); i++) {
        MxlMeasure measure = part.getMeasures().get(i);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Attributes) {
                // check type
                MxlAttributes attr = (MxlAttributes) data;
                MxlNormalTime mxlTime = (MxlNormalTime) attr.getTime().getContent();
                TimeType expectedTime = expectedTimes[iTime++];
                assertEquals("time " + iTime, expectedTime.getNumerator(), mxlTime.getBeats());
                assertEquals("time " + iTime, expectedTime.getDenominator(), mxlTime.getBeatType());
                if (i == 0)
                    // TODO: bug in MusicXML file, should be "Cut"
                    assertEquals("time " + iTime, MxlTimeSymbol.Common, attr.getTime().getSymbol());
                else if (i == 1)
                    assertEquals("time " + iTime, MxlTimeSymbol.Common, attr.getTime().getSymbol());
                else
                    // = Normal
                    assertNull("time " + iTime, attr.getTime().getSymbol());
                // no more time signature in this measure
                break;
            }
        }
    }
    assertEquals("not all times found", expectedTimes.length, iTime);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlAttributes(com.xenoage.zong.musicxml.types.MxlAttributes) MxlNormalTime(com.xenoage.zong.musicxml.types.MxlNormalTime) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) TimeType(com.xenoage.zong.core.music.time.TimeType) Test(org.junit.Test)

Example 5 with MxlPart

use of com.xenoage.zong.musicxml.types.partwise.MxlPart in project Zong by Xenoage.

the class Test13a method test.

@ToDo("Zong! supports only -7 to +7, starting in measure 9, ending in measure 38")
@Test
public void test() {
    MxlPart part = getFirstPart();
    TraditionalKey[] expectedKeys = getExpectedKeys();
    int iKey = 0;
    for (int i = 8; i <= 37; i++) {
        MxlMeasure measure = part.getMeasures().get(i);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Attributes) {
                // check type
                MxlAttributes attr = (MxlAttributes) data;
                MxlKey key = attr.getKey();
                assertEquals(expectedKeys[iKey].getFifths(), key.getFifths());
                assertEquals(expectedKeys[iKey].getMode(), getEnumValue("" + key.getMode(), Mode.values()));
                iKey++;
            }
        }
    }
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlAttributes(com.xenoage.zong.musicxml.types.MxlAttributes) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) MxlKey(com.xenoage.zong.musicxml.types.MxlKey) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Aggregations

MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)12 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)10 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)9 Test (org.junit.Test)8 ToDo (musicxmltestsuite.tests.utils.ToDo)4 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)3 MxlAttributes (com.xenoage.zong.musicxml.types.MxlAttributes)3 Pitch (com.xenoage.zong.core.music.Pitch)2 MxlKey (com.xenoage.zong.musicxml.types.MxlKey)2 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)2 MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)2 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)2 NonNull (com.xenoage.utils.annotations.NonNull)1 Tuple2 (com.xenoage.utils.kernel.Tuple2)1 Fraction (com.xenoage.utils.math.Fraction)1 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)1 MeasureAddUpTo (com.xenoage.zong.commands.core.music.MeasureAddUpTo)1 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)1 VoiceElementWrite (com.xenoage.zong.commands.core.music.VoiceElementWrite)1 Measure (com.xenoage.zong.core.music.Measure)1