Search in sources :

Example 1 with MxlMusicDataContent

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

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

the class MxlMusicData method readElement.

public void readElement(XmlReader reader) {
    MxlMusicDataContent item = null;
    String n = reader.getElementName();
    switch(// switch for performance
    n.charAt(0)) {
        case 'a':
            if (n.equals(MxlAttributes.elemName))
                item = MxlAttributes.read(reader);
            break;
        case 'b':
            if (n.equals(MxlBackup.elemName))
                item = MxlBackup.read(reader);
            else if (n.equals(MxlBarline.elemName))
                item = MxlBarline.read(reader);
            break;
        case 'd':
            if (n.equals(MxlDirection.elemName))
                item = MxlDirection.read(reader);
            break;
        case 'f':
            if (n.equals(MxlForward.elemName))
                item = MxlForward.read(reader);
            break;
        case 'n':
            if (n.equals(MxlNote.elemName))
                item = MxlNote.read(reader);
            break;
        case 'p':
            if (n.equals(MxlPrint.elemName))
                item = MxlPrint.read(reader);
            break;
    }
    if (item != null)
        content.add(item);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)

Example 3 with MxlMusicDataContent

use of com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent 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 4 with MxlMusicDataContent

use of com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent 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 5 with MxlMusicDataContent

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

Aggregations

MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)13 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)11 Test (org.junit.Test)10 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)9 MxlAttributes (com.xenoage.zong.musicxml.types.MxlAttributes)4 ToDo (musicxmltestsuite.tests.utils.ToDo)4 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)3 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)3 Pitch (com.xenoage.zong.core.music.Pitch)2 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)2 MxlDirection (com.xenoage.zong.musicxml.types.MxlDirection)2 MxlKey (com.xenoage.zong.musicxml.types.MxlKey)2 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)2 MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)2 Tuple2 (com.xenoage.utils.kernel.Tuple2)1 Direction (com.xenoage.zong.core.music.direction.Direction)1 TimeType (com.xenoage.zong.core.music.time.TimeType)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