use of com.xenoage.zong.musiclayout.stampings.WedgeStamping in project Zong by Xenoage.
the class WedgeStamper method stampSystem.
/**
* Creates all wedge stampings in the given system.
* @param openWedges input and output parameter: voltas, which are still open from the
* last system. After the method returns, it contains the voltas which
* are still open after this system
*/
public List<WedgeStamping> stampSystem(SystemSpacing system, Score score, StaffStampings staffStampings, OpenWedges openWedges) {
List<WedgeStamping> ret = alist();
// find new wedges beginning in this staff
for (int iStaff : range(score.getStavesCount())) {
Staff staff = score.getStaff(iStaff);
for (int iMeasure : system.getMeasures()) {
Measure measure = staff.getMeasure(iMeasure);
for (BeatE<Direction> dir : measure.getDirections()) {
if (dir.getElement() instanceof Wedge) {
Wedge wedge = (Wedge) dir.getElement();
// if the position of the end element is known
if (wedge.getWedgeEnd().getMP() != null)
openWedges.wedges.add(new ContinuedWedge((Wedge) dir.getElement()));
}
}
}
}
// draw wedges in the cache, and remove them if closed in this system
for (Iterator<ContinuedWedge> itW = openWedges.wedges.iterator(); itW.hasNext(); ) {
ContinuedWedge wedge = itW.next();
ret.add(stamp(wedge.element, staffStampings.get(system.getSystemIndexInFrame(), wedge.element.getMP().staff)));
if (MP.getMP(wedge.element.getWedgeEnd()).measure <= system.getEndMeasure()) {
// wedge is closed
itW.remove();
}
}
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.WedgeStamping in project Zong by Xenoage.
the class WedgeStamper method stamp.
/**
* Creates a {@link WedgeStamping} for the given {@link Wedge} on the given staff.
* The start and end measure of the wedge may be outside the staff, then the
* wedge is clipped to the staff.
*/
public WedgeStamping stamp(Wedge wedge, StaffStamping staffStamping) {
SystemSpacing system = staffStamping.system;
Range systemMeasures = system.getMeasures();
// musical positions of wedge
MP p1 = MP.getMP(wedge);
MP p2 = MP.getMP(wedge.getWedgeEnd());
// clip start to staff
float x1Mm;
if (p1.measure < systemMeasures.getStart()) {
// begins before staff
x1Mm = system.getMeasureStartAfterLeadingMm(systemMeasures.getStart());
} else {
// begins within staff
x1Mm = system.getXMmAt(p1.getTime());
}
// clip end to staff
float x2Mm;
if (p2.measure > systemMeasures.getStop()) {
// ends after staff
x2Mm = system.getMeasureEndMm(systemMeasures.getStop());
} else {
// ends within staff
x2Mm = system.getXMmAt(p2.getTime());
}
// spread
float d1Is = 0;
float d2Is = 0;
float defaultSpreadIS = 1.5f;
if (wedge.getType() == WedgeType.Crescendo) {
d2Is = (wedge.getSpread() != null ? wedge.getSpread() : defaultSpreadIS);
} else if (wedge.getType() == WedgeType.Diminuendo) {
d1Is = (wedge.getSpread() != null ? wedge.getSpread() : defaultSpreadIS);
}
// custom horizontal position
Position customPos = asPosition(wedge.getPositioning());
float length = x2Mm - x1Mm;
if (customPos != null && customPos.x != null)
x1Mm = customPos.x;
x1Mm += Position.getRelativeX(customPos);
x2Mm = x1Mm + length;
// vertical position
float lp;
if (customPos != null && customPos.y != null)
lp = customPos.y;
else
lp = -6;
lp += Position.getRelativeY(customPos);
return new WedgeStamping(lp, x1Mm, x2Mm, d1Is, d2Is, staffStamping);
}
use of com.xenoage.zong.musiclayout.stampings.WedgeStamping 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);
}
Aggregations