Search in sources :

Example 31 with Voice

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

Example 32 with Voice

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

the class VoiceElementWriteTest method testOverwrite5.

/**
 * Write<pre>
 *       x
 * into  aabbccddeeffgghh
 *  =>   x_bbccddeeffgghh</pre>
 */
@Test
public void testOverwrite5() {
    Score score = createTestScoreEighths();
    // in voice 1, write a 1/16 rest at 4/8
    MP mp = atElement(0, 0, 1, 0);
    Voice voice = score.getVoice(mp);
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 16)), null);
    cmd.execute();
    // now, there must be the durations 1/16, 1/8, 1/8, 1/8, 1/8, 1/8, 1/8, 1/8 in voice 1
    assertEquals(8, voice.getElements().size());
    assertEquals(Companion.fr(1, 16), 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));
    assertEquals(Companion.fr(1, 8), getDur(voice, 5));
    assertEquals(Companion.fr(1, 8), getDur(voice, 6));
    assertEquals(Companion.fr(1, 8), getDur(voice, 7));
    // 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 33 with Voice

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

the class VoiceElementWriteTest method assertTestScoreGracesOriginalState.

/**
 * Asserts that the score created by {@link #createTestScoreGraces()} is in its original
 * state again. Useful after undo.
 */
private void assertTestScoreGracesOriginalState(Score score) {
    Voice voice = score.getVoice(atVoice(0, 0, 0));
    assertEquals(11, voice.getElements().size());
    assertEquals(0, getStep(voice, 0));
    assertEquals(1, getStep(voice, 1));
    assertEquals(Companion.fr(1, 4), getDur(voice, 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));
}
Also used : Voice(com.xenoage.zong.core.music.Voice)

Example 34 with Voice

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

the class VoiceElementWriteTest method testElementReferences.

/**
 * When no collisions happen, elements must stay untouched.
 */
@Test
public void testElementReferences() {
    Score score = ScoreFactory.create1Staff();
    Voice voice = score.getVoice(atVoice(0, 0, 0));
    Rest rest0 = new Rest(Companion.fr(1, 4));
    new VoiceElementWrite(voice, atElement(0, 0, 0, 0), rest0, null).execute();
    Rest rest1 = new Rest(Companion.fr(1, 4));
    new VoiceElementWrite(voice, atElement(0, 0, 0, 1), rest1, null).execute();
    Rest rest2 = new Rest(Companion.fr(1, 4));
    new VoiceElementWrite(voice, atElement(0, 0, 0, 2), rest2, null).execute();
    assertTrue(rest0 == voice.getElementAt(Companion.fr(0, 4)));
    assertTrue(rest1 == voice.getElementAt(Companion.fr(1, 4)));
    assertTrue(rest2 == voice.getElementAt(Companion.fr(2, 4)));
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 35 with Voice

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

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