canvas-recorder-lib 0.7.1 → 0.7.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.
Files changed (174) hide show
  1. package/README.md +38 -8
  2. package/dev/audio-builder.ts +5 -1
  3. package/dev/canvas-recorder.css +15 -4
  4. package/dev/canvas-recorder.ts +255 -82
  5. package/dev/delay-files.ts +1 -1
  6. package/dev/format-editor.ts +7 -2
  7. package/dev/fourier-panel.ts +11 -3
  8. package/dev/handwriting-panel.ts +14 -9
  9. package/dev/local-file-row.ts +12 -5
  10. package/dev/multi-text-dialog.ts +15 -6
  11. package/dev/multi-text-panel.ts +6 -2
  12. package/dev/player-body.ts +4 -0
  13. package/dev/schedule-helpers.ts +11 -4
  14. package/dev/sound-clips.ts +4 -1
  15. package/dev/soundtrack.ts +42 -11
  16. package/dev/split-dialog.ts +49 -19
  17. package/dev/static-image-panel.ts +17 -5
  18. package/dev/synced-file.ts +4 -5
  19. package/dev/timeline-display.ts +152 -50
  20. package/dev/transcribe-core.ts +48 -17
  21. package/dev/transcribe-worker.ts +20 -9
  22. package/dev/transcript-align.ts +95 -20
  23. package/dev/transcript-export.ts +18 -7
  24. package/dev/transcript-view.ts +78 -22
  25. package/dev/transcripts.ts +43 -23
  26. package/dev/video-clip-panel.ts +64 -18
  27. package/dev/voice/chirp.ts +21 -5
  28. package/dev/voice/folder.ts +22 -7
  29. package/dev/voice/voice-panel.ts +34 -10
  30. package/dev/voice/voice-recorder.ts +74 -18
  31. package/dist/dev/audio-builder.js.map +1 -1
  32. package/dist/dev/canvas-recorder.css +15 -4
  33. package/dist/dev/canvas-recorder.js +165 -42
  34. package/dist/dev/canvas-recorder.js.map +1 -1
  35. package/dist/dev/format-editor.d.ts.map +1 -1
  36. package/dist/dev/format-editor.js.map +1 -1
  37. package/dist/dev/fourier-panel.d.ts.map +1 -1
  38. package/dist/dev/fourier-panel.js.map +1 -1
  39. package/dist/dev/handwriting-panel.d.ts.map +1 -1
  40. package/dist/dev/handwriting-panel.js +10 -8
  41. package/dist/dev/handwriting-panel.js.map +1 -1
  42. package/dist/dev/local-file-row.d.ts.map +1 -1
  43. package/dist/dev/local-file-row.js +12 -4
  44. package/dist/dev/local-file-row.js.map +1 -1
  45. package/dist/dev/multi-text-dialog.d.ts.map +1 -1
  46. package/dist/dev/multi-text-dialog.js +4 -2
  47. package/dist/dev/multi-text-dialog.js.map +1 -1
  48. package/dist/dev/multi-text-panel.d.ts.map +1 -1
  49. package/dist/dev/multi-text-panel.js +2 -1
  50. package/dist/dev/multi-text-panel.js.map +1 -1
  51. package/dist/dev/player-body.d.ts +1 -1
  52. package/dist/dev/player-body.d.ts.map +1 -1
  53. package/dist/dev/player-body.js +4 -0
  54. package/dist/dev/player-body.js.map +1 -1
  55. package/dist/dev/schedule-helpers.d.ts.map +1 -1
  56. package/dist/dev/schedule-helpers.js +4 -1
  57. package/dist/dev/schedule-helpers.js.map +1 -1
  58. package/dist/dev/sound-clips.d.ts.map +1 -1
  59. package/dist/dev/sound-clips.js.map +1 -1
  60. package/dist/dev/soundtrack.d.ts +12 -0
  61. package/dist/dev/soundtrack.d.ts.map +1 -1
  62. package/dist/dev/soundtrack.js +33 -7
  63. package/dist/dev/soundtrack.js.map +1 -1
  64. package/dist/dev/split-dialog.d.ts.map +1 -1
  65. package/dist/dev/split-dialog.js +17 -10
  66. package/dist/dev/split-dialog.js.map +1 -1
  67. package/dist/dev/static-image-panel.d.ts.map +1 -1
  68. package/dist/dev/static-image-panel.js +7 -3
  69. package/dist/dev/static-image-panel.js.map +1 -1
  70. package/dist/dev/synced-file.d.ts.map +1 -1
  71. package/dist/dev/synced-file.js.map +1 -1
  72. package/dist/dev/timeline-display.d.ts.map +1 -1
  73. package/dist/dev/timeline-display.js +62 -17
  74. package/dist/dev/timeline-display.js.map +1 -1
  75. package/dist/dev/transcribe-core.d.ts.map +1 -1
  76. package/dist/dev/transcribe-core.js +13 -3
  77. package/dist/dev/transcribe-core.js.map +1 -1
  78. package/dist/dev/transcribe-worker.d.ts.map +1 -1
  79. package/dist/dev/transcribe-worker.js +9 -3
  80. package/dist/dev/transcribe-worker.js.map +1 -1
  81. package/dist/dev/transcript-align.d.ts.map +1 -1
  82. package/dist/dev/transcript-align.js +52 -9
  83. package/dist/dev/transcript-align.js.map +1 -1
  84. package/dist/dev/transcript-export.d.ts.map +1 -1
  85. package/dist/dev/transcript-export.js +10 -4
  86. package/dist/dev/transcript-export.js.map +1 -1
  87. package/dist/dev/transcript-view.d.ts +2 -0
  88. package/dist/dev/transcript-view.d.ts.map +1 -1
  89. package/dist/dev/transcript-view.js +32 -11
  90. package/dist/dev/transcript-view.js.map +1 -1
  91. package/dist/dev/transcripts.d.ts.map +1 -1
  92. package/dist/dev/transcripts.js +5 -3
  93. package/dist/dev/transcripts.js.map +1 -1
  94. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  95. package/dist/dev/video-clip-panel.js +25 -8
  96. package/dist/dev/video-clip-panel.js.map +1 -1
  97. package/dist/dev/voice/chirp.d.ts.map +1 -1
  98. package/dist/dev/voice/chirp.js +5 -1
  99. package/dist/dev/voice/chirp.js.map +1 -1
  100. package/dist/dev/voice/folder.d.ts.map +1 -1
  101. package/dist/dev/voice/folder.js +1 -1
  102. package/dist/dev/voice/folder.js.map +1 -1
  103. package/dist/dev/voice/voice-panel.d.ts.map +1 -1
  104. package/dist/dev/voice/voice-panel.js +15 -6
  105. package/dist/dev/voice/voice-panel.js.map +1 -1
  106. package/dist/dev/voice/voice-recorder.d.ts.map +1 -1
  107. package/dist/dev/voice/voice-recorder.js +34 -9
  108. package/dist/dev/voice/voice-recorder.js.map +1 -1
  109. package/dist/lib/main-control.d.ts.map +1 -1
  110. package/dist/lib/main-control.js.map +1 -1
  111. package/dist/src/corner-rounder.d.ts.map +1 -1
  112. package/dist/src/corner-rounder.js +1 -1
  113. package/dist/src/corner-rounder.js.map +1 -1
  114. package/dist/src/local-files.d.ts.map +1 -1
  115. package/dist/src/local-files.js +5 -2
  116. package/dist/src/local-files.js.map +1 -1
  117. package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
  118. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  119. package/dist/src/peano-fourier/fourier-shared.js +8 -1
  120. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  121. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  122. package/dist/src/slide-components/fourier.js +12 -4
  123. package/dist/src/slide-components/fourier.js.map +1 -1
  124. package/dist/src/slide-components/image.d.ts.map +1 -1
  125. package/dist/src/slide-components/image.js +1 -1
  126. package/dist/src/slide-components/image.js.map +1 -1
  127. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  128. package/dist/src/slide-components/in-parallel.js.map +1 -1
  129. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  130. package/dist/src/slide-components/multi-text.js +1 -1
  131. package/dist/src/slide-components/multi-text.js.map +1 -1
  132. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  133. package/dist/src/slide-components/rectangle.js +1 -1
  134. package/dist/src/slide-components/rectangle.js.map +1 -1
  135. package/dist/src/slide-components/registry.js.map +1 -1
  136. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  137. package/dist/src/slide-components/serialize.js +2 -1
  138. package/dist/src/slide-components/serialize.js.map +1 -1
  139. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  140. package/dist/src/slide-components/split-video-clip.js +4 -1
  141. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  142. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  143. package/dist/src/slide-components/video-clip.js +7 -4
  144. package/dist/src/slide-components/video-clip.js.map +1 -1
  145. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  146. package/dist/src/slide-components/video-info.js.map +1 -1
  147. package/dist/src/slow-image-sources.d.ts.map +1 -1
  148. package/dist/src/slow-image-sources.js +1 -1
  149. package/dist/src/slow-image-sources.js.map +1 -1
  150. package/dist/src/snapshot.d.ts.map +1 -1
  151. package/dist/src/snapshot.js +1 -1
  152. package/dist/src/snapshot.js.map +1 -1
  153. package/dist/src/utility.d.ts.map +1 -1
  154. package/dist/src/utility.js +1 -3
  155. package/dist/src/utility.js.map +1 -1
  156. package/lib/main-control.ts +3 -1
  157. package/package.json +4 -1
  158. package/src/corner-rounder.ts +5 -12
  159. package/src/glib/letters-base.ts +1 -1
  160. package/src/local-files.ts +19 -6
  161. package/src/peano-fourier/fourier-shared.ts +8 -1
  162. package/src/slide-components/fourier.ts +32 -10
  163. package/src/slide-components/image.ts +4 -1
  164. package/src/slide-components/in-parallel.ts +1 -2
  165. package/src/slide-components/multi-text.ts +17 -4
  166. package/src/slide-components/rectangle.ts +4 -1
  167. package/src/slide-components/registry.ts +1 -1
  168. package/src/slide-components/serialize.ts +4 -1
  169. package/src/slide-components/split-video-clip.ts +4 -1
  170. package/src/slide-components/video-clip.ts +21 -8
  171. package/src/slide-components/video-info.ts +4 -1
  172. package/src/slow-image-sources.ts +5 -1
  173. package/src/snapshot.ts +13 -4
  174. package/src/utility.ts +70 -33
