use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class SingleVoiceSpacerTest method testGrace1.
/**
* Computes a voice spacing with grace notes,
* where the element before the grace notes has enough empty rear space
* to take all the grace notes.
* <pre>
* Single elements: [-r1------------][g1][g2][--r4--]
* Combined: --r1----~g1~g2~~~r4---
* </pre> (~: area used by two elements)
*/
@Test
public void testGrace1() {
// create voice and notations
Voice voice = new Voice(alist((VoiceElement) r1, g1, g2, r4));
Notations notations = new Notations();
notations.add(new RestNotation(r1, new ElementWidth(2, 2, 13), null));
notations.add(new ChordNotation(g1, new ElementWidth(1, 2, 1)));
notations.add(new ChordNotation(g2, new ElementWidth(1, 2, 1)));
notations.add(new RestNotation(r4, new ElementWidth(3, 2, 3), null));
// compute spacing
VoiceSpacing vs = testee.compute(voice, 300f, Companion.fr(4, 4), 5, notations, layoutSettings);
// check spacing
ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
;
float s = layoutSettings.offsetMeasureStart;
assertEquals(5, ses.length);
assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
assertEquals(s + 9, ses[1].xIs, DELTA_FLOAT);
assertEquals(s + 12, ses[2].xIs, DELTA_FLOAT);
assertEquals(s + 17, ses[3].xIs, DELTA_FLOAT);
assertEquals(s + 22, ses[4].xIs, DELTA_FLOAT);
// check beats
assertEquals(Companion.fr(0, 8), ses[0].beat);
assertEquals(Companion.fr(2, 8), ses[1].beat);
assertEquals(Companion.fr(2, 8), ses[2].beat);
assertEquals(Companion.fr(2, 8), ses[3].beat);
assertEquals(Companion.fr(6, 8), ses[4].beat);
}
use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class SingleVoiceSpacerTest method testGrace3.
/**
* Computes a voice spacing with grace notes,
* where the element before the grace notes has not enough empty rear space
* to take even a single grace notes.
* <pre>
* Single elements: [-r1--][g1][g2][--r4--]
* Combined: --r1_~g1~g2~~~r4---
* </pre> (~: area used by two elements, _: minimal distance between elements)
*/
@Test
public void testGrace3() {
// create voice and notations
Voice voice = new Voice(alist((VoiceElement) r1, g1, g2, r4));
Notations notations = new Notations();
notations.add(new RestNotation(r1, new ElementWidth(2, 2, 3), null));
notations.add(new ChordNotation(g1, new ElementWidth(1, 2, 1)));
notations.add(new ChordNotation(g2, new ElementWidth(1, 2, 1)));
notations.add(new RestNotation(r4, new ElementWidth(3, 2, 3), null));
// compute spacing
VoiceSpacing vs = testee.compute(voice, 400f, Companion.fr(4, 4), 5, notations, layoutSettings);
// check spacing
ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
;
float s = layoutSettings.offsetMeasureStart;
float d = layoutSettings.spacings.widthDistanceMin;
assertEquals(5, ses.length);
assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
assertEquals(s + 5 + d, ses[1].xIs, DELTA_FLOAT);
assertEquals(s + 8 + d, ses[2].xIs, DELTA_FLOAT);
assertEquals(s + 13 + d, ses[3].xIs, DELTA_FLOAT);
assertEquals(s + 18 + d, ses[4].xIs, DELTA_FLOAT);
// check beats
assertEquals(Companion.fr(0, 8), ses[0].beat);
assertEquals(Companion.fr(2, 8), ses[1].beat);
assertEquals(Companion.fr(2, 8), ses[2].beat);
assertEquals(Companion.fr(2, 8), ses[3].beat);
assertEquals(Companion.fr(6, 8), ses[4].beat);
}
use of com.xenoage.zong.core.music.Voice 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);
}
use of com.xenoage.zong.core.music.Voice 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);
}
use of com.xenoage.zong.core.music.Voice 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);
}
Aggregations