@braccato/core 2.0.0-beta.3 → 2.0.0-beta.4

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.
package/js/renderer.js CHANGED
@@ -342,6 +342,9 @@ export function createLyricsRenderer(rendererOptions) {
342
342
  return rust && attached ? rust.lineIndex(lyricElement) : -1;
343
343
  }
344
344
 
345
+ /** The snapshot last handed to Rust. */
346
+ let sent = null;
347
+
345
348
  // What the records and the module-level helpers reach this renderer through.
346
349
  const view = {
347
350
  indexOf,
@@ -362,6 +365,7 @@ export function createLyricsRenderer(rendererOptions) {
362
365
  return index >= 0 ? rust.hangRomanization(index, text ?? undefined, timed ?? null) : false;
363
366
  },
364
367
  resetClock() {
368
+ sent = null;
365
369
  rust?.resetClock();
366
370
  },
367
371
  canvas() {
@@ -379,9 +383,6 @@ export function createLyricsRenderer(rendererOptions) {
379
383
  };
380
384
  live.add(view);
381
385
 
382
- /** The snapshot last handed to Rust. */
383
- let sent = null;
384
-
385
386
  function tick(currentTimeS, options) {
386
387
  if (destroyed) return "lyrics-missing";
387
388
  const resolved = resolveTickOptions(options ?? {});
@@ -443,12 +444,15 @@ export function createLyricsRenderer(rendererOptions) {
443
444
  throw new Error("A lyrics renderer needs a mount: give one to createLyricsRenderer or to setLyrics");
444
445
  }
445
446
  ensure(nextMount);
446
- rust.setLyrics(lyrics, {
447
+ const otherSong = rust.setLyrics(lyrics, {
447
448
  noLyrics: options.noLyrics ?? false,
448
449
  language: normalizeLanguage(options.language) || undefined,
449
450
  songwriters: options.songwriters ? [...options.songwriters] : undefined,
450
451
  songKey: options.songKey,
451
452
  });
453
+ // The last snapshot was the old song's. Carried forward, or held by a stop at zero (the
454
+ // player between songs), it would scroll the new song to wherever the old one had got to.
455
+ if (otherSong) view.resetClock();
452
456
  rust.container.dataset.loaderVisible = String(options.loaderVisible ?? false);
453
457
  },
454
458
  setLanguage(language) {
@@ -469,6 +473,7 @@ export function createLyricsRenderer(rendererOptions) {
469
473
  if (destroyed || !rust) return;
470
474
  rust.clear();
471
475
  attached = false;
476
+ sent = null;
472
477
  syncRecords();
473
478
  },
474
479
  destroy() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braccato/core",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "Synchronized lyrics renderer with word-by-word animations, in Rust and WebGL2",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -72,9 +72,11 @@ export class Renderer {
72
72
  */
73
73
  setLayout(layout: string): void;
74
74
  /**
75
- * The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters? }`.
75
+ * The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters?, songKey? }`.
76
+ * Returns whether it is another song rather than lyrics swapped into the one on screen, so a
77
+ * caller whose last snapshot was the old song's can forget it with `resetClock`.
76
78
  */
77
- setLyrics(lyrics: any, options: any): void;
79
+ setLyrics(lyrics: any, options: any): boolean;
78
80
  /**
79
81
  * Binds a media element as the clock, or unbinds with `null`.
80
82
  */
@@ -182,7 +184,7 @@ export interface InitOutput {
182
184
  readonly renderer_setHost: (a: number, b: any) => void;
183
185
  readonly renderer_setLanguage: (a: number, b: number, c: number) => void;
184
186
  readonly renderer_setLayout: (a: number, b: number, c: number) => void;
185
- readonly renderer_setLyrics: (a: number, b: any, c: any) => [number, number];
187
+ readonly renderer_setLyrics: (a: number, b: any, c: any) => [number, number, number];
186
188
  readonly renderer_setMedia: (a: number, b: number) => void;
187
189
  readonly renderer_setProfiling: (a: number, b: number) => number;
188
190
  readonly renderer_setScrollDetection: (a: number, b: number) => void;
@@ -200,15 +200,19 @@ export class Renderer {
200
200
  wasm.renderer_setLayout(this.__wbg_ptr, ptr0, len0);
201
201
  }
202
202
  /**
203
- * The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters? }`.
203
+ * The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters?, songKey? }`.
204
+ * Returns whether it is another song rather than lyrics swapped into the one on screen, so a
205
+ * caller whose last snapshot was the old song's can forget it with `resetClock`.
204
206
  * @param {any} lyrics
205
207
  * @param {any} options
208
+ * @returns {boolean}
206
209
  */
207
210
  setLyrics(lyrics, options) {
208
211
  const ret = wasm.renderer_setLyrics(this.__wbg_ptr, lyrics, options);
209
- if (ret[1]) {
210
- throw takeFromExternrefTable0(ret[0]);
212
+ if (ret[2]) {
213
+ throw takeFromExternrefTable0(ret[1]);
211
214
  }
215
+ return ret[0] !== 0;
212
216
  }
213
217
  /**
214
218
  * Binds a media element as the clock, or unbinds with `null`.
@@ -1033,6 +1037,10 @@ function __wbg_get_imports() {
1033
1037
  const ret = arg0.next();
1034
1038
  return ret;
1035
1039
  }, arguments); },
1040
+ __wbg_nodeType_5c5050c6571c3463: function(arg0) {
1041
+ const ret = arg0.nodeType;
1042
+ return ret;
1043
+ },
1036
1044
  __wbg_now_043d245551b22f9c: function(arg0) {
1037
1045
  const ret = arg0.now();
1038
1046
  return ret;
Binary file
@@ -24,7 +24,7 @@ export const renderer_setHidden: (a: number, b: number) => void;
24
24
  export const renderer_setHost: (a: number, b: any) => void;
25
25
  export const renderer_setLanguage: (a: number, b: number, c: number) => void;
26
26
  export const renderer_setLayout: (a: number, b: number, c: number) => void;
27
- export const renderer_setLyrics: (a: number, b: any, c: any) => [number, number];
27
+ export const renderer_setLyrics: (a: number, b: any, c: any) => [number, number, number];
28
28
  export const renderer_setMedia: (a: number, b: number) => void;
29
29
  export const renderer_setProfiling: (a: number, b: number) => number;
30
30
  export const renderer_setScrollDetection: (a: number, b: number) => void;