@openartifactsai/motion-stage 0.0.0-stage → 0.23.0-rc.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +70 -4
- package/src/build.d.ts +18 -0
- package/src/build.js +73 -0
- package/src/host.d.ts +37 -0
- package/src/host.js +76 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +6 -0
- package/src/layers.d.ts +30 -0
- package/src/layers.js +56 -0
- package/src/offline/audio.d.ts +19 -0
- package/src/offline/audio.js +20 -0
- package/src/offline/data.d.ts +26 -0
- package/src/offline/data.js +71 -0
- package/src/offline/main.d.ts +9 -0
- package/src/offline/main.js +52 -0
- package/src/offline/player.d.ts +23 -0
- package/src/offline/player.js +157 -0
- package/src/protocol/clip-guards.d.ts +5 -0
- package/src/protocol/clip-guards.js +22 -0
- package/src/protocol/guards.d.ts +6 -0
- package/src/protocol/guards.js +257 -0
- package/src/protocol/layer-guards.d.ts +7 -0
- package/src/protocol/layer-guards.js +100 -0
- package/src/protocol/layers.d.ts +135 -0
- package/src/protocol/layers.js +1 -0
- package/src/protocol/types.d.ts +340 -0
- package/src/protocol/types.js +7 -0
- package/src/protocol.d.ts +2 -0
- package/src/protocol.js +2 -0
- package/src/raster.d.ts +4 -0
- package/src/raster.js +2 -0
- package/src/runtime/assets.d.ts +19 -0
- package/src/runtime/assets.js +63 -0
- package/src/runtime/caption-box.d.ts +3 -0
- package/src/runtime/caption-box.js +16 -0
- package/src/runtime/captions.d.ts +31 -0
- package/src/runtime/captions.js +115 -0
- package/src/runtime/clip-captions.d.ts +9 -0
- package/src/runtime/clip-captions.js +27 -0
- package/src/runtime/clips.d.ts +83 -0
- package/src/runtime/clips.js +259 -0
- package/src/runtime/console.d.ts +13 -0
- package/src/runtime/console.js +99 -0
- package/src/runtime/cut.d.ts +7 -0
- package/src/runtime/cut.js +63 -0
- package/src/runtime/determinism.d.ts +12 -0
- package/src/runtime/determinism.js +47 -0
- package/src/runtime/film.d.ts +43 -0
- package/src/runtime/film.js +31 -0
- package/src/runtime/focus.d.ts +8 -0
- package/src/runtime/focus.js +71 -0
- package/src/runtime/fonts.d.ts +22 -0
- package/src/runtime/fonts.js +109 -0
- package/src/runtime/frame.d.ts +9 -0
- package/src/runtime/frame.js +140 -0
- package/src/runtime/fx/backdrop.d.ts +60 -0
- package/src/runtime/fx/backdrop.js +264 -0
- package/src/runtime/fx/color.d.ts +19 -0
- package/src/runtime/fx/color.js +84 -0
- package/src/runtime/fx/css-color.d.ts +6 -0
- package/src/runtime/fx/css-color.js +44 -0
- package/src/runtime/fx/curve.d.ts +12 -0
- package/src/runtime/fx/curve.js +34 -0
- package/src/runtime/fx/gl.d.ts +29 -0
- package/src/runtime/fx/gl.js +207 -0
- package/src/runtime/fx/glsl.d.ts +35 -0
- package/src/runtime/fx/glsl.js +113 -0
- package/src/runtime/fx/index.d.ts +23 -0
- package/src/runtime/fx/index.js +151 -0
- package/src/runtime/fx/key.d.ts +11 -0
- package/src/runtime/fx/key.js +21 -0
- package/src/runtime/fx/numbers.d.ts +14 -0
- package/src/runtime/fx/numbers.js +57 -0
- package/src/runtime/fx/pace.d.ts +17 -0
- package/src/runtime/fx/pace.js +26 -0
- package/src/runtime/fx/paint.d.ts +28 -0
- package/src/runtime/fx/paint.js +150 -0
- package/src/runtime/guard.d.ts +4 -0
- package/src/runtime/guard.js +141 -0
- package/src/runtime/hand-titles/index.d.ts +9 -0
- package/src/runtime/hand-titles/index.js +73 -0
- package/src/runtime/hand-titles/layer.d.ts +20 -0
- package/src/runtime/hand-titles/layer.js +118 -0
- package/src/runtime/hand-titles/place.d.ts +27 -0
- package/src/runtime/hand-titles/place.js +45 -0
- package/src/runtime/held-store.d.ts +35 -0
- package/src/runtime/held-store.js +63 -0
- package/src/runtime/held.d.ts +19 -0
- package/src/runtime/held.js +225 -0
- package/src/runtime/kit/camera.d.ts +59 -0
- package/src/runtime/kit/camera.js +81 -0
- package/src/runtime/kit/chip.d.ts +25 -0
- package/src/runtime/kit/chip.js +75 -0
- package/src/runtime/kit/count.d.ts +37 -0
- package/src/runtime/kit/count.js +100 -0
- package/src/runtime/kit/cursor.d.ts +46 -0
- package/src/runtime/kit/cursor.js +108 -0
- package/src/runtime/kit/dom.d.ts +14 -0
- package/src/runtime/kit/dom.js +46 -0
- package/src/runtime/kit/geometry.d.ts +24 -0
- package/src/runtime/kit/geometry.js +56 -0
- package/src/runtime/kit/index.d.ts +113 -0
- package/src/runtime/kit/index.js +157 -0
- package/src/runtime/kit/mark-strokes.d.ts +65 -0
- package/src/runtime/kit/mark-strokes.js +226 -0
- package/src/runtime/kit/marks.d.ts +21 -0
- package/src/runtime/kit/marks.js +165 -0
- package/src/runtime/kit/math.d.ts +23 -0
- package/src/runtime/kit/math.js +35 -0
- package/src/runtime/kit/paper.d.ts +7 -0
- package/src/runtime/kit/paper.js +27 -0
- package/src/runtime/kit/random.d.ts +8 -0
- package/src/runtime/kit/random.js +32 -0
- package/src/runtime/kit/text-fx.d.ts +18 -0
- package/src/runtime/kit/text-fx.js +55 -0
- package/src/runtime/kit/typing.d.ts +21 -0
- package/src/runtime/kit/typing.js +42 -0
- package/src/runtime/laid/layer.d.ts +44 -0
- package/src/runtime/laid/layer.js +370 -0
- package/src/runtime/layers/describe.d.ts +41 -0
- package/src/runtime/layers/describe.js +327 -0
- package/src/runtime/layers/item.d.ts +123 -0
- package/src/runtime/layers/item.js +150 -0
- package/src/runtime/layers/parts.d.ts +53 -0
- package/src/runtime/layers/parts.js +158 -0
- package/src/runtime/layers/rows.d.ts +4 -0
- package/src/runtime/layers/rows.js +233 -0
- package/src/runtime/layers/scan.d.ts +24 -0
- package/src/runtime/layers/scan.js +204 -0
- package/src/runtime/layers/walk.d.ts +16 -0
- package/src/runtime/layers/walk.js +337 -0
- package/src/runtime/load.d.ts +10 -0
- package/src/runtime/load.js +267 -0
- package/src/runtime/main.d.ts +1 -0
- package/src/runtime/main.js +90 -0
- package/src/runtime/modules.d.ts +23 -0
- package/src/runtime/modules.js +53 -0
- package/src/runtime/port.d.ts +8 -0
- package/src/runtime/port.js +46 -0
- package/src/runtime/questions.d.ts +24 -0
- package/src/runtime/questions.js +162 -0
- package/src/runtime/recut.d.ts +81 -0
- package/src/runtime/recut.js +325 -0
- package/src/runtime/render.d.ts +80 -0
- package/src/runtime/render.js +358 -0
- package/src/runtime/retouch/ask.d.ts +17 -0
- package/src/runtime/retouch/ask.js +171 -0
- package/src/runtime/retouch/entry.d.ts +77 -0
- package/src/runtime/retouch/entry.js +1 -0
- package/src/runtime/retouch/judge.d.ts +25 -0
- package/src/runtime/retouch/judge.js +209 -0
- package/src/runtime/retouch/look.d.ts +39 -0
- package/src/runtime/retouch/look.js +135 -0
- package/src/runtime/retouch/own-styles.d.ts +19 -0
- package/src/runtime/retouch/own-styles.js +141 -0
- package/src/runtime/retouch/parts.d.ts +22 -0
- package/src/runtime/retouch/parts.js +166 -0
- package/src/runtime/retouch/retouch.d.ts +37 -0
- package/src/runtime/retouch/retouch.js +238 -0
- package/src/runtime/retouch/seat.d.ts +40 -0
- package/src/runtime/retouch/seat.js +228 -0
- package/src/runtime/retouch/state.d.ts +37 -0
- package/src/runtime/retouch/state.js +153 -0
- package/src/runtime/retouch/type-style.d.ts +19 -0
- package/src/runtime/retouch/type-style.js +111 -0
- package/src/runtime/scan.d.ts +2 -0
- package/src/runtime/scan.js +49 -0
- package/src/runtime/scenes/card.d.ts +12 -0
- package/src/runtime/scenes/card.js +56 -0
- package/src/runtime/scenes/install.d.ts +69 -0
- package/src/runtime/scenes/install.js +528 -0
- package/src/runtime/scenes/read.d.ts +27 -0
- package/src/runtime/scenes/read.js +73 -0
- package/src/runtime/scenes/scoped.d.ts +13 -0
- package/src/runtime/scenes/scoped.js +46 -0
- package/src/runtime/score.d.ts +32 -0
- package/src/runtime/score.js +262 -0
- package/src/runtime/sketch/pen.d.ts +3 -0
- package/src/runtime/sketch/pen.js +371 -0
- package/src/runtime/sketch/strokes.d.ts +41 -0
- package/src/runtime/sketch/strokes.js +187 -0
- package/src/runtime/snapshot/draw.d.ts +14 -0
- package/src/runtime/snapshot/draw.js +125 -0
- package/src/runtime/snapshot/hold-first-draw.d.ts +12 -0
- package/src/runtime/snapshot/hold-first-draw.js +128 -0
- package/src/runtime/snapshot/lift.d.ts +41 -0
- package/src/runtime/snapshot/lift.js +161 -0
- package/src/runtime/snapshot/plate.d.ts +20 -0
- package/src/runtime/snapshot/plate.js +79 -0
- package/src/runtime/snapshot/serialize.d.ts +51 -0
- package/src/runtime/snapshot/serialize.js +286 -0
- package/src/runtime/snapshot/styles.d.ts +8 -0
- package/src/runtime/snapshot/styles.js +109 -0
- package/src/runtime/snapshot/xml.d.ts +6 -0
- package/src/runtime/snapshot/xml.js +110 -0
- package/src/runtime/stage-size.d.ts +7 -0
- package/src/runtime/stage-size.js +3 -0
- package/src/runtime/stage.d.ts +27 -0
- package/src/runtime/stage.js +154 -0
- package/src/runtime/stretch.d.ts +13 -0
- package/src/runtime/stretch.js +16 -0
- package/src/runtime/texts.d.ts +24 -0
- package/src/runtime/texts.js +211 -0
- package/src/runtime/video-sync.d.ts +51 -0
- package/src/runtime/video-sync.js +218 -0
- package/src/stills.d.ts +90 -0
- package/src/stills.js +329 -0
- package/src/tools/film.d.ts +13 -0
- package/src/tools/film.js +116 -0
- package/src/tools/levels.d.ts +8 -0
- package/src/tools/levels.js +28 -0
- package/src/tools/main.d.ts +1 -0
- package/src/tools/main.js +223 -0
- package/src/tools/score.d.ts +4 -0
- package/src/tools/score.js +35 -0
- package/src/tools/types.d.ts +84 -0
- package/src/tools/types.js +2 -0
- package/src/tools.d.ts +6 -0
- package/src/tools.js +4 -0
- package/src/virtual.d.ts +11 -0
- package/src/vite.d.ts +8 -0
- package/src/vite.js +43 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { FilmSeconds, PlaySeconds, ScoreData } from '@openartifactsai/motion-core';
|
|
2
|
+
import type { Chapter, FilmPart, PlayedScore } from '../protocol.js';
|
|
3
|
+
/** A part of the film on its own time, before a person's lengths are laid on it. */
|
|
4
|
+
export interface NaturalPart {
|
|
5
|
+
key: string | null;
|
|
6
|
+
label: string;
|
|
7
|
+
a0: FilmSeconds;
|
|
8
|
+
nat: number;
|
|
9
|
+
/** A piece of a scene split by hand. */
|
|
10
|
+
split?: {
|
|
11
|
+
of: string;
|
|
12
|
+
from: number;
|
|
13
|
+
was: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface SceneClock {
|
|
17
|
+
parts: FilmPart[];
|
|
18
|
+
duration: PlaySeconds;
|
|
19
|
+
moved: boolean;
|
|
20
|
+
/** The lengths asked for would take the film past its limit, so every part plays at its own. */
|
|
21
|
+
aside: boolean;
|
|
22
|
+
at(t: PlaySeconds): {
|
|
23
|
+
T: FilmSeconds;
|
|
24
|
+
rate: number;
|
|
25
|
+
};
|
|
26
|
+
back(T: FilmSeconds): PlaySeconds;
|
|
27
|
+
/** The moment of the film is in a hidden scene, so it is never played. */
|
|
28
|
+
hides(T: FilmSeconds): boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The film cut on its own time: at 0, and at each labelled chapter more than CUT_GAP_S from the cut before it and
|
|
32
|
+
* from the end. `ids`: the scenes' ids, in a film made of scenes.
|
|
33
|
+
*/
|
|
34
|
+
export declare function filmParts(duration: number, chapters: readonly Chapter<FilmSeconds>[], ids: readonly string[] | null): NaturalPart[];
|
|
35
|
+
/**
|
|
36
|
+
* The scenes `recut.json` leaves out of the film as played: each by id, while the film still gives it its "was"
|
|
37
|
+
* seconds. Never every scene: then none is left out.
|
|
38
|
+
*/
|
|
39
|
+
export declare function hiddenScenes(scenes: ReadonlyArray<{
|
|
40
|
+
id: string | null;
|
|
41
|
+
dur: number;
|
|
42
|
+
}>, text: string | null): Set<string>;
|
|
43
|
+
/**
|
|
44
|
+
* The entrance a person picked for a scene instead of its own (`own`: the kind `scenes.json` gives it, `cut` for
|
|
45
|
+
* none), while the film still brings it on that way; `null` when they picked none, or it no longer counts.
|
|
46
|
+
*/
|
|
47
|
+
export declare function pickedEntrance(id: string, own: string, text: string | null): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* The film's own parts with the scenes `recut.json` splits made into pieces: each piece a part of its own, at least
|
|
50
|
+
* LEAST_PIECE_S long, and MOST_PIECES parts at most. A split counts while its scene lasts its "was" seconds.
|
|
51
|
+
*/
|
|
52
|
+
export declare function splitParts(own: readonly NaturalPart[], text: string | null): NaturalPart[];
|
|
53
|
+
/**
|
|
54
|
+
* The parts as played, from the film's own parts and `modules/recut.json`. An entry stands only while the film still
|
|
55
|
+
* says its "was", and a length only within the limits; one that does not is ignored, never clamped. A hidden scene is
|
|
56
|
+
* not played: the parts skip its stretch of the film.
|
|
57
|
+
*/
|
|
58
|
+
export declare function sceneClock(given: readonly NaturalPart[], text: string | null): SceneClock;
|
|
59
|
+
/** A scene as played, or a piece of one split by hand: where it starts in the film, how long it runs there, and whether its two ends are played. */
|
|
60
|
+
export interface PlayedPiece {
|
|
61
|
+
id: string;
|
|
62
|
+
/** The scene whose code draws it. */
|
|
63
|
+
of: string;
|
|
64
|
+
a0: number;
|
|
65
|
+
nat: number;
|
|
66
|
+
start: boolean;
|
|
67
|
+
end: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The scenes cut into the pieces `recut.json` splits them into, in film order, each saying whether its first and its
|
|
71
|
+
* last moment are played (not hidden, not trimmed off). A piece after the first is a scene of its own as far as
|
|
72
|
+
* entrances go: it may come on over the piece before it.
|
|
73
|
+
*/
|
|
74
|
+
export declare function playedPieces(scenes: ReadonlyArray<{
|
|
75
|
+
id: string;
|
|
76
|
+
dur: number;
|
|
77
|
+
}>, text: string | null): PlayedPiece[];
|
|
78
|
+
/** The clock of a film nobody retimed. */
|
|
79
|
+
export declare function plainClock(duration: number): SceneClock;
|
|
80
|
+
/** The score is recorded on the film's own time and played on played time; a stretched part's sound slows with it, at the same pitch. */
|
|
81
|
+
export declare function playedScore(score: ScoreData, clock: SceneClock): PlayedScore;
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
const MOST_FILM_S = 36000;
|
|
2
|
+
const NEAR_S = 0.001;
|
|
3
|
+
const EDGE_S = 1e-9;
|
|
4
|
+
const MOST_RECORD_CHARS = 262144;
|
|
5
|
+
const MOST_ENTRIES = 33;
|
|
6
|
+
const CUT_GAP_S = 0.05;
|
|
7
|
+
const MOST_PIECES = 32;
|
|
8
|
+
const LEAST_PIECE_S = 1;
|
|
9
|
+
const ID = /^[a-z][a-z0-9-]{0,31}$/;
|
|
10
|
+
const round6 = (x) => Math.round(x * 1e6) / 1e6;
|
|
11
|
+
const film = (x) => x;
|
|
12
|
+
const play = (x) => x;
|
|
13
|
+
/**
|
|
14
|
+
* The film cut on its own time: at 0, and at each labelled chapter more than CUT_GAP_S from the cut before it and
|
|
15
|
+
* from the end. `ids`: the scenes' ids, in a film made of scenes.
|
|
16
|
+
*/
|
|
17
|
+
export function filmParts(duration, chapters, ids) {
|
|
18
|
+
const cuts = [{ t: 0, label: '' }];
|
|
19
|
+
for (const chapter of chapters) {
|
|
20
|
+
if (chapter.label.trim() === '' || chapter.t >= duration - CUT_GAP_S)
|
|
21
|
+
continue;
|
|
22
|
+
const first = cuts[0];
|
|
23
|
+
if (chapter.t <= CUT_GAP_S) {
|
|
24
|
+
if (cuts.length === 1 && first)
|
|
25
|
+
first.label = chapter.label;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const last = cuts[cuts.length - 1];
|
|
29
|
+
if (last && chapter.t - last.t > CUT_GAP_S)
|
|
30
|
+
cuts.push({ t: chapter.t, label: chapter.label });
|
|
31
|
+
}
|
|
32
|
+
const keyed = !!ids && ids.length === cuts.length;
|
|
33
|
+
return cuts.map((cut, i) => ({
|
|
34
|
+
key: keyed ? (ids?.[i] ?? null) : null,
|
|
35
|
+
label: cut.label,
|
|
36
|
+
a0: film(cut.t),
|
|
37
|
+
nat: round6((cuts[i + 1]?.t ?? duration) - cut.t),
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const record = (value) => (value !== null && typeof value === 'object' ? value : {});
|
|
41
|
+
const HIDDEN_CHARACTERS = /[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Zl}\p{Zp}\p{Noncharacter_Code_Point}\p{Default_Ignorable_Code_Point}⠀\u{16fe4}\s]+/gu;
|
|
42
|
+
const tidyName = (name) => Array.from(name.slice(0, 96)).slice(0, 48).join('').replace(HIDDEN_CHARACTERS, ' ').trim();
|
|
43
|
+
function fits(nat, length) {
|
|
44
|
+
return (typeof length === 'number' &&
|
|
45
|
+
isFinite(length) &&
|
|
46
|
+
length >= nat * 0.5 - 1e-9 &&
|
|
47
|
+
length <= nat * 3 + 1e-9 &&
|
|
48
|
+
length >= Math.min(1, nat) &&
|
|
49
|
+
length <= MOST_FILM_S);
|
|
50
|
+
}
|
|
51
|
+
function readEntries(text) {
|
|
52
|
+
if (typeof text !== 'string' || text.length > MOST_RECORD_CHARS)
|
|
53
|
+
return [];
|
|
54
|
+
let parsed = null;
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(text);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const root = record(parsed);
|
|
62
|
+
return root['v'] === 1 && Array.isArray(root['scenes']) ? root['scenes'].slice(0, MOST_ENTRIES) : [];
|
|
63
|
+
}
|
|
64
|
+
const near = (a, b) => typeof a === 'number' && Math.abs(a - b) <= NEAR_S;
|
|
65
|
+
/**
|
|
66
|
+
* The scenes `recut.json` leaves out of the film as played: each by id, while the film still gives it its "was"
|
|
67
|
+
* seconds. Never every scene: then none is left out.
|
|
68
|
+
*/
|
|
69
|
+
export function hiddenScenes(scenes, text) {
|
|
70
|
+
const entries = readEntries(text).map(record);
|
|
71
|
+
const hidden = new Set();
|
|
72
|
+
for (const scene of scenes) {
|
|
73
|
+
if (scene.id === null)
|
|
74
|
+
continue;
|
|
75
|
+
if (entries.some((entry) => entry['id'] === scene.id && near(record(entry['gone'])['was'], scene.dur)))
|
|
76
|
+
hidden.add(scene.id);
|
|
77
|
+
}
|
|
78
|
+
return hidden.size < scenes.length ? hidden : new Set();
|
|
79
|
+
}
|
|
80
|
+
const ENTER_NAMES = ['cut', 'fade', 'push', 'wipe', 'iris'];
|
|
81
|
+
/**
|
|
82
|
+
* The entrance a person picked for a scene instead of its own (`own`: the kind `scenes.json` gives it, `cut` for
|
|
83
|
+
* none), while the film still brings it on that way; `null` when they picked none, or it no longer counts.
|
|
84
|
+
*/
|
|
85
|
+
export function pickedEntrance(id, own, text) {
|
|
86
|
+
let picked = null;
|
|
87
|
+
for (const entry of readEntries(text).map(record)) {
|
|
88
|
+
if (entry['id'] !== id)
|
|
89
|
+
continue;
|
|
90
|
+
const enter = record(entry['enter']);
|
|
91
|
+
const was = enter['was'];
|
|
92
|
+
const v = enter['v'];
|
|
93
|
+
if (was === own && typeof v === 'string' && v !== was && ENTER_NAMES.includes(v))
|
|
94
|
+
picked = v;
|
|
95
|
+
}
|
|
96
|
+
return picked;
|
|
97
|
+
}
|
|
98
|
+
const isLength = (value) => typeof value === 'number' && isFinite(value) && value > 0 && value <= MOST_FILM_S;
|
|
99
|
+
/**
|
|
100
|
+
* The film's own parts with the scenes `recut.json` splits made into pieces: each piece a part of its own, at least
|
|
101
|
+
* LEAST_PIECE_S long, and MOST_PIECES parts at most. A split counts while its scene lasts its "was" seconds.
|
|
102
|
+
*/
|
|
103
|
+
export function splitParts(own, text) {
|
|
104
|
+
const taken = new Set(own.flatMap((part) => (part.key === null ? [] : [part.key])));
|
|
105
|
+
const cuts = [];
|
|
106
|
+
for (const entry of readEntries(text).map(record)) {
|
|
107
|
+
const id = entry['id'];
|
|
108
|
+
const split = record(entry['split']);
|
|
109
|
+
const { of, was, at } = split;
|
|
110
|
+
if (typeof id !== 'string' || !ID.test(id) || taken.has(id) || typeof of !== 'string' || !isLength(was) || typeof at !== 'number' || !isFinite(at))
|
|
111
|
+
continue;
|
|
112
|
+
taken.add(id);
|
|
113
|
+
cuts.push({ id, of, was, at });
|
|
114
|
+
}
|
|
115
|
+
if (cuts.length === 0)
|
|
116
|
+
return [...own];
|
|
117
|
+
cuts.sort((a, b) => a.at - b.at);
|
|
118
|
+
let room = MOST_PIECES - own.length;
|
|
119
|
+
const pieces = own.flatMap((part) => {
|
|
120
|
+
if (part.key === null)
|
|
121
|
+
return [part];
|
|
122
|
+
const starts = [{ id: part.key, at: 0 }];
|
|
123
|
+
for (const cut of cuts) {
|
|
124
|
+
const after = cut.at - (starts[starts.length - 1]?.at ?? 0);
|
|
125
|
+
if (cut.of !== part.key || !near(cut.was, part.nat) || after < LEAST_PIECE_S - EDGE_S || part.nat - cut.at < LEAST_PIECE_S - EDGE_S || room <= 0)
|
|
126
|
+
continue;
|
|
127
|
+
starts.push({ id: cut.id, at: cut.at });
|
|
128
|
+
room -= 1;
|
|
129
|
+
}
|
|
130
|
+
if (starts.length === 1)
|
|
131
|
+
return [part];
|
|
132
|
+
return starts.map((start, i) => ({
|
|
133
|
+
key: start.id,
|
|
134
|
+
label: part.label,
|
|
135
|
+
a0: film(part.a0 + start.at),
|
|
136
|
+
nat: round6((starts[i + 1]?.at ?? part.nat) - start.at),
|
|
137
|
+
split: { of: part.key ?? start.id, from: start.at, was: part.nat },
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
return pieces;
|
|
141
|
+
}
|
|
142
|
+
/** The stretch of a scene `nat` long that a person kept by trimming it, `[from, to]`; `null` for all of it. */
|
|
143
|
+
function keptSpan(trim, nat) {
|
|
144
|
+
const { was, from, to } = trim;
|
|
145
|
+
if (!near(was, nat) || typeof from !== 'number' || typeof to !== 'number' || from < 0 || to > nat + NEAR_S)
|
|
146
|
+
return null;
|
|
147
|
+
const start = from <= NEAR_S ? 0 : from;
|
|
148
|
+
const end = to >= nat - NEAR_S ? nat : to;
|
|
149
|
+
return end - start >= LEAST_PIECE_S - EDGE_S && (start > 0 || end < nat) ? [start, end] : null;
|
|
150
|
+
}
|
|
151
|
+
/** The trim a person set on a scene (its last one that still fits it), or `null`. */
|
|
152
|
+
function trimOf(key, nat, entries) {
|
|
153
|
+
let kept = null;
|
|
154
|
+
for (const entry of entries) {
|
|
155
|
+
if (entry['id'] !== key)
|
|
156
|
+
continue;
|
|
157
|
+
const span = keptSpan(record(entry['trim']), nat);
|
|
158
|
+
if (span)
|
|
159
|
+
kept = span;
|
|
160
|
+
}
|
|
161
|
+
return kept;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The parts as played, from the film's own parts and `modules/recut.json`. An entry stands only while the film still
|
|
165
|
+
* says its "was", and a length only within the limits; one that does not is ignored, never clamped. A hidden scene is
|
|
166
|
+
* not played: the parts skip its stretch of the film.
|
|
167
|
+
*/
|
|
168
|
+
export function sceneClock(given, text) {
|
|
169
|
+
const entries = readEntries(text);
|
|
170
|
+
const own = splitParts(given, text);
|
|
171
|
+
const hidden = hiddenScenes(own.map((part) => ({ id: part.key, dur: part.nat })), text);
|
|
172
|
+
const read = entries.map(record);
|
|
173
|
+
// A trimmed part shows only the stretch kept: it starts later in the film, and is shorter.
|
|
174
|
+
const shown = own
|
|
175
|
+
.filter((part) => part.key === null || !hidden.has(part.key))
|
|
176
|
+
.map((part) => {
|
|
177
|
+
const kept = part.key === null ? null : trimOf(part.key, part.nat, read);
|
|
178
|
+
if (!kept)
|
|
179
|
+
return part;
|
|
180
|
+
return { ...part, a0: film(part.a0 + kept[0]), nat: round6(kept[1] - kept[0]), trim: { from: kept[0], was: part.nat } };
|
|
181
|
+
});
|
|
182
|
+
const lay = (stretch) => {
|
|
183
|
+
let p0 = 0;
|
|
184
|
+
return shown.map((part) => {
|
|
185
|
+
// Entries for chapters count by the place of the part in the film's own list (a chapter is never split or trimmed).
|
|
186
|
+
const i = given.indexOf(part);
|
|
187
|
+
let dur = part.nat;
|
|
188
|
+
let label = part.label;
|
|
189
|
+
for (const entry of entries) {
|
|
190
|
+
if (entry === null || typeof entry !== 'object')
|
|
191
|
+
continue;
|
|
192
|
+
const fields = record(entry);
|
|
193
|
+
const name = record(fields['name']);
|
|
194
|
+
const length = record(fields['dur']);
|
|
195
|
+
const matches = part.key !== null ? fields['id'] === part.key : fields['part'] === i && fields['id'] === undefined && name['was'] === part.label;
|
|
196
|
+
if (!matches)
|
|
197
|
+
continue;
|
|
198
|
+
const was = length['was'];
|
|
199
|
+
if (stretch && typeof was === 'number' && Math.abs(was - part.nat) <= NEAR_S && fits(part.nat, length['v']))
|
|
200
|
+
dur = length['v'];
|
|
201
|
+
const given = name['v'];
|
|
202
|
+
if (name['was'] === part.label && typeof given === 'string' && tidyName(given) !== '')
|
|
203
|
+
label = tidyName(given);
|
|
204
|
+
}
|
|
205
|
+
const played = {
|
|
206
|
+
key: part.key,
|
|
207
|
+
label,
|
|
208
|
+
own: part.label,
|
|
209
|
+
a0: part.a0,
|
|
210
|
+
nat: part.nat,
|
|
211
|
+
p0: play(p0),
|
|
212
|
+
dur,
|
|
213
|
+
...(part.trim ? { trim: part.trim } : {}),
|
|
214
|
+
...(part.split ? { split: part.split } : {}),
|
|
215
|
+
};
|
|
216
|
+
p0 = round6(p0 + dur);
|
|
217
|
+
return played;
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
const endOf = (parts) => {
|
|
221
|
+
const last = parts[parts.length - 1];
|
|
222
|
+
return last ? round6(last.p0 + last.dur) : 0;
|
|
223
|
+
};
|
|
224
|
+
const isMoved = (parts) => hidden.size > 0 || parts.some((part) => part.dur !== part.nat || part.trim !== undefined);
|
|
225
|
+
let parts = lay(true);
|
|
226
|
+
const aside = endOf(parts) > MOST_FILM_S && isMoved(parts);
|
|
227
|
+
if (aside)
|
|
228
|
+
parts = lay(false);
|
|
229
|
+
// Where nothing is moved the two clocks are one, to the last digit.
|
|
230
|
+
if (!isMoved(parts))
|
|
231
|
+
for (const part of parts)
|
|
232
|
+
part.p0 = play(part.a0);
|
|
233
|
+
const last = parts[parts.length - 1];
|
|
234
|
+
const filmEnd = last ? last.a0 + last.nat : 0;
|
|
235
|
+
const playEnd = endOf(parts);
|
|
236
|
+
const find = (by, value) => {
|
|
237
|
+
let found = parts[0];
|
|
238
|
+
for (const part of parts.slice(1))
|
|
239
|
+
if (part[by] <= value)
|
|
240
|
+
found = part;
|
|
241
|
+
return found;
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
parts,
|
|
245
|
+
duration: play(playEnd),
|
|
246
|
+
moved: isMoved(parts),
|
|
247
|
+
aside,
|
|
248
|
+
// A part stops just short of the next one's first instant.
|
|
249
|
+
at(t) {
|
|
250
|
+
const clamped = t < 0 ? 0 : t > playEnd ? playEnd : t;
|
|
251
|
+
const part = find('p0', clamped);
|
|
252
|
+
if (!part)
|
|
253
|
+
return { T: film(clamped), rate: 1 };
|
|
254
|
+
return {
|
|
255
|
+
T: film(part.a0 + Math.min(part === last ? part.nat : part.nat - EDGE_S, (clamped - part.p0) * (part.nat / part.dur))),
|
|
256
|
+
rate: part.nat / part.dur,
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
// A moment of the film no part shows: in a hidden scene, or in a stretch trimmed off.
|
|
260
|
+
hides(T) {
|
|
261
|
+
if (!isMoved(parts))
|
|
262
|
+
return false;
|
|
263
|
+
const first = given[0];
|
|
264
|
+
const lastOwn = given[given.length - 1];
|
|
265
|
+
if (!first || !lastOwn || T < first.a0 || T >= lastOwn.a0 + lastOwn.nat)
|
|
266
|
+
return false;
|
|
267
|
+
return !parts.some((part) => T >= part.a0 - EDGE_S && T < part.a0 + part.nat - EDGE_S);
|
|
268
|
+
},
|
|
269
|
+
// Before 0 and past the end it runs on at normal speed: a score's lead-in and tail.
|
|
270
|
+
back(T) {
|
|
271
|
+
if (T < 0)
|
|
272
|
+
return play(T);
|
|
273
|
+
if (T >= filmEnd)
|
|
274
|
+
return play(playEnd + (T - filmEnd));
|
|
275
|
+
const part = find('a0', T);
|
|
276
|
+
if (!part)
|
|
277
|
+
return play(T);
|
|
278
|
+
// In a hidden stretch after a part, the moment is that part's end.
|
|
279
|
+
return play(part.p0 + Math.min(T - part.a0, part.nat) * (part.dur / part.nat));
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* The scenes cut into the pieces `recut.json` splits them into, in film order, each saying whether its first and its
|
|
285
|
+
* last moment are played (not hidden, not trimmed off). A piece after the first is a scene of its own as far as
|
|
286
|
+
* entrances go: it may come on over the piece before it.
|
|
287
|
+
*/
|
|
288
|
+
export function playedPieces(scenes, text) {
|
|
289
|
+
const own = [];
|
|
290
|
+
let at = 0;
|
|
291
|
+
for (const scene of scenes) {
|
|
292
|
+
own.push({ key: scene.id, label: scene.id, a0: film(at), nat: scene.dur });
|
|
293
|
+
at += scene.dur;
|
|
294
|
+
}
|
|
295
|
+
const parts = sceneClock(own, text).parts;
|
|
296
|
+
return splitParts(own, text).flatMap((piece) => {
|
|
297
|
+
if (piece.key === null)
|
|
298
|
+
return [];
|
|
299
|
+
const end = piece.a0 + piece.nat;
|
|
300
|
+
return [
|
|
301
|
+
{
|
|
302
|
+
id: piece.key,
|
|
303
|
+
of: piece.split?.of ?? piece.key,
|
|
304
|
+
a0: piece.a0,
|
|
305
|
+
nat: piece.nat,
|
|
306
|
+
start: parts.some((part) => Math.abs(part.a0 - piece.a0) <= NEAR_S),
|
|
307
|
+
end: parts.some((part) => Math.abs(part.a0 + part.nat - end) <= NEAR_S),
|
|
308
|
+
},
|
|
309
|
+
];
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/** The clock of a film nobody retimed. */
|
|
313
|
+
export function plainClock(duration) {
|
|
314
|
+
return sceneClock(filmParts(duration, [], null), null);
|
|
315
|
+
}
|
|
316
|
+
/** The score is recorded on the film's own time and played on played time; a stretched part's sound slows with it, at the same pitch. */
|
|
317
|
+
export function playedScore(score, clock) {
|
|
318
|
+
return {
|
|
319
|
+
...score,
|
|
320
|
+
events: score.events.filter((event) => !clock.hides(event.t)).map((event) => {
|
|
321
|
+
const t = clock.back(event.t);
|
|
322
|
+
return { ...event, t, dur: Math.max(0.01, clock.back(film(event.t + event.dur)) - t) };
|
|
323
|
+
}),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { PlaySeconds } from '@openartifactsai/motion-core';
|
|
2
|
+
import type { VideoMode } from './video-sync.js';
|
|
3
|
+
/** A render promise that never settled: the frame that waits for it fails for good. */
|
|
4
|
+
export declare class RenderStuck extends Error {
|
|
5
|
+
/** A tab in the background, not the film, may be why. */
|
|
6
|
+
inBackground: boolean;
|
|
7
|
+
constructor(message: string, inBackground: boolean);
|
|
8
|
+
}
|
|
9
|
+
interface Unsettled {
|
|
10
|
+
q: Promise<void>;
|
|
11
|
+
/** A wait has given up on it after its full second. */
|
|
12
|
+
waited: boolean;
|
|
13
|
+
done: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const renderState: {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
error: unknown;
|
|
18
|
+
/** How many renders have been begun. */
|
|
19
|
+
count: number;
|
|
20
|
+
warnedAsync: boolean;
|
|
21
|
+
/** A render of a moment drawn for a look alone (drawOwn) has given a promise in this load. */
|
|
22
|
+
gavePromise: boolean;
|
|
23
|
+
/** The played moment renderAt drew last. */
|
|
24
|
+
drawnAt: PlaySeconds | null;
|
|
25
|
+
};
|
|
26
|
+
export declare const unsettledNow: () => Unsettled[];
|
|
27
|
+
/**
|
|
28
|
+
* null: nothing to wait for. Else settles when the pending renders no wait has given up on have settled, or after
|
|
29
|
+
* a second: a render that stays pending costs the waits one second in all, not one each.
|
|
30
|
+
*/
|
|
31
|
+
export declare function rendersSettle(): Promise<unknown> | null;
|
|
32
|
+
/** One turn of the event loop, by a message: a tab in the background slows timers to a second. */
|
|
33
|
+
export declare function nextTask(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* One moment of the film's own time, drawn for a look at the stage alone. false: the film threw there. null: a
|
|
36
|
+
* render has given a promise in this load, so nothing more is drawn here: a render for another moment that finished
|
|
37
|
+
* late could draw that moment over the frame on show.
|
|
38
|
+
*/
|
|
39
|
+
export declare function drawOwn(T: number): boolean | null;
|
|
40
|
+
/**
|
|
41
|
+
* A sample a draw began (drawOwn) that gave a promise paints its own moment when it settles, after that draw. So what
|
|
42
|
+
* relies on the draw waits for it and has its moment drawn again. before: gavePromise ahead of the draw. again:
|
|
43
|
+
* whether the redraw is still wanted then. null: no such sample; else the redraw's own promise, wrapped so it is
|
|
44
|
+
* handed over as it is, or null where it drew at once or was not wanted.
|
|
45
|
+
*/
|
|
46
|
+
export declare function afterSample(before: boolean, t: PlaySeconds | (() => PlaySeconds), again?: () => boolean): Promise<{
|
|
47
|
+
q: Promise<unknown> | null;
|
|
48
|
+
}> | null;
|
|
49
|
+
/** A fault in laying what a person changed by hand costs their changes, not the film. */
|
|
50
|
+
export declare function unretouched(): void;
|
|
51
|
+
/** Draws played moment `t`. Gives back the render's promise, bounded, if it gave one. */
|
|
52
|
+
export declare function renderAt(t: PlaySeconds): Promise<unknown> | null;
|
|
53
|
+
export declare function syncClips(mode: VideoMode, quick?: boolean): Promise<unknown> | null;
|
|
54
|
+
export declare const busy: {
|
|
55
|
+
framing: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** A turn draws moments of its own: live renders wait until {@link releaseStage}. */
|
|
58
|
+
export declare function holdStage(): void;
|
|
59
|
+
export declare function releaseStage(): void;
|
|
60
|
+
export declare function takeTurn(job: () => Promise<void>): void;
|
|
61
|
+
interface Asked {
|
|
62
|
+
t: PlaySeconds;
|
|
63
|
+
seq: number;
|
|
64
|
+
playing: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The stage shows, still, the moment the page last asked for, with nothing to draw over it: what its words are is
|
|
68
|
+
* worth telling. Not before the page's first render of a load, whose own first frame is at 0.
|
|
69
|
+
*/
|
|
70
|
+
export declare const showsAsked: () => boolean;
|
|
71
|
+
/** The moment the page last asked to see, drawn yet or not. */
|
|
72
|
+
export declare const onShow: () => PlaySeconds;
|
|
73
|
+
export declare const isPlaying: () => boolean;
|
|
74
|
+
export declare const hasPending: () => boolean;
|
|
75
|
+
/** A moment a question drew again is the one on show. */
|
|
76
|
+
export declare const setShown: (t: PlaySeconds) => void;
|
|
77
|
+
export declare function askRender(next: Asked): void;
|
|
78
|
+
/** Draws the moment on show again under the same ask, after a change the film reads, such as the render mode. */
|
|
79
|
+
export declare function redraw(): void;
|
|
80
|
+
export {};
|