Search in sources :

Example 1 with ScoreFrameChain

use of com.xenoage.zong.layout.frames.ScoreFrameChain 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 ScoreFrameChain

use of com.xenoage.zong.layout.frames.ScoreFrameChain in project Zong by Xenoage.

the class Layout method getScoreFrame.

/**
 * Computes the adjustment handle at the given position and returns it. If
 * there is none, null is returned.
 * @param layoutPosition the position where to look for a handle
 * @param scaling the current scaling factor
 */
/* TODO
	public FrameHandle computeFrameHandleAt(LayoutPosition layoutPosition, float scaling)
	{
		if (layoutPosition == null)
			return null;
		// find handle on the given page
		FrameHandle handle = null;
		Page givenPage = pages.get(layoutPosition.getPageIndex());
		handle = givenPage.computeFrameHandleAt(layoutPosition.getPosition(), scaling);
		return handle;
	} */
/**
 * Gets the axis-aligned bounding rectangle of the given system, specified
 * by its {@link ScoreLayout}, the index of the frame and the index of the
 * system (relative to the frame) in page coordinates together with the
 * index of the page. If not found, null is returned.
 */
/* TODO
	public Tuple2<Integer, Rectangle2f> getSystemBoundingRect(ScoreLayout scoreLayout,
		int frameIndex, int systemIndex) {
		
		//find the frame
		ScoreFrameChain chain = scoreLayouts.getKeyByValue(scoreLayout);
		ScoreFrame scoreFrame = chain.frames.get(frameIndex);

		//get system boundaries in mm
		ScoreFrameLayout scoreFrameLayout = scoreLayout.frames.get(frameIndex);
		Rectangle2f rectMm = scoreFrameLayout.getSystemBoundaries(systemIndex);
		if (rectMm == null)
			return null;

		//compute corner points (because frame may be rotated) and transform them
		float x = rectMm.position.x - scoreFrame.getSize().width / 2;
		float y = rectMm.position.y - scoreFrame.getSize().height / 2;
		float w = rectMm.size.width;
		float h = rectMm.size.height;
		Point2f nw = scoreFrame.computePagePosition(new Point2f(x, y), this);
		Point2f ne = scoreFrame.computePagePosition(new Point2f(x + w, y), this);
		Point2f se = scoreFrame.computePagePosition(new Point2f(x + w, y + h), this);
		Point2f sw = scoreFrame.computePagePosition(new Point2f(x, y + h), this);

		// compute axis-aligned bounding box and return it
		Rectangle2f ret = new Rectangle2f(nw.x, nw.y, 0, 0);
		ret = ret.extend(ne);
		ret = ret.extend(se);
		ret = ret.extend(sw);

		int pageIndex = pages.indexOf(getPage(scoreFrame));
		return new Tuple2<Integer, Rectangle2f>(pageIndex, ret);
	} */
/**
 * Gets the {@link ScoreFrame} which contains the given measure within
 * the given score. If it can not be found, null is returned.
 */
@Untested
public ScoreFrame getScoreFrame(Score score, int measure) {
    ScoreFrameChain chain = getScoreFrameChain(score);
    if (chain == null || chain.getScoreLayout() == null)
        return null;
    int frameIndex = chain.getScoreLayout().getFrameIndexOf(measure);
    if (frameIndex >= 0 && frameIndex < chain.getFrames().size())
        return chain.getFrames().get(frameIndex);
    return null;
}
Also used : ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) Untested(com.xenoage.utils.annotations.Untested)

Example 3 with ScoreFrameChain

use of com.xenoage.zong.layout.frames.ScoreFrameChain in project Zong by Xenoage.

the class Layout method updateScoreLayouts.

/**
 * Updates the {@link ScoreLayout}s belonging to the given {@link Score}.
 */
public void updateScoreLayouts(Score score) {
    ScoreFrameChain chain = getScoreFrameChain(score);
    if (chain == null)
        return;
    ScoreLayout oldScoreLayout = chain.getScoreLayout();
    // select symbol pool and layout settings
    SymbolPool symbolPool = oldScoreLayout != null ? oldScoreLayout.symbolPool : defaults.getSymbolPool();
    LayoutSettings layoutSettings = oldScoreLayout != null ? oldScoreLayout.layoutSettings : defaults.getLayoutSettings();
    CList<ScoreLayoutArea> areas = clist();
    for (ScoreFrame scoreFrame : chain.getFrames()) {
        areas.add(new ScoreLayoutArea(scoreFrame.getSize(), scoreFrame.getHFill(), scoreFrame.getVFill()));
    }
    areas.close();
    Context context = new Context(score, symbolPool, layoutSettings);
    Target target = new Target(areas, areas.get(areas.size() - 1), false);
    ScoreLayout scoreLayout = new ScoreLayouter(context, target).createScoreLayout();
    // set updated layout
    chain.setScoreLayout(scoreLayout);
}
Also used : Context(com.xenoage.zong.musiclayout.layouter.Context) Target(com.xenoage.zong.musiclayout.layouter.Target) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) SymbolPool(com.xenoage.zong.symbols.SymbolPool) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Example 4 with ScoreFrameChain

use of com.xenoage.zong.layout.frames.ScoreFrameChain in project Zong by Xenoage.

the class Layout method chainUpScoreFrame.

public void chainUpScoreFrame(ScoreFrame frameFrom, ScoreFrame frameTo) {
    if (frameFrom == frameTo)
        throw new IllegalArgumentException("Same frames");
    ScoreFrameChain fromChain = frameFrom.getScoreFrameChain();
    fromChain.add(frameFrom, frameTo);
}
Also used : ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain)

Example 5 with ScoreFrameChain

use of com.xenoage.zong.layout.frames.ScoreFrameChain 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)

Aggregations

ScoreFrameChain (com.xenoage.zong.layout.frames.ScoreFrameChain)6 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)4 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)4 Point2f (com.xenoage.utils.math.geom.Point2f)3 ScoreLayoutArea (com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)3 ScoreLayouter (com.xenoage.zong.musiclayout.layouter.ScoreLayouter)3 Target (com.xenoage.zong.musiclayout.layouter.Target)3 Size2f (com.xenoage.utils.math.geom.Size2f)2 PageFormat (com.xenoage.zong.core.format.PageFormat)2 Layout (com.xenoage.zong.layout.Layout)2 Page (com.xenoage.zong.layout.Page)2 Context (com.xenoage.zong.musiclayout.layouter.Context)2 Paint (android.graphics.Paint)1 Untested (com.xenoage.utils.annotations.Untested)1 Score (com.xenoage.zong.core.Score)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 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 SystemLayout (com.xenoage.zong.core.format.SystemLayout)1