Search in sources :

Example 1 with BezierPoint

use of com.xenoage.zong.core.music.format.BezierPoint in project Zong by Xenoage.

the class SlurReader method readToContext.

public static void readToContext(Chord chord, int noteIndex, int staffIndexInPart, Context context, MxlSlurOrTied mxlSlur) {
    Pitch pitch = chord.getNotes().get(noteIndex).getPitch();
    float noteLP = context.getMusicContext(staffIndexInPart).getLp(pitch);
    // type
    SlurType type = (mxlSlur.getElementType() == MxlElementType.Slur ? SlurType.Slur : SlurType.Tie);
    // number (tied does usually not use a number, but is distinguished by pitch)
    Integer number = mxlSlur.getNumber();
    BezierPoint bezierPoint = readBezierPoint(mxlSlur.getPosition(), mxlSlur.getBezier(), context.getTenthMm(), context.getStaffLinesCount(staffIndexInPart), noteLP, chord.getDuration());
    VSide side = readVSide(mxlSlur.getPlacement());
    // waypoint
    SlurWaypoint wp = new SlurWaypoint(chord, noteIndex, bezierPoint);
    if (type == SlurType.Tie && number == null) {
        // unnumbered tied
        OpenUnnumberedTieds openTieds = context.getOpenElements().getOpenUnnumberedTies();
        if (mxlSlur.getType() == MxlStartStopContinue.Start) {
            openTieds.startTied(wp, side);
        } else if (mxlSlur.getType() == MxlStartStopContinue.Stop) {
            OpenSlur openTied = openTieds.stopTied(wp, side, context);
            if (openTied != null)
                context.createSlur(openTied);
        }
    } else {
        // numbered
        WaypointPosition wpPos;
        if (mxlSlur.getType() == MxlStartStopContinue.Start)
            wpPos = WaypointPosition.Start;
        else if (mxlSlur.getType() == MxlStartStopContinue.Stop)
            wpPos = WaypointPosition.Stop;
        else
            wpPos = WaypointPosition.Continue;
        context.registerSlur(type, wpPos, number, wp, side);
    }
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) OtherReader.readBezierPoint(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readBezierPoint) WaypointPosition(com.xenoage.zong.core.music.WaypointPosition) OpenSlur(com.xenoage.zong.io.musicxml.in.util.OpenSlur) Pitch(com.xenoage.zong.core.music.Pitch) SlurType(com.xenoage.zong.core.music.slur.SlurType) OtherReader.readVSide(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readVSide) VSide(com.xenoage.utils.math.VSide) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) OpenUnnumberedTieds(com.xenoage.zong.io.musicxml.in.util.OpenUnnumberedTieds)

Example 2 with BezierPoint

use of com.xenoage.zong.core.music.format.BezierPoint 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 3 with BezierPoint

use of com.xenoage.zong.core.music.format.BezierPoint in project Zong by Xenoage.

the class SlurStamper method computeEndPoint.

/**
 * Computes the end position of a slur or tie, dependent on its corresponding default position
 * and the bezier information (may be null for default formatting).
 */
SP computeEndPoint(Slur slur, SP defaultSp, BezierPoint bezierPoint) {
    int dir = getSide(slur).getDir();
    if (bezierPoint == null || bezierPoint.getPoint() == null) {
        // default formatting
        // slur is 2 LP away from note center, tie 1.5
        float distanceLP = (slur.getType() == SlurType.Slur ? 2 : 1.5f);
        float lp = defaultSp.lp + dir * distanceLP;
        return defaultSp.withLp(lp);
    } else {
        // custom formatting
        return defaultSp.add(bezierPoint.point);
    }
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 4 with BezierPoint

use of com.xenoage.zong.core.music.format.BezierPoint 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 5 with BezierPoint

use of com.xenoage.zong.core.music.format.BezierPoint 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)

Aggregations

BezierPoint (com.xenoage.zong.core.music.format.BezierPoint)6 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)5 SP (com.xenoage.zong.core.music.format.SP)4 SlurStamping (com.xenoage.zong.musiclayout.stampings.SlurStamping)3 VSide (com.xenoage.utils.math.VSide)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 Pitch (com.xenoage.zong.core.music.Pitch)1 WaypointPosition (com.xenoage.zong.core.music.WaypointPosition)1 Slur (com.xenoage.zong.core.music.slur.Slur)1 SlurType (com.xenoage.zong.core.music.slur.SlurType)1 OtherReader.readBezierPoint (com.xenoage.zong.io.musicxml.in.readers.OtherReader.readBezierPoint)1 OtherReader.readVSide (com.xenoage.zong.io.musicxml.in.readers.OtherReader.readVSide)1 OpenSlur (com.xenoage.zong.io.musicxml.in.util.OpenSlur)1 OpenUnnumberedTieds (com.xenoage.zong.io.musicxml.in.util.OpenUnnumberedTieds)1 ContinuedSlur (com.xenoage.zong.musiclayout.continued.ContinuedSlur)1