Search in sources :

Example 26 with Rest

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

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

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

the class VoiceElementWriteTest method testGraceInsert3.

/**
 * Writes elements in a voice that contains grace notes.
 * <pre>
 *         xxxx___xxxx_xx
 * into  ..aaaa...bbbb.cccc..
 *  =>   ..xxxx___xxxx_xx__..</pre>
 */
@Test
public void testGraceInsert3() {
    Score score = createTestScoreGraces();
    // in voice 0, write a 5/8 rest at position 2
    MP mp = atElement(0, 0, 0, 2);
    Voice voice = score.getVoice(mp);
    Rest r = new Rest(Companion.fr(5, 8));
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
    cmd.execute();
    // check notes
    assertEquals(5, 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(6, getStep(voice, 3));
    assertEquals(0, getStep(voice, 4));
    // 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 29 with Rest

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

the class ScoreTest method getMeasureBeatsTest.

@Test
public void getMeasureBeatsTest() {
    Score score = ScoreFactory.create1Staff4Measures();
    // first measure: no time, 1/4 used
    score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
    // second measure: 3/4 time, 2/4 used
    score.getColumnHeader(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
    score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(1, 4)));
    // third measure: still 3/4 time, 1/4 used
    score.getVoice(atVoice(0, 2, 0)).addElement(new Rest(Companion.fr(1, 4)));
    // check
    assertEquals(Companion.fr(1, 4), score.getMeasureBeats(0));
    assertEquals(Companion.fr(3, 4), score.getMeasureBeats(1));
    assertEquals(Companion.fr(3, 4), score.getMeasureBeats(2));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Example 30 with Rest

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

the class ScoreTest method getMeasureFilledBeatsTest.

@Test
public void getMeasureFilledBeatsTest() {
    // create a little test score, where the first measure only
    // uses 2/4, the second 4/4, the third 0/4, the fourth 3/4.
    Score score = ScoreFactory.create1Staff4Measures();
    score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(2, 4)));
    score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(2, 4)));
    score.getVoice(atVoice(0, 3, 0)).addElement(new Rest(Companion.fr(3, 4)));
    // test method
    assertEquals(Companion.fr(2, 4), score.getMeasureFilledBeats(0));
    assertEquals(Companion.fr(4, 4), score.getMeasureFilledBeats(1));
    assertEquals(Companion.fr(0, 4), score.getMeasureFilledBeats(2));
    assertEquals(Companion.fr(3, 4), score.getMeasureFilledBeats(3));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) 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