Search in sources :

Example 1 with MxlPitch

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

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

the class ChordReader method addChordNote.

/**
 * Reads the given note element, which is part of
 * a chord (but not the first note element of the chord), and adds it to the given chord.
 * Also the notations of this note are read.
 */
private static void addChordNote(Context context, MxlNote mxlNote, Chord chord, int staffIndexInPart) {
    // only pitch is interesting for us, since we do not allow
    // different durations for notes within a chord or other strange stuff
    MxlFullNoteContent mxlFNC = mxlNote.getContent().getFullNote().getContent();
    if (mxlFNC.getFullNoteContentType() == MxlFullNoteContentType.Pitch) {
        Pitch pitch = ((MxlPitch) mxlFNC).getPitch();
        Note note = new Note(pitch);
        chord.addNote(note);
        // notations
        if (mxlNote.getNotations() != null) {
            new NotationsReader(mxlNote.getNotations()).readToNote(chord, chord.getNotes().indexOf(note), staffIndexInPart, context);
        }
    }
}
Also used : MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) 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) MxlFullNoteContent(com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent)

Example 3 with MxlPitch

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

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

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

MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)5 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)5 Pitch (com.xenoage.zong.core.music.Pitch)4 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)3 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)3 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)3 Test (org.junit.Test)3 Note (com.xenoage.zong.core.music.chord.Note)2 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)2 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)2 MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)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 Rest (com.xenoage.zong.core.music.rest.Rest)1 MxlSyllabicText (com.xenoage.zong.musicxml.types.MxlSyllabicText)1 MxlFullNoteContent (com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent)1 MxlFullNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent.MxlFullNoteContentType)1 MxlNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlNoteContent.MxlNoteContentType)1