Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions packages/alphatab/src/rendering/LineBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,32 +693,42 @@ export abstract class LineBarRenderer extends BarRendererBase {
continue;
}

const beatLineX: number = this.getBeatX(beat, BeatXPosition.Stem);
const stemX: number = this.getBeatX(beat, BeatXPosition.Stem);
let y1: number = cy + this.y;
if (direction === BeamDirection.Up) {
y1 += this.getFlagBottomY(beat, direction);
} else {
y1 += this.getFlagTopY(beat, direction);
}

// ensure we are pixel aligned on the end of the stem to avoid anti-aliasing artifacts
// when combining stems and beams on sub-pixel level
const y2: number = (cy + this.y + this.calculateBeamY(h, beatLineX)) | 0;
const y2: number = cy + this.y + this.calculateBeamY(h, stemX);

// improve subpixel related artifacts on stem/beam overlaps
let stemY1: number;
let stemY2: number;
if (y1 < y2) {
stemY1 = y1;
stemY2 = y2;
} else {
stemY1 = y2;
stemY2 = y1;
}

if (y1 < y2) {
this.paintBeamingStem(beat, cy + this.y, cx + this.x + beatLineX, y1, y2, canvas);
this.paintBeamingStem(beat, cy + this.y, cx + this.x + stemX, stemY1, stemY2, canvas);
} else {
this.paintBeamingStem(beat, cy + this.y, cx + this.x + beatLineX, y2, y1, canvas);
this.paintBeamingStem(beat, cy + this.y, cx + this.x + stemX, stemY2, stemY1, canvas);
}

using _ = ElementStyleHelper.beat(canvas, beamsElement, beat);

const brokenBarOffset: number = this.smuflMetrics.brokenBeamWidth * scaleMod;
const barCount: number = ModelUtils.getIndex(beat.duration) - 2;
const barStart: number = cy + this.y;
const stemThickness = this.smuflMetrics.stemThickness;

