use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.
the class StaffStamper method createStaffStampings.
public StaffStampings createStaffStampings(Score score, FrameSpacing frame) {
int systemsCount = frame.getSystems().size();
int stavesCount = score.getStavesCount();
List<StaffStamping> allStaves = alist(systemsCount * stavesCount);
// go through the systems
for (int iSystem : range(systemsCount)) {
SystemSpacing system = frame.getSystems().get(iSystem);
float systemXOffset = system.getMarginLeftMm();
// create staves of the system
float yOffset = system.getOffsetYMm();
for (int iStaff : range(stavesCount)) {
yOffset += system.getStaffDistanceMm(iStaff);
int linesCount = score.getStaff(iStaff).getLinesCount();
float interlineSpace = score.getInterlineSpace(iStaff);
StaffStamping staff = new StaffStamping(system, iStaff, new Point2f(systemXOffset, yOffset), system.widthMm, linesCount, interlineSpace);
allStaves.add(staff);
yOffset += system.getStaffHeightMm(iStaff);
}
}
return new StaffStampings(allStaves, systemsCount, stavesCount);
}
use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.
the class StretchSystems method compute.
@Override
public void compute(FrameSpacing frame, Score score) {
// if there is no or only one system, do nothing
int systemsCount = frame.systems.size();
if (systemsCount > 1) {
// compute remaining space
SystemSpacing lastSystem = getLast(frame.systems);
float lastSystemEndY = lastSystem.getOffsetYMm() + lastSystem.getHeightMm();
float remainingSpace = frame.usableSizeMm.height - lastSystemEndY;
// compute additional space between the systems
float additionalSpace = remainingSpace / (systemsCount - 1);
// compute new y-offsets
for (int i : range(systemsCount)) {
SystemSpacing system = frame.systems.get(i);
system.offsetYMm += i * additionalSpace;
}
}
}
use of com.xenoage.zong.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.
the class SystemSpacer method compute.
/**
* Arranges an optimum number of measures columns in a system, beginning at the given measure,
* if possible.
* @param context the context of the layouter, with the {@link MP} set to the start measure
* @param usableSizeMm the usable size within the score frame in mm
* @param offsetYMm the vertical offset of the system in mm
* @param systemIndex the global system index (over all frames)
* @param isFirst true, iff this system is the first one in a score frame
* @param isAdditional true, iff this system is created for an additional frame, which is created
* for a complete score layout, but is not part of the defined layout
* @param measureColumnSpacings 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 Optional<SystemSpacing> compute(Context context, Size2f usableSizeMm, float offsetYMm, int systemIndex, boolean isFirst, boolean isAdditional, List<ColumnSpacing> measureColumnSpacings, Notations notations) {
int startMeasure = context.mp.measure;
// test if there is enough height for the system
Score score = context.score;
ScoreFormat scoreFormat = score.getFormat();
ScoreHeader scoreHeader = score.getHeader();
// compute spacing of staves
StavesSpacing stavesSpacing = stavesSpacer.compute(score, systemIndex);
// enough space?
if (offsetYMm + stavesSpacing.getTotalHeightMm() > usableSizeMm.height) {
// when the system is the first one in an additional frame, we force it into the frame
if (false == (isFirst && isAdditional))
// not enough space
return absent();
}
// compute the usable width for the system
float systemLeftMarginMm = getLeftMarginMm(systemIndex, scoreFormat, scoreHeader);
float systemRightMarginMm = getRightMarginMm(systemIndex, scoreFormat, scoreHeader);
float usableWidthMm = usableSizeMm.width - systemLeftMarginMm - systemRightMarginMm;
// append system measure-by-measure, until there is no space any more
// or until there are no measures left
int measuresCount = score.getMeasuresCount();
List<ColumnSpacing> system = alist();
float usedWidthMm = 0;
int iMeasure;
while (startMeasure + system.size() < measuresCount) {
iMeasure = startMeasure + system.size();
// decide if to add a leading spacing to the current measure or not
boolean firstMeasure = system.size() == 0;
ColumnSpacing column;
if (firstMeasure) {
// first measure within this system: add leading elements (clef, time sig.)
column = columnSpacer.compute(context, true, /* leading! */
notations);
} else {
// otherwise: use the precomputed spacing (without leading spacing)
column = measureColumnSpacings.get(iMeasure);
}
// this system is created for a complete score layout
if (false == canAppend(column, iMeasure, usableWidthMm, usedWidthMm, scoreHeader, firstMeasure)) {
if (system.size() == 0 && isAdditional) {
// force the single measure in this system
usedWidthMm += column.getWidthMm();
system.add(column);
} else {
// no more space for another measure
break;
}
} else {
usedWidthMm += column.getWidthMm();
system.add(column);
}
}
// we are finished
if (system.size() == 0) {
// not enough space for the system on this area
return absent();
} else {
SystemSpacing ret = new SystemSpacing(system, systemLeftMarginMm, systemRightMarginMm, usedWidthMm, stavesSpacing, offsetYMm);
return of(ret);
}
}
use of com.xenoage.zong.musiclayout.spacing.SystemSpacing 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.musiclayout.spacing.SystemSpacing in project Zong by Xenoage.
the class EmptySystems method compute.
@Override
public void compute(FrameSpacing frame, Score score) {
Size2f usableSize = frame.usableSizeMm;
// compute remaining space
float remainingSpace = usableSize.height;
float offsetY = 0;
if (frame.systems.size() > 0) {
SystemSpacing lastSystem = getLast(frame.systems);
offsetY = lastSystem.getOffsetYMm() + lastSystem.getHeightMm();
remainingSpace -= offsetY;
}
// compute height of an additional system
SystemLayout defaultSystemLayout = score.getFormat().getSystemLayout();
float defaultSystemDistance = defaultSystemLayout.getDistance();
float defaultMargin = defaultSystemLayout.getMarginLeft() + defaultSystemLayout.getMarginRight();
SystemSpacing newSystem = createEmptySystem(score, usableSize.width, 0);
float newSystemHeight = defaultSystemDistance + newSystem.getHeightMm();
// add as many additional empty staves as possible
int newSystemsCount = (int) (remainingSpace / newSystemHeight);
for (int i : range(newSystemsCount)) {
frame.systems.add(createEmptySystem(score, usableSize.width - defaultMargin, offsetY + (i * newSystemHeight) + defaultSystemDistance));
}
}
Aggregations