Search in sources :

Example 1 with CommandPerformer

use of com.xenoage.utils.document.command.CommandPerformer in project Zong by Xenoage.

the class ColumnElementRemoveTest method test.

@Test
public void test() {
    Score score = ScoreFactory.create1Staff4Measures();
    CommandPerformer cmd = score.getCommandPerformer();
    ColumnHeader column2 = score.getColumnHeader(2);
    // write middle barline
    Barline b = Barline.Companion.barline(BarlineStyle.LightHeavy);
    cmd.execute(new ColumnElementWrite(b, column2, Companion.fr(1, 4), null));
    // remove it
    cmd.execute(new ColumnElementRemove(column2, b));
    assertEquals(0, column2.getMiddleBarlines().size());
    // undo. should be here again
    cmd.undo();
    assertEquals(b, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Barline(com.xenoage.zong.core.music.barline.Barline) CommandPerformer(com.xenoage.utils.document.command.CommandPerformer) Test(org.junit.Test)

Example 2 with CommandPerformer

use of com.xenoage.utils.document.command.CommandPerformer 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());
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Barline(com.xenoage.zong.core.music.barline.Barline) CommandPerformer(com.xenoage.utils.document.command.CommandPerformer) Test(org.junit.Test)

Example 3 with CommandPerformer

use of com.xenoage.utils.document.command.CommandPerformer 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);
}
Also used : Score(com.xenoage.zong.core.Score) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) CommandPerformer(com.xenoage.utils.document.command.CommandPerformer) Test(org.junit.Test)

Aggregations

CommandPerformer (com.xenoage.utils.document.command.CommandPerformer)3 Score (com.xenoage.zong.core.Score)3 Test (org.junit.Test)3 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Barline (com.xenoage.zong.core.music.barline.Barline)2 Voice (com.xenoage.zong.core.music.Voice)1 Chord (com.xenoage.zong.core.music.chord.Chord)1