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);
}
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);
}
}
}
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;
}
}
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);
}
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");
}
Aggregations