Search in sources :

Example 1 with ScoreLayout

use of com.xenoage.zong.musiclayout.ScoreLayout 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 ScoreLayout

use of com.xenoage.zong.musiclayout.ScoreLayout 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 3 with ScoreLayout

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

the class ScoreLayouter method createLayoutWithExceptions.

/**
 * Computes the whole layout and returns it.
 * If something fails, an exception is thrown.
 */
public ScoreLayout createLayoutWithExceptions() {
    // notations of elements
    Notations notations = notator.computeAll(context);
    // compute optimal measure column spacings
    List<ColumnSpacing> columns = columnsSpacer.compute(notations, context);
    // break columns into systems and frames
    FramesSpacing frames = framesSpacer.compute(columns, target, context, notations);
    // system stretching (horizontal)
    fillSystemsHorizontally(frames, target);
    // frame filling (vertical)
    fillFramesVertically(frames, target, context.score);
    // compute beam spacings. these are computed only now, after the horizontal
    // and vertical spacing of the score is fixed, since the beam slants depend on the
    // exact spacings
    Map<Beam, BeamSpacing> beams = beamsSpacer.compute(context.score, notations, frames);
    // create score frame layouts from the collected information
    List<ScoreFrameLayout> scoreFrameLayouts = createScoreFrameLayouts(frames, notations, context, beams);
    // create score layout
    return new ScoreLayout(context.score, scoreFrameLayouts, context.symbols, context.settings);
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) FramesSpacing(com.xenoage.zong.musiclayout.spacing.FramesSpacing) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) Notations(com.xenoage.zong.musiclayout.notation.Notations) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 4 with ScoreLayout

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

the class DemoScoreLayoutTry method main.

public static void main(String... args) throws Exception {
    SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
    LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
    try {
        Score score = ScoreRevolutionary.createScore();
        Size2f areaSize = new Size2f(150, 10000);
        Context context = new Context(score, symbolPool, layoutSettings);
        Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
        ScoreLayout layout = new ScoreLayouter(context, target).createLayoutWithExceptions();
        System.out.println(layout.toString());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) Score(com.xenoage.zong.core.Score) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout)

Example 5 with ScoreLayout

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

the class LayoutTest method getScoreFrameLayoutOrException.

default ScoreFrameLayout getScoreFrameLayoutOrException() throws Exception {
    Base base = (Base) this;
    String filepath = Base.dirPath + base.getFileName();
    ScoreDoc doc = new MusicXmlScoreDocFileInput().read(jsePlatformUtils().openFile(filepath), filepath);
    ScoreLayout layout = new ScoreLayouter(doc, targetA4()).createScoreLayout();
    return layout.getScoreFrameLayout(0);
}
Also used : MusicXmlScoreDocFileInput(com.xenoage.zong.desktop.io.musicxml.in.MusicXmlScoreDocFileInput) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) Base(musicxmltestsuite.tests.base.Base) ScoreDoc(com.xenoage.zong.documents.ScoreDoc)

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