use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class ColumnElementWriteTest method test.
@Test
public void test() {
Score score = ScoreFactory.create1Staff4Measures();
CommandPerformer cmd = score.getCommandPerformer();
ColumnHeader column2 = score.getColumnHeader(2);
// write start barline, middle barline and end barline
Barline b1 = Barline.Companion.barlineRegular();
Barline b2 = Barline.Companion.barlineRegular();
Barline b3 = Barline.Companion.barline(BarlineStyle.LightHeavy);
cmd.execute(new ColumnElementWrite(b1, column2, null, MeasureSide.Left));
cmd.execute(new ColumnElementWrite(b2, column2, Companion.fr(1, 4), null));
cmd.execute(new ColumnElementWrite(b3, column2, null, MeasureSide.Right));
assertEquals(b1, column2.getStartBarline());
assertEquals(b2, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
assertEquals(b3, column2.getEndBarline());
// overwrite middle barline
Barline b4 = Barline.Companion.barlineRegular();
cmd.execute(new ColumnElementWrite(b4, column2, Companion.fr(1, 4), null));
assertEquals(b4, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
// undo. b2 should be here again
cmd.undo();
assertEquals(b2, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
// undo all steps. the middle barline should not exist any more
cmd.undoMultipleSteps(3);
assertEquals(0, column2.getMiddleBarlines().size());
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testGraceInsert2.
/**
* Writes elements in a voice that contains grace notes.
* <pre>
* xxxx___xxxx
* into ..aaaa...bbbb.cccc..
* => ..xxxx___xxxx.cccc..</pre>
*/
@Test
public void testGraceInsert2() {
Score score = createTestScoreGraces();
// in voice 0, write a 1/2 rest at position 2
MP mp = atElement(0, 0, 0, 2);
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(1, 2));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// check notes
assertEquals(7, 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(5, getStep(voice, 3));
assertEquals(Companion.fr(1, 4), getDur(voice, 4));
assertEquals(6, getStep(voice, 5));
assertEquals(0, getStep(voice, 6));
// test undo
cmd.undo();
assertTestScoreGracesOriginalState(score);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testWriteAtBeat.
/**
* Write at a beat.<pre>
* xxxxxxx
* into aabbccddeeffgghh
* => aaxxxxxxx_ffgghh</pre>
*/
@Test
public void testWriteAtBeat() {
Score score = createTestScoreEighths();
// in voice 1, write a 7/16 rest at 1/8
MP mp = atBeat(0, 0, 0, Companion.fr(1, 8));
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(7, 16));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// now, there must be the durations 1/18, 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);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite4.
/**
* Write<pre>
* xxxxxxxx
* into aabbccddeeffgghh
* => aabbccddxxxxxxxx</pre>
*/
@Test
public void testOverwrite4() {
Score score = createTestScoreEighths();
// in voice 1, write a half rest at 4/8
MP mp = atElement(0, 0, 1, 4);
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/8, 1/8, 1/8, 1/2 in voice 1
assertEquals(5, voice.getElements().size());
assertEquals(Companion.fr(1, 8), 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, 2), 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 testGraceInsert1.
/**
* Writes elements in a voice that contains grace notes.
* <pre>
* xxxx
* into ..aaaa...bbbb.cccc..</pre>
* => ..aaaa...bbbb.cccc..</pre>
*/
@Test
public void testGraceInsert1() {
Score score = createTestScoreGraces();
// in voice 0, write a 1/4 rest at position 2
MP mp = atElement(0, 0, 0, 2);
Voice voice = score.getVoice(mp);
Rest r = new Rest(Companion.fr(1, 4));
VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
cmd.execute();
// check notes
assertEquals(11, 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(2, getStep(voice, 3));
assertEquals(3, getStep(voice, 4));
assertEquals(4, getStep(voice, 5));
assertEquals(Companion.fr(1, 4), getDur(voice, 6));
assertEquals(5, getStep(voice, 7));
assertEquals(Companion.fr(1, 4), getDur(voice, 8));
assertEquals(6, getStep(voice, 9));
assertEquals(0, getStep(voice, 10));
// test undo
cmd.undo();
assertTestScoreGracesOriginalState(score);
}
Aggregations