/** Reads the given measure element. */ private static MusicReaderContext readMeasure( MusicReaderContext context, MxlMeasure mxlMeasure, int measureIndex) { // begin a new measure context = context.beginNewMeasure(measureIndex); // list all elements PVector<MxlMusicDataContent> content = mxlMeasure.getMusicData().getContent(); for (int i = 0; i < content.size(); i++) { MxlMusicDataContent mxlMDC = content.get(i); switch (mxlMDC.getMusicDataContentType()) { case Note: { // collect all directly following notes with have a chord-element PVector<MxlNote> mxlNotes = pvec((MxlNote) mxlMDC); for (int i2 = i + 1; i2 < content.size(); i2++) { boolean found = false; MxlMusicDataContent mxlMDC2 = content.get(i2); if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Note) { MxlNote mxlNote2 = (MxlNote) mxlMDC2; if (mxlNote2.getContent().getNoteContentType() == MxlNoteContentType.Normal) { if (((MxlNormalNote) mxlNote2.getContent()).getFullNote().isChord()) { mxlNotes = mxlNotes.plus(mxlNote2); i++; found = true; } } } if (!found) break; } context = readChord(context, mxlNotes); break; } case Attributes: context = readAttributes(context, (MxlAttributes) mxlMDC); break; case Backup: context = readBackup(context, (MxlBackup) mxlMDC); break; case Forward: context = readForward(context, (MxlForward) mxlMDC); break; case Print: context = readPrint(context, (MxlPrint) mxlMDC); break; case Direction: context = readDirection(context, (MxlDirection) mxlMDC); break; case Barline: context = readBarline(context, (MxlBarline) mxlMDC); break; } } return context; }
@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) { // Dynamics "fp" assertEquals(0, iMeasure); assertEquals( MxlDirectionTypeContentType.Dynamics, content.getDirectionTypeContentType()); assertEquals(DynamicsType.fp, ((MxlDynamics) content).getElement()); } else if (iDirection == 2) { // Dynamics "p" assertEquals(1, iMeasure); assertEquals( MxlDirectionTypeContentType.Dynamics, content.getDirectionTypeContentType()); assertEquals(DynamicsType.p, ((MxlDynamics) content).getElement()); } iDirection++; } } } assertEquals("not all directions found", expectedDirections.size(), iDirection); }