Search in sources :

Example 11 with BitmapStaff

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

the class BitmapStaffTest method test16Pixel.

@Test
public void test16Pixel() {
    // 1mm -> 2px, 5 lines, interline: 1.8 mm. Displayed staff must be 16px high.
    float scaling = Units.pxToMm(2, 1);
    BitmapStaff ss = new BitmapStaff(5, 1.8f, 0.1f, scaling);
    assertEquals(Units.pxToMm(16, scaling), ss.heightMm, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(-1, scaling), ss.yOffsetMm, Delta.DELTA_FLOAT);
    assertEquals(16 / (2 * 4 * 1.8f), ss.heightScaling, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(4, scaling), ss.interlineSpaceMm, Delta.DELTA_FLOAT);
}
Also used : BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) Test(org.junit.Test)

Example 12 with BitmapStaff

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

the class SlurRenderer method draw.

/**
 * Draws the given {@link SlurStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    SlurStamping slur = (SlurStamping) stamping;
    float scaling = args.targetScaling;
    // compute absolute coordinates in px
    float p1xMm = slur.p1.xMm;
    float p2xMm = slur.p2.xMm;
    float c1xMm = p1xMm + slur.c1.xMm;
    float c2xMm = p2xMm + slur.c2.xMm;
    float p1yMm = 0, p2yMm = 0, c1yMm = 0, c2yMm = 0;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float staff1YMm = slur.staff1.positionMm.y;
        float staff2YMm = slur.staff2.positionMm.y;
        BitmapStaff screenStaff1 = slur.staff1.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff screenStaff2 = slur.staff2.getBitmapInfo().getBitmapStaff(scaling);
        float bottomLineMm1 = staff1YMm + screenStaff1.lp0Mm;
        float bottomLineMm2 = staff2YMm + screenStaff2.lp0Mm;
        float isMm1 = screenStaff1.interlineSpaceMm;
        float isMm2 = screenStaff2.interlineSpaceMm;
        p1yMm = bottomLineMm1 - isMm1 * slur.p1.lp / 2;
        p2yMm = bottomLineMm2 - isMm2 * slur.p2.lp / 2;
        c1yMm = p1yMm - isMm1 * slur.c1.lp / 2;
        c2yMm = p2yMm - isMm2 * slur.c2.lp / 2;
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        p1yMm = slur.staff1.computeYMm(slur.p1.lp);
        p2yMm = slur.staff2.computeYMm(slur.p2.lp);
        c1yMm = slur.staff1.computeYMm(slur.p1.lp + slur.c1.lp);
        c2yMm = slur.staff2.computeYMm(slur.p2.lp + slur.c2.lp);
    }
    Point2f p1 = new Point2f(p1xMm, p1yMm);
    Point2f p2 = new Point2f(p2xMm, p2yMm);
    Point2f c1 = new Point2f(c1xMm, c1yMm);
    Point2f c2 = new Point2f(c2xMm, c2yMm);
    Color color = Color.Companion.getBlack();
    /* //TEST
		Point2i lastPoint = new Point2i(MathTools.bezier(p1, p2, c1, c2, 0));
		for (int i = 1; i <= iterations; i++)
		{
			float t = 1f * i / iterations;
			float width = 0.7f + (0.5f - Math.abs(t - 0.5f)) * 2.5f;
			Point2i p = new Point2i(MathTools.bezier(p1, p2, c1, c2, t));
		  params.renderTarget.drawLine(lastPoint, p, color, MathTools.clampMin((int) (scaling * width), 1));
		  lastPoint = p;
		} */
    SimpleSlurShape slurShape = new SimpleSlurShape(p1, p2, c1, c2, slur.staff1.is);
    canvas.fillPath(slurShape.getPath(), color);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Color(com.xenoage.utils.color.Color) SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) SimpleSlurShape(com.xenoage.zong.renderer.slur.SimpleSlurShape)

Example 13 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff 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)

Example 14 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff 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 15 with BitmapStaff

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

the class StemRenderer method draw.

/**
 * Draws the given {@link StemStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StemStamping stem = (StemStamping) stamping;
    float scaling = args.targetScaling;
    // TODO: stem is thinner
    float lineWidthMm = stem.noteStaff.getLineWidthMm();
    Point2f p1Mm = new Point2f(stem.xMm - lineWidthMm / 2, stem.noteStaff.positionMm.y);
    Point2f p2Mm = new Point2f(stem.xMm + lineWidthMm / 2, stem.endStaff.positionMm.y);
    Color color = Color.Companion.getBlack();
    // shorten stem a little bit at the notehead - TODO: looks good. is code ok?
    float noteLp = stem.noteLp + 0.2f * (stem.endLp > stem.noteLp ? 1 : -1);
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen or print
        BitmapLine screenLine = new BitmapLine(lineWidthMm, color, scaling);
        BitmapStaff noteScreenStaff = stem.noteStaff.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff endScreenStaff = stem.endStaff.getBitmapInfo().getBitmapStaff(scaling);
        p1Mm = new Point2f(p1Mm.x, p1Mm.y + noteScreenStaff.getYMm(noteLp));
        p2Mm = new Point2f(p2Mm.x, p2Mm.y + endScreenStaff.getYMm(stem.endLp));
        // ensure same width for each stem in this staff
        float width = screenLine.widthMm;
        canvas.fillRect(new Rectangle2f(p1Mm.x, p1Mm.y, width, p2Mm.y - p1Mm.y), screenLine.color);
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        // render with high quality
        p1Mm = new Point2f(p1Mm.x, stem.noteStaff.computeYMm(noteLp));
        p2Mm = new Point2f(p2Mm.x, stem.endStaff.computeYMm(stem.endLp));
        canvas.fillRect(new Rectangle2f(p1Mm.x, p1Mm.y, p2Mm.x - p1Mm.x, p2Mm.y - p1Mm.y), color);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Color(com.xenoage.utils.color.Color) BitmapLine(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) StemStamping(com.xenoage.zong.musiclayout.stampings.StemStamping)

Aggregations

BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)18 Point2f (com.xenoage.utils.math.geom.Point2f)11 Color (com.xenoage.utils.color.Color)8 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)8 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)6 Test (org.junit.Test)5 FormattedText (com.xenoage.zong.core.text.FormattedText)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 BeamStamping (com.xenoage.zong.musiclayout.stampings.BeamStamping)1 LegerLineStamping (com.xenoage.zong.musiclayout.stampings.LegerLineStamping)1 SlurStamping (com.xenoage.zong.musiclayout.stampings.SlurStamping)1 StaffCursorStamping (com.xenoage.zong.musiclayout.stampings.StaffCursorStamping)1 StemStamping (com.xenoage.zong.musiclayout.stampings.StemStamping)1 SystemCursorStamping (com.xenoage.zong.musiclayout.stampings.SystemCursorStamping)1 TupletStamping (com.xenoage.zong.musiclayout.stampings.TupletStamping)1 VoltaStamping (com.xenoage.zong.musiclayout.stampings.VoltaStamping)1 WedgeStamping (com.xenoage.zong.musiclayout.stampings.WedgeStamping)1 SimpleSlurShape (com.xenoage.zong.renderer.slur.SimpleSlurShape)1