Search in sources :

Example 1 with MxlFullNote

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

the class Test01b method test.

@Test
public void test() {
    Pitch[] expectedPitches = getExpectedPitches();
    MxlPart part = getFirstPart();
    int iPitch = 0;
    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 note and pitch
                MxlFullNote note = ((MxlNote) data).getContent().getFullNote();
                MxlPitch pitch = (MxlPitch) (note.getContent());
                assertEquals("note " + iPitch, expectedPitches[iPitch++], pitch.getPitch());
            }
        }
    }
    assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) Pitch(com.xenoage.zong.core.music.Pitch) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) Test(org.junit.Test)

Example 2 with MxlFullNote

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

the class MxlGraceNote method read.

public static MxlGraceNote read(XmlReader reader) {
    MxlGraceNote ret = new MxlGraceNote();
    ret.fullNote = new MxlFullNote();
    ret.slash = MxlYesNo.read(reader.getAttribute("slash"));
    return ret;
}
Also used : MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote)

Example 3 with MxlFullNote

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

Example 4 with MxlFullNote

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

the class Test01a method test.

@ToDo("the editiorial sharp (sharp in parenthesis) in the last measure is not supported yet")
@Test
public void test() {
    Pitch[] expectedPitches = getExpectedPitches();
    MxlPart part = getFirstPart();
    assertEquals(26, part.getMeasures().size());
    int iPitch = 0;
    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 note and pitch
                MxlFullNote note = ((MxlNote) data).getContent().getFullNote();
                MxlPitch pitch = (MxlPitch) (note.getContent());
                assertEquals("note " + iPitch, expectedPitches[iPitch++], pitch.getPitch());
            }
        }
    }
    assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) Pitch(com.xenoage.zong.core.music.Pitch) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 5 with MxlFullNote

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

the class Test01c method test.

@Test
public void test() {
    MxlMeasure measure = getFirstMeasure();
    for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
        if (data.getMusicDataContentType() == MxlMusicDataContentType.Note) {
            // check pitch
            MxlNote note = (MxlNote) data;
            MxlFullNote fullNote = note.getContent().getFullNote();
            MxlPitch pitch = (MxlPitch) (fullNote.getContent());
            assertEquals(Companion.pi('G', 0, 4), pitch.getPitch());
            // check lyric
            assertEquals(1, note.getLyrics().size());
            assertEquals("A", ((MxlSyllabicText) note.getLyrics().get(0).getContent()).getText().getValue());
            return;
        }
    }
    fail("note not found");
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlSyllabicText(com.xenoage.zong.musicxml.types.MxlSyllabicText) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) Test(org.junit.Test)

Aggregations

MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)5 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)4 Pitch (com.xenoage.zong.core.music.Pitch)3 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)3 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)3 Test (org.junit.Test)3 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)2 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)2 Fraction (com.xenoage.utils.math.Fraction)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 MxlSyllabicText (com.xenoage.zong.musicxml.types.MxlSyllabicText)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 MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)1 MxlNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlNoteContent.MxlNoteContentType)1 ToDo (musicxmltestsuite.tests.utils.ToDo)1