Search in sources :

Example 6 with StaffStamping

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);
}
Also used : CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) SP(com.xenoage.zong.core.music.format.SP) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol)

Example 7 with StaffStamping

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);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) StaffStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.StaffStampings)

Example 8 with StaffStamping

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);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) 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) TupletStamping(com.xenoage.zong.musiclayout.stampings.TupletStamping)

Example 9 with StaffStamping

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);
    }
}
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 10 with StaffStamping

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);
    }
}
Also used : BarlineRepeat(com.xenoage.zong.core.music.barline.BarlineRepeat) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) BarlineStyle(com.xenoage.zong.core.music.barline.BarlineStyle) BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup)

Aggregations

StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)21 Point2f (com.xenoage.utils.math.geom.Point2f)10 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)8 Color (com.xenoage.utils.color.Color)6 FormattedText (com.xenoage.zong.core.text.FormattedText)5 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)5 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)3 BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)2 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)2 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)2 BarlineStamping (com.xenoage.zong.musiclayout.stampings.BarlineStamping)2 StaffCursorStamping (com.xenoage.zong.musiclayout.stampings.StaffCursorStamping)2 SystemCursorStamping (com.xenoage.zong.musiclayout.stampings.SystemCursorStamping)2 TupletStamping (com.xenoage.zong.musiclayout.stampings.TupletStamping)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 It (com.xenoage.utils.iterators.It)1 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 Barline (com.xenoage.zong.core.music.barline.Barline)1