Search in sources :

Example 1 with StavesSpacing

use of com.xenoage.zong.musiclayout.spacing.StavesSpacing in project Zong by Xenoage.

the class EmptySystems method createEmptySystem.

/**
 * Creates an additional system for the given {@link Score} with
 * the given width and y-offset in mm and returns it.
 */
private SystemSpacing createEmptySystem(Score score, float width, float offsetY) {
    // compute staves spacing
    StavesSpacing stavesSpacing = StavesSpacer.stavesSpacer.compute(score, 0);
    // create and returns system
    SystemLayout defaultSystemLayout = score.getFormat().getSystemLayout();
    return new SystemSpacing(CollectionUtils.<ColumnSpacing>alist(), defaultSystemLayout.getMarginLeft(), defaultSystemLayout.getMarginRight(), width, stavesSpacing, offsetY);
}
Also used : StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) SystemLayout(com.xenoage.zong.core.format.SystemLayout) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 2 with StavesSpacing

use of com.xenoage.zong.musiclayout.spacing.StavesSpacing in project Zong by Xenoage.

the class StavesSpacer method compute.

public StavesSpacing compute(Score score, int systemIndex) {
    // compute staff distances
    ScoreFormat scoreFormat = score.getFormat();
    ScoreHeader scoreHeader = score.getHeader();
    float[] distancesMm = new float[score.getStavesCount() - 1];
    for (int iStaff : range(1, distancesMm.length)) {
        StaffLayout staffLayout = scoreHeader.getStaffLayout(systemIndex, iStaff);
        float staffDistanceMm = 0;
        if (staffLayout != null) {
            // use custom staff distance
            staffDistanceMm = staffLayout.getDistance();
        } else {
            // use default staff distance
            staffDistanceMm = scoreFormat.getStaffLayoutNotNull(iStaff).getDistance();
        }
        distancesMm[iStaff - 1] = staffDistanceMm;
    }
    // create spacing
    StavesSpacing stavesSpacing = new StavesSpacing(score.getStavesList().getStaves(), distancesMm, scoreFormat.getInterlineSpace());
    return stavesSpacing;
}
Also used : ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) StaffLayout(com.xenoage.zong.core.format.StaffLayout)

Example 3 with StavesSpacing

use of com.xenoage.zong.musiclayout.spacing.StavesSpacing 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);
    }
}
Also used : ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 4 with StavesSpacing

use of com.xenoage.zong.musiclayout.spacing.StavesSpacing in project Zong by Xenoage.

the class StretchSystemsTest method createSystem.

/**
 * Creates and returns a simple {@link SystemSpacing} using the
 * given values.
 */
public static SystemSpacing createSystem(int stavesCount, float staffHeight, float staffDistance, float offsetY) {
    float is = staffHeight / 5;
    List<Staff> staves = alist(stavesCount);
    for (int i = 0; i < stavesCount; i++) staves.add(new Staff(alist(), 5, is));
    float[] staffDistances = new float[stavesCount - 1];
    for (int i : range(stavesCount - 1)) staffDistances[i] = staffDistance;
    return new SystemSpacing(CollectionUtils.<ColumnSpacing>alist(), 0, 0, 0, new StavesSpacing(staves, staffDistances, is), offsetY);
}
Also used : StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) Staff(com.xenoage.zong.core.music.Staff) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Aggregations

StavesSpacing (com.xenoage.zong.musiclayout.spacing.StavesSpacing)4 SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)3 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)2 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)2 Score (com.xenoage.zong.core.Score)1 StaffLayout (com.xenoage.zong.core.format.StaffLayout)1 SystemLayout (com.xenoage.zong.core.format.SystemLayout)1 Staff (com.xenoage.zong.core.music.Staff)1 ColumnSpacing (com.xenoage.zong.musiclayout.spacing.ColumnSpacing)1