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);
}
}
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);
}
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);
}
}
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);
}
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());
}
Aggregations