@coderline/alphatab 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -365,6 +365,8 @@ export declare class AlphaTabApiBase<TSettings> {
365
365
  private _player;
366
366
  private _renderer;
367
367
  private _defaultScrollHandler?;
368
+ private _defaultCursorHandler?;
369
+ private _customCursorHandler?;
368
370
  /**
369
371
  * An indicator by how many midi-ticks the song contents are shifted.
370
372
  * Grace beats at start might require a shift for the first beat to start at 0.
@@ -839,6 +841,62 @@ export declare class AlphaTabApiBase<TSettings> {
839
841
  * ```
840
842
  */
841
843
  render(renderHints?: RenderHints): void;
844
+ /**
845
+ * A custom cursor handler which will be used to update the cursor positions during playback.
846
+ *
847
+ * @category Properties - Player
848
+ * @since 1.8.1
849
+ * @example
850
+ * JavaScript
851
+ * ```js
852
+ * const api = new alphaTab.AlphaTabApi(document.querySelector('#alphaTab'));
853
+ * api.customCursorHandler = {
854
+ * _customAdorner: undefined,
855
+ * onAttach(cursors) {
856
+ * this._customAdorner = document.createElement('div');
857
+ * this._customAdorner.classList.add('cursor-adorner');
858
+ * cursors.cursorWrapper.element.appendChild(this._customAdorner);
859
+ * },
860
+ * onDetach(cursors) { this._customAdorner.remove(); },
861
+ * placeBarCursor(barCursor, beatBounds) {
862
+ * const barBoundings = beatBounds.barBounds.masterBarBounds;
863
+ * const barBounds = barBoundings.visualBounds;
864
+ * barCursor.setBounds(barBounds.x, barBounds.y, barBounds.w, barBounds.h);
865
+ * },
866
+ * placeBeatCursor(beatCursor, beatBounds, startBeatX) {
867
+ * const barBoundings = beatBounds.barBounds.masterBarBounds;
868
+ * const barBounds = barBoundings.visualBounds;
869
+ * beatCursor.transitionToX(0, startBeatX);
870
+ * beatCursor.setBounds(startBeatX, barBounds.y, 1, barBounds.h);
871
+ * this._customAdorner.style.left = startBeatX + 'px';
872
+ * this._customAdorner.style.top = (barBounds.y - 10) + 'px';
873
+ * this._customAdorner.style.width = '1px';
874
+ * this._customAdorner.style.height = '10px';
875
+ * this._customAdorner.style.transition = 'left 0ms linear'; // stop animation
876
+ * },
877
+ * transitionBeatCursor(beatCursor, beatBounds, startBeatX, endBeatX, duration, cursorMode) {
878
+ * this._customAdorner.style.transition = `left ${duration}ms linear`; // start animation
879
+ * this._customAdorner.style.left = endBeatX + 'px';
880
+ * }
881
+ * }
882
+ * ```
883
+ *
884
+ * @example
885
+ * C#
886
+ * ```cs
887
+ * var api = new AlphaTabApi<MyControl>(...);
888
+ * api.CustomCursorHandler = new CustomCursorHandler();
889
+ * ```
890
+ *
891
+ * @example
892
+ * Android
893
+ * ```kotlin
894
+ * val api = AlphaTabApi<MyControl>(...)
895
+ * api.customCursorHandler = CustomCursorHandler();
896
+ * ```
897
+ */
898
+ get customCursorHandler(): ICursorHandler | undefined;
899
+ set customCursorHandler(value: ICursorHandler | undefined);
842
900
  private _tickCache;
843
901
  /**
844
902
  * A custom scroll handler which will be used to handle scrolling operations during playback.
@@ -1686,6 +1744,8 @@ export declare class AlphaTabApiBase<TSettings> {
1686
1744
  private _destroyCursors;
1687
1745
  private _createCursors;
1688
1746
  private _updateCursors;
1747
+ private _cursorHandlerMode;
1748
+ private _updateCursorHandler;
1689
1749
  private _scrollHandlerMode;
1690
1750
  private _scrollHandlerVertical;
1691
1751
  private _updateScrollHandler;
@@ -5522,22 +5582,10 @@ declare class Bounds {
5522
5582
  * @public
5523
5583
  */
5524
5584
  declare class BoundsLookup {
5525
- /**
5526
- * @target web
5527
- */
5528
- toJson(): unknown;
5529
- /**
5530
- * @target web
5531
- */
5532
- static fromJson(json: unknown, score: Score): BoundsLookup;
5533
- /**
5534
- * @target web
5535
- */
5585
+ toJson(): Map<string, unknown>;
5586
+ static fromJson(json: Map<string, unknown> | null, score: Score): BoundsLookup | null;
5536
5587
  private static _boundsFromJson;
5537
- /**
5538
- * @target web
5539
- */
5540
- private _boundsToJson;
5588
+ private static _boundsToJson;
5541
5589
  private _beatLookup;
5542
5590
  private _masterBarLookup;
5543
5591
  private _currentStaffSystem;
@@ -8120,6 +8168,7 @@ export declare class Environment {
8120
8168
  */
8121
8169
  private static _globalThis;
8122
8170
 
8171
+
8123
8172
  /**
8124
8173
  * @target web
8125
8174
  */
@@ -8148,13 +8197,6 @@ export declare class Environment {
8148
8197
  * @target web
8149
8198
  */
8150
8199
  static get isRunningInAudioWorklet(): boolean;
8151
-
8152
-
8153
- /**
8154
- * @target web
8155
- * @partial
8156
- */
8157
- static throttle(action: () => void, delay: number): () => void;
8158
8200
  /**
8159
8201
  * @target web
8160
8202
  */
@@ -8203,7 +8245,7 @@ export declare class Environment {
8203
8245
  /**
8204
8246
  * @target web
8205
8247
  */
8206
- static initializeMain(createWebWorker: (settings: Settings) => Worker, createAudioWorklet: (context: AudioContext, settings: Settings) => Promise<void>): void;
8248
+ static initializeMain(createWebWorker: (settings: Settings, nameHint: string) => Worker, createAudioWorklet: (context: AudioContext, settings: Settings) => Promise<void>): void;
8207
8249
 
8208
8250
 
8209
8251
  /**
@@ -9112,6 +9154,7 @@ declare interface IAudioExporter extends Disposable {
9112
9154
  * slightly longer audio is contained in the result.
9113
9155
  *
9114
9156
  * When the song ends, the chunk might contain less than the requested duration.
9157
+ * @async
9115
9158
  */
9116
9159
  render(milliseconds: number): Promise<AudioExportChunk | undefined>;
9117
9160
  destroy(): void;
@@ -9130,6 +9173,7 @@ declare interface IAudioExporterWorker extends IAudioExporter {
9130
9173
  * @param midi The midi file to load
9131
9174
  * @param syncPoints The sync points of the song (if any)
9132
9175
  * @param transpositionPitches The initial transposition pitches for the midi file.
9176
+ * @async
9133
9177
  */
9134
9178
  initialize(options: AudioExportOptions, midi: MidiFile, syncPoints: BackingTrackSyncPoint[], transpositionPitches: Map<number, number>): Promise<void>;
9135
9179
  }
@@ -9283,6 +9327,50 @@ declare interface IContainer {
9283
9327
  mouseUp: IEventEmitterOfT<IMouseEventArgs>;
9284
9328
  }
9285
9329
 
9330
+ /**
9331
+ * Classes implementing this interface can handle the cursor placement logic
9332
+ * as the playback in alphaTab progresses.
9333
+ *
9334
+ * @public
9335
+ */
9336
+ declare interface ICursorHandler {
9337
+ /**
9338
+ * Called when this handler activates. This can be on dynamic cursor creation
9339
+ * or when setting a custom handler with cursors already created.
9340
+ * @param cursors A container holding information about the cursor elements.
9341
+ */
9342
+ onAttach(cursors: Cursors): void;
9343
+ /**
9344
+ * Called when this handler deactivates. This can be on dynamic cursor destroy
9345
+ * or when setting a new custom handler.
9346
+ * @param cursors A container holding information about the cursor elements.
9347
+ */
9348
+ onDetach(cursors: Cursors): void;
9349
+ /**
9350
+ * Instructs the handler to place the bar cursor for the given beat bounds instantly .
9351
+ * @param barCursor The bar cursor.
9352
+ * @param beatBounds The bounds of the currently active beat.
9353
+ */
9354
+ placeBarCursor(barCursor: IContainer, beatBounds: BeatBounds): void;
9355
+ /**
9356
+ * Instructs the handler to place the beat cursor for the given beat bounds instantly.
9357
+ * @param barCursor The beat cursor.
9358
+ * @param beatBounds The bounds of the currently active beat.
9359
+ */
9360
+ placeBeatCursor(beatCursor: IContainer, beatBounds: BeatBounds, startBeatX: number): void;
9361
+ /**
9362
+ * Instructs the handler to initiate a transition of the beat cursor (e.g. for dynamic animation).
9363
+ * @param beatCursor The beat cursor
9364
+ * @param beatBounds The bounds of the currently active beat.
9365
+ * @param startBeatX The X-position where the transition of the beat cursor should start.
9366
+ * @param nextBeatX The X-position where the transition of the beat cursor should end
9367
+ * (typically the next beat or end of bar depending on the cursor mode and seeks)
9368
+ * @param duration The duration in milliseconds on how long the transition should take.
9369
+ * @param cursorMode The active cursor mode for the cursor placement.
9370
+ */
9371
+ transitionBeatCursor(beatCursor: IContainer, beatBounds: BeatBounds, startBeatX: number, nextBeatX: number, duration: number, cursorMode: MidiTickLookupFindBeatResultCursorMode): void;
9372
+ }
9373
+
9286
9374
  /**
9287
9375
  * An emitter for an event without any value passed to the listeners.
9288
9376
  * @public
@@ -9372,6 +9460,18 @@ declare interface IExternalMediaSynthOutput extends IBackingTrackSynthOutput {
9372
9460
  updatePosition(currentTime: number): void;
9373
9461
  }
9374
9462
 
9463
+ /**
9464
+ * A UI element implementation wrapping HTML elements.
9465
+ * @target web
9466
+ * @public
9467
+ */
9468
+ declare interface IHtmlElementContainer extends IContainer {
9469
+ /**
9470
+ * The wrapped UI element.
9471
+ */
9472
+ readonly element: HTMLElement;
9473
+ }
9474
+
9375
9475
  /**
9376
9476
  * @public
9377
9477
  */
@@ -10163,6 +10263,18 @@ declare interface IUiFacade<TSettings> {
10163
10263
  * @param action
10164
10264
  */
10165
10265
  beginInvoke(action: () => void): void;
10266
+ /**
10267
+ * Creates a throttled/debounced version of the provided action.
10268
+ * @param action The action to call.
10269
+ * @param delay The delay to wait for additional call before actually executing.
10270
+ * @returns A function which executes the provided action after the given delay.
10271
+ * If multiple calls are made before the action is started, the already scheduled
10272
+ * action is cancelled and a new one is scheduled after the given delay.
10273
+ * If called endlessly, the action is never executed.
10274
+ *
10275
+ * Already executing actions will not be cancelled but will complete before another action executes.
10276
+ */
10277
+ throttle(action: () => void, delay: number): () => void;
10166
10278
  /**
10167
10279
  * Tells the UI layer to remove all highlights from highlighted music notation elements.
10168
10280
  */
@@ -10317,7 +10429,7 @@ declare class JsonConverter {
10317
10429
  * @param score The score object to serialize
10318
10430
  * @returns A serialized score object without ciruclar dependencies that can be used for further serializations.
10319
10431
  */
10320
- static scoreToJsObject(score: Score): unknown;
10432
+ static scoreToJsObject(score: Score): Map<string, unknown> | null;
10321
10433
  /**
10322
10434
  * Converts the given JavaScript object into a score object.
10323
10435
  * @param jsObject The javascript object created via {@link Score}
@@ -11371,6 +11483,11 @@ declare class MidiTickLookup {
11371
11483
  * This info allows building the correct "next" beat and duration.
11372
11484
  */
11373
11485
  multiBarRestInfo: Map<number, number[]> | null;
11486
+ /**
11487
+ * An optional playback range to consider when performing lookups.
11488
+ * This will mainly influence the used {@link MidiTickLookupFindBeatResultCursorMode}
11489
+ */
11490
+ playbackRange: PlaybackRange | null;
11374
11491
  /**
11375
11492
  * Finds the currently played beat given a list of tracks and the current time.
11376
11493
  * @param trackLookup The tracks indices in which to search the played beat for.
@@ -11488,9 +11605,14 @@ declare enum MidiTickLookupFindBeatResultCursorMode {
11488
11605
  */
11489
11606
  ToNextBext = 1,
11490
11607
  /**
11491
- * The cursor should animate to the end of the bar (typically on repeats and jumps)
11608
+ * @deprecated replaced by {@link ToEndOfBeat}
11609
+ */
11610
+ ToEndOfBar = 2,
11611
+ /**
11612
+ * The cursor should animate to the end of the **beat** (typically on repeats and jumps)
11613
+ * (this is named end of bar historically)
11492
11614
  */
11493
- ToEndOfBar = 2
11615
+ ToEndOfBeat = 3
11494
11616
  }
11495
11617
 
11496
11618
  /**
@@ -13283,12 +13405,13 @@ export declare namespace platform {
13283
13405
  export {
13284
13406
  Cursors,
13285
13407
  ICanvas,
13408
+ MeasuredText,
13286
13409
  TextAlign,
13287
13410
  TextBaseline,
13288
- MeasuredText,
13289
13411
  IContainer,
13290
13412
  IMouseEventArgs,
13291
- IUiFacade
13413
+ IUiFacade,
13414
+ IHtmlElementContainer
13292
13415
  }
13293
13416
  }
13294
13417