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
255 changes: 142 additions & 113 deletions src/AlphaTabApiBase.ts

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/model/Score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ export class Score {
if (this.masterBars.length !== 0) {
bar.previousMasterBar = this.masterBars[this.masterBars.length - 1];
bar.previousMasterBar.nextMasterBar = bar;
bar.start = bar.previousMasterBar.start + bar.previousMasterBar.calculateDuration();
// TODO: this will not work on anacrusis. Correct anacrusis durations are only working
// when there are beats with playback positions already computed which requires full finish
// chicken-egg problem here. temporarily forcing anacrusis length here to 0
bar.start =
bar.previousMasterBar.start +
(bar.previousMasterBar.isAnacrusis ? 0 : bar.previousMasterBar.calculateDuration());
}
// if the group is closed only the next upcoming header can
// reopen the group in case of a repeat alternative, so we
Expand All @@ -129,7 +134,7 @@ export class Score {
}

public finish(settings: Settings): void {
const sharedDataBag = new Map<string, unknown>()
const sharedDataBag = new Map<string, unknown>();
for (let i: number = 0, j: number = this.tracks.length; i < j; i++) {
this.tracks[i].finish(settings, sharedDataBag);
}
Expand Down
3 changes: 3 additions & 0 deletions src/rendering/ScoreRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class ScoreRenderer implements IScoreRenderer {
public canvas: ICanvas | null = null;
public score: Score | null = null;
public tracks: Track[] | null = null;
/**
* @internal
*/
public layout: ScoreLayout | null = null;
public settings: Settings;
public boundsLookup: BoundsLookup | null = null;
Expand Down
29 changes: 21 additions & 8 deletions src/rendering/layout/HorizontalScreenLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StaveGroup } from '@src/rendering/staves/StaveGroup';
import { Logger } from '@src/Logger';

export class HorizontalScreenLayoutPartialInfo {
public x: number = 0;
public width: number = 0;
public masterBars: MasterBar[] = [];
}
Expand All @@ -33,9 +34,9 @@ export class HorizontalScreenLayout extends ScoreLayout {
return false;
}

public get firstBarX(): number{
let x= this._pagePadding![0];
if(this._group) {
public get firstBarX(): number {
let x = this._pagePadding![0];
if (this._group) {
x += this._group.accoladeSpacing;
}
return x;
Expand Down Expand Up @@ -85,6 +86,7 @@ export class HorizontalScreenLayout extends ScoreLayout {
let countPerPartial: number = this.renderer.settings.display.barCountPerPartial;
let partials: HorizontalScreenLayoutPartialInfo[] = [];
let currentPartial: HorizontalScreenLayoutPartialInfo = new HorizontalScreenLayoutPartialInfo();
let renderX = 0;
while (currentBarIndex <= endBarIndex) {
let result = this._group.addBars(this.renderer.tracks!, currentBarIndex);
if (result) {
Expand All @@ -94,14 +96,18 @@ export class HorizontalScreenLayout extends ScoreLayout {
let previousPartial: HorizontalScreenLayoutPartialInfo = partials[partials.length - 1];
previousPartial.masterBars.push(score.masterBars[currentBarIndex]);
previousPartial.width += result.width;
renderX += result.width;
currentPartial.x += renderX;
} else {
currentPartial.masterBars.push(score.masterBars[currentBarIndex]);
currentPartial.width += result.width;
// no targetPartial here because previous partials already handled this code
if (currentPartial.masterBars.length >= countPerPartial) {
if (partials.length === 0) {
currentPartial.width += this._group.x + this._group.accoladeSpacing;
// respect accolade and on first partial
currentPartial.width += this._group.accoladeSpacing + this._pagePadding[0];
}
renderX += currentPartial.width;
partials.push(currentPartial);
Logger.debug(
this.name,
Expand All @@ -112,6 +118,7 @@ export class HorizontalScreenLayout extends ScoreLayout {
null
);
currentPartial = new HorizontalScreenLayoutPartialInfo();
currentPartial.x = renderX;
}
}
}
Expand All @@ -120,7 +127,7 @@ export class HorizontalScreenLayout extends ScoreLayout {
// don't miss the last partial if not empty
if (currentPartial.masterBars.length > 0) {
if (partials.length === 0) {
currentPartial.width += this._group.x + this._group.accoladeSpacing;
currentPartial.width += this._group.accoladeSpacing + this._pagePadding[0];
}
partials.push(currentPartial);
Logger.debug(
Expand All @@ -139,7 +146,7 @@ export class HorizontalScreenLayout extends ScoreLayout {

let x = 0;
for (let i: number = 0; i < partials.length; i++) {
let partial: HorizontalScreenLayoutPartialInfo = partials[i];
const partial: HorizontalScreenLayoutPartialInfo = partials[i];

const e = new RenderFinishedEventArgs();
e.x = x;
Expand All @@ -153,14 +160,20 @@ export class HorizontalScreenLayout extends ScoreLayout {

x += partial.width;

const partialBarIndex = currentBarIndex;
// pull to local scope for lambda
const partialBarIndex = currentBarIndex;
const partialIndex = i;
this._group.buildBoundingsLookup(this._group!.x, this._group!.y);
this.registerPartial(e, canvas => {
canvas.color = this.renderer.settings.display.resources.mainGlyphColor;
canvas.textAlign = TextAlign.Left;
let renderX: number = this._group!.getBarX(partial.masterBars[0].index) + this._group!.accoladeSpacing;
if (i === 0) {
if (partialIndex === 0) {
renderX -= this._group!.x + this._group!.accoladeSpacing;
}

canvas.color = this.renderer.settings.display.resources.mainGlyphColor;
canvas.textAlign = TextAlign.Left;
Logger.debug(
this.name,
'Rendering partial from bar ' +
Expand Down
1 change: 1 addition & 0 deletions src/rendering/layout/PageViewLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export class PageViewLayout extends ScoreLayout {
args.firstMasterBarIndex = group.firstBarIndex;
args.lastMasterBarIndex = group.lastBarIndex;

group.buildBoundingsLookup(0, 0);
this.registerPartial(args, canvas => {
this.renderer.canvas!.color = this.renderer.settings.display.resources.mainGlyphColor;
this.renderer.canvas!.textAlign = TextAlign.Left;
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/layout/ScoreLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LazyPartial {
}

/**
* This is the base public class for creating new layouting engines for the score renderer.
* This is the base class for creating new layouting engines for the score renderer.
*/
export abstract class ScoreLayout {
private _barRendererLookup: Map<string, Map<number, BarRendererBase>> = new Map();
Expand Down Expand Up @@ -296,7 +296,7 @@ export abstract class ScoreLayout {
: this.firstBarX;
e.y = y;
e.totalWidth = this.width;
e.totalHeight = this.height;
e.totalHeight = y + height;
e.firstMasterBarIndex = -1;
e.lastMasterBarIndex = -1;

Expand Down
3 changes: 1 addition & 2 deletions src/rendering/staves/StaveGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export class StaveGroup {
}

public paintPartial(cx: number, cy: number, canvas: ICanvas, startIndex: number, count: number): void {
this.buildBoundingsLookup(cx, cy);
for (let i: number = 0, j: number = this._allStaves.length; i < j; i++) {
this._allStaves[i].paint(cx, cy, canvas, startIndex, count);
}
Expand Down Expand Up @@ -345,7 +344,7 @@ export class StaveGroup {
}
}

private buildBoundingsLookup(cx: number, cy: number): void {
public buildBoundingsLookup(cx: number, cy: number): void {
if (this.layout.renderer.boundsLookup!.isFinished) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/synth/MidiFileSequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SynthEvent } from '@src/synth/synthesis/SynthEvent';
import { TinySoundFont } from '@src/synth/synthesis/TinySoundFont';
import { Logger } from '@src/Logger';
import { SynthConstants } from '@src/synth/SynthConstants';
import { MidiUtils } from '@src/midi/MidiUtils';

export class MidiFileSequencerTempoChange {
public bpm: number;
Expand All @@ -27,7 +28,7 @@ class MidiSequencerState {
public firstTimeSignatureNumerator: number = 0;
public firstTimeSignatureDenominator: number = 0;
public synthData: SynthEvent[] = [];
public division: number = 0;
public division: number = MidiUtils.QuarterTime;
public eventIndex: number = 0;
public currentTime: number = 0;
public playbackRange: PlaybackRange | null = null;
Expand Down
5 changes: 2 additions & 3 deletions src/synth/soundfont/Hydra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,12 @@ export class Hydra {
let samplesPos: number = 0;

const sampleBuffer: Uint8Array = new Uint8Array(2048);
const testBuffer: Int16Array = new Int16Array((sampleBuffer.length / 2) | 0);
while (samplesLeft > 0) {
let samplesToRead: number = Math.min(samplesLeft, (sampleBuffer.length / 2) | 0);
reader.read(sampleBuffer, 0, samplesToRead * 2);
for (let i: number = 0; i < samplesToRead; i++) {
testBuffer[i] = (sampleBuffer[i * 2 + 1] << 8) | sampleBuffer[i * 2];
samples[samplesPos + i] = testBuffer[i] / 32767;
const shortSample = TypeConversions.int32ToInt16((sampleBuffer[i * 2 + 1] << 8) | sampleBuffer[i * 2]);
samples[samplesPos + i] = shortSample / 32767;
}
samplesLeft -= samplesToRead;
samplesPos += samplesToRead;
Expand Down