Search in sources :

Example 1 with LegerLineStamping

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

the class LegerLineRenderer method draw.

/**
 * Draws the given {@link LegerLineStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    LegerLineStamping legerLine = (LegerLineStamping) stamping;
    StaffStamping parentStaff = legerLine.parentStaff;
    float linePosition = legerLine.sp.lp;
    float scaling = args.targetScaling;
    float width = legerLine.widthIs * parentStaff.is;
    float p1xMm = legerLine.sp.xMm - width / 2;
    float p2xMm = p1xMm + width;
    float lineWidthMm = parentStaff.getLineWidthMm();
    Color color = Color.Companion.getBlack();
    float yMm = 0;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen or print
        BitmapLine screenLine = new BitmapLine(lineWidthMm, color, scaling);
        BitmapStaff screenStaff = parentStaff.getBitmapInfo().getBitmapStaff(scaling);
        yMm = parentStaff.positionMm.y + screenStaff.getYMm(linePosition);
        lineWidthMm = screenLine.widthMm;
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        // render with high quality
        yMm = parentStaff.computeYMm(linePosition);
    }
    canvas.drawLine(p(p1xMm, yMm), p(p2xMm, yMm), color, lineWidthMm);
}
Also used : 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) LegerLineStamping(com.xenoage.zong.musiclayout.stampings.LegerLineStamping)

Example 2 with LegerLineStamping

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

the class LegerLinesStamper method stamp.

public LegerLineStamping[] stamp(ChordNotation chordNotation, float chordXMm, StaffStamping staffStamping) {
    NotesNotation notes = chordNotation.notes;
    int bottomCount = getBottomCount(notes.getBottomNote().lp);
    int topCount = getTopCount(notes.getTopNote().lp, staffStamping.linesCount);
    if (bottomCount > 0 || topCount > 0) {
        // horizontal position and width (may differ above and below staff, dependent on suspended notes)
        NoteSuspension bottomSuspension = getBottomSuspension(notes.notes);
        float xTopMm = getXMm(chordXMm, notes.noteheadWidthIs, bottomSuspension, staffStamping.is);
        float widthBottomIs = getWidthIs(bottomSuspension != None);
        NoteSuspension topSuspension = getTopSuspension(notes.notes, staffStamping.linesCount);
        float xBottomMm = getXMm(chordXMm, notes.noteheadWidthIs, topSuspension, staffStamping.is);
        float widthTopIs = getWidthIs(bottomSuspension != None);
        // vertical positions
        int[] bottomLps = getBottomLps(bottomCount);
        int[] topLps = getTopLps(topCount, staffStamping.linesCount);
        // create stampings
        LegerLineStamping[] ret = new LegerLineStamping[bottomCount + topCount];
        for (int i : range(bottomCount)) ret[i] = new LegerLineStamping(sp(xBottomMm, bottomLps[i]), widthBottomIs, staffStamping);
        for (int i : range(topCount)) ret[bottomCount + i] = new LegerLineStamping(sp(xTopMm, topLps[i]), widthTopIs, staffStamping);
        return ret;
    } else {
        return empty;
    }
}
Also used : NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) LegerLineStamping(com.xenoage.zong.musiclayout.stampings.LegerLineStamping) NoteSuspension(com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)

Aggregations

LegerLineStamping (com.xenoage.zong.musiclayout.stampings.LegerLineStamping)2 Color (com.xenoage.utils.color.Color)1 NoteSuspension (com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)1 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)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