use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.
the class SingleVoiceSpacerTest method testGrace2.
/**
* Computes a voice spacing with grace notes,
* where the element before the grace notes has enough empty rear space
* to take at least one of the 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 testGrace2() {
// 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, 7), 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.VoiceElement in project Zong by Xenoage.
the class SingleVoiceSpacerTest method testSimple.
/**
* Computes a simple voice spacing.
* <pre>
* Single elements: [-r1---][-r2-][-r3--][----r4--]
* Combined: --r1--~~r2_~-r3_~~---r4---
* </pre> (~: area used by two elements, _: minimal distance between elements)
*/
@Test
public void testSimple() {
// create voice and notations
Voice voice = new Voice(alist((VoiceElement) r1, r2, r3, r4));
Notations notations = new Notations();
notations.add(new RestNotation(r1, new ElementWidth(2, 2, 4), null));
notations.add(new RestNotation(r2, new ElementWidth(2, 2, 2), null));
notations.add(new RestNotation(r3, new ElementWidth(2, 2, 3), null));
notations.add(new RestNotation(r4, new ElementWidth(5, 2, 3), null));
// compute spacing
VoiceSpacing vs = testee.compute(voice, 200f, 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 + 8, ses[1].xIs, DELTA_FLOAT);
assertEquals(s + 12 + d, ses[2].xIs, DELTA_FLOAT);
assertEquals(s + 19 + 2 * d, ses[3].xIs, DELTA_FLOAT);
assertEquals(s + 24 + 2 * 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(3, 8), ses[2].beat);
assertEquals(Companion.fr(4, 8), ses[3].beat);
assertEquals(Companion.fr(8, 8), ses[4].beat);
}
use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.
the class VoicesBeatOffsetter method computeVoicesBeats.
/**
* Returns a sorted list of all beats, where
* chords or rests begin, from the given list of voice spacings.
* There are no duplicate beats. The ending beats of the voices are not added.
*/
SortedList<Fraction> computeVoicesBeats(List<VoiceSpacing> voiceSpacings) {
SortedList<Fraction> beats = Companion.sortedListNoDuplicates();
Fraction beat;
for (VoiceSpacing voiceSpacing : voiceSpacings) {
beat = Fraction.Companion.get_0();
for (ElementSpacing spacingElement : voiceSpacing.elements) {
MusicElement element = spacingElement.getElement();
if (element instanceof VoiceElement) {
// add beat
beats.add(beat);
// find the next beat
beat = beat.add(((VoiceElement) element).getDuration());
}
}
// do not add beat here, because the ending beat of an incomplete measure
// is not interesting for computing beat offsets.
}
return beats;
}
use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.
the class Utils method checkGraceChords.
public static void checkGraceChords(Staff staff, Chord[] expectedChords, boolean skipRests) {
int iChord = 0;
for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
Voice voice = staff.getMeasure(iM).getVoice(0);
for (VoiceElement e : voice.getElements()) {
if (e instanceof Rest && skipRests)
continue;
// check duration, type and notes
Chord chord = (Chord) e;
Chord expectedChord = expectedChords[iChord];
assertEquals("chord " + iChord, expectedChord.getDuration(), chord.getDuration());
assertEquals("chord " + iChord, expectedChord.getGrace(), chord.getGrace());
assertEquals("chord " + iChord, expectedChord.getNotes(), chord.getNotes());
iChord++;
}
}
assertEquals("not all chords found", expectedChords.length, iChord);
}
use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.
the class VoiceElementIteratorTest method test.
@Test
public void test() {
VoiceElementIterator it = new VoiceElementIterator(createTestScore());
for (int staff : range(4)) {
for (int measure : range(4)) {
if ((staff == 1 || staff == 3) && (measure == 1 || measure == 3)) {
// expect two voices with each 4 quarter rests
for (int voice : range(2)) {
for (int element : range(4)) {
assertTrue(it.hasNext());
VoiceElement e = it.next();
assertEquals(mp(staff, measure, voice, Companion.fr(element, 4), element), it.getMp());
assertEquals(Companion.fr(1, 4), e.getDuration());
}
}
} else {
// expect a full rest
assertTrue(it.hasNext());
VoiceElement e = it.next();
assertEquals(mp(staff, measure, 0, Companion.get_0(), 0), it.getMp());
assertEquals(Companion.fr(1), e.getDuration());
}
}
}
assertFalse(it.hasNext());
}
Aggregations