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
34 changes: 21 additions & 13 deletions packages/alphatab/src/rendering/LineBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,27 +1008,29 @@ export abstract class LineBarRenderer extends BarRendererBase {
if (h.hasTuplet && tupletDirection === direction) {
topY -= this.tupletSize + this.tupletOffset;
}
const lowestBeat = isRest ? h.beats[0] : h.beatOfLowestNote;
const lowestNote = h.lowestNoteInHelper;
const lowestBeat = lowestNote ? lowestNote.beat : h.beats[0];
if (h.hasTuplet && tupletDirection !== direction) {
// Use flag position (matches paintTuplets); getLowestNoteY skips content below the notehead.
bottomY = this.getFlagBottomY(lowestBeat, tupletDirection) + this.tupletSize + this.tupletOffset;
} else if (isRest) {
bottomY = this.getRestY(lowestBeat, NoteYPosition.Bottom);
} else {
} else if (lowestNote) {
bottomY = this.voiceContainer.getLowestNoteY(lowestBeat, NoteYPosition.Bottom);
}
} else {
bottomY = Math.max(drawingInfo.startY, drawingInfo.endY);
if (h.hasTuplet && tupletDirection === direction) {
bottomY += this.tupletSize + this.tupletOffset;
}
const highestBeat = isRest ? h.beats[0] : h.beatOfHighestNote;
const highestNote = h.highestNoteInHelper;
const highestBeat = highestNote ? highestNote.beat : h.beats[0];
if (h.hasTuplet && tupletDirection !== direction) {
// Use flag position (matches paintTuplets); getHighestNoteY skips octave dots.
topY = this.getFlagTopY(highestBeat, tupletDirection) - this.tupletSize - this.tupletOffset;
} else if (isRest) {
topY = this.getRestY(highestBeat, NoteYPosition.Top);
} else {
} else if (highestNote) {
topY = this.voiceContainer.getHighestNoteY(highestBeat, NoteYPosition.Top);
}
}
Expand Down Expand Up @@ -1287,18 +1289,24 @@ export abstract class LineBarRenderer extends BarRendererBase {
// 4. let middle elements shift up/down
if (h.beats.length > 1) {
// check if highest note shifts bar up or down
const highestNote = h.highestNoteInHelper;
const lowestNote = h.lowestNoteInHelper;
if (direction === BeamDirection.Up) {
const yNeededForHighestNote = barDrawingShift + this.getFlagTopY(h.beatOfHighestNote, direction);
const yGivenByCurrentValues = drawingInfo.calcY(this.getBeatX(h.beatOfHighestNote, BeatXPosition.Stem));
if (highestNote) {
const highestBeat = highestNote.beat;
const yNeededForHighestNote = barDrawingShift + this.getFlagTopY(highestBeat, direction);
const yGivenByCurrentValues = drawingInfo.calcY(this.getBeatX(highestBeat, BeatXPosition.Stem));

const diff = yGivenByCurrentValues - yNeededForHighestNote;
if (diff > 0) {
drawingInfo.startY -= diff;
drawingInfo.endY -= diff;
const diff = yGivenByCurrentValues - yNeededForHighestNote;
if (diff > 0) {
drawingInfo.startY -= diff;
drawingInfo.endY -= diff;
}
}
} else {
const yNeededForLowestNote = barDrawingShift + this.getFlagBottomY(h.beatOfLowestNote, direction);
const yGivenByCurrentValues = drawingInfo.calcY(this.getBeatX(h.beatOfLowestNote, BeatXPosition.Stem));
} else if (lowestNote) {
const lowestBeat = lowestNote.beat;
const yNeededForLowestNote = barDrawingShift + this.getFlagBottomY(lowestBeat, direction);
const yGivenByCurrentValues = drawingInfo.calcY(this.getBeatX(lowestBeat, BeatXPosition.Stem));

const diff = yNeededForLowestNote - yGivenByCurrentValues;
if (diff > 0) {
Expand Down
8 changes: 0 additions & 8 deletions packages/alphatab/src/rendering/utils/BeamingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,6 @@ export class BeamingHelper {
return ModelUtils.getIndex(a.duration) - 2 - barIndex > 0 && ModelUtils.getIndex(b.duration) - 2 - barIndex > 0;
}

public get beatOfLowestNote(): Beat {
return this.lowestNoteInHelper!.beat;
}

public get beatOfHighestNote(): Beat {
return this.highestNoteInHelper!.beat;
}

/**
* Per-direction beam drawing info cache. BeamDirection is a 2-value enum
* (Up=0, Down=1) so we use two pre-allocated `BeamingHelperDrawInfo`
Expand Down
15 changes: 15 additions & 0 deletions packages/alphatab/test/visualTests/issues/BrokenRenders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ describe('BrokenRendersTests', () => {
}
});

it('dead-slapped-beats', () => {
for (const tex of [
'\\staff {score tabs slash numbered} r.1 {ds}',
'\\staff {numbered} \\ts 8 4 :-2 r {ds}',
'\\staff {score tabs slash numbered} \\ts 3 2 :1 C4 {tu 3} C4 {tu 3} r {tu 3 ds}',
'\\staff {score tabs slash numbered} :8 r {ds beam merge} r {ds} r r r r r r'
]) {
const results = renderSvg(ScoreLoader.loadAlphaTex(tex), 1300);
expect(results.length, tex).toBeGreaterThan(0);
for (const r of results) {
expect(r.includes('NaN'), `NaN in SVG for ${tex}`).toBe(false);
}
}
});

it('squeezed-bar-warning', () => {
const settings = new Settings();
settings.core.engine = 'svg';
Expand Down
Loading