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
|
@@ -7,8 +7,9 @@ import { Lattice } from "../src/lattice.js";
|
|
|
7
7
|
import { interpolateArrow } from "../src/schedule-helper.js";
|
|
8
8
|
import { applyJsonEntry, applyTree, counterparts, fillTreeDefaults, findSerializedNode, isVideoSnapshot, omitComponentDefaults, registryDefault, omitTreeDefaults, serializeComponents, serializeScalars, serializeSchedules, serializeTree, SNAPSHOT_FORMAT_VERSION, } from "../src/snapshot.js";
|
|
9
9
|
import { downloadBlob, philDebug } from "../src/utility.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { getNewDebugLogEntries } from "../src/debug-log.js";
|
|
11
|
+
import { SAMPLE_RATE, Soundtrack } from "./soundtrack.js";
|
|
12
|
+
import { openVoicePanel } from "./voice/voice-panel.js";
|
|
12
13
|
import { openColorPickerDialog } from "./color-picker.js";
|
|
13
14
|
import { setSwatchColor } from "./color-utils.js";
|
|
14
15
|
import { addName, buildEaseSelect, buildNumericInput, buildScalarSection, parseScheduleFromClipboard, scheduleToTypeScript, } from "./schedule-helpers.js";
|
|
@@ -16,6 +17,7 @@ import { buildTraditionalTextPanel, openFontPickerDialog, } from "./font-widgets
|
|
|
16
17
|
import { buildSlideComponentPanel } from "./slide-panel.js";
|
|
17
18
|
import { buildVideoClipPanel } from "./video-clip-panel.js";
|
|
18
19
|
import { buildTextFramePanel } from "./multi-text-panel.js";
|
|
20
|
+
import { openMultiTextDialog } from "./multi-text-dialog.js";
|
|
19
21
|
import { ownerOf, parseSoundClips, rehomeSoundClip, soundOwners, startWithin, tidyMs, } from "./sound-clips.js";
|
|
20
22
|
import { askHowToSplit, askHowToSplitSound } from "./split-dialog.js";
|
|
21
23
|
import { SyncedFile } from "./synced-file.js";
|
|
@@ -25,6 +27,7 @@ import { transcriptFileName, transcriptJson } from "./transcript-export.js";
|
|
|
25
27
|
import { wordFlag } from "./transcript-align.js";
|
|
26
28
|
import { canvasRecorder } from "../lib/main-control.js";
|
|
27
29
|
import { watchServiceWorkerReady } from "./delay-files.js";
|
|
30
|
+
import { checkLocalFiles, localFilesNeedingPermission, localFileUrlsIn, onLocalFilesChange, requestLocalFileAccess, } from "../src/local-files.js";
|
|
28
31
|
import { DurationAgnosticComponent } from "../src/slide-components/duration-agnostic.js";
|
|
29
32
|
import { componentChoices, componentRegistry, } from "../src/slide-components/registry.js";
|
|
30
33
|
import { pickComponent } from "./component-picker.js";
|
|
@@ -189,6 +192,159 @@ viewport.addEventListener("wheel", (e) => {
|
|
|
189
192
|
return;
|
|
190
193
|
applyZoom(currentZoomFactor, panX - e.deltaX, panY - e.deltaY);
|
|
191
194
|
}, { passive: false });
|
|
195
|
+
// MARK: Video size
|
|
196
|
+
/**
|
|
197
|
+
* The four size fields: the saved file's pixels, and the drawing units.
|
|
198
|
+
* See development-plans/configurable-video-size.md.
|
|
199
|
+
*/
|
|
200
|
+
const videoSizeInputs = {
|
|
201
|
+
pixelWidth: getById("videoPixelWidth", HTMLInputElement),
|
|
202
|
+
pixelHeight: getById("videoPixelHeight", HTMLInputElement),
|
|
203
|
+
width: getById("videoUnitWidth", HTMLInputElement),
|
|
204
|
+
height: getById("videoUnitHeight", HTMLInputElement),
|
|
205
|
+
};
|
|
206
|
+
const videoSizeWarning = getById("videoSizeWarning", HTMLSpanElement);
|
|
207
|
+
/**
|
|
208
|
+
* Where the user's size is remembered. One entry per video, shared by every window
|
|
209
|
+
* and session on this origin. localStorage, not IndexedDB: it's synchronous, so a
|
|
210
|
+
* saved size is in place before the first frame, and its `storage` event tells the
|
|
211
|
+
* other windows about a change for free.
|
|
212
|
+
*/
|
|
213
|
+
const videoSizeStorageKey = `canvas-recorder-size|${startRequest.name}`;
|
|
214
|
+
/** The size this video's user saved, if any. */
|
|
215
|
+
function readSavedVideoSize() {
|
|
216
|
+
try {
|
|
217
|
+
const parsed = JSON.parse(localStorage.getItem(videoSizeStorageKey) ?? "null");
|
|
218
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
219
|
+
return undefined;
|
|
220
|
+
const record = parsed;
|
|
221
|
+
const size = {
|
|
222
|
+
pixelWidth: record.pixelWidth,
|
|
223
|
+
pixelHeight: record.pixelHeight,
|
|
224
|
+
width: record.width,
|
|
225
|
+
height: record.height,
|
|
226
|
+
};
|
|
227
|
+
const valid = Object.values(size).every((value) => typeof value === "number" && Number.isFinite(value) && value > 0);
|
|
228
|
+
return valid ? size : undefined;
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/** Use the saved size, unless the program locked it. A bad saved size is ignored. */
|
|
235
|
+
function applySavedVideoSize() {
|
|
236
|
+
if (canvasRecorder.sizeLocked)
|
|
237
|
+
return;
|
|
238
|
+
const saved = readSavedVideoSize();
|
|
239
|
+
if (!saved)
|
|
240
|
+
return;
|
|
241
|
+
try {
|
|
242
|
+
canvasRecorder.size = saved;
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
console.warn("Ignoring the saved video size.", saved, error);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
applySavedVideoSize();
|
|
249
|
+
/** Copy the size into the fields, except one the user is typing in. */
|
|
250
|
+
function showVideoSize(size) {
|
|
251
|
+
for (const [key, input] of Object.entries(videoSizeInputs)) {
|
|
252
|
+
input.readOnly = canvasRecorder.sizeLocked;
|
|
253
|
+
if (document.activeElement !== input) {
|
|
254
|
+
input.value = String(size[key]);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const pixelAspect = size.pixelWidth / size.pixelHeight;
|
|
258
|
+
const unitAspect = size.width / size.height;
|
|
259
|
+
const stretched = Math.abs(pixelAspect / unitAspect - 1) > 0.001;
|
|
260
|
+
videoSizeWarning.textContent = stretched ? "⚠ stretched" : "";
|
|
261
|
+
videoSizeWarning.title = stretched
|
|
262
|
+
? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
|
|
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.";
|
|
267
|
+
}
|
|
268
|
+
showVideoSize(canvasRecorder.size);
|
|
269
|
+
/**
|
|
270
|
+
* The user asked for this size, in the size fields or with a button like the Video File
|
|
271
|
+
* panel's "Make video this size". Use it, and remember it for this video.
|
|
272
|
+
* @returns False if the size is locked, or `size` isn't usable. Nothing changes then.
|
|
273
|
+
*/
|
|
274
|
+
function setVideoSizeFromGui(size) {
|
|
275
|
+
if (canvasRecorder.sizeLocked)
|
|
276
|
+
return false;
|
|
277
|
+
try {
|
|
278
|
+
canvasRecorder.size = size;
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
// E.g. 0.4 pixels, which rounds to 0. Normal while typing.
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
localStorage.setItem(videoSizeStorageKey, JSON.stringify(canvasRecorder.size));
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
// Private browsing, or storage is full. The size still works until the page reloads.
|
|
289
|
+
}
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
for (const [key, input] of Object.entries(videoSizeInputs)) {
|
|
293
|
+
input.addEventListener("input", () => {
|
|
294
|
+
const value = input.valueAsNumber;
|
|
295
|
+
// Empty, 0 or negative is normal while typing. Wait for a usable number.
|
|
296
|
+
if (!(Number.isFinite(value) && value > 0))
|
|
297
|
+
return;
|
|
298
|
+
setVideoSizeFromGui({ ...canvasRecorder.size, [key]: value });
|
|
299
|
+
});
|
|
300
|
+
// Show the value as stored, e.g. rounded to whole pixels, once the user is done typing.
|
|
301
|
+
input.addEventListener("blur", () => showVideoSize(canvasRecorder.size));
|
|
302
|
+
}
|
|
303
|
+
canvasRecorder.onSizeChange((size) => {
|
|
304
|
+
showVideoSize(size);
|
|
305
|
+
if (isRecording)
|
|
306
|
+
return;
|
|
307
|
+
if (zoomSelect.value === "fit") {
|
|
308
|
+
zoomToFit();
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
applyZoom(currentZoomFactor);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
// Another window changed this video's size.
|
|
315
|
+
addEventListener("storage", (event) => {
|
|
316
|
+
if (event.key === videoSizeStorageKey)
|
|
317
|
+
applySavedVideoSize();
|
|
318
|
+
});
|
|
319
|
+
// MARK: Local files
|
|
320
|
+
/**
|
|
321
|
+
* 🔓: shown when some of the video's files are on this computer, and the browser
|
|
322
|
+
* needs a click before it will read them. See src/local-files.ts.
|
|
323
|
+
*/
|
|
324
|
+
const localFilesBtn = getById("localFilesBtn", HTMLButtonElement);
|
|
325
|
+
function updateLocalFilesButton() {
|
|
326
|
+
const names = localFilesNeedingPermission();
|
|
327
|
+
localFilesBtn.hidden = names.length === 0;
|
|
328
|
+
localFilesBtn.textContent =
|
|
329
|
+
names.length === 1 ? "🔓 Allow local file" : `🔓 Allow ${names.length} local files`;
|
|
330
|
+
localFilesBtn.title =
|
|
331
|
+
"The browser needs your OK before it reads these files again:\n" + names.join("\n");
|
|
332
|
+
}
|
|
333
|
+
onLocalFilesChange(updateLocalFilesButton);
|
|
334
|
+
/** Ask about every file that needs it. Then the sounds can load. */
|
|
335
|
+
async function allowLocalFiles() {
|
|
336
|
+
await requestLocalFileAccess();
|
|
337
|
+
// The images and video clips try again by themselves.
|
|
338
|
+
soundtrack.forgetFailures();
|
|
339
|
+
}
|
|
340
|
+
localFilesBtn.addEventListener("click", () => void allowLocalFiles());
|
|
341
|
+
/**
|
|
342
|
+
* Find out, without asking the user anything, whether the video's local files can be read.
|
|
343
|
+
* Any that can't put the 🔓 button on screen.
|
|
344
|
+
*/
|
|
345
|
+
function checkVideosLocalFiles() {
|
|
346
|
+
void checkLocalFiles(localFileUrlsIn(toShow));
|
|
347
|
+
}
|
|
192
348
|
/**
|
|
193
349
|
* @param timeInMs Draw the animation at this time.
|
|
194
350
|
* @param live True for interactive display (schedule markers drawn on top).
|
|
@@ -338,16 +494,46 @@ function loadPlayPositionSeconds(timeInMs) {
|
|
|
338
494
|
function loadPlayPositionRange() {
|
|
339
495
|
playPositionRange.valueAsNumber = playPositionSeconds.valueAsNumber * 1000;
|
|
340
496
|
}
|
|
341
|
-
|
|
497
|
+
// The same rate as the decoded files and the voice recorder, whatever the hardware uses.
|
|
498
|
+
const audioContext = new AudioContext({ sampleRate: SAMPLE_RATE });
|
|
342
499
|
console.log(audioContext);
|
|
343
500
|
const gainNode = audioContext.createGain();
|
|
344
501
|
gainNode.connect(audioContext.destination);
|
|
345
|
-
/**
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
502
|
+
/**
|
|
503
|
+
* Every sound clip in the video, playing live. Ask it for a new soundtrack with
|
|
504
|
+
* `soundtrack.request()`, as often as you like: it does the rate limiting.
|
|
505
|
+
*/
|
|
506
|
+
const soundtrack = new Soundtrack({
|
|
507
|
+
context: audioContext,
|
|
508
|
+
destination: gainNode,
|
|
509
|
+
root: () => toShow,
|
|
510
|
+
// Sound clips on the timeline can now show their waveforms, and the ones
|
|
511
|
+
// that play to the end of their file now know how long that is.
|
|
512
|
+
onDecoded: () => timelineDisplay.redraw(),
|
|
513
|
+
// The new file may be a local one that needs 🔓.
|
|
514
|
+
onNewSource: () => checkVideosLocalFiles(),
|
|
515
|
+
});
|
|
516
|
+
soundtrack.request();
|
|
517
|
+
// The images and videos may be local files too, even with no sound.
|
|
518
|
+
checkVideosLocalFiles();
|
|
519
|
+
/** True between startAudio() and stopAudio(), unless {@link rafFallbackMode}. */
|
|
520
|
+
let audioPlaying = false;
|
|
521
|
+
/**
|
|
522
|
+
* True from ● Record until the voice recording stops. The soundtrack is muted,
|
|
523
|
+
* and the controls that would spoil the recording are disabled.
|
|
524
|
+
* See {@link startVoiceRecording}.
|
|
525
|
+
*/
|
|
526
|
+
let voiceRecording = false;
|
|
527
|
+
/**
|
|
528
|
+
* True while ● Record's chirp plays, before the video starts. Being paused
|
|
529
|
+
* then doesn't stop the recording.
|
|
530
|
+
*/
|
|
531
|
+
let voiceChirping = false;
|
|
532
|
+
/** The voice recorder's controls, while 🎙 Record mode is showing them. */
|
|
533
|
+
let voicePanel;
|
|
534
|
+
/** audioContext.currentTime at the moment startAudio() last anchored the clock. */
|
|
349
535
|
let audioContextStartTime = 0;
|
|
350
|
-
/** Media position (ms) at the moment startAudio() last
|
|
536
|
+
/** Media position (ms) at the moment startAudio() last anchored the clock. */
|
|
351
537
|
let audioMediaStartMs = 0;
|
|
352
538
|
let audioPlaybackRate = 1;
|
|
353
539
|
/**
|
|
@@ -359,7 +545,7 @@ let audioPlaybackRate = 1;
|
|
|
359
545
|
* https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame
|
|
360
546
|
*/
|
|
361
547
|
let rafFallbackMode = false;
|
|
362
|
-
/** True when fallback-mode "playback" is running (mirrors
|
|
548
|
+
/** True when fallback-mode "playback" is running (mirrors {@link audioPlaying}). */
|
|
363
549
|
let rafFallbackPlaying = false;
|
|
364
550
|
/** performance.now() at the moment fallback playback last started. */
|
|
365
551
|
let rafFallbackStartPerf = 0;
|
|
@@ -395,8 +581,6 @@ function startAudio(fromMs) {
|
|
|
395
581
|
rafFallbackPlaying = true;
|
|
396
582
|
return;
|
|
397
583
|
}
|
|
398
|
-
if (!audioReady)
|
|
399
|
-
return;
|
|
400
584
|
if (audioContext.state !== "running") {
|
|
401
585
|
if (!navigator.userActivation.isActive) {
|
|
402
586
|
// No user gesture available (e.g. restoring play state on page load).
|
|
@@ -404,30 +588,36 @@ function startAudio(fromMs) {
|
|
|
404
588
|
enterRafFallback(fromMs, false);
|
|
405
589
|
return;
|
|
406
590
|
}
|
|
407
|
-
// Has a user gesture. resume() is async — the source
|
|
591
|
+
// Has a user gesture. resume() is async — the source nodes below play
|
|
408
592
|
// once the context transitions to running. Do NOT check state synchronously
|
|
409
593
|
// after this call; it will still read "suspended" before the promise resolves.
|
|
410
594
|
audioContext.resume().catch(() => { });
|
|
411
595
|
}
|
|
412
|
-
const source = audioContext.createBufferSource();
|
|
413
|
-
source.buffer = audioBuilder.getAudioBuffer();
|
|
414
|
-
source.playbackRate.value = audioPlaybackRate;
|
|
415
|
-
source.connect(gainNode);
|
|
416
596
|
const contextNow = audioContext.currentTime;
|
|
417
|
-
source.start(contextNow, fromMs / 1000);
|
|
418
|
-
audioSourceNode = source;
|
|
419
597
|
audioContextStartTime = contextNow;
|
|
420
598
|
audioMediaStartMs = fromMs;
|
|
599
|
+
soundtrack.play({
|
|
600
|
+
contextTime: contextNow,
|
|
601
|
+
mediaMs: fromMs,
|
|
602
|
+
rate: audioPlaybackRate,
|
|
603
|
+
});
|
|
604
|
+
audioPlaying = true;
|
|
605
|
+
if (voiceRecording)
|
|
606
|
+
beginVoiceClip(contextNow, fromMs);
|
|
421
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Stop the sound and the clock. Called for every seek too: the animation loop
|
|
610
|
+
* starts again from the play position on its next frame.
|
|
611
|
+
*
|
|
612
|
+
* While recording a voice, this ends the clip, and the next start begins a new one.
|
|
613
|
+
*/
|
|
422
614
|
function stopAudio() {
|
|
423
615
|
rafFallbackPlaying = false;
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
audioSourceNode.disconnect();
|
|
430
|
-
audioSourceNode = null;
|
|
616
|
+
if (audioPlaying) {
|
|
617
|
+
soundtrack.stop();
|
|
618
|
+
audioPlaying = false;
|
|
619
|
+
if (voiceRecording)
|
|
620
|
+
endVoiceClip();
|
|
431
621
|
}
|
|
432
622
|
}
|
|
433
623
|
/**
|
|
@@ -440,16 +630,26 @@ function setPlaybackRate(rate) {
|
|
|
440
630
|
rafFallbackStartMs = currentMs;
|
|
441
631
|
rafFallbackStartPerf = performance.now();
|
|
442
632
|
}
|
|
443
|
-
else if (
|
|
633
|
+
else if (audioPlaying) {
|
|
444
634
|
const currentMs = currentAudioTimeMs();
|
|
445
635
|
audioContextStartTime = audioContext.currentTime;
|
|
446
636
|
audioMediaStartMs = currentMs;
|
|
447
|
-
|
|
637
|
+
soundtrack.changeRate({
|
|
638
|
+
contextTime: audioContextStartTime,
|
|
639
|
+
mediaMs: audioMediaStartMs,
|
|
640
|
+
rate,
|
|
641
|
+
});
|
|
448
642
|
}
|
|
449
643
|
audioPlaybackRate = rate;
|
|
450
644
|
}
|
|
645
|
+
const volumeSlider = getById("volumeAudio", HTMLInputElement);
|
|
646
|
+
const speedSelect = getById("speedAudio", HTMLSelectElement);
|
|
647
|
+
/** The soundtrack's volume: the slider, unless it's muted, or a voice is being recorded. */
|
|
648
|
+
function updateGain() {
|
|
649
|
+
gainNode.gain.value =
|
|
650
|
+
muteCheckbox.checked || voiceRecording ? 0 : volumeSlider.valueAsNumber;
|
|
651
|
+
}
|
|
451
652
|
{
|
|
452
|
-
const volumeSlider = getById("volumeAudio", HTMLInputElement);
|
|
453
653
|
muteCheckbox.addEventListener("input", () => {
|
|
454
654
|
if (!muteCheckbox.checked && rafFallbackMode) {
|
|
455
655
|
// Un-muting is a user gesture — try to exit fallback and resume real audio.
|
|
@@ -462,66 +662,13 @@ function setPlaybackRate(rate) {
|
|
|
462
662
|
startAudio(currentMs);
|
|
463
663
|
}
|
|
464
664
|
}
|
|
465
|
-
|
|
665
|
+
updateGain();
|
|
466
666
|
});
|
|
467
|
-
volumeSlider.addEventListener("input",
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
667
|
+
volumeSlider.addEventListener("input", updateGain);
|
|
668
|
+
speedSelect.addEventListener("change", () => {
|
|
669
|
+
setPlaybackRate(parseFloat(speedSelect.value));
|
|
471
670
|
});
|
|
472
|
-
getById("speedAudio", HTMLSelectElement).addEventListener("change", (e) => {
|
|
473
|
-
setPlaybackRate(parseFloat(e.target.value));
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
let audioBuilder = new AudioBuilder(toShow.duration);
|
|
477
|
-
let reloadGeneration = 0;
|
|
478
|
-
async function initAudio() {
|
|
479
|
-
const myGen = ++reloadGeneration;
|
|
480
|
-
audioReady = false;
|
|
481
|
-
stopAudio();
|
|
482
|
-
const newBuilder = new AudioBuilder(toShow.duration);
|
|
483
|
-
async function doIt(item, offset) {
|
|
484
|
-
if (myGen !== reloadGeneration)
|
|
485
|
-
return false;
|
|
486
|
-
if (item.soundClips) {
|
|
487
|
-
for (const clip of item.soundClips) {
|
|
488
|
-
// A brand new clip has no source yet, and a URL being typed is wrong
|
|
489
|
-
// until it's finished. Either way, skip that one clip, not all audio.
|
|
490
|
-
if (clip.source === "")
|
|
491
|
-
continue;
|
|
492
|
-
try {
|
|
493
|
-
await newBuilder.add(clip.source, offset + clip.startMsIntoScene, clip.startMsIntoClip, clip.lengthMs);
|
|
494
|
-
}
|
|
495
|
-
catch (reason) {
|
|
496
|
-
debugLog("audio", `Skipped "${clip.source}": ${reason}`);
|
|
497
|
-
}
|
|
498
|
-
if (myGen !== reloadGeneration)
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
if (item.children) {
|
|
503
|
-
for (const { child, start } of item.children) {
|
|
504
|
-
if (!(await doIt(child, offset + start)))
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
return true;
|
|
509
|
-
}
|
|
510
|
-
const time1 = performance.now();
|
|
511
|
-
const completed = await doIt(toShow, 0);
|
|
512
|
-
const time2 = performance.now();
|
|
513
|
-
if (!completed) {
|
|
514
|
-
console.log(`Audio init superseded after ${(time2 - time1).toFixed(0)} ms.`);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
audioBuilder = newBuilder;
|
|
518
|
-
audioReady = true;
|
|
519
|
-
console.log(`Audio ready in ${(time2 - time1).toFixed(0)} ms.`);
|
|
520
|
-
// Sound clips on the timeline can now show their waveforms, and the ones
|
|
521
|
-
// that play to the end of their file now know how long that is.
|
|
522
|
-
timelineDisplay.redraw();
|
|
523
671
|
}
|
|
524
|
-
initAudio();
|
|
525
672
|
/**
|
|
526
673
|
* We disable {@link animationLoop} while rendering to a file.
|
|
527
674
|
* We can reenable it when we are done rendering.
|
|
@@ -539,14 +686,18 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs) => {
|
|
|
539
686
|
if (!playCheckBox.checked) {
|
|
540
687
|
// Paused.
|
|
541
688
|
stopAudio();
|
|
689
|
+
// Pausing is how a voice recording stops, once the video has started.
|
|
690
|
+
if (voiceRecording && !voiceChirping)
|
|
691
|
+
stopVoiceRecording();
|
|
542
692
|
playPositionSeconds.disabled = false;
|
|
543
693
|
showFrame(playPositionSeconds.valueAsNumber * 1000, true);
|
|
544
694
|
return;
|
|
545
695
|
}
|
|
546
696
|
// Playing.
|
|
547
697
|
playPositionSeconds.disabled = true;
|
|
548
|
-
if (!
|
|
549
|
-
//
|
|
698
|
+
if (!audioPlaying && !rafFallbackPlaying) {
|
|
699
|
+
// Not running: first play, after pause/seek, or after repeat.
|
|
700
|
+
// Clips whose file isn't decoded yet join in when it is, so nothing waits for them.
|
|
550
701
|
let startMs = playPositionSeconds.valueAsNumber * 1000;
|
|
551
702
|
if (startMs >= sectionEndTime - 0.05) {
|
|
552
703
|
// At the end — jump to the beginning.
|
|
@@ -555,14 +706,20 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs) => {
|
|
|
555
706
|
loadPlayPositionRange();
|
|
556
707
|
}
|
|
557
708
|
startAudio(startMs);
|
|
558
|
-
// If audio isn't built yet (and not in fallback mode), hold the current frame.
|
|
559
|
-
if (!audioSourceNode && !rafFallbackPlaying) {
|
|
560
|
-
showFrame(playPositionSeconds.valueAsNumber * 1000, true);
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
709
|
}
|
|
564
710
|
const timeInMs = currentAudioTimeMs();
|
|
711
|
+
if (voiceRecording) {
|
|
712
|
+
voicePanel?.setPastEnd(timeInMs > sectionEndTime ? timeInMs - sectionEndTime : undefined);
|
|
713
|
+
}
|
|
565
714
|
if (timeInMs >= sectionEndTime - 0.05) {
|
|
715
|
+
if (voiceRecording) {
|
|
716
|
+
// Talking after the end: freeze on the last frame, and keep recording.
|
|
717
|
+
// The clock keeps going, so the clip does too.
|
|
718
|
+
loadPlayPositionSeconds(sectionEndTime);
|
|
719
|
+
loadPlayPositionRange();
|
|
720
|
+
showFrame(sectionEndTime, true);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
566
723
|
// Repeating nothing would restart the audio on every frame.
|
|
567
724
|
if (repeatRadioButton.checked && sectionEndTime > sectionStartTime) {
|
|
568
725
|
// Loop: restart from the beginning of the section.
|
|
@@ -594,11 +751,16 @@ playPositionSeconds.addEventListener("input", () => {
|
|
|
594
751
|
loadPlayPositionRange();
|
|
595
752
|
});
|
|
596
753
|
// Cmd+Z / Ctrl+Z opens the history (undo) dialog when no text field is focused.
|
|
754
|
+
// A contenteditable, like the Multi Text editor, is a text field with its own undo,
|
|
755
|
+
// and an editor that handled the key itself has said so with preventDefault().
|
|
597
756
|
addEventListener("keydown", (event) => {
|
|
598
757
|
if (!(event.metaKey || event.ctrlKey) || event.key !== "z")
|
|
599
758
|
return;
|
|
759
|
+
if (event.defaultPrevented)
|
|
760
|
+
return;
|
|
600
761
|
if (event.target instanceof HTMLInputElement ||
|
|
601
|
-
event.target instanceof HTMLTextAreaElement
|
|
762
|
+
event.target instanceof HTMLTextAreaElement ||
|
|
763
|
+
(event.target instanceof HTMLElement && event.target.isContentEditable))
|
|
602
764
|
return;
|
|
603
765
|
event.preventDefault();
|
|
604
766
|
if (historyDialog.open)
|
|
@@ -645,6 +807,70 @@ getById("back5s", HTMLButtonElement).addEventListener("click", () => {
|
|
|
645
807
|
* for the live/realtime display. Than can vary significantly.
|
|
646
808
|
*/
|
|
647
809
|
const FPS = canvasRecorder.fps;
|
|
810
|
+
// MARK: Frames
|
|
811
|
+
/**
|
|
812
|
+
* Frame *n* covers the times from n / FPS (inclusive) to (n + 1) / FPS (exclusive), and is
|
|
813
|
+
* always drawn at its center, (n + ½) / FPS. That's true for the whole video and for any part
|
|
814
|
+
* of it, so separately saved pieces line up exactly.
|
|
815
|
+
*
|
|
816
|
+
* These measure in frames from the start of the whole video, with the centers at whole numbers.
|
|
817
|
+
* The play position is stored to 0.1 ms (see {@link loadPlayPositionSeconds}), so a time that
|
|
818
|
+
* was meant to be a center is allowed to miss by a little.
|
|
819
|
+
*/
|
|
820
|
+
const FRAME_TOLERANCE = 0.01;
|
|
821
|
+
/** `ms` in frames, shifted so the frame centers are whole numbers. */
|
|
822
|
+
function framePosition(ms) {
|
|
823
|
+
return (ms * FPS) / 1000 - 0.5;
|
|
824
|
+
}
|
|
825
|
+
/** Where frame `n` is drawn, in ms from the start of the whole video. */
|
|
826
|
+
function frameCenterMs(n) {
|
|
827
|
+
return ((n + 0.5) * 1000) / FPS;
|
|
828
|
+
}
|
|
829
|
+
/** The first frame drawn at or after `ms`. */
|
|
830
|
+
function firstFrameAtOrAfter(ms) {
|
|
831
|
+
return Math.ceil(framePosition(ms) - FRAME_TOLERANCE);
|
|
832
|
+
}
|
|
833
|
+
/** How many frames are drawn from `startMs` (inclusive) to `endMs` (exclusive). */
|
|
834
|
+
function framesBetween(startMs, endMs) {
|
|
835
|
+
return Math.max(0, firstFrameAtOrAfter(endMs) - firstFrameAtOrAfter(startMs));
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Move one frame forward (+1) or back (-1), pausing playback.
|
|
839
|
+
*
|
|
840
|
+
* From a frame's center, that's exactly one frame. From anywhere else, it's the nearest
|
|
841
|
+
* center in that direction, so the playhead always ends up on a time that's really rendered.
|
|
842
|
+
* It stays inside the play limits.
|
|
843
|
+
*/
|
|
844
|
+
function stepOneFrame(direction) {
|
|
845
|
+
const position = framePosition(playPositionSeconds.valueAsNumber * 1000);
|
|
846
|
+
let frame = direction > 0
|
|
847
|
+
? Math.floor(position + FRAME_TOLERANCE) + 1
|
|
848
|
+
: Math.ceil(position - FRAME_TOLERANCE) - 1;
|
|
849
|
+
const first = firstFrameAtOrAfter(sectionStartTime);
|
|
850
|
+
const last = firstFrameAtOrAfter(sectionEndTime) - 1;
|
|
851
|
+
frame = Math.max(first, Math.min(last, frame));
|
|
852
|
+
playCheckBox.checked = false;
|
|
853
|
+
stopAudio();
|
|
854
|
+
loadPlayPositionSeconds(frameCenterMs(frame));
|
|
855
|
+
loadPlayPositionRange();
|
|
856
|
+
}
|
|
857
|
+
// Option-← and Option-→: one frame back or forward. Like the other hot keys, these use Option.
|
|
858
|
+
// They work even in a text field, where they would otherwise move the cursor one word.
|
|
859
|
+
// Arrow keys never cause a keypress event, so this has to be keydown.
|
|
860
|
+
addEventListener("keydown", (event) => {
|
|
861
|
+
if (!event.altKey || event.shiftKey || event.metaKey || event.ctrlKey)
|
|
862
|
+
return;
|
|
863
|
+
if (suspendLiveAnimationLoop)
|
|
864
|
+
return; // Recording.
|
|
865
|
+
if (event.code === "ArrowRight") {
|
|
866
|
+
stepOneFrame(1);
|
|
867
|
+
event.preventDefault();
|
|
868
|
+
}
|
|
869
|
+
else if (event.code === "ArrowLeft") {
|
|
870
|
+
stepOneFrame(-1);
|
|
871
|
+
event.preventDefault();
|
|
872
|
+
}
|
|
873
|
+
});
|
|
648
874
|
/**
|
|
649
875
|
* This is the status of the save. It has no purpose during live / realtime operation
|
|
650
876
|
* so it initialize it to blank.
|
|
@@ -660,6 +886,149 @@ const cancelRecordingButton = getById("cancelRecording", HTMLButtonElement);
|
|
|
660
886
|
* Some of these display the right data, but you can't change them.
|
|
661
887
|
*/
|
|
662
888
|
const liveControls = getById("liveControls", HTMLFieldSetElement);
|
|
889
|
+
// MARK: Voice recording
|
|
890
|
+
//
|
|
891
|
+
// 🎙 Record mode shows the voice recorder's panel and turns on the mic. The
|
|
892
|
+
// panel's ● Record plays a chirp, then starts the video, and records until the
|
|
893
|
+
// video pauses. Every time the video starts moving, a new clip starts; every
|
|
894
|
+
// time it stops or jumps, the clip ends. Each clip goes into the Visual
|
|
895
|
+
// Editor's root as a sound clip. See development-plans/voice-recording.md.
|
|
896
|
+
const recordModeButton = getById("recordModeBtn", HTMLButtonElement);
|
|
897
|
+
const voicePanelHolder = getById("voicePanelHolder", HTMLDivElement);
|
|
898
|
+
const recordJustSoundButton = getById("recordJustSound", HTMLButtonElement);
|
|
899
|
+
const sectionEndRadios = document.querySelectorAll('input[name="onSectionEnd"]');
|
|
900
|
+
/** Where the clip being recorded will go. For its block on the timeline. */
|
|
901
|
+
let liveVoiceClip;
|
|
902
|
+
recordModeButton.addEventListener("click", async () => {
|
|
903
|
+
if (voicePanel) {
|
|
904
|
+
await voicePanel.close();
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
recordModeButton.disabled = true;
|
|
908
|
+
// A panel that couldn't open the mic stays up to say why. Replace it.
|
|
909
|
+
voicePanelHolder.replaceChildren();
|
|
910
|
+
try {
|
|
911
|
+
voicePanel = await openVoicePanel({
|
|
912
|
+
parent: voicePanelHolder,
|
|
913
|
+
context: audioContext,
|
|
914
|
+
onRecord: startVoiceRecording,
|
|
915
|
+
onStop: () => {
|
|
916
|
+
// Same as unchecking Play.
|
|
917
|
+
playCheckBox.checked = false;
|
|
918
|
+
stopAudio();
|
|
919
|
+
stopVoiceRecording();
|
|
920
|
+
},
|
|
921
|
+
onClose: () => {
|
|
922
|
+
stopVoiceRecording();
|
|
923
|
+
voicePanel = undefined;
|
|
924
|
+
},
|
|
925
|
+
});
|
|
926
|
+
philDebug.voicePanel = voicePanel;
|
|
927
|
+
}
|
|
928
|
+
catch (error) {
|
|
929
|
+
console.error("Record mode", error);
|
|
930
|
+
}
|
|
931
|
+
finally {
|
|
932
|
+
recordModeButton.disabled = false;
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
/**
|
|
936
|
+
* ● Record: mute the soundtrack, lock the controls that would spoil the
|
|
937
|
+
* recording, play the chirp, then play the video from where it is.
|
|
938
|
+
*/
|
|
939
|
+
async function startVoiceRecording(recorder, folder) {
|
|
940
|
+
if (suspendLiveAnimationLoop) {
|
|
941
|
+
throw new Error("Wait until the video has finished saving.");
|
|
942
|
+
}
|
|
943
|
+
if (rafFallbackMode) {
|
|
944
|
+
// ● Record is a click, so the audio clock can run now. Recording needs it.
|
|
945
|
+
stopAudio();
|
|
946
|
+
rafFallbackMode = false;
|
|
947
|
+
autoplayFallbackMsg.hidden = true;
|
|
948
|
+
}
|
|
949
|
+
voiceRecording = true;
|
|
950
|
+
voiceChirping = true;
|
|
951
|
+
lockControlsForVoice(true);
|
|
952
|
+
voicePanel?.setRecording(true);
|
|
953
|
+
try {
|
|
954
|
+
// Each file is named after the video, like the properties files.
|
|
955
|
+
await recorder.start(folder, toShowKey);
|
|
956
|
+
}
|
|
957
|
+
catch (error) {
|
|
958
|
+
stopVoiceRecording();
|
|
959
|
+
throw error;
|
|
960
|
+
}
|
|
961
|
+
finally {
|
|
962
|
+
voiceChirping = false;
|
|
963
|
+
}
|
|
964
|
+
// × during the chirp.
|
|
965
|
+
if (!voiceRecording)
|
|
966
|
+
return;
|
|
967
|
+
// Start the clock again from where the video is, so the first clip starts
|
|
968
|
+
// with it, whether the video was playing or not.
|
|
969
|
+
stopAudio();
|
|
970
|
+
playCheckBox.checked = true;
|
|
971
|
+
}
|
|
972
|
+
/** The recording stopped: by Pause, ■ Stop, or closing the panel. Safe to call more than once. */
|
|
973
|
+
function stopVoiceRecording() {
|
|
974
|
+
if (!voiceRecording)
|
|
975
|
+
return;
|
|
976
|
+
voiceRecording = false;
|
|
977
|
+
voicePanel?.recorder.stop();
|
|
978
|
+
liveVoiceClip = undefined;
|
|
979
|
+
voicePanel?.setRecording(false);
|
|
980
|
+
lockControlsForVoice(false);
|
|
981
|
+
refreshTimeline();
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* While recording, the soundtrack is muted and plays at 1×, and these controls
|
|
985
|
+
* are disabled. Each keeps its value, for afterward.
|
|
986
|
+
*/
|
|
987
|
+
function lockControlsForVoice(locked) {
|
|
988
|
+
muteCheckbox.disabled = locked;
|
|
989
|
+
speedSelect.disabled = locked;
|
|
990
|
+
for (const radio of sectionEndRadios)
|
|
991
|
+
radio.disabled = locked;
|
|
992
|
+
startRecordingButton.disabled = locked;
|
|
993
|
+
recordJustSoundButton.disabled = locked;
|
|
994
|
+
updateGain();
|
|
995
|
+
setPlaybackRate(locked ? 1 : parseFloat(speedSelect.value));
|
|
996
|
+
}
|
|
997
|
+
/** The video started moving, while recording: start a clip. */
|
|
998
|
+
function beginVoiceClip(contextTime, fromMs) {
|
|
999
|
+
const recorder = voicePanel?.recorder;
|
|
1000
|
+
const owner = currentRoot();
|
|
1001
|
+
if (!recorder?.recording || !owner)
|
|
1002
|
+
return;
|
|
1003
|
+
const live = { owner, startInOwnerMs: fromMs - rootStartMs };
|
|
1004
|
+
liveVoiceClip = live;
|
|
1005
|
+
recorder.beginClip(contextTime).then((recorded) => addVoiceClip(live.owner, live.startInOwnerMs, recorded), (error) => voicePanel?.say(`Couldn't save a recording: ${error}`, true));
|
|
1006
|
+
refreshTimeline();
|
|
1007
|
+
}
|
|
1008
|
+
/** The video stopped or jumped, while recording: end the clip. */
|
|
1009
|
+
function endVoiceClip() {
|
|
1010
|
+
voicePanel?.recorder.endClip(audioContext.currentTime);
|
|
1011
|
+
if (liveVoiceClip) {
|
|
1012
|
+
liveVoiceClip = undefined;
|
|
1013
|
+
refreshTimeline();
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
/** A clip's file is finished. Put it on the timeline. */
|
|
1017
|
+
function addVoiceClip(owner, startInOwnerMs, recorded) {
|
|
1018
|
+
// The samples are in memory already. Don't read the file back.
|
|
1019
|
+
soundtrack.provide(recorded.url, recorded.buffer);
|
|
1020
|
+
(owner.soundClips ??= []).push({
|
|
1021
|
+
source: recorded.url,
|
|
1022
|
+
startMsIntoScene: tidyMs(startInOwnerMs),
|
|
1023
|
+
startMsIntoClip: tidyMs(recorded.trimMs),
|
|
1024
|
+
lengthMs: tidyMs(recorded.lengthMs),
|
|
1025
|
+
});
|
|
1026
|
+
markDirty();
|
|
1027
|
+
soundtrack.request();
|
|
1028
|
+
refreshTimeline();
|
|
1029
|
+
if ((selectedSlideChild ?? currentRoot()) === owner)
|
|
1030
|
+
updateScheduleEditor(owner);
|
|
1031
|
+
}
|
|
663
1032
|
/**
|
|
664
1033
|
* Someone hit the stop button.
|
|
665
1034
|
*/
|
|
@@ -675,20 +1044,29 @@ function escapeHtml(text) {
|
|
|
675
1044
|
.replace(/</g, "<")
|
|
676
1045
|
.replace(/>/g, ">");
|
|
677
1046
|
}
|
|
678
|
-
|
|
1047
|
+
/**
|
|
1048
|
+
* Record the video and save it to a file the user picks.
|
|
1049
|
+
* @param saveStartMs Where to start, in the video's time.
|
|
1050
|
+
* @param saveEndMs Where to stop.
|
|
1051
|
+
* @param pixelWidth The saved file's width. Usually {@link canvasRecorder.pixelWidth}, but the
|
|
1052
|
+
* Save dialog can change it, just for this file. Nothing else sees the change: the picture
|
|
1053
|
+
* is still drawn in canvasRecorder's units, and simply stretched to this size.
|
|
1054
|
+
* @param pixelHeight The saved file's height. See `pixelWidth`.
|
|
1055
|
+
*/
|
|
1056
|
+
async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixelWidth = canvasRecorder.pixelWidth, pixelHeight = canvasRecorder.pixelHeight) {
|
|
679
1057
|
stopAudio();
|
|
680
1058
|
startRecordingButton.disabled = true;
|
|
681
1059
|
liveControls.disabled = true;
|
|
682
1060
|
cancelRecordingButton.disabled = false;
|
|
683
1061
|
canceled = false;
|
|
684
1062
|
suspendLiveAnimationLoop = true;
|
|
685
|
-
// Lock canvas at
|
|
1063
|
+
// Lock the canvas at the output size for the duration of recording.
|
|
686
1064
|
// Disable all size-changing code paths so the encoder sees a constant frame size.
|
|
687
1065
|
isRecording = true;
|
|
688
1066
|
viewportResizeObserver.disconnect();
|
|
689
1067
|
zoomControls.inert = true;
|
|
690
|
-
canvas.width =
|
|
691
|
-
canvas.height =
|
|
1068
|
+
canvas.width = pixelWidth;
|
|
1069
|
+
canvas.height = pixelHeight;
|
|
692
1070
|
canvas.style.width = "";
|
|
693
1071
|
canvas.style.height = "";
|
|
694
1072
|
canvas.style.maxWidth = "100%";
|
|
@@ -710,7 +1088,7 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration) {
|
|
|
710
1088
|
suggestedName: "canvas-recording.mp4",
|
|
711
1089
|
types: [
|
|
712
1090
|
{
|
|
713
|
-
description: "
|
|
1091
|
+
description: "MP4 Video",
|
|
714
1092
|
accept: { "video/mp4": [".mp4"] },
|
|
715
1093
|
},
|
|
716
1094
|
],
|
|
@@ -721,31 +1099,25 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration) {
|
|
|
721
1099
|
format: new Mp4OutputFormat(),
|
|
722
1100
|
target: new StreamTarget(writableStream, { chunked: true }), // Batch writes for speed
|
|
723
1101
|
});
|
|
724
|
-
//
|
|
1102
|
+
// HEVC (H.265): Macs encode it in hardware, fast and well.
|
|
725
1103
|
const videoSource = new CanvasSource(canvas, {
|
|
726
1104
|
codec: "hevc",
|
|
727
|
-
|
|
1105
|
+
// 16 Mbps. This file is the master that YouTube re-encodes, so a higher rate costs only
|
|
1106
|
+
// file size. See "Export bit rate" in development-plans/review-2026-11.md.
|
|
1107
|
+
bitrate: 16_000_000,
|
|
728
1108
|
});
|
|
729
1109
|
output.addVideoTrack(videoSource, { frameRate: FPS });
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
numberOfChannels: fullAudioBuffer.numberOfChannels,
|
|
742
|
-
length: len,
|
|
743
|
-
sampleRate: sr,
|
|
744
|
-
});
|
|
745
|
-
for (let ch = 0; ch < fullAudioBuffer.numberOfChannels; ch++) {
|
|
746
|
-
audioBuffer.copyToChannel(fullAudioBuffer.getChannelData(ch).subarray(s0, s0 + len), ch);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
1110
|
+
// Frames come from the whole video's grid, even for part of it. See firstFrameAtOrAfter().
|
|
1111
|
+
const firstFrame = firstFrameAtOrAfter(saveStartMs);
|
|
1112
|
+
// The file starts where its first frame starts, so the sound starts there too.
|
|
1113
|
+
const audioStartMs = (firstFrame * 1000) / FPS;
|
|
1114
|
+
// The newest soundtrack, with every file in it decoded. Right after a reload or an
|
|
1115
|
+
// edit, that can take a moment. (After the file picker, which needs the click.)
|
|
1116
|
+
infoDiv.innerHTML = "Waiting for the sound…";
|
|
1117
|
+
await soundtrack.ready();
|
|
1118
|
+
const audioBuffer = soundtrack
|
|
1119
|
+
.mix(audioStartMs, Math.min(saveEndMs, toShow.duration))
|
|
1120
|
+
.getAudioBuffer();
|
|
749
1121
|
const audioSource = new AudioBufferSource({
|
|
750
1122
|
codec: "aac",
|
|
751
1123
|
bitrate: QUALITY_HIGH,
|
|
@@ -759,7 +1131,7 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration) {
|
|
|
759
1131
|
let frameNumber = 0;
|
|
760
1132
|
let warnedNoFramePromises = false;
|
|
761
1133
|
while (!canceled) {
|
|
762
|
-
const timeInMs =
|
|
1134
|
+
const timeInMs = frameCenterMs(firstFrame + frameNumber);
|
|
763
1135
|
if (timeInMs >= saveEndMs) {
|
|
764
1136
|
break;
|
|
765
1137
|
}
|
|
@@ -883,6 +1255,83 @@ const saveInfoStart = getById("saveInfoStart", HTMLTableCellElement);
|
|
|
883
1255
|
const saveInfoEnd = getById("saveInfoEnd", HTMLTableCellElement);
|
|
884
1256
|
const saveInfoDuration = getById("saveInfoDuration", HTMLTableCellElement);
|
|
885
1257
|
const saveInfoFrames = getById("saveInfoFrames", HTMLTableCellElement);
|
|
1258
|
+
const saveWidthInput = getById("saveWidth", HTMLInputElement);
|
|
1259
|
+
const saveHeightInput = getById("saveHeight", HTMLInputElement);
|
|
1260
|
+
const saveKeepAspectCheckbox = getById("saveKeepAspect", HTMLInputElement);
|
|
1261
|
+
const saveSizeNote = getById("saveSizeNote", HTMLDivElement);
|
|
1262
|
+
const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
|
|
1263
|
+
// MARK: Save size
|
|
1264
|
+
/**
|
|
1265
|
+
* Why the Save dialog's size can't be used, or undefined if it can.
|
|
1266
|
+
*
|
|
1267
|
+
* HEVC stores color at half resolution (4:2:0), so both numbers must be even.
|
|
1268
|
+
*/
|
|
1269
|
+
function saveSizeProblem(width, height) {
|
|
1270
|
+
if (!(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0)) {
|
|
1271
|
+
return "The size must be two whole numbers of pixels.";
|
|
1272
|
+
}
|
|
1273
|
+
if (width % 2 || height % 2) {
|
|
1274
|
+
return "Both numbers must be even.";
|
|
1275
|
+
}
|
|
1276
|
+
return undefined;
|
|
1277
|
+
}
|
|
1278
|
+
/** Explain the Save dialog's size, and enable OK only when everything is usable. */
|
|
1279
|
+
function updateSaveSizeNote() {
|
|
1280
|
+
const width = saveWidthInput.valueAsNumber;
|
|
1281
|
+
const height = saveHeightInput.valueAsNumber;
|
|
1282
|
+
const { pixelWidth, pixelHeight } = canvasRecorder;
|
|
1283
|
+
const problem = saveSizeProblem(width, height);
|
|
1284
|
+
if (problem) {
|
|
1285
|
+
saveSizeNote.textContent = problem;
|
|
1286
|
+
saveSizeNote.style.color = "red";
|
|
1287
|
+
}
|
|
1288
|
+
else if (width === pixelWidth && height === pixelHeight) {
|
|
1289
|
+
saveSizeNote.textContent = "The video's own size.";
|
|
1290
|
+
saveSizeNote.style.color = "#555";
|
|
1291
|
+
}
|
|
1292
|
+
else {
|
|
1293
|
+
const stretched = Math.abs((width / height) / (pixelWidth / pixelHeight) - 1) > 0.001;
|
|
1294
|
+
saveSizeNote.textContent = stretched
|
|
1295
|
+
? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
|
|
1296
|
+
: `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
|
|
1297
|
+
saveSizeNote.style.color = stretched ? "#a06000" : "#555";
|
|
1298
|
+
}
|
|
1299
|
+
const startMs = (saveStartSecondsInput.valueAsNumber || 0) * 1000;
|
|
1300
|
+
const endMs = (saveEndSecondsInput.valueAsNumber || 0) * 1000;
|
|
1301
|
+
saveOkBtn.disabled = problem !== undefined || endMs <= startMs;
|
|
1302
|
+
}
|
|
1303
|
+
/** Set the Save dialog's size to the video's own. */
|
|
1304
|
+
function resetSaveSize() {
|
|
1305
|
+
saveWidthInput.value = String(canvasRecorder.pixelWidth);
|
|
1306
|
+
saveHeightInput.value = String(canvasRecorder.pixelHeight);
|
|
1307
|
+
updateSaveSizeNote();
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* With Keep aspect ratio checked, typing one number sets the other.
|
|
1311
|
+
* The shape always comes from the video's own size, not the last pair typed, so it can't drift.
|
|
1312
|
+
* The other number is rounded to an even number of pixels.
|
|
1313
|
+
*/
|
|
1314
|
+
function matchSaveAspect(changed) {
|
|
1315
|
+
if (saveKeepAspectCheckbox.checked) {
|
|
1316
|
+
const aspect = canvasRecorder.pixelWidth / canvasRecorder.pixelHeight;
|
|
1317
|
+
const even = (n) => Math.max(2, Math.round(n / 2) * 2);
|
|
1318
|
+
if (changed === "width") {
|
|
1319
|
+
const width = saveWidthInput.valueAsNumber;
|
|
1320
|
+
if (width > 0)
|
|
1321
|
+
saveHeightInput.value = String(even(width / aspect));
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
const height = saveHeightInput.valueAsNumber;
|
|
1325
|
+
if (height > 0)
|
|
1326
|
+
saveWidthInput.value = String(even(height * aspect));
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
updateSaveSizeNote();
|
|
1330
|
+
}
|
|
1331
|
+
saveWidthInput.addEventListener("input", () => matchSaveAspect("width"));
|
|
1332
|
+
saveHeightInput.addEventListener("input", () => matchSaveAspect("height"));
|
|
1333
|
+
saveKeepAspectCheckbox.addEventListener("input", () => matchSaveAspect("width"));
|
|
1334
|
+
getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener("click", resetSaveSize);
|
|
886
1335
|
function formatTimecode(ms) {
|
|
887
1336
|
const totalFrames = Math.round((ms * FPS) / 1000);
|
|
888
1337
|
const frames = totalFrames % FPS;
|
|
@@ -901,8 +1350,9 @@ function updateSaveDialogInfo() {
|
|
|
901
1350
|
saveInfoEnd.textContent = formatTimecode(endMs);
|
|
902
1351
|
saveInfoDuration.textContent = formatTimecode(durationMs);
|
|
903
1352
|
saveInfoDuration.style.color = invalid ? "red" : "";
|
|
904
|
-
saveInfoFrames.textContent =
|
|
1353
|
+
saveInfoFrames.textContent = framesBetween(startMs, endMs).toLocaleString();
|
|
905
1354
|
saveInfoFrames.style.color = invalid ? "red" : "";
|
|
1355
|
+
updateSaveSizeNote();
|
|
906
1356
|
}
|
|
907
1357
|
function setSaveRange(startMs, endMs) {
|
|
908
1358
|
saveStartSecondsInput.value = (startMs / 1000).toString();
|
|
@@ -951,16 +1401,47 @@ saveEndSecondsInput.addEventListener("input", () => {
|
|
|
951
1401
|
updateSaveDialogInfo();
|
|
952
1402
|
});
|
|
953
1403
|
getById("saveDialogCancelBtn", HTMLButtonElement).addEventListener("click", () => saveDialog.close());
|
|
954
|
-
getById("
|
|
1404
|
+
const saveLocalFilesRow = getById("saveLocalFilesRow", HTMLDivElement);
|
|
1405
|
+
const saveLocalFilesNote = getById("saveLocalFilesNote", HTMLSpanElement);
|
|
1406
|
+
const saveLocalFilesBtn = getById("saveLocalFilesBtn", HTMLButtonElement);
|
|
1407
|
+
/**
|
|
1408
|
+
* Check every local file the video uses, before a long recording starts, so it can't stop
|
|
1409
|
+
* halfway to wait for a permission nobody is there to give.
|
|
1410
|
+
* @returns True if they're all ready. Otherwise the Save dialog says what's wrong.
|
|
1411
|
+
*/
|
|
1412
|
+
async function saveDialogLocalFilesReady() {
|
|
1413
|
+
const problems = await checkLocalFiles(localFileUrlsIn(toShow));
|
|
1414
|
+
saveLocalFilesRow.hidden = problems.length === 0;
|
|
1415
|
+
const needPermission = problems.some((problem) => problem.reason === "permission");
|
|
1416
|
+
saveLocalFilesBtn.hidden = !needPermission;
|
|
1417
|
+
saveLocalFilesNote.textContent = problems.map((problem) => problem.message).join(" ");
|
|
1418
|
+
return problems.length === 0;
|
|
1419
|
+
}
|
|
1420
|
+
saveLocalFilesBtn.addEventListener("click", async () => {
|
|
1421
|
+
await allowLocalFiles();
|
|
1422
|
+
await saveDialogLocalFilesReady();
|
|
1423
|
+
});
|
|
1424
|
+
saveOkBtn.addEventListener("click", async () => {
|
|
955
1425
|
const startMs = (saveStartSecondsInput.valueAsNumber || 0) * 1000;
|
|
956
1426
|
const endMs = (saveEndSecondsInput.valueAsNumber || 0) * 1000;
|
|
1427
|
+
const width = saveWidthInput.valueAsNumber;
|
|
1428
|
+
const height = saveHeightInput.valueAsNumber;
|
|
1429
|
+
if (saveSizeProblem(width, height))
|
|
1430
|
+
return;
|
|
1431
|
+
// Quick: no prompts, just IndexedDB. The click still counts for the file picker afterward.
|
|
1432
|
+
if (!(await saveDialogLocalFilesReady()))
|
|
1433
|
+
return;
|
|
957
1434
|
saveDialog.close();
|
|
958
|
-
startRecording(startMs, endMs);
|
|
1435
|
+
startRecording(startMs, endMs, width, height);
|
|
959
1436
|
});
|
|
960
1437
|
startRecordingButton.addEventListener("click", () => {
|
|
961
1438
|
populateSaveChapterSelect();
|
|
1439
|
+
// Always start from the video's own size, not whatever was used last time.
|
|
1440
|
+
resetSaveSize();
|
|
962
1441
|
setSaveRange(0, toShow.duration);
|
|
1442
|
+
saveLocalFilesRow.hidden = true;
|
|
963
1443
|
saveDialog.showModal();
|
|
1444
|
+
void saveDialogLocalFilesReady();
|
|
964
1445
|
});
|
|
965
1446
|
/**
|
|
966
1447
|
* The flat list of every selectable section in the video, in timeline order.
|
|
@@ -1066,7 +1547,7 @@ const visualEditorAPI = {
|
|
|
1066
1547
|
if (!selectable)
|
|
1067
1548
|
return;
|
|
1068
1549
|
if (howMuch === "sound") {
|
|
1069
|
-
|
|
1550
|
+
soundtrack.request();
|
|
1070
1551
|
}
|
|
1071
1552
|
else if (howMuch === "properties") {
|
|
1072
1553
|
updateScheduleEditor(selectedSlideChild ?? selectable);
|
|
@@ -1088,12 +1569,15 @@ const visualEditorAPI = {
|
|
|
1088
1569
|
return playheadInRootMs();
|
|
1089
1570
|
},
|
|
1090
1571
|
getDecodedBuffer(url) {
|
|
1091
|
-
return
|
|
1572
|
+
return soundtrack.getDecodedBuffer(url);
|
|
1092
1573
|
},
|
|
1093
1574
|
};
|
|
1094
1575
|
// MARK: Console API
|
|
1095
1576
|
philDebug.chapterList = chapterList;
|
|
1096
|
-
|
|
1577
|
+
/** Read and decode every sound file again, e.g. one re-recorded under the same name. */
|
|
1578
|
+
philDebug.refreshSounds = () => soundtrack.forget();
|
|
1579
|
+
/** The live soundtrack. See dev/soundtrack.ts. */
|
|
1580
|
+
philDebug.soundtrack = soundtrack;
|
|
1097
1581
|
/**
|
|
1098
1582
|
* Transcribe one file from scratch, skipping the cache, and report how long
|
|
1099
1583
|
* it took. `device` is "webgpu" or "wasm"; leave it out for the normal choice.
|
|
@@ -1234,13 +1718,12 @@ const scheduleEditorRefreshers = [];
|
|
|
1234
1718
|
const schedulesShowingDurations = new WeakSet();
|
|
1235
1719
|
/** The selectable whose `.parent` is currently set to {@link veRootParent}. */
|
|
1236
1720
|
let _veRootSelectable;
|
|
1237
|
-
let _durationAudioTimer;
|
|
1238
1721
|
/**
|
|
1239
1722
|
* Synthetic {@link ShowableParent} that acts as the root of the editable tree.
|
|
1240
1723
|
* When a selectable's `scheduleHasChanged()` chain reaches this object we:
|
|
1241
1724
|
* - refresh all visible duration inputs,
|
|
1242
1725
|
* - kick the auto-save / dirty-status machinery, and
|
|
1243
|
-
* -
|
|
1726
|
+
* - ask for a new soundtrack (which does nothing if no sound clip moved).
|
|
1244
1727
|
*/
|
|
1245
1728
|
const veRootParent = {
|
|
1246
1729
|
scheduleHasChanged() {
|
|
@@ -1249,13 +1732,9 @@ const veRootParent = {
|
|
|
1249
1732
|
for (const cb of scheduleEditorRefreshers)
|
|
1250
1733
|
cb();
|
|
1251
1734
|
markDirty();
|
|
1252
|
-
|
|
1253
|
-
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
1735
|
+
soundtrack.request();
|
|
1254
1736
|
// Redraw the timeline so block positions/sizes update during drags.
|
|
1255
|
-
|
|
1256
|
-
timelineDisplay.setChapterDuration(_veRootSelectable.duration);
|
|
1257
|
-
timelineDisplay.setBlocks(_buildTimelineBlocks(_veRootSelectable));
|
|
1258
|
-
}
|
|
1737
|
+
refreshTimeline();
|
|
1259
1738
|
scheduleChapterRefresh();
|
|
1260
1739
|
},
|
|
1261
1740
|
};
|
|
@@ -1276,12 +1755,8 @@ const toShowParent = {
|
|
|
1276
1755
|
for (const cb of scheduleEditorRefreshers)
|
|
1277
1756
|
cb();
|
|
1278
1757
|
markDirty();
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
if (_veRootSelectable) {
|
|
1282
|
-
timelineDisplay.setChapterDuration(_veRootSelectable.duration);
|
|
1283
|
-
timelineDisplay.setBlocks(_buildTimelineBlocks(_veRootSelectable));
|
|
1284
|
-
}
|
|
1758
|
+
soundtrack.request();
|
|
1759
|
+
refreshTimeline();
|
|
1285
1760
|
scheduleChapterRefresh();
|
|
1286
1761
|
},
|
|
1287
1762
|
};
|
|
@@ -1488,12 +1963,10 @@ transcriptView = new TranscriptView({
|
|
|
1488
1963
|
clips.splice(index, 1, ...pieces);
|
|
1489
1964
|
selectedSoundClip = pieces[0];
|
|
1490
1965
|
markDirty();
|
|
1491
|
-
|
|
1492
|
-
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
1966
|
+
soundtrack.request();
|
|
1493
1967
|
// Show the owner's Sound Clips, with the remaining piece highlighted.
|
|
1494
1968
|
selectInChapter(owner);
|
|
1495
|
-
|
|
1496
|
-
_updateTimeline(_veRootSelectable);
|
|
1969
|
+
refreshTimeline();
|
|
1497
1970
|
},
|
|
1498
1971
|
});
|
|
1499
1972
|
getById("timelineCanvas", HTMLCanvasElement).after(transcriptView.element);
|
|
@@ -1561,12 +2034,11 @@ timelineDisplay.onBlockClick = (id) => {
|
|
|
1561
2034
|
// MARK: Timeline blocks
|
|
1562
2035
|
/**
|
|
1563
2036
|
* A sound clip's numbers changed, from a field or a drag on the timeline.
|
|
1564
|
-
* Save,
|
|
2037
|
+
* Save, update the soundtrack, and bring the fields and the timeline up to date.
|
|
1565
2038
|
*/
|
|
1566
2039
|
function _onClipValueChanged() {
|
|
1567
2040
|
markDirty();
|
|
1568
|
-
|
|
1569
|
-
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
2041
|
+
soundtrack.request();
|
|
1570
2042
|
for (const cb of soundClipSyncCallbacks)
|
|
1571
2043
|
cb();
|
|
1572
2044
|
timelineDisplay.redraw();
|
|
@@ -1576,7 +2048,7 @@ function _onClipValueChanged() {
|
|
|
1576
2048
|
const MIN_SOUND_CLIP_MS = 50;
|
|
1577
2049
|
/** How long the file `clip` plays from is, once it has been decoded. */
|
|
1578
2050
|
function soundFileMs(clip) {
|
|
1579
|
-
const buffer =
|
|
2051
|
+
const buffer = soundtrack.getDecodedBuffer(clip.source);
|
|
1580
2052
|
return buffer ? buffer.duration * 1000 : undefined;
|
|
1581
2053
|
}
|
|
1582
2054
|
/**
|
|
@@ -1674,7 +2146,7 @@ function soundClipBlock(clip, ownerStart) {
|
|
|
1674
2146
|
startMs: start,
|
|
1675
2147
|
durationMs: () => soundClipLengthMs(clip) ?? 0,
|
|
1676
2148
|
waveform: () => {
|
|
1677
|
-
const buffer =
|
|
2149
|
+
const buffer = soundtrack.getDecodedBuffer(clip.source);
|
|
1678
2150
|
return buffer ? { buffer, fromMs: clip.startMsIntoClip ?? 0 } : undefined;
|
|
1679
2151
|
},
|
|
1680
2152
|
onDragBody: (newStartMs) => {
|
|
@@ -1814,10 +2286,38 @@ function _buildTimelineBlocks(selectable) {
|
|
|
1814
2286
|
blocks.push(soundClipBlock(clip, startMs));
|
|
1815
2287
|
}
|
|
1816
2288
|
}
|
|
2289
|
+
// The voice clip being recorded, growing as you talk.
|
|
2290
|
+
const live = liveVoiceClip;
|
|
2291
|
+
const liveOwnerStart = live && startWithin(selectable, live.owner);
|
|
2292
|
+
if (live && liveOwnerStart !== undefined) {
|
|
2293
|
+
blocks.push({
|
|
2294
|
+
id: live,
|
|
2295
|
+
label: "● Recording",
|
|
2296
|
+
color: "#c62828",
|
|
2297
|
+
lane: "sound",
|
|
2298
|
+
startMs: () => liveOwnerStart + live.startInOwnerMs,
|
|
2299
|
+
durationMs: () => voicePanel?.recorder.liveClip()?.lengthMs ?? 0,
|
|
2300
|
+
waveform: () => {
|
|
2301
|
+
const clip = voicePanel?.recorder.liveClip();
|
|
2302
|
+
return clip && { buffer: clip.buffer, fromMs: clip.trimMs };
|
|
2303
|
+
},
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
1817
2306
|
return blocks;
|
|
1818
2307
|
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Redraw the timeline after an edit. It always shows the chapter, the root picked in the
|
|
2310
|
+
* `<select>`. Not {@link _veRootSelectable}: that's whatever the component editor shows, which
|
|
2311
|
+
* can be a child of the chapter. Passing both, one after the other, looked like a new chapter
|
|
2312
|
+
* every time, and reset the timeline's zoom and pan.
|
|
2313
|
+
*/
|
|
2314
|
+
function refreshTimeline() {
|
|
2315
|
+
const chapter = currentRoot();
|
|
2316
|
+
if (chapter)
|
|
2317
|
+
_updateTimeline(chapter);
|
|
2318
|
+
}
|
|
1819
2319
|
function _updateTimeline(selectable) {
|
|
1820
|
-
timelineDisplay.
|
|
2320
|
+
timelineDisplay.setChapter(selectable, selectable.duration);
|
|
1821
2321
|
timelineDisplay.setBlocks(_buildTimelineBlocks(selectable));
|
|
1822
2322
|
timelineDisplay.setSelectedId(selectedSlideChild ?? undefined);
|
|
1823
2323
|
}
|
|
@@ -2189,10 +2689,6 @@ function buildDiffText() {
|
|
|
2189
2689
|
? JSON.stringify(s.keyframes)
|
|
2190
2690
|
: JSON.stringify(s.value);
|
|
2191
2691
|
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Generate TypeScript constructor + .set() lines for a removable component,
|
|
2194
|
-
* omitting any property whose value matches the class default.
|
|
2195
|
-
*/
|
|
2196
2692
|
/** Variable names already used in this diff, so generated code never declares one twice. */
|
|
2197
2693
|
const usedVarNames = new Set();
|
|
2198
2694
|
function uniqueVarName(base) {
|
|
@@ -2204,11 +2700,12 @@ function buildDiffText() {
|
|
|
2204
2700
|
}
|
|
2205
2701
|
/**
|
|
2206
2702
|
* TypeScript that recreates `comp`, a component added in the Visual Editor, and adds it to
|
|
2207
|
-
* `parentExpr
|
|
2703
|
+
* `parentExpr`'s replaceable children, so the Visual Editor can still edit or delete it.
|
|
2704
|
+
* Covers everything the save file stores for such a component: schedules
|
|
2208
2705
|
* and scalars that differ from the class's defaults, the user's name for it, its own
|
|
2209
2706
|
* replaceable children (recursively), its duration, and its sound clips.
|
|
2210
2707
|
*/
|
|
2211
|
-
function generateComponentCode(comp, indent, parentExpr
|
|
2708
|
+
function generateComponentCode(comp, indent, parentExpr) {
|
|
2212
2709
|
const out = [];
|
|
2213
2710
|
const rk = comp.registryKey ?? "unknown";
|
|
2214
2711
|
const regEntry = componentRegistry.get(rk);
|
|
@@ -2279,10 +2776,33 @@ function buildDiffText() {
|
|
|
2279
2776
|
JSON.stringify(comp.soundClips ?? []) !== JSON.stringify(def.soundClips ?? [])) {
|
|
2280
2777
|
out.push(`${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`);
|
|
2281
2778
|
}
|
|
2282
|
-
out.push(`${indent}${parentExpr}.
|
|
2779
|
+
out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
|
|
2283
2780
|
return out;
|
|
2284
2781
|
}
|
|
2285
|
-
|
|
2782
|
+
/** A component's name in the diff: the user's name for it, or its own. */
|
|
2783
|
+
function displayName(comp) {
|
|
2784
|
+
return comp.userEditableDescription ?? comp.description;
|
|
2785
|
+
}
|
|
2786
|
+
/** `names`, with " #1", " #2"… added to any name used more than once. */
|
|
2787
|
+
function numberedNames(names) {
|
|
2788
|
+
const total = new Map();
|
|
2789
|
+
for (const name of names)
|
|
2790
|
+
total.set(name, (total.get(name) ?? 0) + 1);
|
|
2791
|
+
const seen = new Map();
|
|
2792
|
+
return names.map((name) => {
|
|
2793
|
+
if (total.get(name) < 2)
|
|
2794
|
+
return name;
|
|
2795
|
+
const n = (seen.get(name) ?? 0) + 1;
|
|
2796
|
+
seen.set(name, n);
|
|
2797
|
+
return `${name} #${n}`;
|
|
2798
|
+
});
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* The differences in one component's own properties. The same for a fixed child, whose
|
|
2802
|
+
* default is its TypeScript, and for a replaceable child, whose default is its counterpart
|
|
2803
|
+
* in the TypeScript's list.
|
|
2804
|
+
*/
|
|
2805
|
+
function diffProperties(defaultEntry, sel, path) {
|
|
2286
2806
|
const defSchedules = defaultEntry.schedules ?? [];
|
|
2287
2807
|
const curSchedules = sel.schedules?.length
|
|
2288
2808
|
? serializeSchedules(sel.schedules)
|
|
@@ -2339,13 +2859,66 @@ function buildDiffText() {
|
|
|
2339
2859
|
lines.push(`TypeScript: ${JSON.stringify(defClips)}`);
|
|
2340
2860
|
lines.push(`Current: ${JSON.stringify(curClips)}`);
|
|
2341
2861
|
}
|
|
2342
|
-
|
|
2343
|
-
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* The differences between a component's replaceable children and the TypeScript's.
|
|
2865
|
+
*
|
|
2866
|
+
* Children pair up by kind and name, in order, the way fixed children pair up by description.
|
|
2867
|
+
* Then any left over pair up by kind alone, so a child renamed in the Visual Editor is one
|
|
2868
|
+
* child with a new name, not one deleted and one added.
|
|
2869
|
+
*
|
|
2870
|
+
* A pair prints its property changes, the same way a fixed child does. A child with no
|
|
2871
|
+
* counterpart in the TypeScript prints as the TypeScript that makes it. A deleted child, or
|
|
2872
|
+
* an order that deleting and adding wouldn't give, gets one line. No changes, no lines.
|
|
2873
|
+
*/
|
|
2874
|
+
function diffReplaceable(defaults, sel, path) {
|
|
2875
|
+
// Only components with a registry key are saved, so only they can differ.
|
|
2876
|
+
const live = (sel.replaceableComponents?.get() ?? []).filter((comp) => comp.registryKey !== undefined);
|
|
2877
|
+
const key = (registryKey, name) => `${registryKey}\0${name ?? ""}`;
|
|
2878
|
+
const liveFor = counterparts(defaults.map((d) => ({
|
|
2879
|
+
description: key(d.registryKey, d.userEditableDescription),
|
|
2880
|
+
})), live.map((comp) => ({
|
|
2881
|
+
description: key(comp.registryKey, comp.userEditableDescription),
|
|
2882
|
+
comp,
|
|
2883
|
+
}))).map((match) => match?.comp);
|
|
2884
|
+
for (const [index, d] of defaults.entries()) {
|
|
2885
|
+
liveFor[index] ??= live.find((comp) => comp.registryKey === d.registryKey && !liveFor.includes(comp));
|
|
2886
|
+
}
|
|
2887
|
+
const added = live.filter((comp) => !liveFor.includes(comp));
|
|
2888
|
+
const names = new Map(numberedNames(live.map(displayName)).map((name, index) => [
|
|
2889
|
+
live[index],
|
|
2890
|
+
name,
|
|
2891
|
+
]));
|
|
2892
|
+
const expectedOrder = [
|
|
2893
|
+
...liveFor.filter((comp) => comp !== undefined),
|
|
2894
|
+
...added,
|
|
2895
|
+
];
|
|
2896
|
+
if (expectedOrder.some((comp, index) => comp !== live[index])) {
|
|
2344
2897
|
printPathIfNeeded(path);
|
|
2345
|
-
|
|
2346
|
-
|
|
2898
|
+
lines.push(` [new order: ${live.map((comp) => names.get(comp)).join(", ")}]`);
|
|
2899
|
+
}
|
|
2900
|
+
for (const [index, d] of defaults.entries()) {
|
|
2901
|
+
const comp = liveFor[index];
|
|
2902
|
+
if (comp) {
|
|
2903
|
+
const childPath = [...path, names.get(comp)];
|
|
2904
|
+
diffProperties(d, comp, childPath);
|
|
2905
|
+
diffReplaceable(d.components ?? [], comp, childPath);
|
|
2906
|
+
}
|
|
2907
|
+
else {
|
|
2908
|
+
printPathIfNeeded([...path, d.userEditableDescription ?? d.registryKey]);
|
|
2909
|
+
lines.push(` [deleted]`);
|
|
2347
2910
|
}
|
|
2348
2911
|
}
|
|
2912
|
+
const parentExpr = toVarName(path.at(-1) ?? "") || "parent";
|
|
2913
|
+
for (const comp of added) {
|
|
2914
|
+
printPathIfNeeded([...path, names.get(comp)]);
|
|
2915
|
+
lines.push(` [added]`);
|
|
2916
|
+
lines.push(...generateComponentCode(comp, " ", parentExpr));
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
function diffNode(defaultEntry, sel, path) {
|
|
2920
|
+
diffProperties(defaultEntry, sel, path);
|
|
2921
|
+
diffReplaceable(defaultEntry.components ?? [], sel, path);
|
|
2349
2922
|
const liveFixed = getFixedComponents(sel);
|
|
2350
2923
|
const defaultFixed = defaultEntry.fixedComponents ?? [];
|
|
2351
2924
|
const liveFor = counterparts(defaultFixed, liveFixed);
|
|
@@ -2369,10 +2942,12 @@ function buildDiffText() {
|
|
|
2369
2942
|
if (tsDefaultsTree) {
|
|
2370
2943
|
diffNode(tsDefaultsTree, toShow, [toShow.description]);
|
|
2371
2944
|
}
|
|
2372
|
-
if (lines.length ===
|
|
2945
|
+
if (lines.length === 0)
|
|
2373
2946
|
lines.push("(no differences found)");
|
|
2374
2947
|
return lines.join("\n");
|
|
2375
2948
|
}
|
|
2949
|
+
/** The diff file's text, from the console, with or without syncing the file. */
|
|
2950
|
+
philDebug.diffText = () => console.log(buildDiffText());
|
|
2376
2951
|
// MARK: Load-source helpers
|
|
2377
2952
|
/** Logs abandoned or deleted items; replace console.info with persistent storage if needed. */
|
|
2378
2953
|
function sendToRecycleBin(...args) {
|
|
@@ -2555,6 +3130,17 @@ async function initFromDB(unloadBackup) {
|
|
|
2555
3130
|
updateComponentEditor(currentSel);
|
|
2556
3131
|
updateScheduleEditor(currentSel);
|
|
2557
3132
|
}
|
|
3133
|
+
afterStateApplied();
|
|
3134
|
+
}
|
|
3135
|
+
/**
|
|
3136
|
+
* A saved state was just applied to the tree: restored at startup, opened,
|
|
3137
|
+
* or picked in the history. The sound clips in it are new objects, maybe in
|
|
3138
|
+
* new lists, so the timeline's blocks and the soundtrack are out of date.
|
|
3139
|
+
* The editors are rebuilt separately.
|
|
3140
|
+
*/
|
|
3141
|
+
function afterStateApplied() {
|
|
3142
|
+
refreshTimeline();
|
|
3143
|
+
soundtrack.request();
|
|
2558
3144
|
}
|
|
2559
3145
|
/** Saves current schedule state to IndexedDB as a full data entry.
|
|
2560
3146
|
* Pass force=true (💾 Save button) to bypass the ts-defaults-no-auto-save guard. */
|
|
@@ -2643,6 +3229,10 @@ function currentSaveTarget() {
|
|
|
2643
3229
|
return selectable.schedules?.length ? selectable : null;
|
|
2644
3230
|
}
|
|
2645
3231
|
function saveOnUnload() {
|
|
3232
|
+
// Start closing any voice recording's files. They may not finish in time.
|
|
3233
|
+
// TODO: test this, and add the clip being recorded before the save below.
|
|
3234
|
+
// See "Risks" in development-plans/voice-recording.md.
|
|
3235
|
+
voicePanel?.recorder.flush();
|
|
2646
3236
|
// When the history dialog is open the live tree may hold a transient preview from
|
|
2647
3237
|
// _dialogSelectItem. Back up the pre-dialog state instead, so a preview is never
|
|
2648
3238
|
// persisted as if the user had accepted it.
|
|
@@ -2716,6 +3306,7 @@ function _dialogSelectItem(index, target) {
|
|
|
2716
3306
|
activeRootComponentEditor?.resetAll();
|
|
2717
3307
|
updateComponentEditor(target);
|
|
2718
3308
|
updateScheduleEditor(target);
|
|
3309
|
+
afterStateApplied();
|
|
2719
3310
|
// The Abandon/Save buttons are no longer used; only Keep is shown.
|
|
2720
3311
|
historyOkBtn.hidden = false;
|
|
2721
3312
|
historyAbandonBtn.hidden = true;
|
|
@@ -2943,6 +3534,7 @@ async function _applyDialogSelection() {
|
|
|
2943
3534
|
activeRootComponentEditor?.resetAll();
|
|
2944
3535
|
updateComponentEditor(target);
|
|
2945
3536
|
updateScheduleEditor(target);
|
|
3537
|
+
afterStateApplied();
|
|
2946
3538
|
}
|
|
2947
3539
|
historyOkBtn.addEventListener("click", () => {
|
|
2948
3540
|
void _applyDialogSelection();
|
|
@@ -2967,6 +3559,7 @@ historyCancelBtn.addEventListener("click", () => {
|
|
|
2967
3559
|
activeRootComponentEditor?.resetAll();
|
|
2968
3560
|
updateComponentEditor(target);
|
|
2969
3561
|
updateScheduleEditor(target);
|
|
3562
|
+
afterStateApplied();
|
|
2970
3563
|
}
|
|
2971
3564
|
historyDialog.close();
|
|
2972
3565
|
});
|
|
@@ -3104,9 +3697,18 @@ function buildScheduleSection(info, selectable) {
|
|
|
3104
3697
|
function currentTimeMs() {
|
|
3105
3698
|
return playPositionSeconds.valueAsNumber * 1000;
|
|
3106
3699
|
}
|
|
3107
|
-
/**
|
|
3700
|
+
/**
|
|
3701
|
+
* Where the component that owns this schedule starts, measured from the start of the Visual
|
|
3702
|
+
* Editor's root. 0 for anything in a parallel container at the top, which is why measuring
|
|
3703
|
+
* from the root used to look right. A clip in an In Series starts later.
|
|
3704
|
+
*/
|
|
3705
|
+
function ownerStartMs() {
|
|
3706
|
+
const root = currentRoot();
|
|
3707
|
+
return root ? (startWithin(root, selectable) ?? 0) : 0;
|
|
3708
|
+
}
|
|
3709
|
+
/** Time relative to the start of the component that owns this schedule — what keyframe.time values use. */
|
|
3108
3710
|
function localTimeMs() {
|
|
3109
|
-
return currentTimeMs() - rootStartMs;
|
|
3711
|
+
return currentTimeMs() - rootStartMs - ownerStartMs();
|
|
3110
3712
|
}
|
|
3111
3713
|
function addKeyframeAtCurrentTime() {
|
|
3112
3714
|
const t = localTimeMs();
|
|
@@ -3867,7 +4469,7 @@ function buildScheduleSection(info, selectable) {
|
|
|
3867
4469
|
updateGoTo();
|
|
3868
4470
|
goToButtonUpdaters.push(updateGoTo);
|
|
3869
4471
|
goToBtn.addEventListener("click", () => {
|
|
3870
|
-
const globalMs = Math.max(sectionStartTime, Math.min(sectionEndTime, kf.time + rootStartMs));
|
|
4472
|
+
const globalMs = Math.max(sectionStartTime, Math.min(sectionEndTime, kf.time + rootStartMs + ownerStartMs()));
|
|
3871
4473
|
stopAudio();
|
|
3872
4474
|
loadPlayPositionSeconds(globalMs);
|
|
3873
4475
|
loadPlayPositionRange();
|
|
@@ -3993,10 +4595,13 @@ function updateComponentEditor(selectable) {
|
|
|
3993
4595
|
}
|
|
3994
4596
|
if (replaceable && replaceables) {
|
|
3995
4597
|
const moveChild = (fromIdx, toIdx) => {
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4598
|
+
// In a series, the playhead follows the picture it was showing.
|
|
4599
|
+
keepingScene(selectable, () => {
|
|
4600
|
+
const arr = replaceables.get();
|
|
4601
|
+
const [item] = arr.splice(fromIdx, 1);
|
|
4602
|
+
arr.splice(toIdx, 0, item);
|
|
4603
|
+
replaceables.replace(arr);
|
|
4604
|
+
});
|
|
4000
4605
|
activeRootComponentEditor?.resetAll();
|
|
4001
4606
|
updateComponentEditor(selectable);
|
|
4002
4607
|
};
|
|
@@ -4027,12 +4632,21 @@ function updateComponentEditor(selectable) {
|
|
|
4027
4632
|
const deleteBtn = document.createElement("button");
|
|
4028
4633
|
deleteBtn.type = "button";
|
|
4029
4634
|
deleteBtn.textContent = "🗑";
|
|
4635
|
+
deleteBtn.title = "Delete component";
|
|
4030
4636
|
deleteBtn.addEventListener("click", () => {
|
|
4637
|
+
// In a series, everything after this child moves earlier, and the playhead goes with it.
|
|
4638
|
+
const root = currentRoot();
|
|
4639
|
+
const childStart = root ? startWithin(root, child) : undefined;
|
|
4640
|
+
const childDuration = child.duration;
|
|
4641
|
+
const chainEndMs = seriesChainEndMs(selectable);
|
|
4031
4642
|
const arr = replaceables.get();
|
|
4032
4643
|
const i = arr.indexOf(child);
|
|
4033
4644
|
if (i !== -1)
|
|
4034
4645
|
arr.splice(i, 1);
|
|
4035
4646
|
replaceables.replace(arr);
|
|
4647
|
+
if (childStart !== undefined) {
|
|
4648
|
+
playheadAfterRemoving(childStart, childStart + childDuration, chainEndMs);
|
|
4649
|
+
}
|
|
4036
4650
|
if (selectedSlideChild === child) {
|
|
4037
4651
|
selectedSlideChild = null;
|
|
4038
4652
|
updateScheduleEditor(selectable);
|
|
@@ -4149,6 +4763,16 @@ function updateComponentEditor(selectable) {
|
|
|
4149
4763
|
if (!entry)
|
|
4150
4764
|
return;
|
|
4151
4765
|
const newChild = entry.create();
|
|
4766
|
+
if (newChild instanceof VideoClipComponent) {
|
|
4767
|
+
// The class default is 16 × 9, and saved files rely on defaults never changing.
|
|
4768
|
+
// So fill the canvas here, as a value of its own, whatever size the canvas is.
|
|
4769
|
+
newChild.destinationRectSchedule.set({
|
|
4770
|
+
x: 0,
|
|
4771
|
+
y: 0,
|
|
4772
|
+
width: canvasRecorder.width,
|
|
4773
|
+
height: canvasRecorder.height,
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4152
4776
|
addTarget.replaceableComponents.push(newChild);
|
|
4153
4777
|
afterStructureEdit(newChild);
|
|
4154
4778
|
});
|
|
@@ -4212,29 +4836,32 @@ function updateComponentEditor(selectable) {
|
|
|
4212
4836
|
list.scrollTop = wasAtBottom ? list.scrollHeight : savedScrollTop;
|
|
4213
4837
|
}
|
|
4214
4838
|
/**
|
|
4215
|
-
* The Sound Clips section of the schedule editor,
|
|
4216
|
-
*
|
|
4839
|
+
* The Sound Clips section of the schedule editor. One card per clip, plus Add and Paste.
|
|
4840
|
+
*
|
|
4841
|
+
* Every component gets one. A component with no `soundClips` list gets one
|
|
4842
|
+
* when its first clip is added.
|
|
4217
4843
|
*
|
|
4218
4844
|
* Each card's Owner menu moves the clip to another component without changing
|
|
4219
4845
|
* when it plays. Registers per-field sync callbacks into
|
|
4220
4846
|
* {@link soundClipSyncCallbacks}, so drags on the timeline show up here.
|
|
4221
4847
|
*/
|
|
4222
4848
|
function buildSoundClipSection(selectable) {
|
|
4223
|
-
const clips = selectable.soundClips;
|
|
4849
|
+
const clips = selectable.soundClips ?? [];
|
|
4850
|
+
/** Call before adding a clip. Merely selecting a component doesn't give it a list. */
|
|
4851
|
+
const ensureList = () => (selectable.soundClips ??= clips);
|
|
4224
4852
|
/** The clip list changed shape: save, rebuild the audio, redraw this section and the timeline. */
|
|
4225
4853
|
function afterStructureChange() {
|
|
4226
4854
|
markDirty();
|
|
4227
|
-
|
|
4228
|
-
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
4855
|
+
soundtrack.request();
|
|
4229
4856
|
updateScheduleEditor(selectable);
|
|
4230
|
-
|
|
4231
|
-
_updateTimeline(_veRootSelectable);
|
|
4857
|
+
refreshTimeline();
|
|
4232
4858
|
}
|
|
4233
|
-
/** Every place a sound
|
|
4859
|
+
/** Every place a sound lives in this video, and when each starts. */
|
|
4234
4860
|
const owners = soundOwners(toShow);
|
|
4861
|
+
/** Undefined until this component has a list. Then it has cards, with Owner menus that need it. */
|
|
4235
4862
|
const self = owners.find(({ owner }) => owner === selectable);
|
|
4236
4863
|
/** When this component starts, in video time. 0 if it can't be found, which shouldn't happen. */
|
|
4237
|
-
const selfStartMs =
|
|
4864
|
+
const selfStartMs = startWithin(toShow, selectable) ?? 0;
|
|
4238
4865
|
const section = document.createElement("fieldset");
|
|
4239
4866
|
const legend = document.createElement("legend");
|
|
4240
4867
|
legend.textContent = `Sound Clips (${clips.length})`;
|
|
@@ -4251,6 +4878,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4251
4878
|
addBtn.style.marginLeft = "auto";
|
|
4252
4879
|
addBtn.addEventListener("click", () => {
|
|
4253
4880
|
const clip = { source: "", startMsIntoScene: playheadInOwner() };
|
|
4881
|
+
ensureList();
|
|
4254
4882
|
clips.push(clip);
|
|
4255
4883
|
selectedSoundClip = clip;
|
|
4256
4884
|
afterStructureChange();
|
|
@@ -4275,6 +4903,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4275
4903
|
alert("No sound clips found on the clipboard. Each one needs at least a source.");
|
|
4276
4904
|
return;
|
|
4277
4905
|
}
|
|
4906
|
+
ensureList();
|
|
4278
4907
|
clips.push(...pasted);
|
|
4279
4908
|
selectedSoundClip = pasted[0];
|
|
4280
4909
|
afterStructureChange();
|
|
@@ -4333,7 +4962,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4333
4962
|
});
|
|
4334
4963
|
const delBtn = document.createElement("button");
|
|
4335
4964
|
delBtn.type = "button";
|
|
4336
|
-
delBtn.textContent = "
|
|
4965
|
+
delBtn.textContent = "🗑";
|
|
4337
4966
|
delBtn.title = "Delete clip";
|
|
4338
4967
|
delBtn.addEventListener("click", () => {
|
|
4339
4968
|
clips.splice(i, 1);
|
|
@@ -4512,8 +5141,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4512
5141
|
rehomeSoundClip(clip, self, to);
|
|
4513
5142
|
selectedSoundClip = clip;
|
|
4514
5143
|
markDirty();
|
|
4515
|
-
|
|
4516
|
-
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
5144
|
+
soundtrack.request();
|
|
4517
5145
|
const chapter = currentRoot();
|
|
4518
5146
|
if (chapter && startWithin(chapter, to.owner) !== undefined) {
|
|
4519
5147
|
// Follow the clip to its new owner.
|
|
@@ -4523,8 +5151,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4523
5151
|
// The new owner is in another chapter. Stay here; the clip is gone from this list.
|
|
4524
5152
|
updateScheduleEditor(selectable);
|
|
4525
5153
|
}
|
|
4526
|
-
|
|
4527
|
-
_updateTimeline(_veRootSelectable);
|
|
5154
|
+
refreshTimeline();
|
|
4528
5155
|
});
|
|
4529
5156
|
ownerLabel.append(ownerSelect);
|
|
4530
5157
|
const playsAt = document.createElement("span");
|
|
@@ -4573,6 +5200,9 @@ function buildNameSection(selectable) {
|
|
|
4573
5200
|
const root = currentSaveTarget();
|
|
4574
5201
|
if (root)
|
|
4575
5202
|
updateComponentEditor(root);
|
|
5203
|
+
// The timeline's blocks and the Edit menu show the name, too.
|
|
5204
|
+
refreshTimeline();
|
|
5205
|
+
scheduleChapterRefresh();
|
|
4576
5206
|
}
|
|
4577
5207
|
input.addEventListener("input", () => syncName(input.value));
|
|
4578
5208
|
resetBtn.addEventListener("click", () => {
|
|
@@ -4621,14 +5251,7 @@ function updateScheduleEditor(selectable) {
|
|
|
4621
5251
|
const slideComponent = selectable instanceof SlideComponent ? selectable : null;
|
|
4622
5252
|
const videoClip = selectable instanceof VideoClipComponent ? selectable : null;
|
|
4623
5253
|
const multiText = selectable instanceof MultiTextComponent ? selectable : null;
|
|
4624
|
-
|
|
4625
|
-
!schedules?.length &&
|
|
4626
|
-
!isTraditionalText &&
|
|
4627
|
-
!slideComponent &&
|
|
4628
|
-
selectable.soundClips === undefined) {
|
|
4629
|
-
scheduleEditorFieldset.hidden = true;
|
|
4630
|
-
return;
|
|
4631
|
-
}
|
|
5254
|
+
// Every component has something to edit: at least its name and its sound clips.
|
|
4632
5255
|
scheduleEditorFieldset.hidden = false;
|
|
4633
5256
|
scheduleEditorFieldset.append(buildNameSection(selectable));
|
|
4634
5257
|
let customPanel = null;
|
|
@@ -4642,6 +5265,13 @@ function updateScheduleEditor(selectable) {
|
|
|
4642
5265
|
}
|
|
4643
5266
|
const videoPanel = videoClip
|
|
4644
5267
|
? buildVideoClipPanel(videoClip, {
|
|
5268
|
+
setVideoSize: setVideoSizeFromGui,
|
|
5269
|
+
urlChanged() {
|
|
5270
|
+
activeRootComponentEditor?.update(videoClip, videoClip.urlScalar);
|
|
5271
|
+
markDirty();
|
|
5272
|
+
// Rebuild so the URL field shows the new value.
|
|
5273
|
+
updateScheduleEditor(videoClip);
|
|
5274
|
+
},
|
|
4645
5275
|
scalarsChanged() {
|
|
4646
5276
|
activeRootComponentEditor?.update(videoClip, videoClip.startMsIntoClipScalar);
|
|
4647
5277
|
activeRootComponentEditor?.update(videoClip, videoClip.endMsIntoClipScalar);
|
|
@@ -4678,6 +5308,12 @@ function updateScheduleEditor(selectable) {
|
|
|
4678
5308
|
if (selectable instanceof SingleImageComponent) {
|
|
4679
5309
|
const image = selectable;
|
|
4680
5310
|
const imagePanel = buildStaticImagePanel(image, {
|
|
5311
|
+
urlChanged() {
|
|
5312
|
+
activeRootComponentEditor?.update(image, image.urlSchedule);
|
|
5313
|
+
markDirty();
|
|
5314
|
+
// Rebuild so the URL field shows the new value.
|
|
5315
|
+
updateScheduleEditor(image);
|
|
5316
|
+
},
|
|
4681
5317
|
rectKeyframeChanged(kf) {
|
|
4682
5318
|
// The same sync a drag on the canvas uses, so ✎ edit mode survives.
|
|
4683
5319
|
markerSyncCallbacks.get(kf)?.(kf.value);
|
|
@@ -4763,9 +5399,7 @@ function updateScheduleEditor(selectable) {
|
|
|
4763
5399
|
}
|
|
4764
5400
|
scheduleEditorFieldset.append(section);
|
|
4765
5401
|
}
|
|
4766
|
-
|
|
4767
|
-
scheduleEditorFieldset.append(buildSoundClipSection(selectable));
|
|
4768
|
-
}
|
|
5402
|
+
scheduleEditorFieldset.append(buildSoundClipSection(selectable));
|
|
4769
5403
|
}
|
|
4770
5404
|
// MARK: Split
|
|
4771
5405
|
/**
|
|
@@ -4785,6 +5419,68 @@ function splitTarget(clip) {
|
|
|
4785
5419
|
}
|
|
4786
5420
|
return parent;
|
|
4787
5421
|
}
|
|
5422
|
+
// MARK: Keep the scene
|
|
5423
|
+
/** Move the playhead to this time, measured from the start of the Visual Editor's root. */
|
|
5424
|
+
function seekInRoot(ms) {
|
|
5425
|
+
stopAudio();
|
|
5426
|
+
loadPlayPositionSeconds(rootStartMs + ms);
|
|
5427
|
+
loadPlayPositionRange();
|
|
5428
|
+
// An edit moved the playhead. Keep it on the timeline's screen if it was there.
|
|
5429
|
+
timelineDisplay.movePlayMs(ms);
|
|
5430
|
+
}
|
|
5431
|
+
/**
|
|
5432
|
+
* Before an edit removes time from `series`: where its chain of series ends, measured from the
|
|
5433
|
+
* start of the root. Removing time moves everything up to there earlier, and nothing after it.
|
|
5434
|
+
* Undefined if `series` isn't an In Series in the current root, so nothing moves.
|
|
5435
|
+
*/
|
|
5436
|
+
function seriesChainEndMs(series) {
|
|
5437
|
+
const root = currentRoot();
|
|
5438
|
+
if (!root || !(series instanceof InSeriesComponent))
|
|
5439
|
+
return undefined;
|
|
5440
|
+
let top = series;
|
|
5441
|
+
while (top !== root && top.parent instanceof InSeriesComponent) {
|
|
5442
|
+
top = top.parent;
|
|
5443
|
+
}
|
|
5444
|
+
const start = startWithin(root, top);
|
|
5445
|
+
return start === undefined ? undefined : start + top.duration;
|
|
5446
|
+
}
|
|
5447
|
+
/**
|
|
5448
|
+
* A series just lost the time from `fromMs` to `toMs` (measured from the start of the root), and
|
|
5449
|
+
* everything after it moved earlier to fill the gap. Move the playhead with it, so the preview
|
|
5450
|
+
* keeps showing the same picture. A playhead inside what's gone goes to where the gap was.
|
|
5451
|
+
* @param chainEndMs {@link seriesChainEndMs}, from before the edit.
|
|
5452
|
+
*/
|
|
5453
|
+
function playheadAfterRemoving(fromMs, toMs, chainEndMs) {
|
|
5454
|
+
if (chainEndMs === undefined)
|
|
5455
|
+
return;
|
|
5456
|
+
const at = playheadInRootMs();
|
|
5457
|
+
if (at < fromMs || at >= chainEndMs)
|
|
5458
|
+
return;
|
|
5459
|
+
seekInRoot(at >= toMs ? at - (toMs - fromMs) : fromMs);
|
|
5460
|
+
}
|
|
5461
|
+
/**
|
|
5462
|
+
* Run `edit`, which reorders the children of `series`, then put the playhead on the same moment
|
|
5463
|
+
* of the same child, wherever that child is now.
|
|
5464
|
+
*/
|
|
5465
|
+
function keepingScene(series, edit) {
|
|
5466
|
+
const root = currentRoot();
|
|
5467
|
+
const seriesStart = root && series instanceof InSeriesComponent
|
|
5468
|
+
? startWithin(root, series)
|
|
5469
|
+
: undefined;
|
|
5470
|
+
let anchor;
|
|
5471
|
+
if (seriesStart !== undefined) {
|
|
5472
|
+
const local = playheadInRootMs() - seriesStart;
|
|
5473
|
+
const found = series.children?.find(({ start, child }) => local >= start && local < start + child.duration);
|
|
5474
|
+
if (found)
|
|
5475
|
+
anchor = { child: found.child, offsetMs: local - found.start };
|
|
5476
|
+
}
|
|
5477
|
+
edit();
|
|
5478
|
+
if (!root || !anchor)
|
|
5479
|
+
return;
|
|
5480
|
+
const newStart = startWithin(root, anchor.child);
|
|
5481
|
+
if (newStart !== undefined)
|
|
5482
|
+
seekInRoot(newStart + anchor.offsetMs);
|
|
5483
|
+
}
|
|
4788
5484
|
/** How long a sound plays, for splitting: a clip whose file isn't decoded yet is taken to play forever. */
|
|
4789
5485
|
function soundLengthForSplit(sound) {
|
|
4790
5486
|
return soundClipLengthMs(sound) ?? Infinity;
|
|
@@ -4815,8 +5511,17 @@ async function splitAtPlayhead(clip) {
|
|
|
4815
5511
|
: [second];
|
|
4816
5512
|
const siblings = parent.replaceableComponents.get();
|
|
4817
5513
|
siblings.splice(siblings.indexOf(clip), 1, ...kept);
|
|
5514
|
+
const chainEndMs = seriesChainEndMs(parent);
|
|
4818
5515
|
// Saves, rebuilds the audio, and redraws the timeline and the chapter list.
|
|
4819
5516
|
parent.replaceableComponents.replace(siblings);
|
|
5517
|
+
// Keep showing the same picture: a piece thrown away takes its time with it.
|
|
5518
|
+
const splitMs = clipStart + first.duration;
|
|
5519
|
+
if (choice.keep === "second") {
|
|
5520
|
+
playheadAfterRemoving(clipStart, splitMs, chainEndMs);
|
|
5521
|
+
}
|
|
5522
|
+
else if (choice.keep === "first") {
|
|
5523
|
+
playheadAfterRemoving(splitMs, splitMs + second.duration, chainEndMs);
|
|
5524
|
+
}
|
|
4820
5525
|
selectedSoundClip = undefined;
|
|
4821
5526
|
activeRootComponentEditor?.resetAll();
|
|
4822
5527
|
if (root !== clip) {
|
|
@@ -4898,6 +5603,21 @@ function buildMultiTextFrame(text) {
|
|
|
4898
5603
|
textFrameCanvasStates.set(text, newState);
|
|
4899
5604
|
applyCanvasState();
|
|
4900
5605
|
},
|
|
5606
|
+
editText() {
|
|
5607
|
+
void openMultiTextDialog(text, {
|
|
5608
|
+
saveNow: _flushDirtyToDb,
|
|
5609
|
+
changed: markDirty,
|
|
5610
|
+
copyComponent: (component) => buildComponents(serializeComponents([component]))[0],
|
|
5611
|
+
closed() {
|
|
5612
|
+
// The dialog covered the component list and this panel, so neither was kept up to date.
|
|
5613
|
+
activeRootComponentEditor?.resetAll();
|
|
5614
|
+
const root = currentSaveTarget();
|
|
5615
|
+
if (root)
|
|
5616
|
+
updateComponentEditor(root);
|
|
5617
|
+
updateScheduleEditor(text);
|
|
5618
|
+
},
|
|
5619
|
+
});
|
|
5620
|
+
},
|
|
4901
5621
|
});
|
|
4902
5622
|
// Adding a keyframe to Position, say, means there's no longer one frame.
|
|
4903
5623
|
scheduleEditorRefreshers.push(applyCanvasState, panel.refresh);
|
|
@@ -5948,13 +6668,18 @@ document.addEventListener("keyup", (e) => {
|
|
|
5948
6668
|
}
|
|
5949
6669
|
});
|
|
5950
6670
|
getById("recordJustSound", HTMLButtonElement).addEventListener("click", async () => {
|
|
5951
|
-
|
|
5952
|
-
|
|
6671
|
+
// The newest soundtrack, with every file in it decoded.
|
|
6672
|
+
const before = infoDiv.innerHTML;
|
|
6673
|
+
infoDiv.innerHTML = "Waiting for the sound…";
|
|
6674
|
+
await soundtrack.ready();
|
|
6675
|
+
infoDiv.innerHTML = before;
|
|
6676
|
+
downloadBlob("sound_file.wav", soundtrack.mix(0, toShow.duration).toBlob());
|
|
5953
6677
|
});
|
|
5954
6678
|
function reload() {
|
|
5955
6679
|
initChapters();
|
|
5956
6680
|
updateFromSelect();
|
|
5957
|
-
|
|
6681
|
+
// Reload means everything, including sound files changed on disk.
|
|
6682
|
+
soundtrack.forget();
|
|
5958
6683
|
}
|
|
5959
6684
|
getById("reloadBtn", HTMLButtonElement).addEventListener("click", reload);
|
|
5960
6685
|
// MARK: Debug Log
|
|
@@ -6099,6 +6824,9 @@ function refreshEditorsAfterLoad() {
|
|
|
6099
6824
|
activeRootComponentEditor?.resetAll();
|
|
6100
6825
|
updateComponentEditor(current);
|
|
6101
6826
|
updateScheduleEditor(current);
|
|
6827
|
+
afterStateApplied();
|
|
6828
|
+
// The loaded state may use local files that need 🔓.
|
|
6829
|
+
checkVideosLocalFiles();
|
|
6102
6830
|
}
|
|
6103
6831
|
/**
|
|
6104
6832
|
* Apply a parsed JSON snapshot to all matching selectables in `chapterList`,
|