Search in sources :

Example 21 with Pitch

use of com.xenoage.zong.core.music.Pitch 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 22 with Pitch

use of com.xenoage.zong.core.music.Pitch 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 23 with Pitch

use of com.xenoage.zong.core.music.Pitch 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 24 with Pitch

use of com.xenoage.zong.core.music.Pitch in project Zong by Xenoage.

the class Utils method gr.

/**
 * Sets the given chord to a grace chord.
 */
public static Chord gr(Fraction graceDuration, boolean slash, Pitch... pitches) {
    Grace grace = new Grace(slash, graceDuration);
    ArrayList<Note> notes = alist();
    for (Pitch pitch : pitches) notes.add(new Note(pitch));
    return new Chord(notes, grace);
}
Also used : Grace(com.xenoage.zong.core.music.chord.Grace) Note(com.xenoage.zong.core.music.chord.Note) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord)

Aggregations

Pitch (com.xenoage.zong.core.music.Pitch)24 Chord (com.xenoage.zong.core.music.chord.Chord)12 Test (org.junit.Test)11 MP (com.xenoage.zong.core.position.MP)4 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)4 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)4 Staff (com.xenoage.zong.core.music.Staff)3 Note (com.xenoage.zong.core.music.chord.Note)3 Rest (com.xenoage.zong.core.music.rest.Rest)3 Score (com.xenoage.zong.core.Score)2 Measure (com.xenoage.zong.core.music.Measure)2 Voice (com.xenoage.zong.core.music.Voice)2 VoiceElement (com.xenoage.zong.core.music.VoiceElement)2 Grace (com.xenoage.zong.core.music.chord.Grace)2 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)2 Cursor (com.xenoage.zong.io.selection.Cursor)2 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)2 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)2 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)2 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2