use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.
the class MeasureElementsSpacerTest method notations.
private Notations notations(Rest[] rests, Clef clef) {
Notations ret = new Notations();
ret.add(new ClefNotation(clef, new ElementWidth(clefWidth), 0, 1));
return ret;
}
use of com.xenoage.zong.musiclayout.notation.Notations 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.musiclayout.notation.Notations 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.musiclayout.notation.Notations in project Zong by Xenoage.
the class ScoreLayouter method createLayoutWithExceptions.
/**
* Computes the whole layout and returns it.
* If something fails, an exception is thrown.
*/
public ScoreLayout createLayoutWithExceptions() {
// notations of elements
Notations notations = notator.computeAll(context);
// compute optimal measure column spacings
List<ColumnSpacing> columns = columnsSpacer.compute(notations, context);
// break columns into systems and frames
FramesSpacing frames = framesSpacer.compute(columns, target, context, notations);
// system stretching (horizontal)
fillSystemsHorizontally(frames, target);
// frame filling (vertical)
fillFramesVertically(frames, target, context.score);
// compute beam spacings. these are computed only now, after the horizontal
// and vertical spacing of the score is fixed, since the beam slants depend on the
// exact spacings
Map<Beam, BeamSpacing> beams = beamsSpacer.compute(context.score, notations, frames);
// create score frame layouts from the collected information
List<ScoreFrameLayout> scoreFrameLayouts = createScoreFrameLayouts(frames, notations, context, beams);
// create score layout
return new ScoreLayout(context.score, scoreFrameLayouts, context.symbols, context.settings);
}
use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.
the class Notator method computeAll.
/**
* Computes the {@link Notation}s of all elements and returns them.
*/
public Notations computeAll(Context context) {
context.saveMp();
Score score = context.score;
Notations notations = new Notations();
// iterate over all column elements, measure elements and voice elements
ColumnElementIterator itC = new ColumnElementIterator(score);
for (ColumnElement e : itC) {
// column elements: one notation for each staff
for (int iStaff : range(context.score.getStavesCount())) {
context.mp = itC.getMp().withStaff(iStaff);
notations.add(compute(e, context, notations), iStaff);
}
}
MeasureElementIterator itM = new MeasureElementIterator(score);
for (MeasureElement e : itM) {
context.mp = itM.getMp();
notations.add(compute(e, context, notations));
}
VoiceElementIterator itV = new VoiceElementIterator(score);
for (VoiceElement e : itV) {
context.mp = itV.getMp();
notations.add(compute(e, context, notations));
}
BeamIterator itB = new BeamIterator(score);
for (Beam e : itB) {
context.mp = itB.getMp();
notations.add(compute(e, context, notations));
}
context.restoreMp();
return notations;
}
Aggregations