Search in sources :

Example 1 with MxlDirectionTypeContent

use of com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent in project Zong by Xenoage.

the class Test21d method test.

@Test
public void test() {
    MxlPart part = getFirstPart();
    List<Tuple2<MP, ? extends Direction>> expectedDirections = getExpectedDirections();
    // check only directions in this test
    int iDirection = 0;
    for (int iMeasure = 0; iMeasure <= 1; iMeasure++) {
        MxlMeasure measure = part.getMeasures().get(iMeasure);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Direction) {
                // check type
                MxlDirection dir = (MxlDirection) data;
                MxlDirectionTypeContent content = dir.getDirectionTypes().get(0).getContent();
                if (iDirection == 0) {
                    // Words "Largo"
                    assertEquals(0, iMeasure);
                    assertEquals(MxlDirectionTypeContentType.Words, content.getDirectionTypeContentType());
                    assertEquals("Largo", ((MxlWords) content).getFormattedText().getValue());
                } else if (iDirection == 1) {
                    // Dynamic "fp"
                    assertEquals(0, iMeasure);
                    assertEquals(MxlDirectionTypeContentType.Dynamics, content.getDirectionTypeContentType());
                    assertEquals(DynamicValue.fp, ((MxlDynamics) content).getElement());
                } else if (iDirection == 2) {
                    // Dynamic "p"
                    assertEquals(1, iMeasure);
                    assertEquals(MxlDirectionTypeContentType.Dynamics, content.getDirectionTypeContentType());
                    assertEquals(DynamicValue.p, ((MxlDynamics) content).getElement());
                }
                iDirection++;
            }
        }
    }
    assertEquals("not all directions found", expectedDirections.size(), iDirection);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlDynamics(com.xenoage.zong.musicxml.types.MxlDynamics) Tuple2(com.xenoage.utils.kernel.Tuple2) MxlDirectionTypeContent(com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent) MxlWords(com.xenoage.zong.musicxml.types.MxlWords) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlDirection(com.xenoage.zong.musicxml.types.MxlDirection) Direction(com.xenoage.zong.core.music.direction.Direction) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MxlDirection(com.xenoage.zong.musicxml.types.MxlDirection) Test(org.junit.Test)

Example 2 with MxlDirectionTypeContent

use of com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent in project Zong by Xenoage.

the class MxlDirectionType method read.

/**
 * Returns null, if content is unsupported.
 */
@MaybeNull
public static MxlDirectionType read(XmlReader reader) {
    MxlDirectionTypeContent content = null;
    if (reader.openNextChildElement()) {
        String n = reader.getElementName();
        switch(// switch for performance
        n.charAt(0)) {
            case 'c':
                if (n.equals(MxlCoda.elemName))
                    content = MxlCoda.read(reader);
                break;
            case 'd':
                if (n.equals(MxlDynamics.elemName))
                    content = MxlDynamics.read(reader);
                break;
            case 'i':
                if (n.equals("image"))
                    content = MxlImage.read(reader);
                break;
            case 'p':
                if (n.equals(MxlPedal.elemName))
                    content = MxlPedal.read(reader);
                break;
            case 'm':
                if (n.equals(MxlMetronome.elemName))
                    content = MxlMetronome.read(reader);
                break;
            case 's':
                if (n.equals(MxlSegno.elemName))
                    content = MxlSegno.read(reader);
                break;
            case 'w':
                if (n.equals(MxlWedge.elemName))
                    content = MxlWedge.read(reader);
                else if (n.equals(MxlWords.elemName))
                    content = MxlWords.read(reader);
                break;
        }
        reader.closeElement();
    }
    if (content != null)
        return new MxlDirectionType(content);
    else
        return null;
}
Also used : MxlDirectionTypeContent(com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Aggregations

MxlDirectionTypeContent (com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 Tuple2 (com.xenoage.utils.kernel.Tuple2)1 Direction (com.xenoage.zong.core.music.direction.Direction)1 MxlDirection (com.xenoage.zong.musicxml.types.MxlDirection)1 MxlDynamics (com.xenoage.zong.musicxml.types.MxlDynamics)1 MxlWords (com.xenoage.zong.musicxml.types.MxlWords)1 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)1 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)1 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)1 Test (org.junit.Test)1