Search in sources :

Example 1 with ScoreHeader

use of com.xenoage.zong.core.header.ScoreHeader 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 ScoreHeader

use of com.xenoage.zong.core.header.ScoreHeader in project Zong by Xenoage.

the class ScoreFrameLayouter method computeScoreFrameLayout.

/**
 * Creates a {@link ScoreFrameLayout} from the given {@link FrameSpacing}.
 *
 * @param unclosedElements  unclosed elements from the last frame, like slurs
 *                          spanning over more than one frame
 */
public ScoreFrameLayout computeScoreFrameLayout(FrameSpacing frame, int frameIndex, Notations notations, List<ContinuedElement> unclosedElements, Context layouterContext, Map<Beam, BeamSpacing> beamsSpacing) {
    layouterContext.saveMp();
    Score score = layouterContext.score;
    SymbolPool symbols = layouterContext.symbols;
    StamperContext context = new StamperContext();
    context.layouter = layouterContext;
    context.notations = notations;
    ScoreHeader header = score.getHeader();
    int stavesCount = score.getStavesCount();
    StavesList stavesList = score.getStavesList();
    ArrayList<StaffStamping> staffStampsPool = alist();
    ArrayList<Stamping> otherStampsPool = alist();
    // default lyric style
    FormattedTextStyle defaultLyricStyle = new FormattedTextStyle(score.getFormat().getLyricFont());
    // caches
    OpenSlursCache openCurvedLinesCache = new OpenSlursCache();
    OpenWedges openWedges = new OpenWedges();
    OpenLyricsCache openLyricsCache = new OpenLyricsCache();
    LastLyrics lastLyrics = new LastLyrics();
    OpenTupletsCache openTupletsCache = new OpenTupletsCache();
    OpenVolta openVolta = new OpenVolta();
    // add continued elements
    for (ContinuedElement ce : unclosedElements) {
        if (ce instanceof ContinuedSlur) {
            openCurvedLinesCache.add(SlurCache.createContinued((ContinuedSlur) ce));
        } else if (ce instanceof ContinuedVolta) {
            openVolta.volta = (ContinuedVolta) ce;
        } else if (ce instanceof ContinuedWedge) {
            openWedges.wedges.add((ContinuedWedge) ce);
        }
    }
    // create staff stampings
    StaffStampings staffStampings = staffStamper.createStaffStampings(score, frame);
    staffStampings.addAllTo(staffStampsPool);
    context.staffStampings = staffStampings;
    // go through the systems
    for (int iSystem : range(frame.getSystems())) {
        context.systemIndex = iSystem;
        SystemSpacing system = frame.getSystems().get(iSystem);
        List<StaffStamping> systemStaves = staffStampings.getAllOfSystem(iSystem);
        StaffStamping systemFirstStaff = getFirst(systemStaves);
        // add the part names (first system) or part abbreviations (other systems)
        int iStaffInPart = 0;
        for (Part part : stavesList.getParts()) {
            PartNameStamper.Style style = (frameIndex == 0 && iSystem == 0 ? PartNameStamper.Style.Full : PartNameStamper.Style.Abbreviated);
            addNotNull(otherStampsPool, partNameStamper.stamp(part, iStaffInPart, systemStaves, style));
            iStaffInPart += part.getStavesCount();
        }
        // create the brackets at the beginning of the system
        for (BracketGroup bracketGroup : stavesList.getBracketGroups()) {
            StavesRange r = bracketGroup.getStaves();
            otherStampsPool.add(new BracketStamping(systemStaves.get(r.getStart()), systemStaves.get(r.getStop()), system.getMarginLeftMm() - 1.4f, bracketGroup.getStyle()));
        }
        // create the barlines and measure numbers
        otherStampsPool.addAll(barlinesStamper.stamp(system, systemStaves, score));
        // fill the staves
        for (int iStaff : range(stavesCount)) {
            layouterContext.mp = layouterContext.mp.withStaff(iStaff);
            context.staffIndex = iStaff;
            float xMm = context.getCurrentStaffStamping().positionMm.x;
            for (int iMeasure : range(system.columns)) {
                int globalMeasureIndex = system.getStartMeasure() + iMeasure;
                layouterContext.mp = layouterContext.mp.withMeasure(globalMeasureIndex);
                context.measureIndex = globalMeasureIndex;
                ColumnSpacing measureColumnSpacing = system.columns.get(iMeasure);
                MeasureSpacing measure = measureColumnSpacing.getMeasures().get(iStaff);
                // add leading spacing elements, if available
                otherStampsPool.addAll(measureStamper.stampLeading(measure, xMm, context));
                // add directions
                otherStampsPool.addAll(directionStamper.stamp(context));
                // add measure elements within this measure
                float voicesXMm = xMm + measureColumnSpacing.getLeadingWidthMm();
                otherStampsPool.addAll(measureStamper.stampMeasure(measure, voicesXMm, context));
                // add voice elements within this measure
                otherStampsPool.addAll(voiceStamper.stampVoices(measure, voicesXMm, staffStampings, context, defaultLyricStyle, beamsSpacing, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
                xMm += measureColumnSpacing.getWidthMm();
            }
        }
        // create all voltas in this system, including open voltas from the last system
        otherStampsPool.addAll(voltaStamper.stampSystem(systemFirstStaff, openVolta, header, defaultLyricStyle));
        // create all wedges in this system
        otherStampsPool.addAll(wedgeStamper.stampSystem(system, score, staffStampings, openWedges));
    }
    // create the collected ties and slurs
    otherStampsPool.addAll(createTiesAndSlurs(openCurvedLinesCache, staffStampings, frame.getSystems().size()));
    // create the open lyric underscore lines
    for (Tuple3<StaffTextStamping, NoteheadStamping, Integer> openUnderscore : openLyricsCache.getUnderscores()) {
        // TODO: fetch style efficiently
        FormattedTextStyle style = defaultLyricStyle;
        FormattedTextElement firstElement = openUnderscore.get1().getText().getFirstParagraph().getElements().getFirst();
        if (firstElement instanceof FormattedTextString) {
            style = ((FormattedTextString) firstElement).getStyle();
        }
        otherStampsPool.addAll(lyricStamper.createUnderscoreStampings(openUnderscore.get1(), openUnderscore.get2(), style, staffStampings.getAllOfStaff(openUnderscore.get3())));
    }
    // create tuplet brackets/numbers
    for (Tuplet tuplet : openTupletsCache) {
        otherStampsPool.add(tupletStamper.createTupletStamping(tuplet, openTupletsCache, symbols));
    }
    // collect elements that have to be continued on the next frame
    ArrayList<ContinuedElement> continuedElements = alist();
    for (SlurCache clc : openCurvedLinesCache) {
        continuedElements.add(clc.getContinuedCurvedLine());
    }
    if (openVolta.volta != null)
        continuedElements.add(openVolta.volta);
    continuedElements.addAll(openWedges.wedges);
    layouterContext.restoreMp();
    return new ScoreFrameLayout(frame, staffStampsPool, otherStampsPool, continuedElements);
}
Also used : PartNameStamper(com.xenoage.zong.musiclayout.stamper.PartNameStamper) SlurCache(com.xenoage.zong.musiclayout.layouter.cache.util.SlurCache) LastLyrics(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.LastLyrics) StavesRange(com.xenoage.zong.core.music.group.StavesRange) OpenSlursCache(com.xenoage.zong.musiclayout.layouter.cache.OpenSlursCache) SymbolPool(com.xenoage.zong.symbols.SymbolPool) OpenTupletsCache(com.xenoage.zong.musiclayout.layouter.cache.OpenTupletsCache) FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) BracketGroup(com.xenoage.zong.core.music.group.BracketGroup) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) Tuplet(com.xenoage.zong.core.music.tuplet.Tuplet) StamperContext(com.xenoage.zong.musiclayout.stamper.StamperContext) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) Part(com.xenoage.zong.core.music.Part) StavesList(com.xenoage.zong.core.music.StavesList) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) OpenLyricsCache(com.xenoage.zong.musiclayout.layouter.cache.OpenLyricsCache) StaffStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.StaffStampings) FormattedTextElement(com.xenoage.zong.core.text.FormattedTextElement)

