use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method computeTestGrace.
/**
* Compute offsets of the common beats, when also grace notes are used.
*/
@Test
public void computeTestGrace() {
Score score = createTestScore3VoicesGrace();
BeatOffset[] beatOffsets = testee.compute(createVoiceSpacings(score), Companion.fr(4, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
float is = score.getFormat().getInterlineSpace();
// 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet
// ^: dominating voice
// voice 1: | 4 ...4 4 4 |
// ^^^^^^^^^ ^^^^^
// voice 2: | 8 8 8 8 ..2 |
// ^^^^^^^^
// voice 3: | 3 3 3 .8 8 4 |
// ^^^^^^
// used: * ** * ** * * * *
// checked: * * * * *
assertEquals(10, beatOffsets.length);
assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
assertEquals((0) * is, beatOffsets[0].getOffsetMm(), df);
assertEquals(Companion.fr(1, 4), beatOffsets[3].getBeat());
float offset1 = width_1_4 + 3 * width_grace;
assertEquals(offset1 * is, beatOffsets[3].getOffsetMm(), df);
assertEquals(Companion.fr(2, 4), beatOffsets[6].getBeat());
float offset2 = offset1 + 2 * width_1_8 + 2 * width_grace;
assertEquals(offset2 * is, beatOffsets[6].getOffsetMm(), df);
assertEquals(Companion.fr(3, 4), beatOffsets[8].getBeat());
float offset3 = offset2 + 2 * width_1_8;
assertEquals(offset3 * is, beatOffsets[8].getOffsetMm(), df);
assertEquals(Companion.fr(4, 4), beatOffsets[9].getBeat());
float offset4 = offset3 + width_1_4;
assertEquals(offset4 * is, beatOffsets[9].getOffsetMm(), df);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method computeBeatOffsets_File3.
/**
* Test file "BeatOffsetsStrategyTest-3.xml".
*/
@Test
public void computeBeatOffsets_File3() {
Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("VoicesBeatOffsetterTest-3.xml");
LinkedList<VoiceSpacing> voiceSpacings = createVoiceSpacings(score);
BeatOffset[] beatOffsets = testee.compute(voiceSpacings, Companion.fr(5, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
// file must have 8 beat offsets with increasing mm offsets
// special difficulty: last eighth note must be further to the right as preceding quarter
// in other voice, even the distance between the whole note and the last eighth would be big enough
assertEquals(8, beatOffsets.length);
assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
assertEquals(Companion.fr(1, 8), beatOffsets[1].getBeat());
assertEquals(Companion.fr(1, 4), beatOffsets[2].getBeat());
assertEquals(Companion.fr(2, 4), beatOffsets[3].getBeat());
assertEquals(Companion.fr(3, 4), beatOffsets[4].getBeat());
assertEquals(Companion.fr(4, 4), beatOffsets[5].getBeat());
assertEquals(Companion.fr(9, 8), beatOffsets[6].getBeat());
assertEquals(Companion.fr(5, 4), beatOffsets[7].getBeat());
for (int i = 0; i < beatOffsets.length - 1; i++) {
assertTrue("beat " + (i + 1) + " wrong", beatOffsets[i].getOffsetMm() < beatOffsets[i + 1].getOffsetMm());
}
// distance between beat 1/4 and 2/4 must be width_1_4
float is = score.getFormat().getInterlineSpace();
assertEquals(width_1_4 * is, beatOffsets[3].getOffsetMm() - beatOffsets[2].getOffsetMm(), df);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method computeTest1.
/**
* Compute offsets of the common beats.
*/
@Test
public void computeTest1() {
Score score = createTestScore3Voices();
BeatOffset[] beatOffsets = testee.compute(createVoiceSpacings(score), Companion.fr(4, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
float is = score.getFormat().getInterlineSpace();
// 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet
// ^: dominating voice
// voice 1: | 4 4 4 4 |
// ^^^^^
// voice 2: | 8 8 8 8 2 |
// ^^^^^^^^^^^^
// voice 3: | 3 3 3 8 8 4 |
// ^^^^^^
// used: * ** * ** * * * *
// checked: * * * * *
assertEquals(10, beatOffsets.length);
assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
assertEquals((0) * is, beatOffsets[0].getOffsetMm(), df);
assertEquals(Companion.fr(1, 4), beatOffsets[3].getBeat());
assertEquals((2 * width_1_8) * is, beatOffsets[3].getOffsetMm(), df);
assertEquals(Companion.fr(2, 4), beatOffsets[6].getBeat());
assertEquals((4 * width_1_8) * is, beatOffsets[6].getOffsetMm(), df);
assertEquals(Companion.fr(3, 4), beatOffsets[8].getBeat());
assertEquals((6 * width_1_8) * is, beatOffsets[8].getOffsetMm(), df);
assertEquals(Companion.fr(4, 4), beatOffsets[9].getBeat());
assertEquals((6 * width_1_8 + width_1_4) * is, beatOffsets[9].getOffsetMm(), df);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method createTestScore3VoicesGrace.
private Score createTestScore3VoicesGrace() {
Score score = new Score();
score.getFormat().setInterlineSpace(10);
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(Companion.getTime_4_4()));
// 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet, .: grace note
// voice 1: | 4 ...4 4 4 | (staff 1)
// voice 2: | 8 8 8 8 ..2 | (staff 1)
// voice 3: | 3 3 3 .8 8 4 | (staff 2)
// voice 1 (staff 1)
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(graceChord(Companion.pi(0, 0, 0)));
cursor.write(graceChord(Companion.pi(0, 0, 0)));
cursor.write(graceChord(Companion.pi(0, 0, 0)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
// voice 2 (staff 1)
cursor.setMp(atElement(0, 0, 1, 0));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(graceChord(Companion.pi(0, 0, 0)));
cursor.write(graceChord(Companion.pi(0, 0, 0)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
// voice 3 (staff 2)
cursor.setMp(atElement(1, 0, 0, 0));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
cursor.write(graceChord(Companion.pi(0, 0, 0)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
return score;
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method computeBeatOffsets_File2.
/**
* Test file "BeatOffsetsStrategyTest-2.xml".
*/
@Test
public void computeBeatOffsets_File2() {
Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("VoicesBeatOffsetterTest-2.xml");
LinkedList<VoiceSpacing> voiceSpacings = createVoiceSpacings(score);
BeatOffset[] beatOffsets = testee.compute(voiceSpacings, Companion.fr(3, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
// file must have 6 beat offsets with increasing mm offsets
assertEquals(6, beatOffsets.length);
assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
assertEquals(Companion.fr(1, 8), beatOffsets[1].getBeat());
assertEquals(Companion.fr(1, 4), beatOffsets[2].getBeat());
assertEquals(Companion.fr(2, 4), beatOffsets[3].getBeat());
assertEquals(Companion.fr(5, 8), beatOffsets[4].getBeat());
assertEquals(Companion.fr(3, 4), beatOffsets[5].getBeat());
for (int i = 0; i < beatOffsets.length - 1; i++) {
assertTrue(beatOffsets[i].getOffsetMm() < beatOffsets[i + 1].getOffsetMm());
}
// distance between beat 1/4 and 2/4 must be width_1_4
float is = score.getFormat().getInterlineSpace();
assertEquals(width_1_4 * is, beatOffsets[3].getOffsetMm() - beatOffsets[2].getOffsetMm(), df);
}
Aggregations