for (let barIndex: number = 0; barIndex < barCount; barIndex++) {
let barStartX: number = 0;
let barStartX: number = Math.floor(stemX + stemThickness);
let barEndX: number = 0;
let barStartY: number = 0;
let barEndY: number = 0;
Expand All @@ -737,8 +747,7 @@ export abstract class LineBarRenderer extends BarRendererBase {
beat.beamingMode === BeatBeamingMode.ForceSplitOnSecondaryToNext
) {
// start part
barStartX = beatLineX;
barEndX = barStartX + brokenBarOffset;
barEndX = Math.ceil(barStartX + brokenBarOffset);
barStartY = barY + this.calculateBeamY(h, barStartX);
barEndY = barY + this.calculateBeamY(h, barEndX);
LineBarRenderer.paintSingleBar(
Expand All @@ -751,8 +760,8 @@ export abstract class LineBarRenderer extends BarRendererBase {
);

// end part
barEndX = this.getBeatX(h.beats[i + 1], BeatXPosition.Stem);
barStartX = barEndX - brokenBarOffset;
barEndX = Math.floor(this.getBeatX(h.beats[i + 1], BeatXPosition.Stem));
barStartX = Math.floor(barEndX - brokenBarOffset);
barStartY = barY + this.calculateBeamY(h, barStartX);
barEndY = barY + this.calculateBeamY(h, barEndX);
LineBarRenderer.paintSingleBar(
Expand All @@ -766,24 +775,15 @@ export abstract class LineBarRenderer extends BarRendererBase {
} else {
if (isFullBarJoin) {
// full bar?
barStartX = beatLineX;
barEndX = this.getBeatX(h.beats[i + 1], BeatXPosition.Stem);
barEndX = Math.ceil(this.getBeatX(h.beats[i + 1], BeatXPosition.Stem));
} else if (i === 0 || !BeamingHelper.isFullBarJoin(h.beats[i - 1], beat, barIndex)) {
barStartX = beatLineX;
barEndX = barStartX + brokenBarOffset;
barEndX = Math.ceil(barStartX + brokenBarOffset);
} else {
continue;
}
barStartY = barY + this.calculateBeamY(h, barStartX);
barEndY = barY + this.calculateBeamY(h, barEndX);

// ensure we are pixel aligned on the end of the stem to avoid anti-aliasing artifacts
// when combining stems and beams on sub-pixel level
if (barIndex === 0) {
barStartY = barStartY | 0;
barEndY = barEndY | 0;
}

LineBarRenderer.paintSingleBar(
canvas,
cx + this.x + barStartX,
Expand All @@ -794,9 +794,8 @@ export abstract class LineBarRenderer extends BarRendererBase {
);
}
} else if (i > 0 && !BeamingHelper.isFullBarJoin(beat, h.beats[i - 1], barIndex)) {
barStartX = beatLineX - brokenBarOffset;
barEndX = beatLineX;
barEndX = beatLineX;
barEndX = Math.ceil(stemX);
barStartX = Math.floor(stemX - brokenBarOffset);
barStartY = barY + this.calculateBeamY(h, barStartX);
barEndY = barY + this.calculateBeamY(h, barEndX);
LineBarRenderer.paintSingleBar(
Expand All @@ -811,6 +810,19 @@ export abstract class LineBarRenderer extends BarRendererBase {
}
}

// const firstStartX = this.getBeatX(h.beats[0], BeatXPosition.Stem);
// const firstStartY = this.calculateBeamY(h, firstStartX);
// const lastEndX = this.getBeatX(h.beats[h.beats.length - 1], BeatXPosition.Stem);
// const lastEndY = this.calculateBeamY(h, lastEndX);
// canvas.lineWidth = 0.5;
// const c = canvas.color;
// canvas.color = new Color(255, 0, 0);
// canvas.moveTo(cx + this.x + firstStartX, cy + this.y + firstStartY);
// canvas.lineTo(cx + this.x + lastEndX, cy + this.y + lastEndY);
// canvas.stroke();
// canvas.lineWidth = 1;
// canvas.color = c;

if (h.graceType === GraceType.BeforeBeat) {
const beatLineX: number = this.getBeatX(h.beats[0], BeatXPosition.Stem);
const flagWidth =
Expand Down Expand Up @@ -1131,6 +1143,15 @@ export abstract class LineBarRenderer extends BarRendererBase {
}
}
}

// avoid subpixel induced problems by rounding
if (direction === BeamDirection.Up) {
drawingInfo.startY = Math.round(drawingInfo.startY);
drawingInfo.endY = Math.round(drawingInfo.endY);
} else {
drawingInfo.startY = Math.round(drawingInfo.startY);
drawingInfo.endY = Math.round(drawingInfo.endY);
}
}
protected applyBarShift(
h: BeamingHelper,
Expand Down
16 changes: 14 additions & 2 deletions packages/alphatab/src/rendering/glyphs/BeatContainerGlyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { BeatGlyphBase } from '@coderline/alphatab/rendering/glyphs/BeatGly
import type { BeatOnNoteGlyphBase } from '@coderline/alphatab/rendering/glyphs/BeatOnNoteGlyphBase';
import { Glyph } from '@coderline/alphatab/rendering/glyphs/Glyph';
import type { ITieGlyph } from '@coderline/alphatab/rendering/glyphs/TieGlyph';
import type { LineBarRenderer } from '@coderline/alphatab/rendering/LineBarRenderer';
import type { BarLayoutingInfo } from '@coderline/alphatab/rendering/staves/BarLayoutingInfo';
import type { BarBounds } from '@coderline/alphatab/rendering/utils/BarBounds';
import type { BeamingHelper } from '@coderline/alphatab/rendering/utils/BeamingHelper';
Expand Down Expand Up @@ -135,11 +136,22 @@ export class BeatContainerGlyph extends BeatContainerGlyphBase {
}

public override getBoundingBoxTop(): number {
return ModelUtils.minBoundingBox(this.preNotes.getBoundingBoxTop(), this.onNotes.getBoundingBoxTop());
let top = ModelUtils.minBoundingBox(this.preNotes.getBoundingBoxTop(), this.onNotes.getBoundingBoxTop());
if (Number.isNaN(top)) {
top = (this.renderer as LineBarRenderer).middleYPosition;
}
return top;
}

public override getBoundingBoxBottom(): number {
return ModelUtils.maxBoundingBox(this.preNotes.getBoundingBoxBottom(), this.onNotes.getBoundingBoxBottom());
let bottom = ModelUtils.maxBoundingBox(
this.preNotes.getBoundingBoxBottom(),
this.onNotes.getBoundingBoxBottom()
);
if (Number.isNaN(bottom)) {
bottom = (this.renderer as LineBarRenderer).middleYPosition;
}
return bottom;
}

protected drawBeamHelperAsFlags(helper: BeamingHelper): boolean {
Expand Down
Binary file modified packages/alphatab/test-data/musicxml-samples/BeetAnGeSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/Binchois.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/BrahWiMeSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/DebuMandSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/Dichterliebe01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/Echigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/FaurReveSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/MahlFaGe4Sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/MozaChloSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/MozaVeilSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/MozartPianoSonata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/MozartTrio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/Saltarello.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/SchbAvMaSample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-samples/Telemann.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-testsuite/02e-Rests-NoType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/alphatab/test-data/musicxml-testsuite/23a-Tuplets.png
Binary file modified packages/alphatab/test-data/musicxml-testsuite/24a-GraceNotes.png
Binary file modified packages/alphatab/test-data/musicxml-testsuite/34b-Colors.png
Binary file modified packages/alphatab/test-data/musicxml-testsuite/34c-Font-Size.png
Binary file modified packages/alphatab/test-data/musicxml-testsuite/71e-TabStaves.png
Binary file modified packages/alphatab/test-data/musicxml-testsuite/73a-Percussion.png
Binary file modified packages/alphatab/test-data/musicxml-testsuite/74a-FiguredBass.png
Binary file modified packages/alphatab/test-data/musicxml3/chord-diagram.png
Binary file modified packages/alphatab/test-data/musicxml3/tie-destination.png
Binary file modified packages/alphatab/test-data/musicxml4/bends.png
Binary file modified packages/alphatab/test-data/visual-tests/bounds-lookup/real-bar.png
Binary file modified packages/alphatab/test-data/visual-tests/general/colors.png
Binary file modified packages/alphatab/test-data/visual-tests/layout/multi-track.png
Binary file modified packages/alphatab/test-data/visual-tests/layout/multi-voice.png
Binary file modified packages/alphatab/test-data/visual-tests/layout/page-layout.png
Binary file modified packages/alphatab/test-data/visual-tests/special-tracks/slash.png
2 changes: 1 addition & 1 deletion packages/alphatab/test/visualTests/VisualTestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class VisualTestHelper {
let errorMessage = '';
const oldActual = actual;

const tolerancePercent = options.tolerancePercent ?? 1;
const tolerancePercent = options.tolerancePercent ?? 0;

if (expected) {
const sizeMismatch = expected.width !== actual.width || expected.height !== actual.height;
Expand Down