Example 3 with ScoreHeader

use of com.xenoage.zong.core.header.ScoreHeader in project Zong by Xenoage.

the class StavesSpacer method compute.

public StavesSpacing compute(Score score, int systemIndex) {
    // compute staff distances
    ScoreFormat scoreFormat = score.getFormat();
    ScoreHeader scoreHeader = score.getHeader();
    float[] distancesMm = new float[score.getStavesCount() - 1];
    for (int iStaff : range(1, distancesMm.length)) {
        StaffLayout staffLayout = scoreHeader.getStaffLayout(systemIndex, iStaff);
        float staffDistanceMm = 0;
        if (staffLayout != null) {
            // use custom staff distance
            staffDistanceMm = staffLayout.getDistance();
        } else {
            // use default staff distance
            staffDistanceMm = scoreFormat.getStaffLayoutNotNull(iStaff).getDistance();
        }
        distancesMm[iStaff - 1] = staffDistanceMm;
    }
    // create spacing
    StavesSpacing stavesSpacing = new StavesSpacing(score.getStavesList().getStaves(), distancesMm, scoreFormat.getInterlineSpace());
    return stavesSpacing;
}
Also used : ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) StaffLayout(com.xenoage.zong.core.format.StaffLayout)

Example 4 with ScoreHeader

