Search in sources :

Example 1 with ScoreFrame

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

the class Content method onClick.

/**
 * This method is called when the mouse was clicked on the content.
 * A message with the clicked element is shown to the user.
 */
public void onClick(Point2f positionPx) {
    if (layout.getScoreFrames().size() == 0)
        return;
    // get the layout of first score frame
    ScoreFrame frame = layout.getScoreFrames().get(0);
    ScoreFrameLayout frameLayout = frame.getScoreFrameLayout();
    // convert position from screen space to page space, then from page space
    // to frame space, and them from frame space to score frame space
    Point2f positionMm = positionPx.scale(Units.pxToMm(1, mainWindow.getZoom()));
    Point2f framePositionMm = positionMm.sub(frame.getAbsolutePosition());
    Point2f scorePositionMm = frame.getScoreLayoutPosition(framePositionMm);
    // find elements under this position
    for (Stamping stamping : frameLayout.getAllStampings()) {
        if (stamping.getBoundingShape() != null && stamping.getBoundingShape().contains(scorePositionMm)) {
            MusicElement element = stamping.getMusicElement();
            if (element != null) {
                // music element found
                String message = "An element was clicked: " + element;
                if (element instanceof MPElement) {
                    // music element with a known musical position found
                    MPElement mpElement = (MPElement) element;
                    if (mpElement.getParent() != null)
                        message += " at " + mpElement.getMP();
                }
                mainWindow.showMessageDialog(message);
            }
        }
    }
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Point2f(com.xenoage.utils.math.geom.Point2f) MusicElement(com.xenoage.zong.core.music.MusicElement) MPElement(com.xenoage.zong.core.position.MPElement) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 2 with ScoreFrame

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

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

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

the class ScoreFrameRenderer method paintTransformed.

@Override
protected void paintTransformed(Frame frame, Canvas canvas, RendererArgs args) {
    Rectangle2f rect = getLocalRect(frame);
    // draw musical elements
    ScoreFrame scoreFrame = (ScoreFrame) frame;
    ScoreFrameLayout scoreLayout = scoreFrame.getScoreFrameLayout();
    if (scoreLayout != null) {
        // the coordinates of the layout elements are relative to the upper left
        // corner, so we have to translate them
        canvas.transformSave();
        canvas.transformTranslate(rect.x1(), rect.y1());
        // get musical stampings, and in interactive mode, also
        // stampings like for playback and selection
        Iterable<Stamping> stampings = (canvas.getDecoration() == CanvasDecoration.Interactive ? scoreLayout.getAllStampings() : scoreLayout.getMusicalStampings());
        // render them
        for (Stamping s : stampings) {
            StampingRenderer.drawAny(s, canvas, args);
        }
        // restore old transformation
        canvas.transformRestore();
    }
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 5 with ScoreFrame

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

the class PageTest method createPageWithUnrotatedFrames.

/**
 * Creates a layout with a page with some unrotated frames for testing.
 */
private Layout createPageWithUnrotatedFrames() {
    Layout layout = new Layout(null);
    PageFormat pf = new PageFormat(new Size2f(200, 200), new PageMargins(10, 10, 10, 10));
    Page page = new Page(pf);
    layout.addPage(page);
    // Frame 1
    frm1 = new ScoreFrame();
    frm1.setPosition(p(120, 120));
    frm1.setSize(s(60, 80));
    page.addFrame(frm1);
    // Frame 2
    frm2 = new GroupFrame();
    frm2.setPosition(p(90, 110));
    frm2.setSize(s(60, 40));
    page.addFrame(frm2);
    // Childframe 2a
    frm2a = new ScoreFrame();
    frm2a.setPosition(p(30, 0));
    frm2a.setSize(s(10, 10));
    frm2.addChildFrame(frm2a);
    // Childframe 2b
    frm2b = new ScoreFrame();
    frm2b.setPosition(p(-10, -20));
    frm2b.setSize(s(10, 10));
    frm2.addChildFrame(frm2b);
    // Frame 3
    frm3 = new ScoreFrame();
    frm3.setPosition(p(30, 80));
    frm3.setSize(s(30, 60));
    page.addFrame(frm3);
    return layout;
}
Also used : PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Size2f(com.xenoage.utils.math.geom.Size2f) GroupFrame(com.xenoage.zong.layout.frames.GroupFrame)

Aggregations

ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)9 Point2f (com.xenoage.utils.math.geom.Point2f)5 Size2f (com.xenoage.utils.math.geom.Size2f)5 PageFormat (com.xenoage.zong.core.format.PageFormat)4 ScoreFrameChain (com.xenoage.zong.layout.frames.ScoreFrameChain)4 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)4 PageMargins (com.xenoage.zong.core.format.PageMargins)3 Layout (com.xenoage.zong.layout.Layout)3 Page (com.xenoage.zong.layout.Page)3 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)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 Score (com.xenoage.zong.core.Score)2 GroupFrame (com.xenoage.zong.layout.frames.GroupFrame)2 Context (com.xenoage.zong.musiclayout.layouter.Context)2 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)2 Paint (android.graphics.Paint)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1