Search in sources :

Example 11 with Voice

use of com.xenoage.zong.core.music.Voice 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 12 with Voice

use of com.xenoage.zong.core.music.Voice 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 13 with Voice

use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.

the class VoiceElementWriteTest method assertTestScoreEighthsOriginalState.

/**
 * Asserts that the score created by {@link #createTestScoreEighths()} is in its original
 * state again. Useful after undo.
 */
private void assertTestScoreEighthsOriginalState(Score score) {
    for (int iVoice : range(2)) {
        Voice voice = score.getVoice(atVoice(0, 0, iVoice));
        assertEquals(8, voice.getElements().size());
        for (int i : range(8)) assertEquals(Companion.fr(1, 8), getDur(voice, i));
    }
}
Also used : Voice(com.xenoage.zong.core.music.Voice)

Example 14 with Voice

use of com.xenoage.zong.core.music.Voice 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 15 with Voice

use of com.xenoage.zong.core.music.Voice 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

Voice (com.xenoage.zong.core.music.Voice)39 Test (org.junit.Test)25 Rest (com.xenoage.zong.core.music.rest.Rest)16 Score (com.xenoage.zong.core.Score)15 MP (com.xenoage.zong.core.position.MP)14 VoiceElement (com.xenoage.zong.core.music.VoiceElement)12 Chord (com.xenoage.zong.core.music.chord.Chord)10 Measure (com.xenoage.zong.core.music.Measure)8 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)7 Staff (com.xenoage.zong.core.music.Staff)6 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)6 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)5 Fraction (com.xenoage.utils.math.Fraction)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 Notations (com.xenoage.zong.musiclayout.notation.Notations)4 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)4 MP.atVoice (com.xenoage.zong.core.position.MP.atVoice)3 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)3