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);
}
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)));
}
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);
}
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);
}
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;
}
Aggregations