Search in sources :

Example 1 with SystemLayout

use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.

the class ScoreDocScoreView method updateScreen.

@Override
public void updateScreen(Size2i screenSizePx, float zoom) {
    this.screenSizePx = screenSizePx;
    this.zoom = zoom;
    // recompute the layout, so that each page fits into the available screen space
    Size2f pageSizeMm = pxToMm(screenSizePx, zoom);
    float marginMm = pxToMm(marginPx, zoom);
    PageFormat pageFormat = new PageFormat(pageSizeMm, new PageMargins(marginMm, marginMm, marginMm, marginMm));
    Size2f frameSizeMm = new Size2f(pageFormat.getUseableWidth(), pageFormat.getUseableHeight());
    // first page needs space for title text
    titleTextHeightPx = screenSizePx.height / 20f;
    float firstFrameOffsetY = pxToMm(titleTextHeightPx, zoom);
    Size2f firstFrameSizeMm = new Size2f(frameSizeMm.width, frameSizeMm.height - firstFrameOffsetY);
    // delete unnecessary layout information, like system distances or system breaks
    Score score = doc.getScore();
    score.setFormat(new ScoreFormat());
    ScoreHeader header = score.getHeader();
    for (int i : range(header.getSystemLayouts())) {
        SystemLayout sl = header.getSystemLayout(i);
        if (sl != null)
            sl.setDistance(SystemLayout.defaultDistance);
    }
    for (int i : range(header.getColumnHeaders())) {
        ColumnHeader ch = header.getColumnHeader(i);
        if (ch.getMeasureBreak() != null)
            ch.setBreak(null);
    }
    // layout the score to find out the needed space
    Context context = new Context(score, App.getSymbolPool(), doc.getLayout().getDefaults().getLayoutSettings());
    Target target = new Target(alist(new ScoreLayoutArea(firstFrameSizeMm)), new ScoreLayoutArea(frameSizeMm), true);
    ScoreLayouter layouter = new ScoreLayouter(context, target);
    ScoreLayout scoreLayout = layouter.createScoreLayout();
    // create and fill at least one page
    Layout layout = new Layout(doc.getLayout().getDefaults());
    ScoreFrameChain chain = null;
    for (int i = 0; i < scoreLayout.frames.size(); i++) {
        Page page = new Page(pageFormat);
        Point2f position;
        Size2f size;
        if (i == 0) {
            // first page
            position = new Point2f(pageSizeMm.width / 2, pageSizeMm.height / 2 + firstFrameOffsetY);
            size = firstFrameSizeMm;
        } else {
            // other pages
            position = new Point2f(pageSizeMm.width / 2, pageSizeMm.height / 2);
            size = frameSizeMm;
        }
        ScoreFrame frame = new ScoreFrame();
        frame.setPosition(position);
        frame.setSize(size);
        page.addFrame(frame);
        layout.addPage(page);
        if (chain == null) {
            chain = new ScoreFrameChain(score);
            chain.setScoreLayout(scoreLayout);
        }
        chain.add(frame);
    }
    this.layout = layout;
}
Also used : Context(com.xenoage.zong.musiclayout.layouter.Context) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) Page(com.xenoage.zong.layout.Page) Paint(android.graphics.Paint) ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Target(com.xenoage.zong.musiclayout.layouter.Target) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) Layout(com.xenoage.zong.layout.Layout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) Size2f(com.xenoage.utils.math.geom.Size2f) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Example 2 with SystemLayout

use of com.xenoage.zong.core.format.SystemLayout 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 3 with SystemLayout

use of com.xenoage.zong.core.format.SystemLayout 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));
    }
}
Also used : SystemLayout(com.xenoage.zong.core.format.SystemLayout) Size2f(com.xenoage.utils.math.geom.Size2f) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 4 with SystemLayout

use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.

the class PrintReader method readSystemLayout.

private SystemLayout readSystemLayout(boolean isPageStarted, float tenthMm) {
    MxlLayout mxlLayout = mxlPrint.getLayout();
    if (mxlLayout != null) {
        MxlSystemLayout mxlSystemLayout = mxlLayout.getSystemLayout();
        if (mxlSystemLayout != null) {
            SystemLayoutReader systemLayoutReader = new SystemLayoutReader(mxlSystemLayout, tenthMm);
            SystemLayout systemLayout = systemLayoutReader.read();
            Float topSystemDistance = systemLayoutReader.getTopSystemDistance();
            // for first systems on a page, use top-system-distance
            if (isPageStarted && topSystemDistance != null)
                systemLayout.setDistance(topSystemDistance);
            return systemLayout;
        }
    }
    return null;
}
Also used : MxlSystemLayout(com.xenoage.zong.musicxml.types.MxlSystemLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) MxlSystemLayout(com.xenoage.zong.musicxml.types.MxlSystemLayout) MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout)

