Search in sources :

Example 1 with MxlNormalNote

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

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

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

the class ChordReader method readFirstNote.

private void readFirstNote() {
    mxlFirstNote = mxlNotes.get(0);
    MxlNoteContentType mxlFirstNoteType = mxlFirstNote.getContent().getNoteContentType();
    // type of chord/rest
    // (unpitched is still unsupported)
    MxlFullNote mxlFirstFullNote = mxlFirstNote.getContent().getFullNote();
    MxlNormalNote mxlFirstNormalNote = null;
    MxlCueNote mxlFirstCueNote = null;
    MxlGraceNote mxlFirstGraceNote = null;
    boolean isCue = false;
    boolean isGrace = false;
    if (mxlFirstNoteType == MxlNoteContentType.Normal) {
        mxlFirstNormalNote = (MxlNormalNote) mxlNotes.get(0).getContent();
    } else if (mxlFirstNoteType == MxlNoteContentType.Cue) {
        mxlFirstCueNote = (MxlCueNote) mxlNotes.get(0).getContent();
        isCue = true;
    } else if (mxlFirstNoteType == MxlNoteContentType.Grace) {
        mxlFirstGraceNote = (MxlGraceNote) mxlNotes.get(0).getContent();
        isGrace = true;
        // may also be true later, see (TODO) "Zong-Library/Discussions/MusicXML/Note - cue vs grace.txt"
        isCue = false;
    }
    MxlFullNoteContentType mxlFNCType = mxlFirstFullNote.getContent().getFullNoteContentType();
    // duration. here, the first duration is the duration of the whole chord.
    Fraction duration = Companion.get_0();
    if (mxlFirstNormalNote != null) {
        duration = readDuration(mxlFirstNormalNote.getDuration(), context.getDivisions());
    } else if (mxlFirstCueNote != null) {
        duration = readDuration(mxlFirstCueNote.getDuration(), context.getDivisions());
    }
    // when duration of normal note is 0, ignore the chord
    if (false == isGrace && false == duration.isGreater0()) {
        context.reportError("duration of chord is 0");
        return;
    }
    // create new chord or rest
    if (mxlFNCType == MxlFullNoteContentType.Pitch || mxlFNCType == MxlFullNoteContentType.Unpitched) {
        // create a chord
        Pitch pitch;
        if (mxlFNCType == MxlFullNoteContentType.Pitch)
            pitch = ((MxlPitch) mxlFirstFullNote.getContent()).getPitch();
        else
            // TODO (ZONG-96): better support for unpitched notes
            pitch = Pitch.Companion.pi(0, 4);
        Grace grace = null;
        if (mxlFirstGraceNote != null) {
            // read grace duration from note-type ("eighth", "16th", ...)
            Fraction graceDuration = Companion.fr(1, 8);
            if (mxlFirstNote.getNoteType() != null)
                graceDuration = mxlFirstNote.getNoteType().getDuration();
            boolean slash = mxlFirstGraceNote.getSlash() == MxlYesNo.Yes;
            grace = new Grace(slash, graceDuration);
            chord = new Chord(alist(new Note(pitch)), grace);
        } else {
            chord = new Chord(alist(new Note(pitch)), duration);
        }
        chord.setCue(isCue);
        chordOrRest = chord;
    } else if (mxlFNCType == MxlFullNoteContentType.Rest) {
        // create a rest
        Rest rest = new Rest(duration);
        rest.setCue(isCue);
        chordOrRest = rest;
    }
}
Also used : MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlCueNote(com.xenoage.zong.musicxml.types.choice.MxlCueNote) Grace(com.xenoage.zong.core.music.chord.Grace) Fraction(com.xenoage.utils.math.Fraction) MxlFullNoteContentType(com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent.MxlFullNoteContentType) Rest(com.xenoage.zong.core.music.rest.Rest) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlGraceNote(com.xenoage.zong.musicxml.types.choice.MxlGraceNote) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) Note(com.xenoage.zong.core.music.chord.Note) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) MxlCueNote(com.xenoage.zong.musicxml.types.choice.MxlCueNote) MxlGraceNote(com.xenoage.zong.musicxml.types.choice.MxlGraceNote) Pitch(com.xenoage.zong.core.music.Pitch) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) MxlNoteContentType(com.xenoage.zong.musicxml.types.choice.MxlNoteContent.MxlNoteContentType) Chord(com.xenoage.zong.core.music.chord.Chord)

Aggregations

MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)3 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)2 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)2 ToDo (musicxmltestsuite.tests.utils.ToDo)2 Test (org.junit.Test)2 Fraction (com.xenoage.utils.math.Fraction)1 Pitch (com.xenoage.zong.core.music.Pitch)1 Chord (com.xenoage.zong.core.music.chord.Chord)1 Grace (com.xenoage.zong.core.music.chord.Grace)1 Note (com.xenoage.zong.core.music.chord.Note)1 Rest (com.xenoage.zong.core.music.rest.Rest)1 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)1 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)1 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)1 MxlFullNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent.MxlFullNoteContentType)1 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)1 MxlNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlNoteContent.MxlNoteContentType)1 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)1