Search in sources :

Example 21 with Rest

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

the class CursorTest method write_MeasureElement_Test.

@Test
public void write_MeasureElement_Test() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mpe0, true);
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    // write clef at 1/4
    Clef clef1 = new Clef(ClefType.Companion.getClefBass());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef1);
    BeatEList<Clef> clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(1, clefs.size());
    assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
    // write clef at 2/4
    Clef clef2 = new Clef(ClefType.Companion.getClefTreble());
    cursor.setMp(atElement(0, 0, 0, 2));
    cursor.write(clef2);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
    assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
    // overwrite clef at 1/4
    Clef clef3 = new Clef(ClefType.Companion.getClefTreble());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef3);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(Companion.beatE(clef3, Companion.fr(1, 4)), clefs.getFirst());
    assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
    // write key at 1/4
    Key key = new TraditionalKey(5, Mode.Major);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) key);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // write direction at 1/4
    Direction direction1 = new Dynamic(DynamicValue.ff);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction1);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write another direction at 1/4, which does not replace the first one
    Direction direction2 = new Coda();
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction2);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // now two directions
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write instrument change at 1/4
    InstrumentChange instrChange = new InstrumentChange(Instrument.Companion.getDefaultInstrument());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(instrChange);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // directions must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getInstrumentChanges().size());
    // check all added elements
    BeatEList<MeasureElement> all = score.getMeasure(atMeasure(0, 0)).getMeasureElements();
    assertEquals(6, all.size());
    assertEquals(clef3, all.getElements().get(0).getElement());
    assertEquals(key, all.getElements().get(1).getElement());
    assertEquals(direction1, all.getElements().get(2).getElement());
    assertEquals(direction2, all.getElements().get(3).getElement());
    assertEquals(instrChange, all.getElements().get(4).getElement());
    assertEquals(clef2, all.getElements().get(5).getElement());
}
Also used : InstrumentChange(com.xenoage.zong.core.music.InstrumentChange) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Coda(com.xenoage.zong.core.music.direction.Coda) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Direction(com.xenoage.zong.core.music.direction.Direction) MeasureElement(com.xenoage.zong.core.music.MeasureElement) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key) Test(org.junit.Test)

Example 22 with Rest

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

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

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

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

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