Search in sources :

Example 76 with Score

use of com.xenoage.zong.core.Score 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 77 with Score

use of com.xenoage.zong.core.Score 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 78 with Score

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

Example 79 with Score

use of com.xenoage.zong.core.Score 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 80 with Score

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

the class ChannelMapperTest method createScore.

private Score createScore(int[] midiPrograms, int... partStavesCount) {
    val score = new Score();
    for (int iPart : range(partStavesCount)) {
        Instrument instrument;
        if (midiPrograms[iPart] == drums)
            instrument = new UnpitchedInstrument("part " + iPart);
        else
            instrument = new PitchedInstrument("part " + iPart, midiPrograms[iPart]);
        new PartAdd(score, new Part("", null, partStavesCount[iPart], alist(instrument)), iPart, null).execute();
    }
    return score;
}
Also used : lombok.val(lombok.val) UnpitchedInstrument(com.xenoage.zong.core.instrument.UnpitchedInstrument) Score(com.xenoage.zong.core.Score) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Part(com.xenoage.zong.core.music.Part) UnpitchedInstrument(com.xenoage.zong.core.instrument.UnpitchedInstrument) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Instrument(com.xenoage.zong.core.instrument.Instrument) PartAdd(com.xenoage.zong.commands.core.music.PartAdd)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4