Search in sources :

Example 1 with BitmapStaff

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

the class BitmapStaffTest method test13Pixel.

@Test
public void test13Pixel() {
    // 1mm -> 1px, 10 lines, interline: 1.4 mm. Displayed simplified staff must be (9*1.4)px high.
    float scaling = Units.pxToMm(1, 1);
    BitmapStaff ss = new BitmapStaff(10, 1.4f, 0.1f, scaling);
    assertTrue(ss.isSimplifiedStaff);
    assertEquals(Units.pxToMm(9 * 1.4f, scaling), ss.heightMm, Delta.DELTA_FLOAT_ROUGH);
    assertEquals(Units.pxToMm(0, scaling), ss.yOffsetMm, Delta.DELTA_FLOAT);
    assertEquals(1, ss.heightScaling, Delta.DELTA_FLOAT);
    // simplified staff
    assertTrue(ss.interlineSpaceMm < 2);
}
Also used : BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) Test(org.junit.Test)

Example 2 with BitmapStaff

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

the class BitmapStaffTest method test2Pixel.

@Test
public void test2Pixel() {
    // 1mm -> 1px, 5 lines, interline: 0.55 mm. Displayed simplified staff must be (4*0.55)px high.
    float scaling = Units.pxToMm(1, 1);
    BitmapStaff ss = new BitmapStaff(5, 0.55f, 0.1f, scaling);
    assertTrue(ss.isSimplifiedStaff);
    assertEquals(Units.pxToMm(4 * 0.55f, scaling), ss.heightMm, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(0, scaling), ss.yOffsetMm, Delta.DELTA_FLOAT);
    assertEquals(1, ss.heightScaling, Delta.DELTA_FLOAT);
    // simplified staff
    assertTrue(ss.interlineSpaceMm < 2);
}
Also used : BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) Test(org.junit.Test)

Example 3 with BitmapStaff

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

the class BitmapStaffTest method test8Pixel1.

@Test
public void test8Pixel1() {
    // 1mm -> 1px, 5 lines, interline: 2 mm. Displayed staff must be 8px high.
    float scaling = Units.pxToMm(1, 1);
    BitmapStaff ss = new BitmapStaff(5, 2, 0.1f, scaling);
    assertEquals(Units.pxToMm(8, scaling), ss.heightMm, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(0, scaling), ss.yOffsetMm, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(1, scaling), ss.heightScaling, Delta.DELTA_FLOAT);
    assertEquals(Units.pxToMm(2, scaling), ss.interlineSpaceMm, Delta.DELTA_FLOAT);
}
Also used : BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) Test(org.junit.Test)

Example 4 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff 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 5 with BitmapStaff

use of com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff 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)

Aggregations

BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)18 Point2f (com.xenoage.utils.math.geom.Point2f)11 Color (com.xenoage.utils.color.Color)8 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)8 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)6 Test (org.junit.Test)5 FormattedText (com.xenoage.zong.core.text.FormattedText)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 BeamStamping (com.xenoage.zong.musiclayout.stampings.BeamStamping)1 LegerLineStamping (com.xenoage.zong.musiclayout.stampings.LegerLineStamping)1 SlurStamping (com.xenoage.zong.musiclayout.stampings.SlurStamping)1 StaffCursorStamping (com.xenoage.zong.musiclayout.stampings.StaffCursorStamping)1 StemStamping (com.xenoage.zong.musiclayout.stampings.StemStamping)1 SystemCursorStamping (com.xenoage.zong.musiclayout.stampings.SystemCursorStamping)1 TupletStamping (com.xenoage.zong.musiclayout.stampings.TupletStamping)1 VoltaStamping (com.xenoage.zong.musiclayout.stampings.VoltaStamping)1 WedgeStamping (com.xenoage.zong.musiclayout.stampings.WedgeStamping)1 SimpleSlurShape (com.xenoage.zong.renderer.slur.SimpleSlurShape)1