use of com.xenoage.zong.musiclayout.stampings.StaffStamping in project Zong by Xenoage.
the class DirectionStamper method createDynamics.
/**
* Creates a {@link StaffTextStamping} for the given {@link Dynamic}s
* below the given {@link Chord} and its {@link ChordStampings}.
*/
public StaffTextStamping createDynamics(Dynamic dynamics, Chord chord, ChordStampings chordStampings, SymbolPool symbolPool) {
StaffStamping staff = chordStampings.staff;
// positioning
// below (default): 3 IS below the base line, or 2 IS below the lowest note
// above: 2 IS above the top line, or 1 IS above the highest note
float defaultLPBelow = -3f * 2;
float defaultLPAbove = (staff.linesCount - 1) * 2 + 2 * 2;
if (chordStampings.noteheads.length > 0) {
defaultLPBelow = Math.min(defaultLPBelow, chordStampings.getFirstNotehead().position.lp - 2 * 2);
defaultLPAbove = Math.max(defaultLPAbove, chordStampings.getLastNotehead().position.lp + 1 * 2);
}
SP sp = computePosition(dynamics, staff, defaultLPBelow, defaultLPAbove, defaultLPBelow);
// create text
CList<FormattedTextElement> elements = clist();
for (CommonSymbol s : CommonSymbol.getDynamics(dynamics.getValue())) {
Symbol symbol = symbolPool.getSymbol(s);
elements.add(new FormattedTextSymbol(symbol, staff.is * FONT_SIZE_IN_IS, FormattedTextStyle.Companion.getDefaultColor()));
}
elements.close();
FormattedTextParagraph paragraph = new FormattedTextParagraph(elements, Alignment.Center);
FormattedText text = Companion.fText(paragraph);
// create stamping
return new StaffTextStamping(text, sp, staff, dynamics);
}
use of com.xenoage.zong.musiclayout.stampings.StaffStamping in project Zong by Xenoage.
the class StaffStamper method createStaffStampings.
public StaffStampings createStaffStampings(Score score, FrameSpacing frame) {
int systemsCount = frame.getSystems().size();
int stavesCount = score.getStavesCount();
List<StaffStamping> allStaves = alist(systemsCount * stavesCount);
// go through the systems
for (int iSystem : range(systemsCount)) {
SystemSpacing system = frame.getSystems().get(iSystem);
float systemXOffset = system.getMarginLeftMm();
// create staves of the system
float yOffset = system.getOffsetYMm();
for (int iStaff : range(stavesCount)) {
yOffset += system.getStaffDistanceMm(iStaff);
int linesCount = score.getStaff(iStaff).getLinesCount();
float interlineSpace = score.getInterlineSpace(iStaff);
StaffStamping staff = new StaffStamping(system, iStaff, new Point2f(systemXOffset, yOffset), system.widthMm, linesCount, interlineSpace);
allStaves.add(staff);
yOffset += system.getStaffHeightMm(iStaff);
}
}
return new StaffStampings(allStaves, systemsCount, stavesCount);
}
use of com.xenoage.zong.musiclayout.stampings.StaffStamping in project Zong by Xenoage.
the class TupletRenderer method draw.
/**
* Draws the given {@link TupletStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
TupletStamping tuplet = (TupletStamping) stamping;
StaffStamping parentStaff = tuplet.parentStaff;
float scaling = args.targetScaling;
// horizontal position
float x1Mm = tuplet.leftSP.xMm;
float x2Mm = tuplet.rightSP.xMm;
// height of hook is 1 IS
float hookHeightPx = Units.mmToPx(parentStaff.is, scaling);
// width and color of the line
Color color = Color.Companion.getBlack();
// a little bit thicker than staff line
float width = parentStaff.getLineWidthMm() * 1.5f;
float paintWidth;
// compute the horizontal line and color
float y1Mm, y2Mm;
Color paintColor;
if (canvas.getFormat() == CanvasFormat.Raster) {
BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
y1Mm = parentStaff.positionMm.y + ss.getYMm(tuplet.leftSP.lp);
y2Mm = parentStaff.positionMm.y + ss.getYMm(tuplet.rightSP.lp);
BitmapLine screenLine = parentStaff.getBitmapInfo().getBitmapLine(scaling, width, color);
paintColor = screenLine.color;
paintWidth = screenLine.widthMm;
} else {
y1Mm = parentStaff.computeYMm(tuplet.leftSP.lp);
y2Mm = parentStaff.computeYMm(tuplet.rightSP.lp);
paintColor = color;
paintWidth = width;
}
// compute gap for text
FormattedText text = tuplet.text;
float gapMm = 0;
float textMm = 0;
if (text != null && text.getParagraphs().size() > 0) {
textMm = text.getFirstParagraph().getMetrics().getWidth();
gapMm = textMm * 2;
}
// draw line and hooks
if (gapMm > 0) {
// two lines, when there is text in between
float xGapLMm = (x2Mm + x1Mm) / 2 - gapMm / 2;
float xGapRMm = xGapLMm + gapMm;
float gapVerticalMm = gapMm / (x2Mm - x1Mm) * (y2Mm - y1Mm);
float yGapLMm = (y2Mm + y1Mm) / 2 - gapVerticalMm / 2;
float yGapRMm = yGapLMm + gapVerticalMm;
canvas.drawLine(new Point2f(x1Mm, y1Mm), new Point2f(xGapLMm, yGapLMm), paintColor, paintWidth);
canvas.drawLine(new Point2f(xGapRMm, yGapRMm), new Point2f(x2Mm, y2Mm), paintColor, paintWidth);
} else {
// no gap
canvas.drawLine(new Point2f(x1Mm, y1Mm), new Point2f(x2Mm, y2Mm), paintColor, paintWidth);
}
// hooks
canvas.drawLine(new Point2f(x1Mm, y1Mm), new Point2f(x1Mm, y1Mm + hookHeightPx * (tuplet.leftSP.lp < 0 ? -1 : 1)), paintColor, paintWidth);
canvas.drawLine(new Point2f(x2Mm, y2Mm), new Point2f(x2Mm, y2Mm + hookHeightPx * (tuplet.rightSP.lp < 0 ? -1 : 1)), paintColor, paintWidth);
// draw text
if (text != null && text.getParagraphs().size() > 0) {
float textAscent = text.getFirstParagraph().getMetrics().getAscent();
float textX = (x1Mm + x2Mm) / 2 - textMm / 2;
float textY = (y1Mm + y2Mm) / 2 + textAscent / 2;
canvas.drawText(tuplet.text, null, new Point2f(textX, textY), true, 0);
}
}
use of com.xenoage.zong.musiclayout.stampings.StaffStamping in project Zong by Xenoage.
the class VoltaRenderer method draw.
/**
* Draws the given {@link VoltaStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
VoltaStamping volta = (VoltaStamping) stamping;
StaffStamping parentStaff = volta.parentStaff;
float scaling = args.scaling;
// horizontal position
float x1 = volta.leftXMm + parentStaff.positionMm.x;
float x2 = volta.rightXMm + parentStaff.positionMm.x;
// compute hooks
boolean hook = volta.leftHook || volta.rightHook;
float hookHeight = 0;
if (hook) {
// height of hook is 2 interline spaces
hookHeight = parentStaff.is * 2;
}
// width and color of the line
Color color = Color.Companion.getBlack();
// a little bit thicker than staff line
float width = parentStaff.getLineWidthMm() * 1.5f;
float paintWidth;
// compute the horizontal line and color
float y;
Color paintColor;
if (canvas.getFormat() == CanvasFormat.Raster) {
BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
y = parentStaff.positionMm.y + ss.getYMm(volta.lp);
BitmapLine screenLine = parentStaff.getBitmapInfo().getBitmapLine(scaling, width, color);
paintColor = screenLine.color;
paintWidth = screenLine.widthMm;
} else {
y = parentStaff.computeYMm(volta.lp);
paintColor = color;
paintWidth = width;
}
// draw line and hooks
canvas.drawLine(new Point2f(x1, y), new Point2f(x2, y), paintColor, paintWidth);
if (volta.leftHook) {
canvas.drawLine(new Point2f(x1, y), new Point2f(x1, y + hookHeight), paintColor, paintWidth);
}
if (volta.rightHook) {
canvas.drawLine(new Point2f(x2, y), new Point2f(x2, y + hookHeight), paintColor, paintWidth);
}
// draw text
FormattedText text = volta.text;
if (text != null && text.getParagraphs().size() > 0) {
float textAscent = text.getFirstParagraph().getMetrics().getAscent();
float textX = x1 + parentStaff.is * 1;
float textY = y + textAscent;
canvas.drawText(volta.text, null, new Point2f(textX, textY), true, 0);
}
}
use of com.xenoage.zong.musiclayout.stampings.StaffStamping in project Zong by Xenoage.
the class BarlineRenderer method draw.
/**
* Draws the given {@link BarlineStamping} on the given {@link Canvas},
* using the given {@link RendererArgs}.
*/
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
BarlineStamping barlineSt = (BarlineStamping) stamping;
List<StaffStamping> staves = barlineSt.staves;
float xPosition = barlineSt.xMm;
float xCorrection = 0;
// lines
BarlineGroup.Style group = barlineSt.groupStyle;
BarlineStyle style = barlineSt.barline.getStyle();
if (group == null || group == BarlineGroup.Style.Single || group == BarlineGroup.Style.Common) {
// draw single barlines
for (StaffStamping staff : staves) {
xCorrection = paintBarline(canvas, args, staff, (staff.linesCount - 1) * 2, staff, 0, xPosition, style);
}
}
if (group == BarlineGroup.Style.Mensurstrich || group == BarlineGroup.Style.Common) {
// draw barlines between staves
for (int i = 0; i < staves.size() - 1; i++) {
xCorrection = paintBarline(canvas, args, staves.get(i), 0, staves.get(i + 1), (staves.get(i + 1).linesCount - 1) * 2, xPosition, style);
}
}
// repeat dots
// TODO: xCorrection is the value of the last staff, but this may differ
// draw repeat dots directly after drawing the corresponding staff!
BarlineRepeat repeat = barlineSt.barline.getRepeat();
if (repeat == BarlineRepeat.Forward || repeat == BarlineRepeat.Both) {
paintRepeatDots(staves, xPosition + xCorrection, 1, canvas, args);
}
if (repeat == BarlineRepeat.Backward || repeat == BarlineRepeat.Both) {
paintRepeatDots(staves, xPosition + xCorrection, -1, canvas, args);
}
}
Aggregations