Search in sources :

Example 1 with MxlDirection

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

the class MeasureReader method readToContext.

/**
 * Reads the given measure element.
 */
public static void readToContext(MxlMeasure mxlMeasure, int measureIndex, Context context) {
    // begin a new measure
    context.beginNewMeasure(measureIndex);
    // list all elements
    List<MxlMusicDataContent> content = mxlMeasure.getMusicData().getContent();
    for (int i = 0; i < content.size(); i++) {
        // i may be modified within this loop
        MxlMusicDataContent mxlMDC = content.get(i);
        switch(mxlMDC.getMusicDataContentType()) {
            case Note:
                {
                    MxlNote mxlNote = ((MxlNote) mxlMDC);
                    // when it is a chord, ignore it, because we did already read it
                    if (mxlNote.getContent().getFullNote().isChord()) {
                        continue;
                    }
                    // instrument change?
                    MxlInstrument mxlInstrument = mxlNote.getInstrument();
                    if (mxlInstrument != null) {
                        String instrumentID = mxlInstrument.getId();
                        if (context.getInstrumentID() == null || !context.getInstrumentID().equals(instrumentID)) {
                            // instrument change detected!
                            context.writeInstrumentChange(instrumentID);
                        }
                    }
                    // collect all following notes which have a chord-element
                    // inbetween there may be direction elements, so we collect the
                    // notes until the first non-chord or non-direction element and after
                    // that go on at the current position + 1
                    List<MxlNote> mxlNotes = alist(mxlNote);
                    for (int i2 = i + 1; i2 < content.size(); i2++) {
                        MxlMusicDataContent mxlMDC2 = content.get(i2);
                        boolean goOn = false;
                        if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Note) {
                            MxlNote mxlNote2 = (MxlNote) mxlMDC2;
                            if (mxlNote2.getContent().getFullNote().isChord()) {
                                mxlNotes.add(mxlNote2);
                                goOn = true;
                            }
                        } else if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Direction) {
                            goOn = true;
                        }
                        if (!goOn)
                            break;
                    }
                    new ChordReader(mxlNotes).readToContext(context);
                    break;
                }
            case Attributes:
                new AttributesReader((MxlAttributes) mxlMDC).readToContext(context);
                break;
            case Backup:
                readBackupToContext((MxlBackup) mxlMDC, context);
                break;
            case Forward:
                readForwardToContext((MxlForward) mxlMDC, context);
                break;
            case Print:
                new PrintReader((MxlPrint) mxlMDC).readToContext(context);
                break;
            case Direction:
                new DirectionReader((MxlDirection) mxlMDC).readToContext(context);
                break;
            case Barline:
                new BarlineReader((MxlBarline) mxlMDC).readToContext(context);
                break;
        }
    }
}
Also used : MxlInstrument(com.xenoage.zong.musicxml.types.MxlInstrument) MxlPrint(com.xenoage.zong.musicxml.types.MxlPrint) MxlBarline(com.xenoage.zong.musicxml.types.MxlBarline) MxlPrint(com.xenoage.zong.musicxml.types.MxlPrint) MxlDirection(com.xenoage.zong.musicxml.types.MxlDirection) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlAttributes(com.xenoage.zong.musicxml.types.MxlAttributes) List(java.util.List)

Example 2 with MxlDirection

use of com.xenoage.zong.musicxml.types.MxlDirection 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)

Aggregations

MxlDirection (com.xenoage.zong.musicxml.types.MxlDirection)2 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2 Tuple2 (com.xenoage.utils.kernel.Tuple2)1 Direction (com.xenoage.zong.core.music.direction.Direction)1 MxlAttributes (com.xenoage.zong.musicxml.types.MxlAttributes)1 MxlBarline (com.xenoage.zong.musicxml.types.MxlBarline)1 MxlDynamics (com.xenoage.zong.musicxml.types.MxlDynamics)1 MxlInstrument (com.xenoage.zong.musicxml.types.MxlInstrument)1 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)1 MxlPrint (com.xenoage.zong.musicxml.types.MxlPrint)1 MxlWords (com.xenoage.zong.musicxml.types.MxlWords)1 MxlDirectionTypeContent (com.xenoage.zong.musicxml.types.choice.MxlDirectionTypeContent)1 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)1 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)1 List (java.util.List)1 Test (org.junit.Test)1