Search in sources :

Example 16 with StaffStamping

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

the class StaffRenderer method draw.

/**
 * Draws the given {@link StaffStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StaffStamping staff = (StaffStamping) stamping;
    float scaling = args.targetScaling;
    Point2f position = staff.positionMm;
    // TODO: custom line width
    float lineWidthMm = staff.getLineWidthMm();
    float length = staff.lengthMm;
    Color color = Color.Companion.getBlack();
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen
        BitmapLine screenLine = staff.getBitmapInfo().getBitmapLine(scaling, lineWidthMm, color);
        BitmapStaff ss = staff.getBitmapInfo().getBitmapStaff(scaling);
        position = new Point2f(position.x, position.y + ss.yOffsetMm);
        if (ss.isSimplifiedStaff) {
            // simplified staff (fill rectangle)
            color = screenLine.color;
            color = Companion.color(color.getR(), color.getG(), color.getB(), (int) (0.7f * color.getA()));
            // don't forget the line heights, they belong into the rectangle
            position = position.add(0, -1 * ss.lineHeightMm / 2);
            canvas.drawSimplifiedStaff(position, length, ss.heightMm + ss.lineHeightMm, color);
        } else {
            // normal staff (draw lines)
            canvas.drawStaff(position, length, staff.linesCount, screenLine.color, screenLine.widthMm, ss.interlineSpaceMm);
        }
    } else // if (canvas.getFormat() == CanvasFormat.Vector)
    {
        // render with high quality
        canvas.drawStaff(position, length, staff.linesCount, color, lineWidthMm, staff.is);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) 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)

Example 17 with StaffStamping

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

the class BarlineRenderer method paintRepeatDots.

/**
 * Draws repeat dots at the given side (-1 or 1) at the given
 * horizontal position on the given staves.
 */
private static void paintRepeatDots(List<StaffStamping> staves, float xPosition, int side, Canvas canvas, RendererArgs args) {
    for (StaffStamping staff : staves) {
        int lp1 = (staff.linesCount + 1) / 2;
        int lp2 = lp1 + 2;
        float x = xPosition + staff.is * 1.2f * side;
        paintRepeatDot(canvas, args, staff, sp(x, lp1));
        paintRepeatDot(canvas, args, staff, sp(x, lp2));
    }
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping)

Example 18 with StaffStamping

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

the class BeamRenderer method draw.

/**
 * Draws the given {@link BeamStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    BeamStamping beam = (BeamStamping) stamping;
    StaffStamping staff = beam.staff;
    float scaling = args.targetScaling;
    // TODO: stem should be thinner than lineWidth?
    float stemWidthMm = staff.getLineWidthMm();
    float x1Mm = staff.positionMm.x + beam.sp1.xMm - stemWidthMm / 2f;
    float x2Mm = staff.positionMm.x + beam.sp2.xMm + stemWidthMm / 2f;
    Color color = Color.Companion.getBlack();
    float leftYStart, rightYStart, beamHeightMm;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen
        float staffYPos = staff.positionMm.y;
        BitmapStaff screenStaff = staff.getBitmapInfo().getBitmapStaff(scaling);
        leftYStart = staffYPos + screenStaff.getYMm(beam.sp1.lp);
        rightYStart = staffYPos + screenStaff.getYMm(beam.sp2.lp);
        beamHeightMm = BeamNotation.lineHeightIs * screenStaff.interlineSpaceMm;
    } else {
        leftYStart = staff.computeYMm(beam.sp1.lp);
        rightYStart = staff.computeYMm(beam.sp2.lp);
        beamHeightMm = BeamNotation.lineHeightIs * staff.is;
    }
    // TODO: avoid edges at the stem end points
    // beam sits on or hangs from the vertical position, dependent on stem direction
    float vAdd = (beam.stemDir.getSign() - 1) / 2f * beamHeightMm;
    Point2f sw = new Point2f(x1Mm, leftYStart + vAdd);
    Point2f nw = new Point2f(x1Mm, sw.y + beamHeightMm);
    Point2f se = new Point2f(x2Mm, rightYStart + vAdd);
    Point2f ne = new Point2f(x2Mm, se.y + beamHeightMm);
    List<PathElement> elements = alist(4);
    elements.add(new MoveTo(sw));
    elements.add(new LineTo(nw));
    elements.add(new LineTo(ne));
    elements.add(new LineTo(se));
    elements.add(new ClosePath());
    Path path = new Path(elements);
    canvas.fillPath(path, color);
}
Also used : BeamStamping(com.xenoage.zong.musiclayout.stampings.BeamStamping) Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Color(com.xenoage.utils.color.Color) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 19 with StaffStamping

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

the class WedgeRenderer method draw.

/**
 * Draws the given {@link WedgeStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    WedgeStamping wedge = (WedgeStamping) stamping;
    StaffStamping parentStaff = wedge.parentStaff;
    float scaling = args.scaling;
    // horizontal position
    float x1Mm = wedge.leftXMm + parentStaff.positionMm.x;
    float x2Mm = wedge.rightXMm + parentStaff.positionMm.x;
    // compute vertical distances at the start and end point
    float d1Mm = wedge.leftDistanceIs * parentStaff.is;
    float d2Mm = wedge.rightDistanceIs * parentStaff.is;
    // width and color of the line
    Color color = Color.Companion.getBlack();
    // like staff line
    float width = parentStaff.getLineWidthMm();
    float paintWidth;
    // compute the horizontal line and color
    float yMm;
    Color paintColor;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        yMm = parentStaff.positionMm.y + ss.getYMm(wedge.lp);
        BitmapLine screenLine = parentStaff.getBitmapInfo().getBitmapLine(scaling, width, color);
        paintColor = screenLine.color;
        paintWidth = screenLine.widthMm;
    } else {
        yMm = parentStaff.computeYMm(wedge.lp);
        paintColor = color;
        paintWidth = width;
    }
    // draw lines
    canvas.drawLine(new Point2f(x1Mm, yMm - d1Mm / 2), new Point2f(x2Mm, yMm - d2Mm / 2), paintColor, paintWidth);
    canvas.drawLine(new Point2f(x1Mm, yMm + d1Mm / 2), new Point2f(x2Mm, yMm + d2Mm / 2), paintColor, paintWidth);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) 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) WedgeStamping(com.xenoage.zong.musiclayout.stampings.WedgeStamping)

Example 20 with StaffStamping

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

the class ScoreFrameLayout method getSystemBoundaries.

/**
 * Computes and returns the bounding rectangle of the system with the given index
 * (relative to the frame). Only the staves are regarded, not text around them
 * or notes over the top staff or notes below the bottom staff.
 * If there are no staves in this system, null is returned.
 */
public Rectangle2f getSystemBoundaries(int systemIndex) {
    boolean found = false;
    float minX = Float.MAX_VALUE;
    float minY = Float.MAX_VALUE;
    float maxX = Float.MIN_VALUE;
    float maxY = Float.MIN_VALUE;
    for (StaffStamping staff : staffStampings) {
        if (staff.system.getSystemIndexInFrame() == systemIndex) {
            found = true;
            minX = Math.min(minX, staff.positionMm.x);
            minY = Math.min(minY, staff.positionMm.y);
            maxX = Math.max(maxX, staff.positionMm.x + staff.lengthMm);
            maxY = Math.max(maxY, staff.positionMm.y + (staff.linesCount - 1) * staff.is);
        }
    }
    if (found)
        return new Rectangle2f(minX, minY, maxX - minX, maxY - minY);
    else
        return null;
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

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