canvas-recorder-lib 0.5.0 → 0.7.0
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/BREAKING-CHANGES.md +24 -0
- package/README.md +131 -25
- package/dev/audio-builder.ts +69 -161
- package/dev/canvas-recorder.css +59 -0
- package/dev/canvas-recorder.ts +1006 -212
- package/dev/delay-files.ts +1 -1
- package/dev/font-utils.ts +8 -1
- package/dev/format-editor.ts +734 -0
- package/dev/format-string.ts +110 -0
- package/dev/local-file-row.ts +107 -0
- package/dev/multi-text-dialog.ts +360 -0
- package/dev/multi-text-panel.ts +11 -0
- package/dev/player-body.ts +94 -6
- package/dev/rect-snap.ts +9 -9
- package/dev/slide-panel.ts +1 -1
- package/dev/sound-clips.ts +3 -2
- package/dev/soundtrack.ts +434 -0
- package/dev/split-dialog.ts +13 -2
- package/dev/static-image-panel.ts +35 -5
- package/dev/timeline-display.ts +50 -5
- package/dev/transcripts.ts +5 -3
- package/dev/video-clip-panel.ts +202 -16
- package/dev/voice/chirp.ts +129 -0
- package/dev/voice/folder.ts +84 -0
- package/dev/voice/voice-panel.ts +513 -0
- package/dev/voice/voice-recorder.ts +603 -0
- package/dist/dev/audio-builder.d.ts +14 -31
- package/dist/dev/audio-builder.d.ts.map +1 -1
- package/dist/dev/audio-builder.js +62 -134
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.css +59 -0
- package/dist/dev/canvas-recorder.js +926 -198
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/delay-files.js +1 -1
- package/dist/dev/delay-files.js.map +1 -1
- package/dist/dev/font-utils.d.ts.map +1 -1
- package/dist/dev/font-utils.js +9 -1
- package/dist/dev/font-utils.js.map +1 -1
- package/dist/dev/format-editor.d.ts +75 -0
- package/dist/dev/format-editor.d.ts.map +1 -0
- package/dist/dev/format-editor.js +642 -0
- package/dist/dev/format-editor.js.map +1 -0
- package/dist/dev/format-string.d.ts +62 -0
- package/dist/dev/format-string.d.ts.map +1 -0
- package/dist/dev/format-string.js +86 -0
- package/dist/dev/format-string.js.map +1 -0
- package/dist/dev/local-file-row.d.ts +22 -0
- package/dist/dev/local-file-row.d.ts.map +1 -0
- package/dist/dev/local-file-row.js +84 -0
- package/dist/dev/local-file-row.js.map +1 -0
- package/dist/dev/multi-text-dialog.d.ts +30 -0
- package/dist/dev/multi-text-dialog.d.ts.map +1 -0
- package/dist/dev/multi-text-dialog.js +297 -0
- package/dist/dev/multi-text-dialog.js.map +1 -0
- package/dist/dev/multi-text-panel.d.ts +2 -0
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +4 -0
- package/dist/dev/multi-text-panel.js.map +1 -1
- package/dist/dev/player-body.d.ts +1 -1
- package/dist/dev/player-body.d.ts.map +1 -1
- package/dist/dev/player-body.js +94 -6
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/rect-snap.d.ts +1 -1
- package/dist/dev/rect-snap.js +7 -7
- package/dist/dev/rect-snap.js.map +1 -1
- package/dist/dev/slide-panel.d.ts +1 -1
- package/dist/dev/slide-panel.d.ts.map +1 -1
- package/dist/dev/slide-panel.js +1 -1
- package/dist/dev/slide-panel.js.map +1 -1
- package/dist/dev/sound-clips.d.ts +3 -2
- package/dist/dev/sound-clips.d.ts.map +1 -1
- package/dist/dev/sound-clips.js +3 -2
- package/dist/dev/sound-clips.js.map +1 -1
- package/dist/dev/soundtrack.d.ts +115 -0
- package/dist/dev/soundtrack.d.ts.map +1 -0
- package/dist/dev/soundtrack.js +369 -0
- package/dist/dev/soundtrack.js.map +1 -0
- package/dist/dev/split-dialog.d.ts.map +1 -1
- package/dist/dev/split-dialog.js +14 -2
- package/dist/dev/split-dialog.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts +2 -0
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/static-image-panel.js +29 -5
- package/dist/dev/static-image-panel.js.map +1 -1
- package/dist/dev/timeline-display.d.ts +23 -2
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +47 -5
- package/dist/dev/timeline-display.js.map +1 -1
- package/dist/dev/transcripts.d.ts.map +1 -1
- package/dist/dev/transcripts.js +5 -3
- package/dist/dev/transcripts.js.map +1 -1
- package/dist/dev/video-clip-panel.d.ts +8 -0
- package/dist/dev/video-clip-panel.d.ts.map +1 -1
- package/dist/dev/video-clip-panel.js +176 -10
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/dev/voice/chirp.d.ts +27 -0
- package/dist/dev/voice/chirp.d.ts.map +1 -0
- package/dist/dev/voice/chirp.js +107 -0
- package/dist/dev/voice/chirp.js.map +1 -0
- package/dist/dev/voice/folder.d.ts +18 -0
- package/dist/dev/voice/folder.d.ts.map +1 -0
- package/dist/dev/voice/folder.js +68 -0
- package/dist/dev/voice/folder.js.map +1 -0
- package/dist/dev/voice/voice-panel.d.ts +44 -0
- package/dist/dev/voice/voice-panel.d.ts.map +1 -0
- package/dist/dev/voice/voice-panel.js +418 -0
- package/dist/dev/voice/voice-panel.js.map +1 -0
- package/dist/dev/voice/voice-recorder.d.ts +141 -0
- package/dist/dev/voice/voice-recorder.d.ts.map +1 -0
- package/dist/dev/voice/voice-recorder.js +506 -0
- package/dist/dev/voice/voice-recorder.js.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/main-control.d.ts +50 -4
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js +94 -12
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/binary-search.js +1 -1
- package/dist/src/binary-search.js.map +1 -1
- package/dist/src/corner-rounder.d.ts +17 -0
- package/dist/src/corner-rounder.d.ts.map +1 -0
- package/dist/src/corner-rounder.js +89 -0
- package/dist/src/corner-rounder.js.map +1 -0
- package/dist/src/cross-fade.d.ts +1 -1
- package/dist/src/cross-fade.d.ts.map +1 -1
- package/dist/src/cross-fade.js +3 -3
- package/dist/src/cross-fade.js.map +1 -1
- package/dist/src/fancy-text.d.ts +116 -0
- package/dist/src/fancy-text.d.ts.map +1 -0
- package/dist/src/fancy-text.js +211 -0
- package/dist/src/fancy-text.js.map +1 -0
- package/dist/src/glib/letters-base.d.ts +1 -1
- package/dist/src/glib/letters-base.d.ts.map +1 -1
- package/dist/src/glib/letters-base.js +4 -3
- package/dist/src/glib/letters-base.js.map +1 -1
- package/dist/src/glib/line-font.d.ts +2 -2
- package/dist/src/glib/line-font.d.ts.map +1 -1
- package/dist/src/glib/line-font.js +2 -2
- package/dist/src/glib/line-font.js.map +1 -1
- package/dist/src/glib/paragraph-layout.d.ts +2 -2
- package/dist/src/glib/paragraph-layout.d.ts.map +1 -1
- package/dist/src/glib/paragraph-layout.js +1 -1
- package/dist/src/glib/paragraph-layout.js.map +1 -1
- package/dist/src/glib/path-shape-splitter.d.ts +1 -1
- package/dist/src/glib/path-shape-splitter.d.ts.map +1 -1
- package/dist/src/glib/path-shape-splitter.js +1 -1
- package/dist/src/glib/path-shape-splitter.js.map +1 -1
- package/dist/src/glib/path-shape.js +2 -2
- package/dist/src/glib/path-shape.js.map +1 -1
- package/dist/src/interpolate.d.ts +2 -2
- package/dist/src/interpolate.d.ts.map +1 -1
- package/dist/src/interpolate.js +1 -1
- package/dist/src/interpolate.js.map +1 -1
- package/dist/src/lattice.d.ts +1 -1
- package/dist/src/lattice.d.ts.map +1 -1
- package/dist/src/local-files.d.ts +129 -0
- package/dist/src/local-files.d.ts.map +1 -0
- package/dist/src/local-files.js +327 -0
- package/dist/src/local-files.js.map +1 -0
- package/dist/src/morph-animation.d.ts +1 -1
- package/dist/src/morph-animation.d.ts.map +1 -1
- package/dist/src/morph-animation.js +2 -2
- package/dist/src/morph-animation.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +17 -4
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/schedule-helper.d.ts +4 -4
- package/dist/src/schedule-helper.d.ts.map +1 -1
- package/dist/src/schedule-helper.js +2 -2
- package/dist/src/schedule-helper.js.map +1 -1
- package/dist/src/showable.d.ts +45 -4
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js +37 -1
- package/dist/src/showable.js.map +1 -1
- package/dist/src/slide-components/arrow.d.ts +4 -4
- package/dist/src/slide-components/arrow.d.ts.map +1 -1
- package/dist/src/slide-components/arrow.js +2 -2
- package/dist/src/slide-components/arrow.js.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.d.ts +3 -3
- package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.js +3 -3
- package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
- package/dist/src/slide-components/duration-agnostic.d.ts +3 -3
- package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
- package/dist/src/slide-components/duration-agnostic.js +1 -1
- package/dist/src/slide-components/duration-agnostic.js.map +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
- package/dist/src/slide-components/fixed-duration.js +1 -1
- package/dist/src/slide-components/fixed-duration.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts +6 -6
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +6 -6
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/frame-counter.d.ts +2 -2
- package/dist/src/slide-components/frame-counter.d.ts.map +1 -1
- package/dist/src/slide-components/frame-counter.js +1 -1
- package/dist/src/slide-components/frame-counter.js.map +1 -1
- package/dist/src/slide-components/function-graph.d.ts +2 -2
- package/dist/src/slide-components/function-graph.d.ts.map +1 -1
- package/dist/src/slide-components/function-graph.js +3 -3
- package/dist/src/slide-components/function-graph.js.map +1 -1
- package/dist/src/slide-components/halftone-shadow.d.ts +4 -4
- package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
- package/dist/src/slide-components/halftone-shadow.js +2 -2
- package/dist/src/slide-components/halftone-shadow.js.map +1 -1
- package/dist/src/slide-components/handwriting-effect.d.ts +5 -5
- package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
- package/dist/src/slide-components/handwriting-effect.js +5 -5
- package/dist/src/slide-components/handwriting-effect.js.map +1 -1
- package/dist/src/slide-components/hold.d.ts +3 -3
- package/dist/src/slide-components/hold.d.ts.map +1 -1
- package/dist/src/slide-components/hold.js +3 -3
- package/dist/src/slide-components/hold.js.map +1 -1
- package/dist/src/slide-components/image.d.ts +3 -3
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +3 -3
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts +3 -3
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js +2 -2
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/in-series.d.ts +4 -4
- package/dist/src/slide-components/in-series.d.ts.map +1 -1
- package/dist/src/slide-components/in-series.js +5 -1
- package/dist/src/slide-components/in-series.js.map +1 -1
- package/dist/src/slide-components/live-duration.d.ts +1 -1
- package/dist/src/slide-components/live-duration.d.ts.map +1 -1
- package/dist/src/slide-components/live-duration.js +1 -1
- package/dist/src/slide-components/live-duration.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts +76 -15
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +170 -25
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/rectangle.d.ts +3 -3
- package/dist/src/slide-components/rectangle.d.ts.map +1 -1
- package/dist/src/slide-components/rectangle.js +1 -1
- package/dist/src/slide-components/rectangle.js.map +1 -1
- package/dist/src/slide-components/registry.d.ts +1 -1
- package/dist/src/slide-components/registry.d.ts.map +1 -1
- package/dist/src/slide-components/registry.js +18 -18
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/serialize.d.ts +1 -1
- package/dist/src/slide-components/serialize.d.ts.map +1 -1
- package/dist/src/slide-components/serialize.js +2 -2
- package/dist/src/slide-components/serialize.js.map +1 -1
- package/dist/src/slide-components/show-error.js +2 -2
- package/dist/src/slide-components/show-error.js.map +1 -1
- package/dist/src/slide-components/simple-text.d.ts +4 -4
- package/dist/src/slide-components/simple-text.d.ts.map +1 -1
- package/dist/src/slide-components/simple-text.js +4 -4
- package/dist/src/slide-components/simple-text.js.map +1 -1
- package/dist/src/slide-components/slide-component.d.ts +5 -5
- package/dist/src/slide-components/slide-component.d.ts.map +1 -1
- package/dist/src/slide-components/slide-component.js +4 -4
- package/dist/src/slide-components/slide-component.js.map +1 -1
- package/dist/src/slide-components/slide-left.d.ts +3 -3
- package/dist/src/slide-components/slide-left.d.ts.map +1 -1
- package/dist/src/slide-components/slide-left.js +3 -3
- package/dist/src/slide-components/slide-left.js.map +1 -1
- package/dist/src/slide-components/split-video-clip.d.ts +2 -2
- package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/split-video-clip.js +3 -3
- package/dist/src/slide-components/split-video-clip.js.map +1 -1
- package/dist/src/slide-components/text-effect.d.ts +2 -2
- package/dist/src/slide-components/text-effect.d.ts.map +1 -1
- package/dist/src/slide-components/traditional-text.d.ts +4 -4
- package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
- package/dist/src/slide-components/traditional-text.js +3 -3
- package/dist/src/slide-components/traditional-text.js.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts +17 -5
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +52 -11
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/dist/src/slide-components/video-info.d.ts +11 -11
- package/dist/src/slide-components/video-info.d.ts.map +1 -1
- package/dist/src/slide-components/video-info.js +32 -21
- package/dist/src/slide-components/video-info.js.map +1 -1
- package/dist/src/slow-image-sources.d.ts +7 -1
- package/dist/src/slow-image-sources.d.ts.map +1 -1
- package/dist/src/slow-image-sources.js +36 -5
- package/dist/src/slow-image-sources.js.map +1 -1
- package/dist/src/snapshot.d.ts +2 -2
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +31 -15
- package/dist/src/snapshot.js.map +1 -1
- package/dist/src/stroke-colors.d.ts +1 -1
- package/dist/src/stroke-colors.d.ts.map +1 -1
- package/dist/src/stroke-colors.js +4 -4
- package/dist/src/stroke-colors.js.map +1 -1
- package/dist/src/utility.d.ts +3 -4
- package/dist/src/utility.d.ts.map +1 -1
- package/dist/src/utility.js +4 -4
- package/dist/src/utility.js.map +1 -1
- package/lib/index.ts +3 -0
- package/lib/main-control.ts +119 -12
- package/package.json +7 -5
- package/src/binary-search.ts +2 -2
- package/src/corner-rounder.ts +128 -0
- package/src/cross-fade.ts +3 -3
- package/src/fancy-text.ts +255 -0
- package/src/glib/letters-base.ts +4 -3
- package/src/glib/line-font.ts +2 -2
- package/src/glib/paragraph-layout.ts +2 -2
- package/src/glib/path-shape-splitter.ts +1 -1
- package/src/glib/path-shape.ts +2 -2
- package/src/interpolate.ts +3 -3
- package/src/lattice.ts +1 -1
- package/src/local-files.ts +389 -0
- package/src/morph-animation.ts +2 -2
- package/src/peano-fourier/fourier-shared.ts +17 -4
- package/src/schedule-helper.ts +4 -4
- package/src/showable.ts +63 -4
- package/src/slide-components/arrow.ts +4 -4
- package/src/slide-components/cross-fade-transition.ts +4 -4
- package/src/slide-components/duration-agnostic.ts +3 -3
- package/src/slide-components/fixed-duration.ts +1 -1
- package/src/slide-components/fourier.ts +9 -9
- package/src/slide-components/frame-counter.ts +2 -2
- package/src/slide-components/function-graph.ts +4 -4
- package/src/slide-components/halftone-shadow.ts +4 -4
- package/src/slide-components/handwriting-effect.ts +7 -7
- package/src/slide-components/hold.ts +4 -4
- package/src/slide-components/image.ts +5 -5
- package/src/slide-components/in-parallel.ts +4 -4
- package/src/slide-components/in-series.ts +7 -4
- package/src/slide-components/live-duration.ts +1 -1
- package/src/slide-components/multi-text.ts +195 -30
- package/src/slide-components/rectangle.ts +3 -3
- package/src/slide-components/registry.ts +19 -19
- package/src/slide-components/serialize.ts +2 -2
- package/src/slide-components/show-error.ts +2 -2
- package/src/slide-components/simple-text.ts +7 -7
- package/src/slide-components/slide-component.ts +7 -7
- package/src/slide-components/slide-left.ts +4 -4
- package/src/slide-components/split-video-clip.ts +4 -4
- package/src/slide-components/text-effect.ts +2 -2
- package/src/slide-components/traditional-text.ts +5 -5
- package/src/slide-components/video-clip.ts +64 -13
- package/src/slide-components/video-info.ts +33 -21
- package/src/slow-image-sources.ts +38 -6
- package/src/snapshot.ts +34 -19
- package/src/stroke-colors.ts +4 -4
- package/src/utility.ts +5 -5
package/dev/player-body.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Originally generated from canvas-recorder's canvas-recorder.html. This is the master copy now.
|
|
2
2
|
|
|
3
3
|
/** The contents of the player's `<body>`. {@link canvasRecorder.start} puts this in the page. */
|
|
4
4
|
export const playerBodyHtml = `
|
|
@@ -16,6 +16,29 @@ export const playerBodyHtml = `
|
|
|
16
16
|
<option value="2.00">200%</option>
|
|
17
17
|
</select>
|
|
18
18
|
</label>
|
|
19
|
+
<span
|
|
20
|
+
id="videoSizeControls"
|
|
21
|
+
style="white-space: nowrap"
|
|
22
|
+
title="The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video."
|
|
23
|
+
>Size:
|
|
24
|
+
<input type="number" id="videoPixelWidth" min="2" step="2" style="width: 4.5em" />
|
|
25
|
+
×
|
|
26
|
+
<input type="number" id="videoPixelHeight" min="2" step="2" style="width: 4.5em" />
|
|
27
|
+
px,
|
|
28
|
+
<input type="number" id="videoUnitWidth" min="0" step="any" style="width: 3.5em" />
|
|
29
|
+
×
|
|
30
|
+
<input type="number" id="videoUnitHeight" min="0" step="any" style="width: 3.5em" />
|
|
31
|
+
units
|
|
32
|
+
<span id="videoSizeWarning" style="color: #a06000"></span>
|
|
33
|
+
</span>
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
id="localFilesBtn"
|
|
37
|
+
hidden
|
|
38
|
+
title="Some of this video's files are on your computer, and the browser needs your OK before it reads them again."
|
|
39
|
+
>
|
|
40
|
+
🔓 Allow local files
|
|
41
|
+
</button>
|
|
19
42
|
<button type="button" id="loadJsonTestBtn">📂 Import</button>
|
|
20
43
|
<!-- Each status is outside its label: clicking inside a label
|
|
21
44
|
toggles the checkbox, and a status can hold buttons. -->
|
|
@@ -100,7 +123,12 @@ export const playerBodyHtml = `
|
|
|
100
123
|
/>Repeat</label
|
|
101
124
|
>) </span
|
|
102
125
|
>
|
|
103
|
-
<input
|
|
126
|
+
<input
|
|
127
|
+
type="number"
|
|
128
|
+
id="playPositionSeconds"
|
|
129
|
+
value="0"
|
|
130
|
+
title="The play position, in seconds. Option-← and Option-→ step one frame."
|
|
131
|
+
/>
|
|
104
132
|
<input type="range" id="playPositionRange" value="0" step="any" />
|
|
105
133
|
</div>
|
|
106
134
|
</fieldset>
|
|
@@ -163,8 +191,16 @@ export const playerBodyHtml = `
|
|
|
163
191
|
<option value="2">2×</option>
|
|
164
192
|
</select>
|
|
165
193
|
</label>
|
|
194
|
+
<button
|
|
195
|
+
type="button"
|
|
196
|
+
id="recordModeBtn"
|
|
197
|
+
title="Show or hide the voice recorder. It turns the mic on while it's showing."
|
|
198
|
+
>
|
|
199
|
+
🎙 Record mode
|
|
200
|
+
</button>
|
|
166
201
|
</div>
|
|
167
202
|
</fieldset>
|
|
203
|
+
<div id="voicePanelHolder"></div>
|
|
168
204
|
<div
|
|
169
205
|
style="
|
|
170
206
|
border: 0.3em inset rgb(178, 178, 178);
|
|
@@ -177,10 +213,16 @@ export const playerBodyHtml = `
|
|
|
177
213
|
<button id="recordJustSound">Record Just Sound</button>
|
|
178
214
|
<div id="info"><i>status goes here</i>...</div>
|
|
179
215
|
</div>
|
|
180
|
-
<
|
|
181
|
-
Hot keys:
|
|
182
|
-
|
|
183
|
-
|
|
216
|
+
<div style="margin: 1em 0">
|
|
217
|
+
Hot keys:
|
|
218
|
+
<ul style="margin: 0">
|
|
219
|
+
<li>⌥Space to play or pause.</li>
|
|
220
|
+
<li>⌥B to go back 5 seconds and play.</li>
|
|
221
|
+
<li>⌥0 to jump to the start of the current section.</li>
|
|
222
|
+
<li>⌥← and ⌥→ to step one frame back or forward.</li>
|
|
223
|
+
</ul>
|
|
224
|
+
Alt instead of ⌥ on a PC.
|
|
225
|
+
</div>
|
|
184
226
|
<br />
|
|
185
227
|
<h1>Debug Log</h1>
|
|
186
228
|
<button id="debugLogClearBtn" type="button">Clear</button>
|
|
@@ -343,6 +385,44 @@ export const playerBodyHtml = `
|
|
|
343
385
|
/>
|
|
344
386
|
</label>
|
|
345
387
|
</div>
|
|
388
|
+
<div style="margin-bottom: 0.6em">
|
|
389
|
+
<label
|
|
390
|
+
>Size:
|
|
391
|
+
<input
|
|
392
|
+
type="number"
|
|
393
|
+
id="saveWidth"
|
|
394
|
+
min="2"
|
|
395
|
+
step="2"
|
|
396
|
+
style="width: 6em"
|
|
397
|
+
/>
|
|
398
|
+
</label>
|
|
399
|
+
×
|
|
400
|
+
<label
|
|
401
|
+
><input
|
|
402
|
+
type="number"
|
|
403
|
+
id="saveHeight"
|
|
404
|
+
min="2"
|
|
405
|
+
step="2"
|
|
406
|
+
style="width: 6em"
|
|
407
|
+
/>
|
|
408
|
+
px</label
|
|
409
|
+
>
|
|
410
|
+
|
|
411
|
+
<label
|
|
412
|
+
title="Change the other number to match, keeping the video's shape. Uncheck to stretch or squish the picture."
|
|
413
|
+
><input type="checkbox" id="saveKeepAspect" checked /> Keep aspect
|
|
414
|
+
ratio</label
|
|
415
|
+
>
|
|
416
|
+
|
|
417
|
+
<button
|
|
418
|
+
type="button"
|
|
419
|
+
id="saveVideoSizeBtn"
|
|
420
|
+
title="Use the video's own size."
|
|
421
|
+
>
|
|
422
|
+
Video size
|
|
423
|
+
</button>
|
|
424
|
+
<div id="saveSizeNote" style="font-size: 0.85em; min-height: 1.2em"></div>
|
|
425
|
+
</div>
|
|
346
426
|
<table style="margin-bottom: 0.75em; border-collapse: collapse">
|
|
347
427
|
<tr>
|
|
348
428
|
<td>Start:</td>
|
|
@@ -373,6 +453,14 @@ export const playerBodyHtml = `
|
|
|
373
453
|
></td>
|
|
374
454
|
</tr>
|
|
375
455
|
</table>
|
|
456
|
+
<div
|
|
457
|
+
id="saveLocalFilesRow"
|
|
458
|
+
hidden
|
|
459
|
+
style="margin-bottom: 0.6em; color: #a06000"
|
|
460
|
+
>
|
|
461
|
+
<span id="saveLocalFilesNote"></span>
|
|
462
|
+
<button type="button" id="saveLocalFilesBtn">🔓 Allow</button>
|
|
463
|
+
</div>
|
|
376
464
|
<div>
|
|
377
465
|
<button type="button" id="saveOkBtn">OK — Choose File</button>
|
|
378
466
|
|
package/dev/rect-snap.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
canvasHeightUnits,
|
|
4
|
+
canvasWidthUnits,
|
|
5
5
|
} from "../src/slide-components/video-info.ts";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* One button that moves or stretches a rectangle to the canvas.
|
|
9
9
|
*
|
|
10
|
-
* The canvas is taken to be the
|
|
10
|
+
* The canvas is taken to be the whole drawing area (see canvasRecorder.width), which is true
|
|
11
11
|
* unless it sits inside a transformed parent like a Slide.
|
|
12
12
|
*/
|
|
13
13
|
export type RectSnap = {
|
|
@@ -28,12 +28,12 @@ export const ALIGN_HORIZONTALLY: readonly RectSnap[] = [
|
|
|
28
28
|
{
|
|
29
29
|
text: "⇆",
|
|
30
30
|
title: "Center horizontally on the canvas",
|
|
31
|
-
place: (r) => ({ ...r, x: (
|
|
31
|
+
place: (r) => ({ ...r, x: (canvasWidthUnits() - r.width) / 2 }),
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
text: "⇥",
|
|
35
35
|
title: "Move the right edge to the right of the canvas",
|
|
36
|
-
place: (r) => ({ ...r, x:
|
|
36
|
+
place: (r) => ({ ...r, x: canvasWidthUnits() - r.width }),
|
|
37
37
|
},
|
|
38
38
|
];
|
|
39
39
|
|
|
@@ -47,12 +47,12 @@ export const ALIGN_VERTICALLY: readonly RectSnap[] = [
|
|
|
47
47
|
{
|
|
48
48
|
text: "⇵",
|
|
49
49
|
title: "Center vertically on the canvas",
|
|
50
|
-
place: (r) => ({ ...r, y: (
|
|
50
|
+
place: (r) => ({ ...r, y: (canvasHeightUnits() - r.height) / 2 }),
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
text: "⤓",
|
|
54
54
|
title: "Move the bottom edge to the bottom of the canvas",
|
|
55
|
-
place: (r) => ({ ...r, y:
|
|
55
|
+
place: (r) => ({ ...r, y: canvasHeightUnits() - r.height }),
|
|
56
56
|
},
|
|
57
57
|
];
|
|
58
58
|
|
|
@@ -61,12 +61,12 @@ export const STRETCH_TO_CANVAS: readonly RectSnap[] = [
|
|
|
61
61
|
{
|
|
62
62
|
text: "↔",
|
|
63
63
|
title: "Stretch across the full width of the canvas",
|
|
64
|
-
place: (r) => ({ ...r, x: 0, width:
|
|
64
|
+
place: (r) => ({ ...r, x: 0, width: canvasWidthUnits() }),
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
text: "↕",
|
|
68
68
|
title: "Stretch across the full height of the canvas",
|
|
69
|
-
place: (r) => ({ ...r, y: 0, height:
|
|
69
|
+
place: (r) => ({ ...r, y: 0, height: canvasHeightUnits() }),
|
|
70
70
|
},
|
|
71
71
|
];
|
|
72
72
|
|
package/dev/slide-panel.ts
CHANGED
package/dev/sound-clips.ts
CHANGED
|
@@ -26,8 +26,9 @@ function displayName(showable: Showable): string {
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Every Showable under `root` (including `root`) whose `soundClips` is
|
|
29
|
-
* defined, in tree order.
|
|
30
|
-
*
|
|
29
|
+
* defined, in tree order. Any Showable can hold sounds, but these are the
|
|
30
|
+
* ones that have a list, usually because they have, or had, a clip.
|
|
31
|
+
* That keeps the Owner menus short.
|
|
31
32
|
*
|
|
32
33
|
* This is the same walk the audio builder does, so the start times agree with
|
|
33
34
|
* what you hear. A Showable that appears more than once in the tree is listed
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The video's sound, live: every sound clip in the tree, each played by its own
|
|
3
|
+
* `AudioBufferSourceNode`, mixed by the browser.
|
|
4
|
+
*
|
|
5
|
+
* - **Decoded files are kept** for the life of the page, mixed down to mono.
|
|
6
|
+
* An edit never fetches or decodes a file again.
|
|
7
|
+
* - **An edit only touches the clips it changed.** {@link Soundtrack.request} is
|
|
8
|
+
* cheap enough to call on every mouse move: when no clip moved, it does nothing,
|
|
9
|
+
* and otherwise it replaces only the nodes whose clips changed. Everything else
|
|
10
|
+
* keeps playing, sample for sample.
|
|
11
|
+
* - **A file that isn't decoded yet doesn't hold anything up.** Its clips join in
|
|
12
|
+
* when it's ready.
|
|
13
|
+
* - **The saved video gets one mixed buffer,** from {@link Soundtrack.mix}, after
|
|
14
|
+
* {@link Soundtrack.ready}.
|
|
15
|
+
*
|
|
16
|
+
* The clock belongs to the player. It says where the video is with an
|
|
17
|
+
* {@link Anchor}, and this follows.
|
|
18
|
+
*
|
|
19
|
+
* See development-plans/live-sound-mixing.md.
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { debugLog } from "../src/debug-log.ts";
|
|
24
|
+
import { fetchMedia } from "../src/local-files.ts";
|
|
25
|
+
import { Showable } from "../src/showable.ts";
|
|
26
|
+
import { AudioBuilder } from "./audio-builder.ts";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Every file is decoded at this rate, and the saved video's sound uses it too.
|
|
30
|
+
* So do the player's AudioContext and the voice recorder.
|
|
31
|
+
*/
|
|
32
|
+
export const SAMPLE_RATE = 48000;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* How far ahead a change while playing takes effect, in seconds.
|
|
36
|
+
* The old node stops and the new one starts at the same moment, so both requests
|
|
37
|
+
* must reach the audio thread before that moment comes.
|
|
38
|
+
*/
|
|
39
|
+
const SWAP_AHEAD_S = 0.03;
|
|
40
|
+
|
|
41
|
+
/** One sound clip, in the video's time. */
|
|
42
|
+
export type PlacedSoundClip = {
|
|
43
|
+
readonly source: string;
|
|
44
|
+
/** When the clip starts, in ms from the start of the video. Can be negative. */
|
|
45
|
+
readonly startMs: number;
|
|
46
|
+
/** Where in the file to start, in ms. Negative means silence first. */
|
|
47
|
+
readonly trimMs: number;
|
|
48
|
+
/** How much to play. Infinity plays to the end of the file. */
|
|
49
|
+
readonly lengthMs: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Every sound clip in the tree, in the video's time. Read only.
|
|
54
|
+
*
|
|
55
|
+
* A clip with no source yet is left out: a brand new clip, or a URL that's still
|
|
56
|
+
* being typed.
|
|
57
|
+
*/
|
|
58
|
+
export function collectSoundClips(root: Showable): PlacedSoundClip[] {
|
|
59
|
+
const result: PlacedSoundClip[] = [];
|
|
60
|
+
function walk(item: Showable, offset: number) {
|
|
61
|
+
for (const clip of item.soundClips ?? []) {
|
|
62
|
+
if (clip.source === "") continue;
|
|
63
|
+
result.push({
|
|
64
|
+
source: clip.source,
|
|
65
|
+
startMs: offset + clip.startMsIntoScene,
|
|
66
|
+
trimMs: clip.startMsIntoClip ?? 0,
|
|
67
|
+
lengthMs: clip.lengthMs ?? Infinity,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (const { child, start } of item.children ?? []) {
|
|
71
|
+
walk(child, offset + start);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
walk(root, 0);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Where the video is: at `contextTime`, in the audio context's clock, the video
|
|
80
|
+
* is at `mediaMs`, moving at `rate`.
|
|
81
|
+
*/
|
|
82
|
+
export type Anchor = {
|
|
83
|
+
readonly contextTime: number;
|
|
84
|
+
readonly mediaMs: number;
|
|
85
|
+
readonly rate: number;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
type PlayingNode = {
|
|
89
|
+
readonly node: AudioBufferSourceNode;
|
|
90
|
+
/** Which clip this plays. See {@link Soundtrack.#keyOf}. */
|
|
91
|
+
readonly key: string;
|
|
92
|
+
/** The {@link Soundtrack.#anchorVersion} it was scheduled for. */
|
|
93
|
+
readonly anchorVersion: number;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type SoundtrackOptions = {
|
|
97
|
+
/** Where the clips play. An `OfflineAudioContext` works too, for testing. */
|
|
98
|
+
readonly context: BaseAudioContext;
|
|
99
|
+
/** Usually a gain node, for the volume and mute controls. */
|
|
100
|
+
readonly destination: AudioNode;
|
|
101
|
+
/** The whole video. Read on every {@link Soundtrack.request}. */
|
|
102
|
+
readonly root: () => Showable;
|
|
103
|
+
/** A file finished decoding: its waveform and length are known now. */
|
|
104
|
+
readonly onDecoded?: () => void;
|
|
105
|
+
/** A clip names a file that wasn't in the list before. */
|
|
106
|
+
readonly onNewSource?: () => void;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export class Soundtrack {
|
|
110
|
+
readonly #options: SoundtrackOptions;
|
|
111
|
+
|
|
112
|
+
constructor(options: SoundtrackOptions) {
|
|
113
|
+
this.#options = options;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// MARK: Decoded files
|
|
117
|
+
|
|
118
|
+
/** Decodes, and resamples to {@link SAMPLE_RATE}. It never renders anything. */
|
|
119
|
+
readonly #decoder = new OfflineAudioContext({
|
|
120
|
+
length: 1,
|
|
121
|
+
sampleRate: SAMPLE_RATE,
|
|
122
|
+
});
|
|
123
|
+
readonly #decoding = new Map<string, Promise<AudioBuffer>>();
|
|
124
|
+
readonly #decoded = new Map<string, AudioBuffer>();
|
|
125
|
+
/** Files that couldn't be read. Not tried again until {@link forgetFailures}. */
|
|
126
|
+
readonly #failed = new Set<string>();
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The decoded file, mono, or null if it hasn't been decoded yet (or can't be).
|
|
130
|
+
* Its length is the file's length.
|
|
131
|
+
*/
|
|
132
|
+
getDecodedBuffer(url: string): AudioBuffer | null {
|
|
133
|
+
return this.#decoded.get(url) ?? null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Read and decode every file again, e.g. one re-recorded under the same name. */
|
|
137
|
+
forget(): void {
|
|
138
|
+
this.#decoding.clear();
|
|
139
|
+
this.#decoded.clear();
|
|
140
|
+
this.#failed.clear();
|
|
141
|
+
this.#knownSources.clear();
|
|
142
|
+
this.request();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Use `buffer` as the decoded file for `url`, instead of reading the file.
|
|
147
|
+
* For a file this page just wrote, like a voice recording, whose samples are
|
|
148
|
+
* already in memory. It must be mono, at {@link SAMPLE_RATE}, and exactly as
|
|
149
|
+
* long as the file.
|
|
150
|
+
*/
|
|
151
|
+
provide(url: string, buffer: AudioBuffer): void {
|
|
152
|
+
this.#decoding.set(url, Promise.resolve(buffer));
|
|
153
|
+
this.#decoded.set(url, buffer);
|
|
154
|
+
this.#failed.delete(url);
|
|
155
|
+
this.#options.onDecoded?.();
|
|
156
|
+
if (this.#anchor) this.#resync();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Try the files that couldn't be read again, e.g. after 🔓 Allow local files. */
|
|
160
|
+
forgetFailures(): void {
|
|
161
|
+
for (const url of this.#failed) this.#decoding.delete(url);
|
|
162
|
+
this.#failed.clear();
|
|
163
|
+
this.request();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#load(url: string): Promise<AudioBuffer> {
|
|
167
|
+
return this.#decoding.getOrInsertComputed(url, () => {
|
|
168
|
+
const promise = this.#decode(url).then(
|
|
169
|
+
(buffer) => {
|
|
170
|
+
// forget() may have come in the meantime.
|
|
171
|
+
if (this.#decoding.get(url) === promise) {
|
|
172
|
+
this.#decoded.set(url, buffer);
|
|
173
|
+
this.#options.onDecoded?.();
|
|
174
|
+
if (this.#anchor) this.#resync();
|
|
175
|
+
}
|
|
176
|
+
return buffer;
|
|
177
|
+
},
|
|
178
|
+
(reason) => {
|
|
179
|
+
if (this.#decoding.get(url) === promise) this.#failed.add(url);
|
|
180
|
+
debugLog("audio", `Skipped "${url}": ${reason}`);
|
|
181
|
+
throw reason;
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
// ready() looks at failures with allSettled(). This is for everyone else.
|
|
185
|
+
promise.catch(() => {});
|
|
186
|
+
return promise;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async #decode(url: string): Promise<AudioBuffer> {
|
|
191
|
+
const time1 = performance.now();
|
|
192
|
+
const response = await fetchMedia(url);
|
|
193
|
+
const encoded = await response.arrayBuffer();
|
|
194
|
+
const time2 = performance.now();
|
|
195
|
+
// decodeAudioData() takes about ⅜ - ¾ of a second to decode 4 minutes and 18 seconds of audio.
|
|
196
|
+
const decoded = await this.#decoder.decodeAudioData(encoded);
|
|
197
|
+
const time3 = performance.now();
|
|
198
|
+
debugLog(
|
|
199
|
+
"audio",
|
|
200
|
+
`Decoded "${url}": ${(encoded.byteLength / 1024).toFixed(0)} KB, ` +
|
|
201
|
+
`read ${(time2 - time1).toFixed(0)} ms, decode ${(time3 - time2).toFixed(0)} ms`,
|
|
202
|
+
);
|
|
203
|
+
if (decoded.numberOfChannels === 1) return decoded;
|
|
204
|
+
// Average the channels, don't sum them: identical channels (the usual
|
|
205
|
+
// "stereo") come out exactly as they went in, where a sum would double
|
|
206
|
+
// the level and clip.
|
|
207
|
+
const mono = new AudioBuffer({
|
|
208
|
+
numberOfChannels: 1,
|
|
209
|
+
length: decoded.length,
|
|
210
|
+
sampleRate: decoded.sampleRate,
|
|
211
|
+
});
|
|
212
|
+
const out = mono.getChannelData(0);
|
|
213
|
+
for (let channel = 0; channel < decoded.numberOfChannels; channel++) {
|
|
214
|
+
const data = decoded.getChannelData(channel);
|
|
215
|
+
for (let i = 0; i < out.length; i++) out[i] += data[i];
|
|
216
|
+
}
|
|
217
|
+
const scale = 1 / decoded.numberOfChannels;
|
|
218
|
+
for (let i = 0; i < out.length; i++) out[i] *= scale;
|
|
219
|
+
return mono;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// MARK: The clip list
|
|
223
|
+
|
|
224
|
+
#clips: readonly PlacedSoundClip[] = [];
|
|
225
|
+
/** {@link #clips} and the video's length, as JSON: how a request knows nothing changed. */
|
|
226
|
+
#clipsJson = "";
|
|
227
|
+
#requested = false;
|
|
228
|
+
/** Every source a clip has named, so {@link SoundtrackOptions.onNewSource} only fires for new ones. */
|
|
229
|
+
readonly #knownSources = new Set<string>();
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Something may have changed: a clip, a component's timing, the tree.
|
|
233
|
+
*
|
|
234
|
+
* Call it as often as you like, even several times per mouse move. Calls in the
|
|
235
|
+
* same task are combined into one, and that one does almost nothing unless a clip
|
|
236
|
+
* moved. Nothing here allocates anything the size of the video.
|
|
237
|
+
*/
|
|
238
|
+
request(): void {
|
|
239
|
+
if (this.#requested) return;
|
|
240
|
+
this.#requested = true;
|
|
241
|
+
queueMicrotask(() => this.#update());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#update(): void {
|
|
245
|
+
this.#requested = false;
|
|
246
|
+
const root = this.#options.root();
|
|
247
|
+
const clips = collectSoundClips(root);
|
|
248
|
+
const json = JSON.stringify([root.duration, clips]);
|
|
249
|
+
if (json === this.#clipsJson) return;
|
|
250
|
+
this.#clipsJson = json;
|
|
251
|
+
this.#clips = clips;
|
|
252
|
+
let newSource = false;
|
|
253
|
+
for (const { source } of clips) {
|
|
254
|
+
if (!this.#knownSources.has(source)) {
|
|
255
|
+
this.#knownSources.add(source);
|
|
256
|
+
newSource = true;
|
|
257
|
+
}
|
|
258
|
+
void this.#load(source).catch(() => {});
|
|
259
|
+
}
|
|
260
|
+
if (newSource) this.#options.onNewSource?.();
|
|
261
|
+
if (this.#anchor) this.#resync();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Resolves when every file the newest clip list names has been decoded, or has
|
|
266
|
+
* failed. The newest: if the list changes while this waits, it waits for that
|
|
267
|
+
* one too.
|
|
268
|
+
*/
|
|
269
|
+
async ready(): Promise<void> {
|
|
270
|
+
for (;;) {
|
|
271
|
+
if (this.#requested) this.#update();
|
|
272
|
+
const json = this.#clipsJson;
|
|
273
|
+
await Promise.allSettled(this.#clips.map(({ source }) => this.#load(source)));
|
|
274
|
+
if (!this.#requested && json === this.#clipsJson) return;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The soundtrack from `fromMs` to `toMs`, mixed into one mono buffer, for saving.
|
|
280
|
+
* Call {@link ready} first, or clips whose file isn't decoded yet are left out.
|
|
281
|
+
*/
|
|
282
|
+
mix(fromMs: number, toMs: number): AudioBuilder {
|
|
283
|
+
if (this.#requested) this.#update();
|
|
284
|
+
const builder = new AudioBuilder(
|
|
285
|
+
Math.max(0, toMs - fromMs),
|
|
286
|
+
SAMPLE_RATE,
|
|
287
|
+
);
|
|
288
|
+
for (const clip of this.#clips) {
|
|
289
|
+
const buffer = this.#decoded.get(clip.source);
|
|
290
|
+
if (buffer) {
|
|
291
|
+
builder.add(buffer, clip.startMs - fromMs, clip.trimMs, clip.lengthMs);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return builder;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// MARK: Playing
|
|
298
|
+
|
|
299
|
+
/** Undefined when stopped. */
|
|
300
|
+
#anchor: Anchor | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Changes whenever the anchor moves (a seek, a new speed). A node scheduled for an
|
|
303
|
+
* older anchor plays at the wrong times, so it has to be replaced.
|
|
304
|
+
*/
|
|
305
|
+
#anchorVersion = 0;
|
|
306
|
+
#nodes: PlayingNode[] = [];
|
|
307
|
+
|
|
308
|
+
/** Start playing at `anchor`, from scratch. */
|
|
309
|
+
play(anchor: Anchor): void {
|
|
310
|
+
this.stop();
|
|
311
|
+
this.#anchor = anchor;
|
|
312
|
+
this.#anchorVersion++;
|
|
313
|
+
for (const clip of this.#clips) {
|
|
314
|
+
this.#schedule(clip, anchor.mediaMs);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Keep playing, at a new speed. `anchor` must agree with the old one about where
|
|
320
|
+
* the video is now, so nothing jumps.
|
|
321
|
+
*/
|
|
322
|
+
changeRate(anchor: Anchor): void {
|
|
323
|
+
if (!this.#anchor) return;
|
|
324
|
+
// The nodes already playing are right again at once. The ones waiting to start
|
|
325
|
+
// were timed for the old speed, so all of them are replaced, a moment from now.
|
|
326
|
+
for (const { node } of this.#nodes) node.playbackRate.value = anchor.rate;
|
|
327
|
+
this.#anchor = anchor;
|
|
328
|
+
this.#anchorVersion++;
|
|
329
|
+
this.#resync();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Stop at once. */
|
|
333
|
+
stop(): void {
|
|
334
|
+
for (const { node } of this.#nodes) {
|
|
335
|
+
try {
|
|
336
|
+
node.stop();
|
|
337
|
+
} catch {
|
|
338
|
+
// Already stopped.
|
|
339
|
+
}
|
|
340
|
+
node.disconnect();
|
|
341
|
+
}
|
|
342
|
+
this.#nodes = [];
|
|
343
|
+
this.#anchor = undefined;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** The video's time at `contextTime`, by the current anchor. */
|
|
347
|
+
#mediaMsAt(contextTime: number): number {
|
|
348
|
+
const anchor = this.#anchor!;
|
|
349
|
+
return anchor.mediaMs + (contextTime - anchor.contextTime) * anchor.rate * 1000;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Identifies one clip at one place: equal keys play exactly the same sound at the
|
|
354
|
+
* same time, so a node can be kept.
|
|
355
|
+
*/
|
|
356
|
+
#keyOf(clip: PlacedSoundClip): string {
|
|
357
|
+
return JSON.stringify([clip.source, clip.startMs, clip.trimMs, clip.lengthMs]);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Bring the nodes up to date with {@link #clips}, while playing.
|
|
362
|
+
* A node whose clip is unchanged keeps playing. Every other node stops, and its
|
|
363
|
+
* replacement starts, at the same moment, {@link SWAP_AHEAD_S} from now.
|
|
364
|
+
*/
|
|
365
|
+
#resync(): void {
|
|
366
|
+
const swapTime = this.#options.context.currentTime + SWAP_AHEAD_S;
|
|
367
|
+
const fromMs = this.#mediaMsAt(swapTime);
|
|
368
|
+
/** Clips with no node yet, by key. An array, in case two clips are identical. */
|
|
369
|
+
const unplayed = new Map<string, PlacedSoundClip[]>();
|
|
370
|
+
for (const clip of this.#clips) {
|
|
371
|
+
unplayed.getOrInsertComputed(this.#keyOf(clip), () => []).push(clip);
|
|
372
|
+
}
|
|
373
|
+
const kept: PlayingNode[] = [];
|
|
374
|
+
for (const playing of this.#nodes) {
|
|
375
|
+
const waiting = unplayed.get(playing.key);
|
|
376
|
+
if (playing.anchorVersion === this.#anchorVersion && waiting?.length) {
|
|
377
|
+
waiting.pop();
|
|
378
|
+
kept.push(playing);
|
|
379
|
+
} else {
|
|
380
|
+
try {
|
|
381
|
+
playing.node.stop(swapTime);
|
|
382
|
+
} catch {
|
|
383
|
+
// Already stopped.
|
|
384
|
+
}
|
|
385
|
+
playing.node.onended = () => playing.node.disconnect();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
this.#nodes = kept;
|
|
389
|
+
for (const clips of unplayed.values()) {
|
|
390
|
+
for (const clip of clips) this.#schedule(clip, fromMs);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Start a node for the part of `clip` from `fromMs` on, in the video's time, if
|
|
396
|
+
* its file is decoded and there's anything left to play.
|
|
397
|
+
*/
|
|
398
|
+
#schedule(clip: PlacedSoundClip, fromMs: number): void {
|
|
399
|
+
const buffer = this.#decoded.get(clip.source);
|
|
400
|
+
const anchor = this.#anchor;
|
|
401
|
+
if (!buffer || !anchor) return;
|
|
402
|
+
let { startMs, trimMs, lengthMs } = clip;
|
|
403
|
+
if (trimMs < 0) {
|
|
404
|
+
// Nothing to play before the file starts: start later instead.
|
|
405
|
+
startMs -= trimMs;
|
|
406
|
+
lengthMs += trimMs;
|
|
407
|
+
trimMs = 0;
|
|
408
|
+
}
|
|
409
|
+
const endMs = Math.min(
|
|
410
|
+
startMs + lengthMs,
|
|
411
|
+
startMs + buffer.duration * 1000 - trimMs,
|
|
412
|
+
this.#options.root().duration,
|
|
413
|
+
);
|
|
414
|
+
// Nothing before the video starts, either, and nothing already played.
|
|
415
|
+
const beginMs = Math.max(startMs, fromMs, 0);
|
|
416
|
+
if (endMs - beginMs < 0.001) return;
|
|
417
|
+
const node = this.#options.context.createBufferSource();
|
|
418
|
+
node.buffer = buffer; // Shared, not copied.
|
|
419
|
+
node.playbackRate.value = anchor.rate;
|
|
420
|
+
node.connect(this.#options.destination);
|
|
421
|
+
// Only `when` depends on the speed. The offset and the duration are in the
|
|
422
|
+
// file's own time.
|
|
423
|
+
node.start(
|
|
424
|
+
anchor.contextTime + (beginMs - anchor.mediaMs) / 1000 / anchor.rate,
|
|
425
|
+
(trimMs + beginMs - startMs) / 1000,
|
|
426
|
+
(endMs - beginMs) / 1000,
|
|
427
|
+
);
|
|
428
|
+
this.#nodes.push({
|
|
429
|
+
node,
|
|
430
|
+
key: this.#keyOf(clip),
|
|
431
|
+
anchorVersion: this.#anchorVersion,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
package/dev/split-dialog.ts
CHANGED
|
@@ -395,9 +395,17 @@ export function askHowToSplitSound(options: {
|
|
|
395
395
|
// MARK: Behavior
|
|
396
396
|
const inside = (atMs: number) => atMs > 0 && atMs < lengthMs;
|
|
397
397
|
|
|
398
|
-
/**
|
|
398
|
+
/**
|
|
399
|
+
* `atMs`, moved to the nearest quiet moment between words if it's in the middle of one.
|
|
400
|
+
*
|
|
401
|
+
* Anywhere between one word's `cutAfterMs` and the next word's `cutBeforeMs` is already quiet,
|
|
402
|
+
* so a split there stays where it is. Snapping out of a long pause moved a split a whole second.
|
|
403
|
+
*/
|
|
399
404
|
function snapped(atMs: number): number {
|
|
400
405
|
if (!snapInput.checked || !words?.length) return atMs;
|
|
406
|
+
const fileMs = startMsIntoClip + atMs;
|
|
407
|
+
const inWord = words.some((w) => w.cutBeforeMs < fileMs && fileMs < w.cutAfterMs);
|
|
408
|
+
if (!inWord) return atMs;
|
|
401
409
|
let best = atMs;
|
|
402
410
|
let bestDistance = Infinity;
|
|
403
411
|
for (const word of words) {
|
|
@@ -448,8 +456,11 @@ export function askHowToSplitSound(options: {
|
|
|
448
456
|
return;
|
|
449
457
|
}
|
|
450
458
|
const moved = Math.abs(atMs - typed) > 0.05;
|
|
459
|
+
const direction = atMs < typed ? "earlier" : "later";
|
|
451
460
|
whereNote.textContent =
|
|
452
|
-
(moved
|
|
461
|
+
(moved
|
|
462
|
+
? `Snapped to ${Math.round(atMs)} ms, ${Math.round(Math.abs(atMs - typed))} ms ${direction}.`
|
|
463
|
+
: "") + aroundWords(atMs);
|
|
453
464
|
whereNote.style.color = whereNote.textContent.includes("⚠") ? "#a06000" : "#555";
|
|
454
465
|
|
|
455
466
|
const kept = keep();
|