Search in sources :

Example 1 with FrameSpacing

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

the class FramesSpacer method compute.

public FramesSpacing compute(List<ColumnSpacing> columns, Target target, Context context, Notations notations) {
    context.saveMp();
    ArrayList<FrameSpacing> frames = alist();
    int measuresCount = context.score.getMeasuresCount();
    int iMeasure = 0;
    int iSystem = 0;
    int iFrame = 0;
    boolean additionalFrameIteration;
    while (true) {
        additionalFrameIteration = false;
        // find score frame
        Size2f frameSize;
        if (iFrame < target.areas.size()) {
            // there is another existing score frame
            frameSize = target.getArea(iFrame).sizeMm;
        } else {
            // there is no another existing score frame
            if (false == target.isCompleteLayout) {
                // we are not interested in the stuff after the last score frame. exit.
                break;
            } else if (iMeasure >= measuresCount) {
                // all measures layouted. exit.
                break;
            } else {
                // still material to layout and additional frames requested. create one.
                frameSize = target.additionalArea.sizeMm;
                additionalFrameIteration = true;
            }
        }
        // some material left to layout?
        if (iMeasure < measuresCount) {
            // more measures to layout
            context.mp = atMeasure(iMeasure);
            FrameSpacing frame = frameSpacer.compute(context, iSystem, frameSize, additionalFrameIteration, columns, notations);
            if (frame.getSystems().size() > 0) {
                // at least one measure in this frame. remember frame
                frames.add(frame);
                iMeasure = frame.getEndMeasure() + 1;
                iSystem += frame.getSystems().size();
            } else {
                // do not create endless list of empty additional frames
                if (!additionalFrameIteration) {
                    frames.add(FrameSpacing.empty(frameSize));
                } else {
                    break;
                }
            }
        } else {
            // no material left. empty frame.
            frames.add(FrameSpacing.empty(frameSize));
        }
        // next frame
        iFrame++;
    }
    context.restoreMp();
    return new FramesSpacing(frames);
}
Also used : FramesSpacing(com.xenoage.zong.musiclayout.spacing.FramesSpacing) FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) Size2f(com.xenoage.utils.math.geom.Size2f)

Example 2 with FrameSpacing

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

the class ScoreLayouter method fillSystemsHorizontally.

/**
 * Fills the systems horizontally according to the {@link SystemFiller}
 * of the frame.
 */
void fillSystemsHorizontally(FramesSpacing frames, Target target) {
    for (int iFrame : range(frames.size())) {
        FrameSpacing frameArr = frames.get(iFrame);
        SystemFiller hFill = target.getArea(iFrame).hFill;
        // apply strategy
        for (SystemSpacing oldSystemArr : frameArr.getSystems()) {
            float usableWidth = frameArr.getUsableSizeMm().width - oldSystemArr.getMarginLeftMm() - oldSystemArr.getMarginRightMm();
            hFill.compute(oldSystemArr, usableWidth);
        }
    }
}
Also used : SystemFiller(com.xenoage.zong.musiclayout.spacer.system.fill.SystemFiller) FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 3 with FrameSpacing

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

Example 4 with FrameSpacing

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

the class StretchSystemsTest method computeTest.

@Test
public void computeTest() {
    // create a simple frame for testing
    float usableHeight = 400;
    int stavesCount = 2;
    float staffHeight = 10;
    float staffDistance = 30;
    float offset1 = 0;
    float offset2 = 100;
    float offset3 = 200;
    SystemSpacing system1 = createSystem(stavesCount, staffHeight, staffDistance, offset1);
    SystemSpacing system2 = createSystem(stavesCount, staffHeight, staffDistance, offset2);
    SystemSpacing system3 = createSystem(stavesCount, staffHeight, staffDistance, offset3);
    FrameSpacing frame = new FrameSpacing(ilist(system1, system2, system3), new Size2f(10, usableHeight));
    // apply strategy
    testee.compute(frame, null);
    // compare values
    // remaining space is usable height - offset3 - (height of last system)
    float remainingSpace = usableHeight - offset3 - system3.getHeightMm();
    // the last two systems are moved down, each remainingSpace/2
    float additionalSpace = remainingSpace / 2;
    // compare new offsets
    assertEquals(offset2 + 1 * additionalSpace, frame.getSystems().get(1).offsetYMm, df);
    assertEquals(offset3 + 2 * additionalSpace, frame.getSystems().get(2).offsetYMm, df);
}
Also used : FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) Size2f(com.xenoage.utils.math.geom.Size2f) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) Test(org.junit.Test)

Aggregations

FrameSpacing (com.xenoage.zong.musiclayout.spacing.FrameSpacing)4 SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)3 Size2f (com.xenoage.utils.math.geom.Size2f)2 Score (com.xenoage.zong.core.Score)1 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)1 SystemFiller (com.xenoage.zong.musiclayout.spacer.system.fill.SystemFiller)1 FramesSpacing (com.xenoage.zong.musiclayout.spacing.FramesSpacing)1 Test (org.junit.Test)1