Search in sources :

Example 11 with StaffStamping

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

the class LegerLineRenderer method draw.

/**
 * Draws the given {@link LegerLineStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    LegerLineStamping legerLine = (LegerLineStamping) stamping;
    StaffStamping parentStaff = legerLine.parentStaff;
    float linePosition = legerLine.sp.lp;
    float scaling = args.targetScaling;
    float width = legerLine.widthIs * parentStaff.is;
    float p1xMm = legerLine.sp.xMm - width / 2;
    float p2xMm = p1xMm + width;
    float lineWidthMm = parentStaff.getLineWidthMm();
    Color color = Color.Companion.getBlack();
    float yMm = 0;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen or print
        BitmapLine screenLine = new BitmapLine(lineWidthMm, color, scaling);
        BitmapStaff screenStaff = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        yMm = parentStaff.positionMm.y + screenStaff.getYMm(linePosition);
        lineWidthMm = screenLine.widthMm;
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        // render with high quality
        yMm = parentStaff.computeYMm(linePosition);
    }
    canvas.drawLine(p(p1xMm, yMm), p(p2xMm, yMm), color, lineWidthMm);
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Color(com.xenoage.utils.color.Color) BitmapLine(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) LegerLineStamping(com.xenoage.zong.musiclayout.stampings.LegerLineStamping)

Example 12 with StaffStamping

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

the class SystemCursorRenderer method draw.

/**
 * Draws the given {@link SystemCursorStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    SystemCursorStamping cursor = (SystemCursorStamping) stamping;
    float viewScaling = args.targetScaling;
    StaffStamping topStaff = cursor.topStaff;
    StaffStamping bottomStaff = cursor.bottomStaff;
    float x, y1, y2;
    x = topStaff.positionMm.x + cursor.xMm;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float staffY = topStaff.positionMm.y;
        BitmapStaff ss = topStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        // top staff: top line
        y1 = staffY + ss.getYMm(topStaff.linesCount * 2);
        // bottom staff: bottom line
        staffY = bottomStaff.positionMm.y;
        ss = bottomStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        y2 = staffY + ss.getYMm(-2);
    } else {
        y1 = topStaff.computeYMm(topStaff.linesCount * 2);
        y2 = bottomStaff.computeYMm(-2);
    }
    canvas.drawLine(new Point2f(x, y1), new Point2f(x, y2), Companion.color(50, 50, 230), getCursorWidth(viewScaling));
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) SystemCursorStamping(com.xenoage.zong.musiclayout.stampings.SystemCursorStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 13 with StaffStamping

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

the class BarlinesStamper method stamp.

public List<Stamping> stamp(SystemSpacing system, List<StaffStamping> systemStaves, Score score) {
    List<Stamping> ret = alist();
    StaffStamping firstStaff = getFirst(systemStaves);
    int stavesCount = systemStaves.size();
    int systemIndex = system.getSystemIndexInFrame();
    float xOffset = firstStaff.positionMm.x;
    // common barline at the beginning, when system has at least one measure
    if (system.columns.size() > 0) {
        ret.add(new BarlineStamping(Barline.Companion.barlineRegular(), systemStaves, xOffset, BarlineGroup.Style.Common));
    }
    // barlines within the system and measure numbers
    for (int iMeasure : range(system.columns)) {
        float xLeft = xOffset;
        // measure numbering
        MeasureNumbering measureNumbering = score.getFormat().getMeasureNumbering();
        int globalMeasureIndex = system.getStartMeasure() + iMeasure;
        boolean showMeasureNumber = false;
        if (measureNumbering == MeasureNumbering.System) {
            // measure number at the beginning of each system (except the first one)
            showMeasureNumber = (iMeasure == 0 && globalMeasureIndex > 0);
        } else if (measureNumbering == MeasureNumbering.Measure) {
            // measure number at each measure (except the first one)
            showMeasureNumber = (globalMeasureIndex > 0);
        }
        if (showMeasureNumber) {
            FormattedText text = Companion.fText("" + (globalMeasureIndex + 1), new FormattedTextStyle(8), Alignment.Left);
            ret.add(new StaffTextStamping(text, sp(xLeft, firstStaff.linesCount * 2), firstStaff, null));
        }
        // for the first measure in the system: begin after leading spacing
        if (iMeasure == 0)
            xLeft += system.columns.get(iMeasure).getLeadingWidthMm();
        xOffset += system.columns.get(iMeasure).getWidthMm();
        float xRight = xOffset;
        // regard the groups of the score
        for (int iStaff : range(stavesCount)) {
            ColumnHeader columnHeader = score.getColumnHeader(globalMeasureIndex);
            BarlineGroup.Style barlineGroupStyle = BarlineGroup.Style.Single;
            BarlineGroup group = score.getStavesList().getBarlineGroupByStaff(iStaff);
            if (group != null)
                barlineGroupStyle = group.getStyle();
            List<StaffStamping> groupStaves = getBarlineGroupStaves(systemStaves, group);
            // start barline
            Barline startBarline = columnHeader.getStartBarline();
            if (startBarline != null) {
                // don't draw a regular barline at the left side of first measure of a system
                if ((startBarline.getStyle() == BarlineStyle.Regular && systemIndex == 0) == false)
                    ret.add(new BarlineStamping(startBarline, groupStaves, xLeft, barlineGroupStyle));
            }
            // end barline. if none is set, use a regular one.
            Barline endBarline = columnHeader.getEndBarline();
            if (endBarline == null)
                endBarline = Barline.Companion.barlineRegular();
            ret.add(new BarlineStamping(endBarline, groupStaves, xRight, barlineGroupStyle));
            // middle barlines
            for (BeatE<Barline> middleBarline : columnHeader.getMiddleBarlines()) {
                ret.add(new BarlineStamping(middleBarline.getElement(), groupStaves, xLeft + system.columns.get(iMeasure).getBarlineOffsetMm(middleBarline.getBeat()), barlineGroupStyle));
            }
            // go to next group
            if (group != null)
                iStaff = group.getStaves().getStop();
        }
    }
    return ret;
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) MeasureNumbering(com.xenoage.zong.core.format.MeasureNumbering) Barline(com.xenoage.zong.core.music.barline.Barline) BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup)

Example 14 with StaffStamping

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

the class PartNameStamper method stamp.

@MaybeNull
public FrameTextStamping stamp(Part part, int firstStaffIndex, List<StaffStamping> systemStaves, Style style) {
    StaffStamping firstStaff = systemStaves.get(firstStaffIndex);
    StaffStamping lastStaff = systemStaves.get(firstStaffIndex + part.getStavesCount() - 1);
    String name = (style == Style.Full ? part.getName() : part.getAbbreviation());
    if (name == null || name.length() == 0)
        return null;
    // in the middle of the staves
    float top = firstStaff.positionMm.y;
    float bottom = lastStaff.positionMm.y + (lastStaff.linesCount - 1) * lastStaff.is;
    FormattedText text = // TODO
    Companion.fText(// TODO
    name, // TODO
    new FormattedTextStyle(firstStaff.is * 2.5f * 2.67f), Alignment.Right);
    if (text.getParagraphs().size() == 0)
        return null;
    // TODO correction of baseline. /3 looks good.
    float middle = (top + bottom) / 2 + text.getFirstParagraph().getMetrics().getAscent() / 3;
    return new FrameTextStamping(text, new Point2f(firstStaff.positionMm.x - firstStaff.is * 2.5f, middle), // TODO
    null);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FrameTextStamping(com.xenoage.zong.musiclayout.stampings.FrameTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 15 with StaffStamping

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

the class StaffCursorRenderer method draw.

/**
 * Draws the given {@link StaffCursorStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StaffCursorStamping cursor = (StaffCursorStamping) stamping;
    float viewScaling = args.targetScaling;
    StaffStamping parentStaff = cursor.parentStaff;
    float x, y1, y2;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float staffY = parentStaff.positionMm.y;
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        // top: one interline space above staff
        y1 = staffY + ss.getYMm(parentStaff.linesCount * 2);
        // bottom: one interline space under staff
        y2 = staffY + ss.getYMm(-2);
    } else {
        y1 = parentStaff.computeYMm(parentStaff.linesCount * 2);
        y2 = parentStaff.computeYMm(-2);
    }
    x = parentStaff.positionMm.x + cursor.xMm + cursor.offsetIs * parentStaff.is;
    canvas.drawLine(new Point2f(x, y1), new Point2f(x, y2), Companion.color(30, 200, 30), getCursorWidth(viewScaling));
}
Also used : StaffCursorStamping(com.xenoage.zong.musiclayout.stampings.StaffCursorStamping) Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Aggregations

StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)21 Point2f (com.xenoage.utils.math.geom.Point2f)10 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)8 Color (com.xenoage.utils.color.Color)6 FormattedText (com.xenoage.zong.core.text.FormattedText)5 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)5 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)3 BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)2 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)2 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)2 BarlineStamping (com.xenoage.zong.musiclayout.stampings.BarlineStamping)2 StaffCursorStamping (com.xenoage.zong.musiclayout.stampings.StaffCursorStamping)2 SystemCursorStamping (com.xenoage.zong.musiclayout.stampings.SystemCursorStamping)2 TupletStamping (com.xenoage.zong.musiclayout.stampings.TupletStamping)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 It (com.xenoage.utils.iterators.It)1 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 Barline (com.xenoage.zong.core.music.barline.Barline)1