use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite5.
/**
* Write<pre>
* x
* into aabbccddeeffgghh
* => x_bbccddeeffgghh</pre>
*/
@Test
public void testOverwrite5() {
Score score = createTestScoreEighths();
// in voice 1, write a 1/16 rest at 4/8
MP mp = atElement(0, 0, 1, 0);
Voice voice = score.getVoice(mp);
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 16)), null);
cmd.execute();
// now, there must be the durations 1/16, 1/8, 1/8, 1/8, 1/8, 1/8, 1/8, 1/8 in voice 1
assertEquals(8, voice.getElements().size());
assertEquals(Companion.fr(1, 16), 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));
assertEquals(Companion.fr(1, 8), getDur(voice, 5));
assertEquals(Companion.fr(1, 8), getDur(voice, 6));
assertEquals(Companion.fr(1, 8), getDur(voice, 7));
// test undo
cmd.undo();
assertTestScoreEighthsOriginalState(score);
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class VoiceElementWriteTest method testElementReferences.
/**
* When no collisions happen, elements must stay untouched.
*/
@Test
public void testElementReferences() {
Score score = ScoreFactory.create1Staff();
Voice voice = score.getVoice(atVoice(0, 0, 0));
Rest rest0 = new Rest(Companion.fr(1, 4));
new VoiceElementWrite(voice, atElement(0, 0, 0, 0), rest0, null).execute();
Rest rest1 = new Rest(Companion.fr(1, 4));
new VoiceElementWrite(voice, atElement(0, 0, 0, 1), rest1, null).execute();
Rest rest2 = new Rest(Companion.fr(1, 4));
new VoiceElementWrite(voice, atElement(0, 0, 0, 2), rest2, null).execute();
assertTrue(rest0 == voice.getElementAt(Companion.fr(0, 4)));
assertTrue(rest1 == voice.getElementAt(Companion.fr(1, 4)));
assertTrue(rest2 == voice.getElementAt(Companion.fr(2, 4)));
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class VoiceElementWriteTest method testGraceInsert3.
/**
* Writes elements in a voice that contains grace notes.
* <pre>
* xxxx___xxxx_xx
* into ..aaaa...bbbb.cccc..
* => ..xxxx___xxxx_xx__..</pre>
*/
@Test
public void testGraceInsert3() {
Score score = createTestScoreGraces();
// in voice 0, write a 5/8 rest at position 2
MP mp = atElement(0, 0, 0, 2);
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(5, 8));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// check notes
assertEquals(5, voice.getElements().size());
// here 1st grace note has step 0, 2nd 1, ...
assertEquals(0, getStep(voice, 0));
assertEquals(1, getStep(voice, 1));
assertEquals(r, voice.getElement(2));
assertEquals(6, getStep(voice, 3));
assertEquals(0, getStep(voice, 4));
// test undo
cmd.undo();
assertTestScoreGracesOriginalState(score);
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class ScoreTest method getMeasureBeatsTest.
@Test
public void getMeasureBeatsTest() {
Score score = ScoreFactory.create1Staff4Measures();
// first measure: no time, 1/4 used
score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
// second measure: 3/4 time, 2/4 used
score.getColumnHeader(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(1, 4)));
score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(1, 4)));
// third measure: still 3/4 time, 1/4 used
score.getVoice(atVoice(0, 2, 0)).addElement(new Rest(Companion.fr(1, 4)));
// check
assertEquals(Companion.fr(1, 4), score.getMeasureBeats(0));
assertEquals(Companion.fr(3, 4), score.getMeasureBeats(1));
assertEquals(Companion.fr(3, 4), score.getMeasureBeats(2));
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class ScoreTest method getMeasureFilledBeatsTest.
@Test
public void getMeasureFilledBeatsTest() {
// create a little test score, where the first measure only
// uses 2/4, the second 4/4, the third 0/4, the fourth 3/4.
Score score = ScoreFactory.create1Staff4Measures();
score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(2, 4)));
score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(2, 4)));
score.getVoice(atVoice(0, 3, 0)).addElement(new Rest(Companion.fr(3, 4)));
// test method
assertEquals(Companion.fr(2, 4), score.getMeasureFilledBeats(0));
assertEquals(Companion.fr(4, 4), score.getMeasureFilledBeats(1));
assertEquals(Companion.fr(0, 4), score.getMeasureFilledBeats(2));
assertEquals(Companion.fr(3, 4), score.getMeasureFilledBeats(3));
}
Aggregations