use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class VoiceElementWriteTest method testGraceAdd.
/**
* Writes grace notes in a voice.
* <pre>
* ..
* into aabb__ccddeeffgghh
* => aabb..ccddeeffgghh</pre>
*/
@Test
public void testGraceAdd() {
Score score = createTestScoreEighths();
CommandPerformer cp = score.getCommandPerformer();
// in voice 1, write two grace notes
Voice voice = score.getVoice(atVoice(0, 0, 1));
Chord g1 = grace(1), g2 = grace(2);
cp.execute(new VoiceElementWrite(voice, atElement(0, 0, 1, 2), g1, null));
cp.execute(new VoiceElementWrite(voice, atElement(0, 0, 1, 3), g2, null));
// now we must find the other elements unchanged but the grace notes inserted
assertEquals(10, voice.getElements().size());
assertEquals(Companion.fr(1, 8), getDur(voice, 0));
assertEquals(Companion.fr(1, 8), getDur(voice, 1));
assertEquals(Companion.fr(0), getDur(voice, 2));
assertEquals(Companion.fr(0), getDur(voice, 3));
assertEquals(Companion.fr(1, 8), getDur(voice, 4));
assertEquals(Companion.fr(1, 8), getDur(voice, 5));
assertEquals(Companion.fr(1, 8), getDur(voice, 6));
assertEquals(Companion.fr(1, 8), getDur(voice, 7));
assertEquals(Companion.fr(1, 8), getDur(voice, 8));
assertEquals(Companion.fr(1, 8), getDur(voice, 9));
// right elements?
assertEquals(g1, voice.getElement(2));
assertEquals(g2, voice.getElement(3));
// test undo
cp.undoMultipleSteps(2);
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class VoiceTest method grace.
public static Chord grace(int step) {
Chord chord = new Chord(new Note(Companion.pi(step, 0)), Companion.fr(0, 4));
chord.setGrace(new Grace(true, Companion.fr(1, 16)));
return chord;
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class VoiceTest method getElementIndexTest.
@Test
public void getElementIndexTest() {
// our test example: (g: grace note)
// Beats: 0 1 2 3 4 5
// Elements |g1|-----a-----|g2|g3|--b--|--c--|g4|
// Indices 0 1 2 3 4 5 6 7
// Checked: x x x x x x
Rest a = new Rest(Companion.fr(2)), b = new Rest(Companion.fr(1)), c = new Rest(Companion.fr(1));
Chord g1 = grace(1), g2 = grace(2), g3 = grace(3), g4 = grace(4);
Voice voice = new Voice(ilist(g1, a, g2, g3, b, c, g4));
assertEquals(1, voice.getElementIndex(Companion.fr(0)));
assertEquals(1, voice.getElementIndex(Companion.fr(1)));
assertEquals(4, voice.getElementIndex(Companion.fr(2)));
assertEquals(5, voice.getElementIndex(Companion.fr(3)));
assertEquals(7, voice.getElementIndex(Companion.fr(4)));
assertEquals(7, voice.getElementIndex(Companion.fr(5)));
}
use of com.xenoage.zong.core.music.chord.Chord 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.Chord in project Zong by Xenoage.
the class Test21a method test.
@Test
public void test() {
Chord chord = (Chord) getFirstVoice().getElement(0);
assertEquals(2, chord.getNotes().size());
assertEquals(expectedChord.getNotes(), chord.getNotes());
assertEquals(expectedChord.getDuration(), chord.getDuration());
}
Aggregations