use of com.xenoage.zong.core.header.ScoreHeader in project Zong by Xenoage.

the class SystemSpacer method compute.

/**
 * Arranges an optimum number of measures columns in a system, beginning at the given measure,
 * if possible.
 * @param context        the context of the layouter, with the {@link MP} set to the start measure
 * @param usableSizeMm   the usable size within the score frame in mm
 * @param offsetYMm      the vertical offset of the system in mm
 * @param systemIndex    the global system index (over all frames)
 * @param isFirst        true, iff this system is the first one in a score frame
 * @param isAdditional   true, iff this system is created for an additional frame, which is created
 *                       for a complete score layout, but is not part of the defined layout
 * @param measureColumnSpacings  a list of all measure column spacings without leading spacings
 * @param notations      the notations of the elements, needed when a column has to be recomputed
 *                       because of a leading spacing
 */
public Optional<SystemSpacing> compute(Context context, Size2f usableSizeMm, float offsetYMm, int systemIndex, boolean isFirst, boolean isAdditional, List<ColumnSpacing> measureColumnSpacings, Notations notations) {
    int startMeasure = context.mp.measure;
    // test if there is enough height for the system
    Score score = context.score;
    ScoreFormat scoreFormat = score.getFormat();
    ScoreHeader scoreHeader = score.getHeader();
    // compute spacing of staves
    StavesSpacing stavesSpacing = stavesSpacer.compute(score, systemIndex);
    // enough space?
    if (offsetYMm + stavesSpacing.getTotalHeightMm() > usableSizeMm.height) {
        // when the system is the first one in an additional frame, we force it into the frame
        if (false == (isFirst && isAdditional))
            // not enough space
            return absent();
    }
    // compute the usable width for the system
    float systemLeftMarginMm = getLeftMarginMm(systemIndex, scoreFormat, scoreHeader);
    float systemRightMarginMm = getRightMarginMm(systemIndex, scoreFormat, scoreHeader);
    float usableWidthMm = usableSizeMm.width - systemLeftMarginMm - systemRightMarginMm;
    // append system measure-by-measure, until there is no space any more
    // or until there are no measures left
    int measuresCount = score.getMeasuresCount();
    List<ColumnSpacing> system = alist();
    float usedWidthMm = 0;
    int iMeasure;
    while (startMeasure + system.size() < measuresCount) {
        iMeasure = startMeasure + system.size();
        // decide if to add a leading spacing to the current measure or not
        boolean firstMeasure = system.size() == 0;
        ColumnSpacing column;
        if (firstMeasure) {
            // first measure within this system: add leading elements (clef, time sig.)
            column = columnSpacer.compute(context, true, /* leading! */
            notations);
        } else {
            // otherwise: use the precomputed spacing (without leading spacing)
            column = measureColumnSpacings.get(iMeasure);
        }
        // this system is created for a complete score layout
        if (false == canAppend(column, iMeasure, usableWidthMm, usedWidthMm, scoreHeader, firstMeasure)) {
            if (system.size() == 0 && isAdditional) {
                // force the single measure in this system
                usedWidthMm += column.getWidthMm();
                system.add(column);
            } else {
                // no more space for another measure
                break;
            }
        } else {
            usedWidthMm += column.getWidthMm();
            system.add(column);
        }
    }
    // we are finished
    if (system.size() == 0) {
        // not enough space for the system on this area
        return absent();
    } else {
        SystemSpacing ret = new SystemSpacing(system, systemLeftMarginMm, systemRightMarginMm, usedWidthMm, stavesSpacing, offsetYMm);
        return of(ret);
    }
}
Also used : ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) StavesSpacing(com.xenoage.zong.musiclayout.spacing.StavesSpacing) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 5 with ScoreHeader

