use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.
the class MeasureElementsSpacerTest method testNeedAdditionalSpace.
/**
* If there is not enough space left for the measure elements,
* the voice spacings have to be moved to create enough space.
* To understand the following sketch, have a look at the comments
* in {@link MeasureElementsSpacer}.
* <pre>
* enough space:
* beat: 0 2 4 6 8
* offset: 3 5 7 9 13 17 21
* . . . . . . . . . .
* clef: *[clef]* (on beat 4)
* voice 1: o 2
* voice 2: 1 o
* </pre>
* Between VE1 and VE2, there are 6 spaces.
* Assuming a padding width of 1 and a clef width of 6,
* the clef can be moved two spaces to the left, but this is not
* enough. All elements at or after beat 3 have to be moved 2 spaces
* to the right.
*/
@Test
public void testNeedAdditionalSpace() {
Rest[] ve = ve();
List<VoiceSpacing> vs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 11))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 16))));
Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
BeatEList<Clef> innerClefs = Companion.beatEList();
innerClefs.add(Companion.beatE(innerClef, Companion.fr(4)));
List<ElementSpacing> mes = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
// voice spacings
assertEquals(2, vs.size());
assertEqualsSpacings(ilist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 13)), vs.get(0).elements);
assertEqualsSpacings(ilist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 18)), vs.get(1).elements);
// clef must be at offset 13 - padding - clefwidth/2
ElementSpacing[] se = mes.toArray(new ElementSpacing[0]);
assertEquals(1, se.length);
assertEquals(Companion.fr(4), se[0].beat);
assertEquals(13 - paddingWidth - clefWidth / 2, se[0].xIs, Delta.DELTA_FLOAT);
}
use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.
the class StretchMeasuresTest method createSystemWith1MeasureGrace.
/**
* Creates and returns a simple {@link SystemSpacing} with only one
* measure and three notes: two main notes and two grace notes between them.
*/
public static SystemSpacing createSystemWith1MeasureGrace(float offsetChord1, float offsetChord2, float offsetMeasureEnd, float graceDistance) {
Chord chord1 = chord(Companion.pi(0, 0, 4), Companion.fr(2, 4));
Chord chord2grace = graceChord(Companion.pi(1, 0, 4));
Chord chord3grace = graceChord(Companion.pi(2, 0, 4));
Chord chord4 = chord(Companion.pi(3, 0, 4), Companion.fr(2, 4));
Voice voice = new Voice(alist(chord1, chord2grace, chord3grace, chord4));
List<BeatOffset> beatOffsets = alist(new BeatOffset(Companion.fr(0, 4), offsetChord1), new BeatOffset(Companion.fr(2, 4), offsetChord2), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd));
float is = 1;
List<VoiceSpacing> voiceSpacings = alist(new VoiceSpacing(voice, is, alist(new ChordSpacing(new ChordNotation(chord1), beatOffsets.get(0).getBeat(), beatOffsets.get(0).getOffsetMm()), new ChordSpacing(new ChordNotation(chord2grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 2 * graceDistance), new ChordSpacing(new ChordNotation(chord3grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 1 * graceDistance), new ChordSpacing(new ChordNotation(chord4), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm()))));
MeasureSpacing measureSpacing = new MeasureSpacing(atMeasure(0, 0), is, voiceSpacings, empty, null);
ColumnSpacing mcs = new ColumnSpacing(-1, alist(measureSpacing), beatOffsets, alist(new BeatOffset(Companion.fr(0, 4), 0), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd)));
SystemSpacing system = new SystemSpacing(alist(mcs), 0, 0, offsetMeasureEnd, null, 0);
return system;
}
use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.
the class AlignedVoicesSpacerTest method computeTest3.
@Test
public void computeTest3() {
float is = 4;
// voice spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 2f)));
// given beat offsets:
// beats: 0.2
// offsets: | |
// | ⌎- 6
// ⌎--- 2
List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 2f), new BeatOffset(beat(2), 6f));
// shared beats: 0, 2.
//
// resulting spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 6
// ⌎--- 2
testee.compute(voiceSpacing, beatOffsets);
List<ElementSpacing> finalSpacing = voiceSpacing.elements;
assertEquals(2, finalSpacing.size());
assertEquals(beat(0), finalSpacing.get(0).beat);
assertEquals(2f / is, finalSpacing.get(0).xIs, df);
assertEquals(beat(2), finalSpacing.get(1).beat);
assertEquals(6f / is, finalSpacing.get(1).xIs, df);
}
use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.
the class AlignedVoicesSpacerTest method computeTest2.
@Test
public void computeTest2() {
float is = 3;
// voice spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 2f)));
// given beat offsets:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 0f), new BeatOffset(beat(2), 2f));
// shared beats: 0, 2.
//
// resulting spacing:
// beats: 0.2
// offsets: | |
// | ⌎- 2
// ⌎--- 0
testee.compute(voiceSpacing, beatOffsets);
List<ElementSpacing> finalSpacing = voiceSpacing.elements;
assertEquals(2, finalSpacing.size());
assertEquals(beat(0), finalSpacing.get(0).beat);
assertEquals(0f / is, finalSpacing.get(0).xIs, df);
assertEquals(beat(2), finalSpacing.get(1).beat);
assertEquals(2f / is, finalSpacing.get(1).xIs, df);
}
use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing 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);
}
Aggregations