Example 5 with SystemLayout

use of com.xenoage.zong.core.format.SystemLayout in project Zong by Xenoage.

the class PrintReader method readToContext.

public void readToContext(Context context) {
    ScoreHeader header = context.getScore().getHeader();
    int measure = context.getMp().measure;
    // system and page break
    Break break_ = readBreak();
    if (break_ != null) {
        // MusicXML print is in the first broken measure, but we
        // store the break in the last measure before the break (thus -1)
        int breakMeasure = measure - 1;
        if (// ignore, when in the first measure
        breakMeasure >= 0)
            context.writeColumnElement(break_, breakMeasure);
    }
    // the first measure of a score is also ok.
    if (measure == 0 || break_ != null) {
        // first page or new page?
        boolean isPageBreak = break_ != null && break_.getPageBreak() == PageBreak.NewPage;
        boolean isPageStarted = (measure == 0 || isPageBreak);
        if (isPageBreak) {
            // increment page index
            context.incPageIndex();
        }
        // first system or new system?
        boolean isSystemBreak = isPageBreak || (break_ != null && break_.getSystemBreak() == SystemBreak.NewSystem);
        if (isSystemBreak) {
            // increment system index
            context.incSystemIndex();
        }
        // read system layout, if there
        SystemLayout systemLayout = readSystemLayout(isPageStarted, context.getTenthMm());
        if (systemLayout != null)
            header.setSystemLayout(context.getSystemIndex(), systemLayout);
        // staff layouts
        MxlLayout mxlLayout = mxlPrint.getLayout();
        if (mxlLayout != null) {
            for (MxlStaffLayout mxlStaffLayout : it(mxlLayout.getStaffLayouts())) {
                int staffIndex = mxlStaffLayout.getNumberNotNull() - 1;
                // get system layout. if it does not exist yet, create it
                systemLayout = header.getSystemLayout(context.getSystemIndex());
                if (systemLayout == null) {
                    systemLayout = new SystemLayout();
                    header.setSystemLayout(context.getSystemIndex(), systemLayout);
                }
                StaffLayout staffLayout = new StaffLayoutReader(mxlStaffLayout, context.getTenthMm()).read();
                systemLayout.setStaffLayout(context.getPartStaffIndices().getStart() + staffIndex, staffLayout);
            }
        }
    }
}
Also used : ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) MxlStaffLayout(com.xenoage.zong.musicxml.types.MxlStaffLayout) StaffLayout(com.xenoage.zong.core.format.StaffLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) MxlSystemLayout(com.xenoage.zong.musicxml.types.MxlSystemLayout) SystemBreak(com.xenoage.zong.core.music.layout.SystemBreak) PageBreak(com.xenoage.zong.core.music.layout.PageBreak) Break(com.xenoage.zong.core.format.Break) MxlLayout(com.xenoage.zong.musicxml.types.groups.MxlLayout) MxlStaffLayout(com.xenoage.zong.musicxml.types.MxlStaffLayout) MxlPrint(com.xenoage.zong.musicxml.types.MxlPrint)

Aggregations

SystemLayout (com.xenoage.zong.core.format.SystemLayout)6 MxlSystemLayout (com.xenoage.zong.musicxml.types.MxlSystemLayout)3 Size2f (com.xenoage.utils.math.geom.Size2f)2 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)2 SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)2 MxlLayout (com.xenoage.zong.musicxml.types.groups.MxlLayout)2 Paint (android.graphics.Paint)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 Score (com.xenoage.zong.core.Score)1 Break (com.xenoage.zong.core.format.Break)1 PageFormat (com.xenoage.zong.core.format.PageFormat)1 PageMargins (com.xenoage.zong.core.format.PageMargins)1 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 StaffLayout (com.xenoage.zong.core.format.StaffLayout)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 PageBreak (com.xenoage.zong.core.music.layout.PageBreak)1 SystemBreak (com.xenoage.zong.core.music.layout.SystemBreak)1 Layout (com.xenoage.zong.layout.Layout)1 Page (com.xenoage.zong.layout.Page)1 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)1