Search in sources :

Example 1 with VoltaStamping

use of com.xenoage.zong.musiclayout.stampings.VoltaStamping in project Zong by Xenoage.

the class VoltaStamper method stampSystem.

/**
 * Creates all volta stampings in the given system, including the voltas which
 * are still open from the last system.
 * @param openVolta  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<VoltaStamping> stampSystem(StaffStamping systemFirstStaff, OpenVolta openVolta, ScoreHeader header, FormattedTextStyle textStyle) {
    List<VoltaStamping> ret = alist();
    // stamp open volta
    if (openVolta.volta != null) {
        ret.add(stamp(openVolta.volta.element, systemFirstStaff, textStyle));
    }
    // stamp voltas beginning in this system
    for (int iMeasure : systemFirstStaff.system.getMeasures()) {
        ColumnHeader columnHeader = header.getColumnHeader(iMeasure);
        if (columnHeader.getVolta() != null) {
            ret.add(stamp(columnHeader.getVolta(), systemFirstStaff, textStyle));
        }
    }
    // remember open volta
    int systemEndMeasureIndex = systemFirstStaff.system.getEndMeasure();
    if (ret.size() > 0 && getLast(ret).element.getEndMeasureIndex() > systemEndMeasureIndex) {
        openVolta.volta = new ContinuedVolta(getLast(ret).element);
    } else {
        openVolta.volta = null;
    }
    return ret;
}
Also used : ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) VoltaStamping(com.xenoage.zong.musiclayout.stampings.VoltaStamping) ContinuedVolta(com.xenoage.zong.musiclayout.continued.ContinuedVolta)

Example 2 with VoltaStamping

use of com.xenoage.zong.musiclayout.stampings.VoltaStamping 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);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) VoltaStamping(com.xenoage.zong.musiclayout.stampings.VoltaStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Color(com.xenoage.utils.color.Color) BitmapLine(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) FormattedText(com.xenoage.zong.core.text.FormattedText)

Example 3 with VoltaStamping

use of com.xenoage.zong.musiclayout.stampings.VoltaStamping in project Zong by Xenoage.

the class VoltaStamper method stampInStaff.

/**
 * Creates a {@link VoltaStamping} for the given volta spanning
 * from the given start measure to the given end measure on the given staff
 * (global measure indices). Left and right hooks and the caption are optional.
 * The measure indices must be within the staff.
 */
private VoltaStamping stampInStaff(Volta volta, int startMeasureIndex, int endMeasureIndex, StaffStamping staff, FormattedTextStyle textStyle, boolean drawCaption, boolean drawLeftHook, boolean drawRightHook) {
    // get start and end x coordinate of measure
    float x1 = staff.system.getMeasureStartMm(startMeasureIndex) + staff.is / 2;
    float x2 = staff.system.getMeasureEndMm(endMeasureIndex) - staff.is / 2;
    // line position of volta line: 5 IS over top line
    float lp = (staff.linesCount - 1 + 5) * 2;
    // caption
    FormattedText caption = null;
    if (drawCaption && volta.getCaption().length() > 0) {
        caption = Companion.fText(volta.getCaption(), textStyle, Alignment.Left);
    }
    // create stamping
    return new VoltaStamping(volta, lp, x1, x2, caption, drawLeftHook, drawRightHook, staff);
}
Also used : VoltaStamping(com.xenoage.zong.musiclayout.stampings.VoltaStamping) FormattedText(com.xenoage.zong.core.text.FormattedText)

Aggregations

VoltaStamping (com.xenoage.zong.musiclayout.stampings.VoltaStamping)3 FormattedText (com.xenoage.zong.core.text.FormattedText)2 Color (com.xenoage.utils.color.Color)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 ContinuedVolta (com.xenoage.zong.musiclayout.continued.ContinuedVolta)1 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)1 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)1 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)1