Search in sources :

Example 6 with ScoreFrame

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

the class PageTest method createPageWithRotatedFrames.

/**
 * Creates a layout with a page with some rotated frames for testing.
 * See PageTest.odg for a preview of the page.
 */
private Layout createPageWithRotatedFrames() {
    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));
    frm1.setRotation(-30);
    page.addFrame(frm1);
    // Frame 2
    frm2 = new GroupFrame();
    frm2.setPosition(p(90, 110));
    frm2.setSize(s(60, 40));
    frm2.setRotation(70);
    page.addFrame(frm2);
    // Childframe 2a
    frm2a = new ScoreFrame();
    frm2a.setPosition(p(20, 10));
    frm2a.setSize(s(10, 10));
    frm2a.setRotation(0);
    frm2.addChildFrame(frm2a);
    // Childframe 2b
    frm2b = new ScoreFrame();
    frm2b.setPosition(p(-10, -5));
    frm2b.setSize(s(20, 20));
    frm2b.setRotation(70);
    frm2.addChildFrame(frm2b);
    // Frame 3
    frm3 = new ScoreFrame();
    frm3.setPosition(p(95, 155));
    frm3.setSize(s(80, 40));
    frm3.setRotation(30);
    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)

Example 7 with ScoreFrame

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

the class CursorOutput method write.

public JsonObject write(ScoreDoc doc) {
    JsonObject ret = new JsonObject();
    // create midi sequence and mp mappings
    Score score = doc.getScore();
    val seq = MidiConverter.convertToSequence(score, optionsForFileExport, new JseMidiSequenceWriter());
    // save time map
    JsonArray jsonMPs = new JsonArray();
    val timeMap = seq.getTimeMap();
    for (int iRep : range(timeMap.getRepetitionsCount())) {
        for (val time : timeMap.getTimesSorted(iRep)) {
            val midiTime = timeMap.getByRepTime(iRep, time);
            JsonObject jsonMP = new JsonObject();
            jsonMP.addProperty("measure", time.measure);
            jsonMP.addProperty("beat", "" + time.beat);
            jsonMP.addProperty("ms", midiTime.ms);
            jsonMPs.add(jsonMP);
        }
    }
    ret.add("mps", jsonMPs);
    // collect data
    int measuresCount = score.getMeasuresCount();
    ArrayList<System> systems = new ArrayList<>();
    ArrayList<Measure> measures = new ArrayList<>();
    for (int i = 0; i < measuresCount; i++) {
        measures.add(new Measure());
    }
    int systemCount = 0;
    Layout layout = doc.getLayout();
    for (int iPage : range(layout.getPages())) {
        Page page = layout.getPages().get(iPage);
        Size2f pageSize = page.getFormat().getSize();
        for (Frame frame : page.getFrames()) {
            if (frame instanceof ScoreFrame) {
                Point2f absPos = frame.getAbsolutePosition();
                float offsetX = absPos.x - frame.getSize().width / 2;
                float offsetY = absPos.y - frame.getSize().height / 2;
                ScoreFrameLayout sfl = ((ScoreFrame) frame).getScoreFrameLayout();
                for (SystemSpacing systemSpacing : sfl.getFrameSpacing().getSystems()) {
                    // read system data
                    int systemIndex = systemCount + systemSpacing.getSystemIndexInFrame();
                    while (systems.size() - 1 < systemIndex) systems.add(new System());
                    System system = systems.get(systemIndex);
                    system.page = iPage;
                    system.top = (offsetY + systemSpacing.offsetYMm) / pageSize.height;
                    system.bottom = (offsetY + systemSpacing.offsetYMm + systemSpacing.getHeightMm()) / pageSize.height;
                    // read measure beats
                    float systemOffsetX = systemSpacing.marginLeftMm;
                    for (int iMeasure : systemSpacing.getMeasures()) {
                        Measure measure = measures.get(iMeasure);
                        measure.system = systemIndex;
                        measure.left = (offsetX + systemOffsetX + systemSpacing.getMeasureStartMm(iMeasure)) / pageSize.width;
                        measure.right = (offsetX + systemOffsetX + systemSpacing.getMeasureEndMm(iMeasure)) / pageSize.width;
                        for (BeatOffset bo : systemSpacing.getColumn(iMeasure).getBeatOffsets()) {
                            measure.beats.put(bo.getBeat(), (offsetX + systemOffsetX + bo.getOffsetMm()) / pageSize.width);
                        }
                    }
                }
                systemCount += sfl.getFrameSpacing().getSystems().size();
            }
        }
    }
    // save systems
    JsonArray jsonSystems = new JsonArray();
    for (int i = 0; i < systems.size(); i++) {
        System system = systems.get(i);
        JsonObject jsonSystem = new JsonObject();
        jsonSystem.addProperty("number", i);
        jsonSystem.addProperty("page", system.page);
        jsonSystem.addProperty("top", system.top);
        jsonSystem.addProperty("bottom", system.bottom);
        jsonSystems.add(jsonSystem);
    }
    ret.add("systems", jsonSystems);
    // save measures
    JsonArray jsonMeasures = new JsonArray();
    for (int i = 0; i < measuresCount; i++) {
        Measure measure = measures.get(i);
        JsonObject jsonMeasure = new JsonObject();
        jsonMeasure.addProperty("number", i);
        jsonMeasure.addProperty("system", measure.system);
        jsonMeasure.addProperty("left", measure.left);
        jsonMeasure.addProperty("right", measure.right);
        // beats
        JsonArray jsonBeats = new JsonArray();
        ArrayList<Fraction> sortedBeats = new ArrayList<>(measure.beats.keySet());
        Collections.sort(sortedBeats);
        for (Fraction beat : sortedBeats) {
            JsonObject jsonBeat = new JsonObject();
            jsonBeat.addProperty("at", "" + beat);
            jsonBeat.addProperty("x", measure.beats.get(beat));
            jsonBeats.add(jsonBeat);
        }
        jsonMeasure.add("beats", jsonBeats);
        jsonMeasures.add(jsonMeasure);
    }
    ret.add("measures", jsonMeasures);
    // save time cursors
    JsonArray jsonTCs = new JsonArray();
    for (int iRep : range(timeMap.getRepetitionsCount())) {
        for (val time : timeMap.getTimesSorted(iRep)) {
            val midiTime = timeMap.getByRepTime(iRep, time);
            JsonObject jsonTC = new JsonObject();
            jsonTC.addProperty("time", midiTime.ms);
            Measure measure = measures.get(time.measure);
            System system = systems.get(measure.system);
            jsonTC.addProperty("page", system.page);
            jsonTC.addProperty("top", system.top);
            jsonTC.addProperty("left", measure.beats.get(time.beat));
            jsonTC.addProperty("bottom", system.bottom);
            jsonTCs.add(jsonTC);
        }
    }
    ret.add("timecursors", jsonTCs);
    return ret;
}
Also used : lombok.val(lombok.val) Frame(com.xenoage.zong.layout.frames.Frame) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Page(com.xenoage.zong.layout.Page) Fraction(com.xenoage.utils.math.Fraction) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) JsonArray(com.google.gson.JsonArray) Score(com.xenoage.zong.core.Score) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) Layout(com.xenoage.zong.layout.Layout) Size2f(com.xenoage.utils.math.geom.Size2f) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) JseMidiSequenceWriter(com.xenoage.zong.desktop.io.midi.out.JseMidiSequenceWriter) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 8 with ScoreFrame

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

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

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