use of com.xenoage.zong.core.header.ScoreHeader in project Zong by Xenoage.

the class FrameSpacer method compute.

/**
 * Arranges an optimum number of systems in a frame, beginning at the given measure,
 * if possible.
 * @param context         the context of the layouter, with the {@link MP} set to the start measure
 * @param startSystem     the index of the system where to start
 * @param usableSizeMm    the usable size within the score frame in mm
 * @param isAdditional    true, when this frame is created for a complete score layout,
 *                         but is not part of the defined layout
 * @param columnSpacings  a list of all measure column spacings without leading spacings
 * @param notations       the notations of the elements, needed when a column has to be recomputed
 *                        because of a leading spacing
 */
public FrameSpacing compute(Context context, int startSystem, Size2f usableSizeMm, boolean isAdditional, List<ColumnSpacing> columnSpacings, Notations notations) {
    context.saveMp();
    int startMeasure = context.mp.measure;
    Score score = context.score;
    ScoreFormat scoreFormat = score.getFormat();
    ScoreHeader scoreHeader = score.getHeader();
    int measuresCount = score.getMeasuresCount();
    int measureIndex = startMeasure;
    int systemIndex = startSystem;
    // top margin
    float offsetY = getTopSystemDistance(systemIndex, scoreFormat, scoreHeader);
    // append systems to the frame
    List<SystemSpacing> systems = alist();
    while (measureIndex < measuresCount) {
        // try to create system on this frame
        context.mp = atMeasure(measureIndex);
        boolean isFirst = (systems.size() == 0);
        SystemSpacing system = systemSpacer.compute(context, usableSizeMm, offsetY, systemIndex, isFirst, isAdditional, columnSpacings, notations).orNull();
        // was there enough place for this system?
        if (system != null) {
            // yes, there is enough place. add system
            systems.add(system);
            // update offset and start measure index for next system
            // add height of this system
            offsetY += system.getHeightMm();
            // add system distance of the following system
            offsetY += getSystemDistance(systemIndex + 1, scoreFormat, scoreHeader);
            // increase indexes
            systemIndex++;
            measureIndex = system.getEndMeasure() + 1;
        } else {
            break;
        }
    }
    context.restoreMp();
    return new FrameSpacing(systems, usableSizeMm);
}
Also used : ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Aggregations

ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)6 Score (com.xenoage.zong.core.Score)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 StaffLayout (com.xenoage.zong.core.format.StaffLayout)2 SystemLayout (com.xenoage.zong.core.format.SystemLayout)2 StavesSpacing (com.xenoage.zong.musiclayout.spacing.StavesSpacing)2 SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)2 Paint (android.graphics.Paint)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 Break (com.xenoage.zong.core.format.Break)1 PageFormat (com.xenoage.zong.core.format.PageFormat)1 PageMargins (com.xenoage.zong.core.format.PageMargins)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 Part (com.xenoage.zong.core.music.Part)1 StavesList (com.xenoage.zong.core.music.StavesList)1 BracketGroup (com.xenoage.zong.core.music.group.BracketGroup)1 StavesRange (com.xenoage.zong.core.music.group.StavesRange)1 PageBreak (com.xenoage.zong.core.music.layout.PageBreak)1 SystemBreak (com.xenoage.zong.core.music.layout.SystemBreak)1