@@ -136,7 +136,7 @@ function applyZoom(zoom, px = panX, py = panY) {
136
136
  canvas.height = physH;
137
137
  canvas.style.width = `${cssW}px`;
138
138
  canvas.style.height = `${cssH}px`;
139
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
139
+ showFrame(playheadInVideoMs(), true);
140
140
  }
141
141
  [panX, panY] = clampPan(cssW, cssH, px, py);
142
142
  canvas.style.left = `${panX}px`;
@@ -166,7 +166,7 @@ function zoomToFit() {
166
166
  canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
167
167
  canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
168
168
  // Immediately redraw so the canvas clear doesn't show as a gray flash.
169
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
169
+ showFrame(playheadInVideoMs(), true);
170
170
  }
171
171
  zoomSelect.addEventListener("change", () => {
172
172
  if (zoomSelect.value === "fit") {
@@ -261,9 +261,10 @@ function showVideoSize(size) {
261
261
  videoSizeWarning.title = stretched
262
262
  ? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
263
263
  : "";
264
- getById("videoSizeControls", HTMLSpanElement).title = canvasRecorder.sizeLocked
265
- ? "The size of the video. This program sets it, so it can't be changed here."
266
- : "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
264
+ getById("videoSizeControls", HTMLSpanElement).title =
265
+ canvasRecorder.sizeLocked
266
+ ? "The size of the video. This program sets it, so it can't be changed here."
267
+ : "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
267
268
  }
268
269
  showVideoSize(canvasRecorder.size);
269
270
  /**
@@ -326,9 +327,12 @@ function updateLocalFilesButton() {
326
327
  const names = localFilesNeedingPermission();
327
328
  localFilesBtn.hidden = names.length === 0;
328
329
  localFilesBtn.textContent =
329
- names.length === 1 ? "🔓 Allow local file" : `🔓 Allow ${names.length} local files`;
330
+ names.length === 1
331
+ ? "🔓 Allow local file"
332
+ : `🔓 Allow ${names.length} local files`;
330
333
  localFilesBtn.title =
331
- "The browser needs your OK before it reads these files again:\n" + names.join("\n");
334
+ "The browser needs your OK before it reads these files again:\n" +
335
+ names.join("\n");
332
336
  }
333
337
  onLocalFilesChange(updateLocalFilesButton);
334
338
  /** Ask about every file that needs it. Then the sounds can load. */
@@ -461,29 +465,65 @@ const playPositionRange = getById("playPositionRange", HTMLInputElement);
461
465
  * This can be a number outside of the normal range of the current section.
462
466
  * This, like all user visible number, is measured in seconds. Internal
463
467
  * things measure time in milliseconds.
468
+ *
469
+ * It's measured from the start of the Visual Editor's root when
470
+ * {@link playPositionLocal} is checked, otherwise from the start of the video.
471
+ * Read it with {@link playheadInVideoMs} and write it with
472
+ * {@link loadPlayPositionSeconds}, which take care of that.
464
473
  */
465
474
  const playPositionSeconds = getById("playPositionSeconds", HTMLInputElement);
475
+ /**
476
+ * Checked: {@link playPositionSeconds} is measured from the start of the
477
+ * Visual Editor's root. Unchecked: from the start of the video.
478
+ */
479
+ const playPositionLocal = getById("playPositionLocal", HTMLInputElement);
466
480
  /**
467
481
  * When we get to the end of the section, automatically jump back to the
468
482
  * beginning of the section.
469
483
  */
470
484
  const repeatRadioButton = querySelector('input[name="onSectionEnd"][value="repeat"]', HTMLInputElement);
485
+ /**
486
+ * The playhead, measured from the start of the whole video.
487
+ * {@link playPositionSeconds} is the source of truth.
488
+ */
489
+ function playheadInVideoMs() {
490
+ const shownMs = playPositionSeconds.valueAsNumber * 1000;
491
+ return playPositionLocal.checked ? shownMs + rootStartMs : shownMs;
492
+ }
471
493
  /**
472
494
  * The playhead, measured from the start of the Visual Editor's root: the
473
495
  * time its keyframes use.
474
496
  */
475
497
  function playheadInRootMs() {
476
- return playPositionSeconds.valueAsNumber * 1000 - rootStartMs;
498
+ return playheadInVideoMs() - rootStartMs;
477
499
  }
478
500
  /**
479
501
  * Update the input that shows the time as a number.
480
- * @param timeInMs The time to display in the number control.
502
+ * @param timeInMs The time to display in the number control, measured from the start of the
503
+ * video. It's shown from the start of the root instead if {@link playPositionLocal} says so.
481
504
  * This is *automatically* converted to seconds and rounded to the nearest ⅒ of a millisecond.
482
505
  * We only use milliseconds, not seconds, inside the code.
483
506
  */
484
507
  function loadPlayPositionSeconds(timeInMs) {
485
- playPositionSeconds.value = (timeInMs / 1000).toFixed(4);
508
+ const shownMs = playPositionLocal.checked ? timeInMs - rootStartMs : timeInMs;
509
+ playPositionSeconds.value = (shownMs / 1000).toFixed(4);
486
510
  }
511
+ /**
512
+ * Move the Visual Editor's root. The playhead stays where it is in the video, so a local
513
+ * {@link playPositionSeconds} changes to match.
514
+ */
515
+ function setRootStartMs(ms) {
516
+ if (ms === rootStartMs)
517
+ return;
518
+ const playheadMs = playheadInVideoMs();
519
+ rootStartMs = ms;
520
+ loadPlayPositionSeconds(playheadMs);
521
+ }
522
+ playPositionLocal.addEventListener("input", () => {
523
+ // The same time, shown the other way. The number still means what the checkbox used to say.
524
+ const shownMs = playPositionSeconds.valueAsNumber * 1000;
525
+ loadPlayPositionSeconds(playPositionLocal.checked ? shownMs : shownMs + rootStartMs);
526
+ });
487
527
  /**
488
528
  * Update the range input to show the same time as the number input.
489
529
  *
@@ -493,7 +533,7 @@ function loadPlayPositionSeconds(timeInMs) {
493
533
  * If the user changes the range input, and the value is immediately copied to the number input for use in the program.
494
534
  */
495
535
  function loadPlayPositionRange() {
496
- playPositionRange.valueAsNumber = playPositionSeconds.valueAsNumber * 1000;
536
+ playPositionRange.valueAsNumber = playheadInVideoMs();
497
537
  }
498
538
  // The same rate as the decoded files and the voice recorder, whatever the hardware uses.
499
539
  const audioContext = new AudioContext({ sampleRate: SAMPLE_RATE });
@@ -510,7 +550,9 @@ const soundtrack = new Soundtrack({
510
550
  root: () => toShow,
511
551
  // Sound clips on the timeline can now show their waveforms, and the ones
512
552
  // that play to the end of their file now know how long that is.
513
- onDecoded: () => timelineDisplay.redraw(),
553
+ onDecoded: soundFileLoaded,
554
+ // Marked ⚠, on the timeline and on its card. See soundFileProblem().
555
+ onFailed: soundFileLoaded,
514
556
  // The new file may be a local one that needs 🔓.
515
557
  onNewSource: () => checkVideosLocalFiles(),
516
558
  });
@@ -691,7 +733,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs) => {
691
733
  if (voiceRecording && !voiceChirping)
692
734
  stopVoiceRecording();
693
735
  playPositionSeconds.disabled = false;
694
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
736
+ showFrame(playheadInVideoMs(), true);
695
737
  return;
696
738
  }
697
739
  // Playing.
@@ -699,7 +741,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs) => {
699
741
  if (!audioPlaying && !rafFallbackPlaying) {
700
742
  // Not running: first play, after pause/seek, or after repeat.
701
743
  // Clips whose file isn't decoded yet join in when it is, so nothing waits for them.
702
- let startMs = playPositionSeconds.valueAsNumber * 1000;
744
+ let startMs = playheadInVideoMs();
703
745
  if (startMs >= sectionEndTime - 0.05) {
704
746
  // At the end — jump to the beginning.
705
747
  startMs = sectionStartTime;
@@ -795,7 +837,7 @@ addEventListener("keypress", (event) => {
795
837
  }
796
838
  });
797
839
  getById("back5s", HTMLButtonElement).addEventListener("click", () => {
798
- const backMs = Math.max(sectionStartTime, playPositionSeconds.valueAsNumber * 1000 - 5000);
840
+ const backMs = Math.max(sectionStartTime, playheadInVideoMs() - 5000);
799
841
  loadPlayPositionSeconds(backMs);
800
842
  loadPlayPositionRange();
801
843
  stopAudio();
@@ -843,7 +885,7 @@ function framesBetween(startMs, endMs) {
843
885
  * It stays inside the play limits.
844
886
  */
845
887
  function stepOneFrame(direction) {
846
- const position = framePosition(playPositionSeconds.valueAsNumber * 1000);
888
+ const position = framePosition(playheadInVideoMs());
847
889
  let frame = direction > 0
848
890
  ? Math.floor(position + FRAME_TOLERANCE) + 1
849
891
  : Math.ceil(position - FRAME_TOLERANCE) - 1;
@@ -1094,6 +1136,12 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixe
1094
1136
  },
1095
1137
  ],
1096
1138
  });
1139
+ // The newest soundtrack, with every file in it decoded. Right after a reload or an
1140
+ // edit, that can take a moment. (After the file picker, which needs the click.)
1141
+ // Before anything is written: a sound that can't be read stops the save here.
1142
+ infoDiv.innerHTML = "Waiting for the sound…";
1143
+ await soundtrack.ready();
1144
+ assertSoundFilesLoaded();
1097
1145
  const writableStream = await fileHandle.createWritable();
1098
1146
  // Set up Mediabunny output (streaming to file)
1099
1147
  output = new Output({
@@ -1112,10 +1160,6 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixe
1112
1160
  const firstFrame = firstFrameAtOrAfter(saveStartMs);
1113
1161
  // The file starts where its first frame starts, so the sound starts there too.
1114
1162
  const audioStartMs = (firstFrame * 1000) / FPS;
1115
- // The newest soundtrack, with every file in it decoded. Right after a reload or an
1116
- // edit, that can take a moment. (After the file picker, which needs the click.)
1117
- infoDiv.innerHTML = "Waiting for the sound…";
1118
- await soundtrack.ready();
1119
1163
  const audioBuffer = soundtrack
1120
1164
  .mix(audioStartMs, Math.min(saveEndMs, toShow.duration))
1121
1165
  .getAudioBuffer();
@@ -1268,7 +1312,10 @@ const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
1268
1312
  * HEVC stores color at half resolution (4:2:0), so both numbers must be even.
1269
1313
  */
1270
1314
  function saveSizeProblem(width, height) {
1271
- if (!(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0)) {
1315
+ if (!(Number.isInteger(width) &&
1316
+ width > 0 &&
1317
+ Number.isInteger(height) &&
1318
+ height > 0)) {
1272
1319
  return "The size must be two whole numbers of pixels.";
1273
1320
  }
1274
1321
  if (width % 2 || height % 2) {
@@ -1291,7 +1338,7 @@ function updateSaveSizeNote() {
1291
1338
  saveSizeNote.style.color = "#555";
1292
1339
  }
1293
1340
  else {
1294
- const stretched = Math.abs((width / height) / (pixelWidth / pixelHeight) - 1) > 0.001;
1341
+ const stretched = Math.abs(width / height / (pixelWidth / pixelHeight) - 1) > 0.001;
1295
1342
  saveSizeNote.textContent = stretched
1296
1343
  ? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
1297
1344
  : `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
@@ -1415,7 +1462,9 @@ async function saveDialogLocalFilesReady() {
1415
1462
  saveLocalFilesRow.hidden = problems.length === 0;
1416
1463
  const needPermission = problems.some((problem) => problem.reason === "permission");
1417
1464
  saveLocalFilesBtn.hidden = !needPermission;
1418
- saveLocalFilesNote.textContent = problems.map((problem) => problem.message).join(" ");
1465
+ saveLocalFilesNote.textContent = problems
1466
+ .map((problem) => problem.message)
1467
+ .join(" ");
1419
1468
  return problems.length === 0;
1420
1469
  }
1421
1470
  saveLocalFilesBtn.addEventListener("click", async () => {
@@ -1844,7 +1893,7 @@ function applyLimits() {
1844
1893
  */
1845
1894
  function updateFromSelect() {
1846
1895
  const info = chapterList[select.selectedIndex];
1847
- rootStartMs = info.start;
1896
+ setRootStartMs(info.start);
1848
1897
  if (keepLimitsCheckbox.checked && limitsShowable) {
1849
1898
  // Only the "Play this one" button changes. Playback carries on.
1850
1899
  applyLimits();
@@ -1890,7 +1939,7 @@ playRootBtn.addEventListener("click", () => {
1890
1939
  */
1891
1940
  function refreshChapters() {
1892
1941
  if (initChapters()) {
1893
- rootStartMs = chapterList[select.selectedIndex].start;
1942
+ setRootStartMs(chapterList[select.selectedIndex].start);
1894
1943
  applyLimits();
1895
1944
  // The range clamped itself to the new bounds; show the real position again. The
1896
1945
  // number input stays the source of truth, so a playhead past a shortened end is left
@@ -1945,8 +1994,11 @@ transcriptView = new TranscriptView({
1945
1994
  const status = transcriptStatus(source);
1946
1995
  if (!status)
1947
1996
  return undefined;
1948
- return status.kind === "ready" ? status.transcript : (statusText(status) ?? "");
1997
+ return status.kind === "ready"
1998
+ ? status.transcript
1999
+ : (statusText(status) ?? "");
1949
2000
  },
2001
+ problem: (clip) => soundFileProblem(clip),
1950
2002
  seek: (rootMs) => timelineDisplay.onSeek?.(rootMs),
1951
2003
  selectClip: (clip) => timelineDisplay.onBlockClick?.(clip),
1952
2004
  selectedClip: () => selectedSoundClip,
@@ -2047,6 +2099,35 @@ function _onClipValueChanged() {
2047
2099
  // MARK: Sound clips
2048
2100
  /** Shortest a sound clip can be trimmed to by dragging, in ms. */
2049
2101
  const MIN_SOUND_CLIP_MS = 50;
2102
+ /** A sound file was decoded, or failed: update the timeline and the Sound Clips cards. */
2103
+ function soundFileLoaded() {
2104
+ timelineDisplay.redraw();
2105
+ for (const cb of soundClipSyncCallbacks)
2106
+ cb();
2107
+ }
2108
+ /**
2109
+ * Why `clip`'s file can't be played, or undefined if nothing is wrong, as far as we know yet.
2110
+ * Shown on the timeline, on the clip's card and in the 📖 Text view. A missing file must not
2111
+ * look like a file full of silence, even when its old transcript still shows.
2112
+ */
2113
+ function soundFileProblem(clip) {
2114
+ const reason = soundtrack.failure(clip.source);
2115
+ if (reason === undefined)
2116
+ return undefined;
2117
+ return reason instanceof Error ? reason.message : String(reason);
2118
+ }
2119
+ /** Stop a save, if any sound in it can't be read. Otherwise the saved sound would have holes. */
2120
+ function assertSoundFilesLoaded() {
2121
+ const failed = soundtrack.failures();
2122
+ if (failed.length === 0)
2123
+ return;
2124
+ const { url, reason } = failed[0];
2125
+ const why = (reason instanceof Error ? reason.message : String(reason)).replace(/([^.!?)])$/, "$1.");
2126
+ const which = failed.length === 1
2127
+ ? ""
2128
+ : `${failed.length} sound files couldn't be read. The first: `;
2129
+ throw new Error(`${which}Can't play "${url}": ${why} Each clip that uses ${failed.length === 1 ? "it" : "one"} is marked ⚠ on the timeline.`);
2130
+ }
2050
2131
  /** How long the file `clip` plays from is, once it has been decoded. */
2051
2132
  function soundFileMs(clip) {
2052
2133
  const buffer = soundtrack.getDecodedBuffer(clip.source);
@@ -2125,11 +2206,16 @@ function soundClipBlock(clip, ownerStart) {
2125
2206
  return {
2126
2207
  id: clip,
2127
2208
  get label() {
2209
+ const problem = soundFileProblem(clip);
2210
+ if (problem !== undefined)
2211
+ return `⚠ ${problem}`;
2128
2212
  // Notes if there are any, or else the first few words, so clips can be
2129
2213
  // told apart even zoomed out.
2130
2214
  return clip.notes || clipText(clip, 6) || clip.source || "—";
2131
2215
  },
2132
- color: "#3aab3a",
2216
+ get color() {
2217
+ return soundFileProblem(clip) === undefined ? "#3aab3a" : "#9a3412";
2218
+ },
2133
2219
  lane: "sound",
2134
2220
  transcript: () => {
2135
2221
  // Asking is what queues the file for transcribing.
@@ -2331,7 +2417,10 @@ function saveState() {
2331
2417
  sessionStorage.setItem("index", select.selectedIndex.toString());
2332
2418
  sessionStorage.setItem("keepLimits", keepLimitsCheckbox.checked ? "1" : "0");
2333
2419
  sessionStorage.setItem("limitsIndex", chapterList.findIndex((d) => d.selectable === limitsShowable).toString());
2334
- sessionStorage.setItem("timeInSeconds", playPositionSeconds.value);
2420
+ // From the start of the video, however the field shows it. "" for an empty field.
2421
+ const playheadMs = playheadInVideoMs();
2422
+ sessionStorage.setItem("timeInSeconds", isFinite(playheadMs) ? (playheadMs / 1000).toString() : "");
2423
+ sessionStorage.setItem("playPositionLocal", playPositionLocal.checked ? "1" : "0");
2335
2424
  sessionStorage.setItem("state", querySelector('input[name="onSectionEnd"]:checked', HTMLInputElement).value);
2336
2425
  sessionStorage.setItem("wasPlaying", playCheckBox.checked ? "1" : "0");
2337
2426
  sessionStorage.setItem("zoomSelect", zoomSelect.value);
@@ -2553,7 +2642,9 @@ const jsonSync = new SyncedFile({
2553
2642
  if (enabled) {
2554
2643
  // Only one file per video is synced (and so "active") at a time.
2555
2644
  for (const r of getAllReq.result) {
2556
- if (r.videoKey === toShowKey && r.filename !== filename && r.isActive)
2645
+ if (r.videoKey === toShowKey &&
2646
+ r.filename !== filename &&
2647
+ r.isActive)
2557
2648
  store.put({ ...r, isActive: false, syncEnabled: false });
2558
2649
  }
2559
2650
  }
@@ -2774,7 +2865,8 @@ function buildDiffText() {
2774
2865
  out.push(`${indent}${varName}.setDuration(${comp.duration});`);
2775
2866
  }
2776
2867
  if ((comp.soundClips?.length || def.soundClips?.length) &&
2777
- JSON.stringify(comp.soundClips ?? []) !== JSON.stringify(def.soundClips ?? [])) {
2868
+ JSON.stringify(comp.soundClips ?? []) !==
2869
+ JSON.stringify(def.soundClips ?? [])) {
2778
2870
  out.push(`${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`);
2779
2871
  }
2780
2872
  out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
@@ -2906,7 +2998,10 @@ function buildDiffText() {
2906
2998
  diffReplaceable(d.components ?? [], comp, childPath);
2907
2999
  }
2908
3000
  else {
2909
- printPathIfNeeded([...path, d.userEditableDescription ?? d.registryKey]);
3001
+ printPathIfNeeded([
3002
+ ...path,
3003
+ d.userEditableDescription ?? d.registryKey,
3004
+ ]);
2910
3005
  lines.push(` [deleted]`);
2911
3006
  }
2912
3007
  }
@@ -3692,7 +3787,7 @@ function buildScheduleSection(info, selectable) {
3692
3787
  markDirty();
3693
3788
  }
3694
3789
  function currentTimeMs() {
3695
- return playPositionSeconds.valueAsNumber * 1000;
3790
+ return playheadInVideoMs();
3696
3791
  }
3697
3792
  /**
3698
3793
  * Where the component that owns this schedule starts, measured from the start of the Visual
@@ -3988,8 +4083,10 @@ function buildScheduleSection(info, selectable) {
3988
4083
  else {
3989
4084
  const none = document.createElement("span");
3990
4085
  none.textContent = "—";
3991
- none.title = "The last keyframe has no duration: nothing comes after it.";
3992
- none.style.cssText = "display:inline-block;width:6em;text-align:center;color:#888";
4086
+ none.title =
4087
+ "The last keyframe has no duration: nothing comes after it.";
4088
+ none.style.cssText =
4089
+ "display:inline-block;width:6em;text-align:center;color:#888";
3993
4090
  cell.append(none);
3994
4091
  }
3995
4092
  const atLabel = document.createElement("span");
@@ -4866,12 +4963,14 @@ function buildSoundClipSection(selectable) {
4866
4963
  const header = document.createElement("div");
4867
4964
  header.style.cssText =
4868
4965
  "display:flex;align-items:center;gap:0.4em;margin-bottom:0.3em;font-size:0.85em;color:#555";
4869
- header.textContent = "Times are in ms, measured from the start of this component.";
4870
- const playheadInOwner = () => tidyMs(playPositionSeconds.valueAsNumber * 1000 - selfStartMs);
4966
+ header.textContent =
4967
+ "Times are in ms, measured from the start of this component.";
4968
+ const playheadInOwner = () => tidyMs(playheadInVideoMs() - selfStartMs);
4871
4969
  const addBtn = document.createElement("button");
4872
4970
  addBtn.type = "button";
4873
4971
  addBtn.textContent = "+ Add";
4874
- addBtn.title = "Add an empty sound clip at the playhead. Then fill in its source.";
4972
+ addBtn.title =
4973
+ "Add an empty sound clip at the playhead. Then fill in its source.";
4875
4974
  addBtn.style.marginLeft = "auto";
4876
4975
  addBtn.addEventListener("click", () => {
4877
4976
  const clip = { source: "", startMsIntoScene: playheadInOwner() };
@@ -5063,6 +5162,17 @@ function buildSoundClipSection(selectable) {
5063
5162
  _onClipValueChanged();
5064
5163
  });
5065
5164
  row2.append(srcLabel, sourceInput);
5165
+ // Why the file can't be played, if it can't.
5166
+ const problemLine = document.createElement("div");
5167
+ problemLine.style.cssText =
5168
+ "margin-top:0.2em;font-size:0.85em;color:#b00020";
5169
+ const showProblem = () => {
5170
+ const problem = soundFileProblem(clip);
5171
+ problemLine.hidden = problem === undefined;
5172
+ problemLine.textContent = `⚠ ${problem}`;
5173
+ };
5174
+ showProblem();
5175
+ soundClipSyncCallbacks.push(showProblem);
5066
5176
  // Row 3: numeric time fields
5067
5177
  const row3 = document.createElement("div");
5068
5178
  row3.style.cssText =
@@ -5113,7 +5223,8 @@ function buildSoundClipSection(selectable) {
5113
5223
  row4.style.cssText =
5114
5224
  "display:flex;gap:0.4em;align-items:center;margin-top:0.2em;flex-wrap:wrap;font-size:0.85em";
5115
5225
  const ownerLabel = document.createElement("label");
5116
- ownerLabel.style.cssText = "display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
5226
+ ownerLabel.style.cssText =
5227
+ "display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
5117
5228
  ownerLabel.textContent = "owner:";
5118
5229
  ownerLabel.title =
5119
5230
  "Which component this sound belongs to. It moves when its owner moves. " +
@@ -5165,7 +5276,7 @@ function buildSoundClipSection(selectable) {
5165
5276
  drawPlaysAt();
5166
5277
  soundClipSyncCallbacks.push(drawPlaysAt);
5167
5278
  row4.append(ownerLabel, playsAt);
5168
- card.append(row1, row2, row3, row4);
5279
+ card.append(row1, row2, problemLine, row3, row4);
5169
5280
  section.append(card);
5170
5281
  if (clip === selectedSoundClip) {
5171
5282
  requestAnimationFrame(() => card.scrollIntoView({ block: "nearest" }));
@@ -5234,7 +5345,8 @@ function updateScheduleEditor(selectable) {
5234
5345
  soundClipSyncCallbacks.length = 0;
5235
5346
  rectAspectLock = null;
5236
5347
  // A highlighted sound clip stays highlighted only while its owner is selected.
5237
- if (selectedSoundClip && !selectable.soundClips?.includes(selectedSoundClip)) {
5348
+ if (selectedSoundClip &&
5349
+ !selectable.soundClips?.includes(selectedSoundClip)) {
5238
5350
  selectedSoundClip = undefined;
5239
5351
  }
5240
5352
  timelineDisplay.setSelectedSoundId(selectedSoundClip);
@@ -5658,8 +5770,7 @@ function rectHandlePositions(r) {
5658
5770
  * level, so local == logical and no conversion is needed).
5659
5771
  */
5660
5772
  function getMarkerRelTf() {
5661
- const component = selectedSlideChild ??
5662
- currentRoot();
5773
+ const component = selectedSlideChild ?? currentRoot();
5663
5774
  if (!component)
5664
5775
  return null;
5665
5776
  const compTf = componentTransforms.get(component);
@@ -6416,6 +6527,11 @@ function applyMarkerDrag(localX, localY, shiftKey = false) {
6416
6527
  // So when you configure the web page, and you hit refresh, or the page automatically
6417
6528
  // refreshes, you don't lose your settings.
6418
6529
  try {
6530
+ if (sessionStorage.getItem("playPositionLocal") === "0") {
6531
+ const playheadMs = playheadInVideoMs();
6532
+ playPositionLocal.checked = false;
6533
+ loadPlayPositionSeconds(playheadMs);
6534
+ }
6419
6535
  const index = sessionStorage.getItem("index");
6420
6536
  const timeInSeconds = sessionStorage.getItem("timeInSeconds");
6421
6537
  const state = sessionStorage.getItem("state");
@@ -6669,6 +6785,13 @@ getById("recordJustSound", HTMLButtonElement).addEventListener("click", async ()
6669
6785
  const before = infoDiv.innerHTML;
6670
6786
  infoDiv.innerHTML = "Waiting for the sound…";
6671
6787
  await soundtrack.ready();
6788
+ try {
6789
+ assertSoundFilesLoaded();
6790
+ }
6791
+ catch (error) {
6792
+ infoDiv.innerHTML = `<strong style="color:red">Not saved:</strong> ${escapeHtml(String(error instanceof Error ? error.message : error))}`;
6793
+ return;
6794
+ }
6672
6795
  infoDiv.innerHTML = before;
6673
6796
  downloadBlob("sound_file.wav", soundtrack.mix(0, toShow.duration).toBlob());
6674
6797
  });