Search in sources :

Example 6 with ScoreLayout

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

the class ScoreDocFactory method read.

/**
 * Creates a {@link ScoreDoc} instance from the given score.
 * TIDY: move elsewhere, e.g. in a ScoreDocFactory class
 */
public ScoreDoc read(Score score) throws InvalidFormatException, IOException {
    // page format
    LayoutFormat layoutFormat = Companion.getDefaultLayoutFormat();
    Object oLayoutFormat = score.getMetaData().get("layoutformat");
    if (oLayoutFormat instanceof LayoutFormat) {
        layoutFormat = (LayoutFormat) oLayoutFormat;
    }
    LayoutDefaults layoutDefaults = new LayoutDefaults(layoutFormat);
    // create the document
    ScoreDoc ret = new ScoreDoc(score, layoutDefaults);
    Layout layout = ret.getLayout();
    // layout basics
    PageFormat pageFormat = layoutFormat.getPageFormat(0);
    Size2f frameSize = new Size2f(pageFormat.getUseableWidth(), pageFormat.getUseableHeight());
    Point2f framePos = new Point2f(pageFormat.getMargins().getLeft() + frameSize.width / 2, pageFormat.getMargins().getTop() + frameSize.height / 2);
    // layout the score to find out the needed space
    Target target = Target.completeLayoutTarget(new ScoreLayoutArea(frameSize));
    ScoreLayouter layouter = new ScoreLayouter(ret, target);
    ScoreLayout scoreLayout = isErrorLayoutEnabled ? layouter.createScoreLayout() : layouter.createLayoutWithExceptions();
    // create and fill at least one page
    if (scoreLayout.frames.size() > 0) {
        // normal layout: one frame per page
        ScoreFrameChain chain = null;
        for (int i = 0; i < scoreLayout.frames.size(); i++) {
            Page page = new Page(pageFormat);
            layout.addPage(page);
            ScoreFrame frame = new ScoreFrame();
            frame.setPosition(framePos);
            frame.setSize(frameSize);
            // TEST frame = frame.withHFill(NoHorizontalSystemFillingStrategy.getInstance());
            page.addFrame(frame);
            if (chain == null) {
                chain = new ScoreFrameChain(score);
                chain.setScoreLayout(scoreLayout);
            }
            chain.add(frame);
        }
    } else {
        // no frames: create a single empty page
        Page page = new Page(pageFormat);
        layout.addPage(page);
    }
    return ret;
}
Also used : ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) LayoutFormat.defaultLayoutFormat(com.xenoage.zong.core.format.LayoutFormat.defaultLayoutFormat) LayoutFormat(com.xenoage.zong.core.format.LayoutFormat) Page(com.xenoage.zong.layout.Page) LayoutDefaults(com.xenoage.zong.layout.LayoutDefaults) ScoreDoc(com.xenoage.zong.documents.ScoreDoc) PageFormat(com.xenoage.zong.core.format.PageFormat) Target(com.xenoage.zong.musiclayout.layouter.Target) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) Layout(com.xenoage.zong.layout.Layout) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) Size2f(com.xenoage.utils.math.geom.Size2f) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Example 7 with ScoreLayout

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

the class Layout method computeLP.

/**
 * Returns the {@link LayoutPos} of the given {@link MP} within the given {@link Score}
 * at the given line position, or null if unknown.
 */
public LayoutPos computeLP(Score score, MP mp, float lp) {
    ScoreFrameChain chain = getScoreFrameChain(score);
    if (chain != null) {
        ScoreLayout sl = chain.getScoreLayout();
        ScoreLayoutPos slp = sl.getScoreLP(mp, lp);
        if (slp != null) {
            ScoreFrame frame = chain.getFrames().get(slp.frameIndex);
            Page page = frame.getParentPage();
            if (page != null) {
                Point2f frameP = slp.pMm.sub(frame.getSize().width / 2, frame.getSize().height / 2);
                int pageIndex = pages.indexOf(page);
                Point2f pMm = frame.getPagePosition(frameP);
                return layoutPos(this, pageIndex, pMm);
            }
        }
    }
    return null;
}
Also used : ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) ScoreLayoutPos(com.xenoage.zong.musiclayout.ScoreLayoutPos)

Aggregations

ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)7 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)4 ScoreFrameChain (com.xenoage.zong.layout.frames.ScoreFrameChain)4 ScoreLayouter (com.xenoage.zong.musiclayout.layouter.ScoreLayouter)4 Point2f (com.xenoage.utils.math.geom.Point2f)3 Size2f (com.xenoage.utils.math.geom.Size2f)3 ScoreLayoutArea (com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)3 Target (com.xenoage.zong.musiclayout.layouter.Target)3 Score (com.xenoage.zong.core.Score)2 PageFormat (com.xenoage.zong.core.format.PageFormat)2 ScoreDoc (com.xenoage.zong.documents.ScoreDoc)2 Layout (com.xenoage.zong.layout.Layout)2 Page (com.xenoage.zong.layout.Page)2 Context (com.xenoage.zong.musiclayout.layouter.Context)2 LayoutSettings (com.xenoage.zong.musiclayout.settings.LayoutSettings)2 SymbolPool (com.xenoage.zong.symbols.SymbolPool)2 Paint (android.graphics.Paint)1 LayoutFormat (com.xenoage.zong.core.format.LayoutFormat)1 LayoutFormat.defaultLayoutFormat (com.xenoage.zong.core.format.LayoutFormat.defaultLayoutFormat)1 PageMargins (com.xenoage.zong.core.format.PageMargins)1