use of com.xenoage.zong.core.music.format.Position in project Zong by Xenoage.
the class DirectionStamper method computePosition.
/**
* Computes the position for the given {@link Direction}
* within the given {@link StaffStamping}.
*/
private SP computePosition(Direction direction, StaffStamping staffStamping, float defaultLP, float defaultLPAbove, float defaultLPBelow) {
Positioning customPos = direction.getPositioning();
MP mp = direction.getMP();
if (mp == null)
// TODO. Happens. But just with offical MusicXML sample Telemann.xml
return SP.sp(0, 0);
float x, lp;
// default positioning
x = notNull(staffStamping.system.getXMmAt(mp.getTime()), 0f) + staffStamping.positionMm.x;
lp = defaultLP;
// custom positioning
if (customPos instanceof Placement) {
Placement placement = (Placement) customPos;
if (placement == Placement.Above)
lp = defaultLPAbove;
else
lp = defaultLPBelow;
} else if (customPos instanceof Position) {
// coordinates
Position pos = (Position) customPos;
if (pos.x != null)
x = pos.x;
x += Position.getRelativeX(pos);
// vertical position
if (pos.y != null)
lp = pos.y;
lp += Position.getRelativeY(pos);
}
return sp(x, lp);
}
use of com.xenoage.zong.core.music.format.Position 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);
}
Aggregations