use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite2.
/**
* Write<pre>
* xxxxxxxx
* into aabbccddeeffgghh
* => aaxxxxxxxxffgghh</pre>
*/
@Test
public void testOverwrite2() {
Score score = createTestScoreEighths();
// in voice 1, write a half rest at 1/8
MP mp = atElement(0, 0, 1, 1);
Voice voice = score.getVoice(mp);
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 2)), null);
cmd.execute();
// now, there must be the durations 1/8, 1/2, 1/8, 1/8, 1/8 in voice 1
assertEquals(5, voice.getElements().size());
assertEquals(Companion.fr(1, 8), getDur(voice, 0));
assertEquals(Companion.fr(1, 2), getDur(voice, 1));
assertEquals(Companion.fr(1, 8), getDur(voice, 2));
assertEquals(Companion.fr(1, 8), getDur(voice, 3));
assertEquals(Companion.fr(1, 8), getDur(voice, 4));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testWriteAfterEnd.
/**
* Write at a beat after the end of the elements.<pre>
* xxxx
* into aabbccddeeffgghh
* => aabbccddeeffgghhrrxxxx</pre> (r is a rest)
*/
@Test
public void testWriteAfterEnd() {
Score score = createTestScoreEighths();
// in voice 1, write a 1/4 rest at 9/8 (1/8 after the end)
MP mp = atBeat(0, 0, 0, Companion.fr(9, 8));
Voice voice = score.getVoice(mp);
Rest x = new Rest(Companion.fr(1, 4));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, x, null);
cmd.execute();
// check elements
assertEquals(10, voice.getElements().size());
for (int i : range(8)) assertEquals(Companion.fr(1, 8), getDur(voice, i));
assertTrue(voice.getElement(8) instanceof Rest);
assertEquals(Companion.fr(1, 8), getDur(voice, 8));
assertEquals(x, voice.getElement(9));
assertEquals(Companion.fr(1, 4), getDur(voice, 9));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite3.
/**
* Write<pre>
* xxxxxxxx
* into aabbccddeeffgghh
* => xxxxxxxxeeffgghh</pre>
*/
@Test
public void testOverwrite3() {
Score score = createTestScoreEighths();
// in voice 1, write a half rest at 0/8
MP mp = atElement(0, 0, 1, 0);
Voice voice = score.getVoice(mp);
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 2)), null);
cmd.execute();
// now, there must be the durations 1/2, 1/8, 1/8, 1/8, 1/8 in voice 1
assertEquals(5, voice.getElements().size());
assertEquals(Companion.fr(1, 2), getDur(voice, 0));
assertEquals(Companion.fr(1, 8), getDur(voice, 1));
assertEquals(Companion.fr(1, 8), getDur(voice, 2));
assertEquals(Companion.fr(1, 8), getDur(voice, 3));
assertEquals(Companion.fr(1, 8), getDur(voice, 4));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method createTestScoreGraces.
/**
* Creates a score with a single staff, one measure and one voice:
* <pre>..aaaa...bbbb.cccc..</pre> (. are grace notes, a-c are rests)
*/
private Score createTestScoreGraces() {
Score score = ScoreFactory.create1Staff();
Voice voice = score.getVoice(atVoice(0, 0, 0));
voice.addElement(grace(0));
voice.addElement(grace(1));
voice.addElement(new Rest(Companion.fr(1, 4)));
voice.addElement(grace(2));
voice.addElement(grace(3));
voice.addElement(grace(4));
voice.addElement(new Rest(Companion.fr(1, 4)));
voice.addElement(grace(5));
voice.addElement(new Rest(Companion.fr(1, 4)));
voice.addElement(grace(6));
voice.addElement(grace(0));
// ensure that assert method works correctly. if not, fail now
assertTestScoreGracesOriginalState(score);
return score;
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite1.
/**
* Write<pre>
* xxxxxxx
* into aabbccddeeffgghh
* => aaxxxxxxx_ffgghh</pre>
*/
@Test
public void testOverwrite1() {
Score score = createTestScoreEighths();
// in voice 1, write a 7/16 rest at 1/8
MP mp = atElement(0, 0, 1, 1);
Voice voice = score.getVoice(mp);
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(7, 16)), null);
cmd.execute();
// now, there must be the durations 1/8, 7/16, 1/8, 1/8, 1/8 in voice 1
assertEquals(5, voice.getElements().size());
assertEquals(Companion.fr(1, 8), getDur(voice, 0));
assertEquals(Companion.fr(7, 16), getDur(voice, 1));
assertEquals(Companion.fr(1, 8), getDur(voice, 2));
assertEquals(Companion.fr(1, 8), getDur(voice, 3));
assertEquals(Companion.fr(1, 8), getDur(voice, 4));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
Aggregations