Search in sources :

Example 1 with SlurStamping

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

the class SlurStamper method createStartForFirstSystem.

/**
 * Creates a {@link SlurStamping} for a curved line that
 * starts at this system but spans at least one other system.
 */
SlurStamping createStartForFirstSystem(StaffStamping staff, SP defaultSp, Slur slur) {
    SlurWaypoint wp1 = slur.getStart();
    // end points of the bezier curve
    SP p1 = computeEndPoint(slur, defaultSp, wp1.getBezierPoint());
    SP p2 = sp(staff.positionMm.x + staff.lengthMm, p1.lp);
    // control points of the bezier curve
    BezierPoint b1 = wp1.getBezierPoint();
    SP c1 = (// custom formatting
    b1 != null && b1.getControl() != null ? // custom formatting
    b1.getControl() : // default formatting
    computeLeftControlPoint(slur, p1, p2, staff));
    // default formatting
    SP c2 = computeRightControlPoint(slur, p1, p2, staff);
    return new SlurStamping(slur, p1, p2, c1, c2, staff, staff);
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) SP(com.xenoage.zong.core.music.format.SP) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 2 with SlurStamping

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

the class SlurStamper method createForMiddleSystem.

/**
 * Creates a {@link SlurStamping} for a curved line that
 * starts at an earlier system and ends at a later system, but
 * spans also the given system.
 */
SlurStamping createForMiddleSystem(StaffStamping staff, Slur slur) {
    if (slur.getType() == SlurType.Tie) {
        // ties can not have middle staves
        return null;
    }
    // end points of the bezier curve
    float p1x = staff.positionMm.x + staff.system.getMeasureStartAfterLeadingMm(staff.system.getStartMeasure()) - // TODO
    5;
    float p2x = staff.positionMm.x + staff.lengthMm;
    float lp;
    if (slur.getSide() == VSide.Top)
        // 1 IS over the top staff line
        lp = (staff.linesCount - 1) * 2 + 2;
    else
        // 1 IS below the bottom staff line
        lp = -2;
    SP p1 = sp(p1x, lp);
    SP p2 = sp(p2x, lp);
    // control points of the bezier curve
    // default formatting
    SP c1 = computeLeftControlPoint(slur, p1, p2, staff);
    // default formatting
    SP c2 = computeRightControlPoint(slur, p1, p2, staff);
    return new SlurStamping(slur, p1, p2, c1, c2, staff, staff);
}
Also used : SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) SP(com.xenoage.zong.core.music.format.SP)

Example 3 with SlurStamping

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

the class SlurStamper method createStopForLastSystem.

/**
 * Creates a {@link SlurStamping} for a last part of a slur or tie
 * that spans at least two systems.
 */
SlurStamping createStopForLastSystem(StaffStamping staff, SP defaultSp, Slur slur) {
    SlurWaypoint wp2 = slur.getStop();
    // end points of the bezier curve
    SP p2 = computeEndPoint(slur, defaultSp, wp2.getBezierPoint());
    SP p1 = sp(staff.positionMm.x + staff.system.getMeasureStartAfterLeadingMm(staff.system.getStartMeasure()) - 5, // TODO
    p2.lp);
    // control points of the bezier curve
    BezierPoint b2 = wp2.getBezierPoint();
    // default formatting
    SP c1 = computeLeftControlPoint(slur, p1, p2, staff);
    SP c2 = (// custom formatting
    b2 != null && b2.getControl() != null ? // custom formatting
    b2.getControl() : // default formatting
    computeRightControlPoint(slur, p1, p2, staff));
    return new SlurStamping(slur, p1, p2, c1, c2, staff, staff);
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) SP(com.xenoage.zong.core.music.format.SP) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 4 with SlurStamping

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

the class SlurStamper method createForSingleSystem.

/**
 * Creates a {@link SlurStamping} for a curved line that
 * uses only a single system. The slur may span over multiple staves.
 */
SlurStamping createForSingleSystem(SlurCache slurCache) {
    Slur slur = slurCache.getSlur();
    SlurWaypoint wp1 = slur.getStart();
    SlurWaypoint wp2 = slur.getStop();
    // end points of the bezier curve
    VSide side = slurCache.getSide();
    SP p1 = computeEndPoint(slur, slurCache.getDefaultStartSp(), wp1.getBezierPoint());
    SP p2 = computeEndPoint(slur, slurCache.getDefaultStopSp(), wp2.getBezierPoint());
    // control points of the bezier curve
    BezierPoint b1 = wp1.getBezierPoint();
    BezierPoint b2 = wp2.getBezierPoint();
    SP c1 = (// custom formatting
    b1 != null && b1.getControl() != null ? // custom formatting
    b1.getControl() : // default formatting
    computeLeftControlPoint(slur, p1, p2, slurCache.getStartStaff()));
    SP c2 = (// custom formatting
    b2 != null && b2.getControl() != null ? // custom formatting
    b2.getControl() : // default formatting
    computeRightControlPoint(slur, p1, p2, slurCache.getStopStaff()));
    return new SlurStamping(slur, p1, p2, c1, c2, slurCache.getStartStaff(), slurCache.getStopStaff());
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) Slur(com.xenoage.zong.core.music.slur.Slur) ContinuedSlur(com.xenoage.zong.musiclayout.continued.ContinuedSlur) SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) SP(com.xenoage.zong.core.music.format.SP) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) VSide(com.xenoage.utils.math.VSide)

Example 5 with SlurStamping

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

Aggregations

SlurStamping (com.xenoage.zong.musiclayout.stampings.SlurStamping)5 SP (com.xenoage.zong.core.music.format.SP)4 BezierPoint (com.xenoage.zong.core.music.format.BezierPoint)3 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)3 Color (com.xenoage.utils.color.Color)1 VSide (com.xenoage.utils.math.VSide)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 Slur (com.xenoage.zong.core.music.slur.Slur)1 ContinuedSlur (com.xenoage.zong.musiclayout.continued.ContinuedSlur)1 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)1 SimpleSlurShape (com.xenoage.zong.renderer.slur.SimpleSlurShape)1