Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed flickering of beat cursor in firefox #651

Merged
merged 2 commits into from
Aug 22, 2021
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
27 changes: 0 additions & 27 deletions src.csharp/AlphaTab.Windows/WinForms/ControlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,39 +105,12 @@ public void Clear()
Control.Controls.Clear();
}

private readonly Bounds _lastBounds = new Bounds();

public Bounds GetBounds()
{
return _lastBounds;
}

public void SetBounds(double x, double y, double w, double h)
{
if (double.IsNaN(x))
{
x = _lastBounds.X;
}
if (double.IsNaN(y))
{
y = _lastBounds.Y;
}
if (double.IsNaN(w))
{
w = _lastBounds.W;
}
if (double.IsNaN(h))
{
h = _lastBounds.H;
}
Control.Left = (int)x;
Control.Top = (int)y;
Control.Width = (int)w;
Control.Height = (int)h;
_lastBounds.X = x;
_lastBounds.Y = y;
_lastBounds.W = w;
_lastBounds.H = h;
}

public IEventEmitter Resize { get; set; }
Expand Down
28 changes: 0 additions & 28 deletions src.csharp/AlphaTab.Windows/Wpf/FrameworkElementContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,40 +130,12 @@ public void Clear()
}
}

private readonly Bounds _lastBounds = new Bounds();

public Bounds GetBounds()
{
return _lastBounds;
}

public void SetBounds(double x, double y, double w, double h)
{
if (double.IsNaN(x))
{
x = _lastBounds.X;
}
if (double.IsNaN(y))
{
y = _lastBounds.Y;
}
if (double.IsNaN(w))
{
w = _lastBounds.W;
}
if (double.IsNaN(h))
{
h = _lastBounds.H;
}

Canvas.SetLeft(Control, x);
Canvas.SetTop(Control, y);
Control.Width = w;
Control.Height = h;
_lastBounds.X = x;
_lastBounds.Y = y;
_lastBounds.W = w;
_lastBounds.H = h;
}

public IEventEmitter Resize { get; set; }
Expand Down
38 changes: 11 additions & 27 deletions src/AlphaTabApiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,13 @@ export class AlphaTabApiBase<TSettings> {
this._playerState = PlayerState.Paused;
// we need to update our position caches if we render a tablature
this.renderer.postRenderFinished.on(() => {
this.cursorUpdateTick(this._previousTick, false, true);
this.cursorUpdateTick(this._previousTick, false);
});
if (this.player) {
this.player.positionChanged.on(e => {
this._previousTick = e.currentTick;
this.uiFacade.beginInvoke(() => {
this.cursorUpdateTick(e.currentTick, false, e.isSeek);
this.cursorUpdateTick(e.currentTick, false);
});
});
this.player.stateChanged.on(e => {
Expand All @@ -790,14 +790,14 @@ export class AlphaTabApiBase<TSettings> {
* @param tick
* @param stop
*/
private cursorUpdateTick(tick: number, stop: boolean, forceImmediateUpdate: boolean): void {
private cursorUpdateTick(tick: number, stop: boolean): void {
let cache: MidiTickLookup | null = this._tickCache;
if (cache) {
let tracks: Track[] = this.tracks;
if (tracks.length > 0) {
let beat: MidiTickLookupFindBeatResult | null = cache.findBeat(tracks, tick, this._currentBeat);
if (beat) {
this.cursorUpdateBeat(beat, stop, forceImmediateUpdate);
this.cursorUpdateBeat(beat, stop);
}
}
}
Expand All @@ -808,8 +808,7 @@ export class AlphaTabApiBase<TSettings> {
*/
private cursorUpdateBeat(
lookupResult: MidiTickLookupFindBeatResult,
stop: boolean,
forceImmediateUpdate: boolean
stop: boolean
): void {
const beat: Beat = lookupResult.currentBeat;
const nextBeat: Beat | null = lookupResult.nextBeat;
Expand Down Expand Up @@ -845,8 +844,7 @@ export class AlphaTabApiBase<TSettings> {
stop,
beatsToHighlight,
cache!,
beatBoundings!,
forceImmediateUpdate
beatBoundings!
);
});
}
Expand All @@ -858,24 +856,17 @@ export class AlphaTabApiBase<TSettings> {
stop: boolean,
beatsToHighlight: Beat[] | null,
cache: BoundsLookup,
beatBoundings: BeatBounds,
forceImmediateUpdate: boolean
beatBoundings: BeatBounds
) {
let barCursor: IContainer = this._barCursor!;
let beatCursor: IContainer = this._beatCursor!;

let barBoundings: MasterBarBounds = beatBoundings.barBounds.masterBarBounds;
let barBounds: Bounds = barBoundings.visualBounds;
let needsNewAnimationFrame = false;

barCursor.setBounds(barBounds.x, barBounds.y, barBounds.w, barBounds.h);

// move beat to start position immediately
const previousBeatBounds: Bounds = beatCursor.getBounds();
needsNewAnimationFrame =
forceImmediateUpdate ||
previousBeatBounds!.y !== barBounds.y ||
beatBoundings.visualBounds.x < previousBeatBounds!.x;
if (this.settings.player.enableAnimatedBeatCursor) {
beatCursor.stopAnimation();
}
Expand Down Expand Up @@ -918,16 +909,9 @@ export class AlphaTabApiBase<TSettings> {

// we need to put the transition to an own animation frame
// otherwise the stop animation above is not applied.
// but only if we changed on the y axis.
// as long we scroll horizontally we can keep the animation
// alive.
if (needsNewAnimationFrame) {
this.uiFacade.beginInvoke(() => {
beatCursor!.transitionToX(duration, nextBeatX);
});
} else {
beatCursor.transitionToX(duration, nextBeatX);
}
this.uiFacade.beginInvoke(() => {
beatCursor!.transitionToX(duration, nextBeatX);
});
}
}
if (!this._beatMouseDown && this.settings.player.scrollMode !== ScrollMode.Off) {
Expand Down Expand Up @@ -1081,7 +1065,7 @@ export class AlphaTabApiBase<TSettings> {
// move to selection start
this._currentBeat = null; // reset current beat so it is updating the cursor
if (this._playerState === PlayerState.Paused) {
this.cursorUpdateTick(this._selectionStart.beat.absolutePlaybackStart, false, true);
this.cursorUpdateTick(this._selectionStart.beat.absolutePlaybackStart, false);
}
this.tickPosition = realMasterBarStart + this._selectionStart.beat.playbackStart;
// set playback range
Expand Down
7 changes: 0 additions & 7 deletions src/platform/IContainer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IEventEmitter, IEventEmitterOfT } from '@src/EventEmitter';
import { IMouseEventArgs } from '@src/platform/IMouseEventArgs';
import { Bounds } from '@src/rendering/utils/Bounds';

/**
* This interface represents a container control in the UI layer.
Expand Down Expand Up @@ -51,12 +50,6 @@ export interface IContainer {
*/
setBounds(x: number, y: number, w: number, h: number): void;

/**
* Gets the current position and size of the container. These
* values might be only filled correctly after a call to setBounds.
*/
getBounds(): Bounds;

/**
* Tells the control to move to the given X-position in the given time.
* @param duration The milliseconds that should be needed to reach the new X-position
Expand Down
4 changes: 0 additions & 4 deletions src/platform/javascript/HtmlElementContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ export class HtmlElementContainer implements IContainer {

private _lastBounds: Bounds = new Bounds();

public getBounds() {
return this._lastBounds;
}

public setBounds(x: number, y: number, w: number, h: number) {
if (isNaN(x)) {
x = this._lastBounds.x;
Expand Down