use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class FrameSpacer method compute.
/**
* Arranges an optimum number of systems in a frame, beginning at the given measure,
* if possible.
* @param context the context of the layouter, with the {@link MP} set to the start measure
* @param startSystem the index of the system where to start
* @param usableSizeMm the usable size within the score frame in mm
* @param isAdditional true, when this frame is created for a complete score layout,
* but is not part of the defined layout
* @param columnSpacings a list of all measure column spacings without leading spacings
* @param notations the notations of the elements, needed when a column has to be recomputed
* because of a leading spacing
*/
public FrameSpacing compute(Context context, int startSystem, Size2f usableSizeMm, boolean isAdditional, List<ColumnSpacing> columnSpacings, Notations notations) {
context.saveMp();
int startMeasure = context.mp.measure;
Score score = context.score;
ScoreFormat scoreFormat = score.getFormat();
ScoreHeader scoreHeader = score.getHeader();
int measuresCount = score.getMeasuresCount();
int measureIndex = startMeasure;
int systemIndex = startSystem;
// top margin
float offsetY = getTopSystemDistance(systemIndex, scoreFormat, scoreHeader);
// append systems to the frame
List<SystemSpacing> systems = alist();
while (measureIndex < measuresCount) {
// try to create system on this frame
context.mp = atMeasure(measureIndex);
boolean isFirst = (systems.size() == 0);
SystemSpacing system = systemSpacer.compute(context, usableSizeMm, offsetY, systemIndex, isFirst, isAdditional, columnSpacings, notations).orNull();
// was there enough place for this system?
if (system != null) {
// yes, there is enough place. add system
systems.add(system);
// update offset and start measure index for next system
// add height of this system
offsetY += system.getHeightMm();
// add system distance of the following system
offsetY += getSystemDistance(systemIndex + 1, scoreFormat, scoreHeader);
// increase indexes
systemIndex++;
measureIndex = system.getEndMeasure() + 1;
} else {
break;
}
}
context.restoreMp();
return new FrameSpacing(systems, usableSizeMm);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class StemDirector method compute.
/**
* Computes the {@link StemDirection} of the given chord (and maybe connected
* ones) and returns them. The chord must be part of a score.
*/
public Map<Chord, StemDirection> compute(Chord chord) {
Map<Chord, StemDirection> ret = map();
Beam beam = chord.getBeam();
Score score = chord.getScore();
if (beam != null) {
// compute stem directions for all chords of the beam
StemDirection[] beamedStems = beamedStemDirector.compute(beam, score);
for (int iChord : range(beam.size())) ret.put(beam.getChord(iChord), beamedStems[iChord]);
} else {
// compute stem direction for single chord
MP mp = MP.getMP(chord);
StemDirection stem = singleStemDirector.compute(chord, score.getMusicContext(mp, BeforeOrAt, Before));
ret.put(chord, stem);
}
// but it was bad and outdated, so we removed it.
return ret;
}
use of com.xenoage.zong.core.Score 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;
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method computeTest2.
/**
* Compute offsets of the common beats,
* this time for an incomplete measure.
*/
@Test
public void computeTest2() {
Score score = createTestScore3VoicesIncomplete();
BeatOffset[] beatOffsets = testee.compute(createVoiceSpacings(score), Companion.fr(4, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
float is = score.getFormat().getInterlineSpace();
// 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet, x: missing (empty)
// ^: dominating voice
// voice 1: | 4 4 4 8 xxx|
// ^^^^^^^^^^^^
// voice 2: | 8 8 8 8 4 xxxxxx|
// ^^^^^^^^^^^^
// voice 3: | 3 3 3 8 xxxxxxxxx|
//
// used: * ** * ** * * ° * (°: total final used beat)
// checked: * * * * * *
assertEquals(10, beatOffsets.length);
assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
assertEquals((0) * is, beatOffsets[0].getOffsetMm(), df);
assertEquals(Companion.fr(1, 4), beatOffsets[3].getBeat());
assertEquals((2 * width_1_8) * is, beatOffsets[3].getOffsetMm(), df);
assertEquals(Companion.fr(2, 4), beatOffsets[6].getBeat());
assertEquals((4 * width_1_8) * is, beatOffsets[6].getOffsetMm(), df);
assertEquals(Companion.fr(3, 4), beatOffsets[7].getBeat());
assertEquals((4 * width_1_8 + width_1_4) * is, beatOffsets[7].getOffsetMm(), df);
assertEquals(Companion.fr(7, 8), beatOffsets[8].getBeat());
assertEquals((4 * width_1_8 + width_1_4 + width_1_8) * is, beatOffsets[8].getOffsetMm(), df);
assertEquals(Companion.fr(4, 4), beatOffsets[9].getBeat());
assertEquals((4 * width_1_8 + width_1_4 + width_1_8 + minimalBeatsOffsetIs) * is, beatOffsets[9].getOffsetMm(), df);
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method createTestScore3VoicesIncomplete.
private Score createTestScore3VoicesIncomplete() {
Score score = new Score();
score.getFormat().setInterlineSpace(2);
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(Companion.getTime_4_4()));
// 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet, x: missing (empty)
// voice 1: | 4 4 4 8 xxx| (staff 1)
// voice 2: | 8 8 8 8 4 xxxxxx| (staff 1)
// voice 3: | 3 3 3 8 xxxxxxxxx| (staff 2)
// voice 1
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
// voice 2
cursor.setMp(atElement(0, 0, 1, 0));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
// voice 3
cursor.setMp(atElement(0, 0, 2, 0));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
return score;
}
Aggregations