Search in sources :

Example 71 with Score

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());
}
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 72 with Score

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);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 73 with 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);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 74 with 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);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 75 with 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);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4