Search in sources :

Example 6 with Rest

use of com.xenoage.zong.core.music.rest.Rest 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);
}
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 7 with Rest

use of com.xenoage.zong.core.music.rest.Rest 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);
}
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 8 with Rest

use of com.xenoage.zong.core.music.rest.Rest 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);
}
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 9 with Rest

use of com.xenoage.zong.core.music.rest.Rest 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;
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Voice(com.xenoage.zong.core.music.Voice)

Example 10 with Rest

use of com.xenoage.zong.core.music.rest.Rest 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);
}
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

Rest (com.xenoage.zong.core.music.rest.Rest)35 Score (com.xenoage.zong.core.Score)22 Test (org.junit.Test)22 Voice (com.xenoage.zong.core.music.Voice)16 MP (com.xenoage.zong.core.position.MP)11 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)9 Cursor (com.xenoage.zong.io.selection.Cursor)8 Chord (com.xenoage.zong.core.music.chord.Chord)6 Clef (com.xenoage.zong.core.music.clef.Clef)4 Pitch (com.xenoage.zong.core.music.Pitch)3 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)3 Fraction (com.xenoage.utils.math.Fraction)2 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)2 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)2 Measure (com.xenoage.zong.core.music.Measure)2 Part (com.xenoage.zong.core.music.Part)2 Staff (com.xenoage.zong.core.music.Staff)2 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)2 Words (com.xenoage.zong.core.music.direction.Words)2 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)2