use of com.xenoage.zong.core.music.chord.Note 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;
}
}
use of com.xenoage.zong.core.music.chord.Note 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);
}
Aggregations