alpha2 0.4.6 → 0.5.1
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/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +51 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +125 -176
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +96 -162
- package/dist/frame-supply.js +181 -171
- package/dist/frames.d.ts +23 -0
- package/dist/frames.js +34 -0
- package/dist/generated/project-schema.d.ts +712 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +276 -16
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +82 -67
- package/dist/hdr-frames.js +112 -49
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +48 -63
- package/dist/layout.js +37 -37
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +178 -246
- package/dist/mediabunny.js +781 -583
- package/dist/paint.d.ts +23 -0
- package/dist/paint.js +37 -0
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +74 -118
- package/dist/project.js +384 -445
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +97 -71
- package/dist/text.js +33 -70
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -95
- package/dist/worker.js +235 -143
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +501 -587
- package/wasm/alpha2_wasm.js +661 -616
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +22 -12
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-070d94113471ef0a/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline3.js +0 -0
package/dist/edit.js
CHANGED
|
@@ -1,54 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Document editing operations
|
|
3
|
-
*
|
|
4
|
-
* clip down (insert, overwrite, append), as pure functions from one valid
|
|
5
|
-
* project to another.
|
|
2
|
+
* Document editing operations (split, trim, ripple, roll, slip, slide, retime, move, insert,
|
|
3
|
+
* overwrite, append) as pure functions from one valid project to another.
|
|
6
4
|
*
|
|
7
|
-
* Each
|
|
8
|
-
*
|
|
9
|
-
* new project that passes {@link validateProject}, or a typed error, and never
|
|
10
|
-
* changes its input. History, selection, and snapping stay with the host: a
|
|
11
|
-
* host keeps the projects it has returned to undo.
|
|
5
|
+
* Each returns a new project that passes {@link validateProject}, or a typed error, and never
|
|
6
|
+
* modifies its input. Undo history, selection and snapping are the host's job.
|
|
12
7
|
*
|
|
13
|
-
* Times are ticks. A clip keeps its speed
|
|
14
|
-
*
|
|
15
|
-
* loses the end of its source.
|
|
8
|
+
* Times, deltas and durations are whole ticks (`invalid_time` otherwise). A clip keeps its speed
|
|
9
|
+
* across an edit, so a reversed clip trimmed at its start loses the end of its source.
|
|
16
10
|
*
|
|
17
|
-
* A clip's composition keeps its own time
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* splitting gives the right half a copy of the composition and of the group
|
|
21
|
-
* definitions it draws ({@link copyComposition}), starting where the cut
|
|
22
|
-
* falls in it.
|
|
11
|
+
* A clip's composition keeps its own time: moving a clip moves its animation with it, trimming the
|
|
12
|
+
* start by `delta` adds `delta * scale` to the offset, and splitting gives the right half a copy
|
|
13
|
+
* ({@link copyComposition}).
|
|
23
14
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* (`outside_source`). A source without a recorded length is bounded only at
|
|
27
|
-
* its start.
|
|
15
|
+
* Edits may not read before a source's start or past its fingerprint's `duration_ticks`
|
|
16
|
+
* (`outside_source`).
|
|
28
17
|
*
|
|
29
|
-
* Ripple edits
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* track whose clip, transition, or caption cue lies across the edit point
|
|
33
|
-
* refuses the whole edit (`sync_conflict`): nothing is split or trimmed on a
|
|
34
|
-
* track the edit does not target. So does one where content the edit pulls
|
|
35
|
-
* earlier would land on content that stays.
|
|
18
|
+
* Ripple edits move later content on the edited track and on `syncTracks` by the same amount. A
|
|
19
|
+
* sync track with content across the edit point, or where pulled content would land on content
|
|
20
|
+
* that stays, refuses the whole edit (`sync_conflict`).
|
|
36
21
|
*
|
|
37
|
-
*
|
|
38
|
-
* (`invalid_time`).
|
|
39
|
-
*
|
|
40
|
-
* A batch of edits valid only as a whole runs in {@link deferValidation}, whose caller validates
|
|
41
|
-
* the project it keeps instead of each edit validating its own.
|
|
22
|
+
* Use {@link deferValidation} for a batch of edits that is valid only as a whole.
|
|
42
23
|
*/
|
|
43
24
|
import { validateProject } from "./project.js";
|
|
44
25
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* taken), so editing one half does not edit the other. Refused inside a transition or a fade (a
|
|
50
|
-
* fade is a ramp from the clip's edge, which neither half could continue), for a clip that is
|
|
51
|
-
* another clip's matte, and for a loop.
|
|
26
|
+
* Splits a clip at `at`. The left part keeps the id, incoming transitions and fade in; the right
|
|
27
|
+
* part becomes `newId` with outgoing transitions, fade out, and its own copy of the composition
|
|
28
|
+
* ({@link copyComposition}). Refused inside a transition or fade, for a matte source, and for a
|
|
29
|
+
* loop.
|
|
52
30
|
*/
|
|
53
31
|
export function split(project, clipId, at, newId) {
|
|
54
32
|
const time = notTicks(at, "the split time");
|
|
@@ -80,7 +58,6 @@ export function split(project, clipId, at, newId) {
|
|
|
80
58
|
if (sources === undefined) {
|
|
81
59
|
return failure("unsupported_time_map", `a loop cannot be split`);
|
|
82
60
|
}
|
|
83
|
-
// The fade in stays at the clip's start, the fade out at its end.
|
|
84
61
|
const audio = clip.audio;
|
|
85
62
|
const left = {
|
|
86
63
|
...clip,
|
|
@@ -122,9 +99,8 @@ export function split(project, clipId, at, newId) {
|
|
|
122
99
|
}));
|
|
123
100
|
}
|
|
124
101
|
/**
|
|
125
|
-
* Moves one edge of a clip to `to`, keeping
|
|
126
|
-
*
|
|
127
|
-
* source (`outside_source`); a loop's start cannot move.
|
|
102
|
+
* Moves one edge of a clip to `to`, keeping its speed. Refused for an edge in a transition, before
|
|
103
|
+
* the timeline start, past the source (`outside_source`), or at a loop's start.
|
|
128
104
|
*/
|
|
129
105
|
export function trim(project, clipId, edge, to) {
|
|
130
106
|
const time = notTicks(to, "the trim time");
|
|
@@ -136,11 +112,8 @@ export function trim(project, clipId, edge, to) {
|
|
|
136
112
|
return finish(replaceClip(project, trimmed.track, trimmed.clip));
|
|
137
113
|
}
|
|
138
114
|
/**
|
|
139
|
-
* Trims like {@link trim} and
|
|
140
|
-
*
|
|
141
|
-
* Trimming the start keeps the clip's start in place and moves its end, so
|
|
142
|
-
* `to` may be before the timeline's start: the head grows by as much as the
|
|
143
|
-
* source has before it.
|
|
115
|
+
* Trims like {@link trim} and shifts later clips on the track by the same amount. A start trim
|
|
116
|
+
* keeps the clip's start in place, so `to` may be before the timeline start.
|
|
144
117
|
*/
|
|
145
118
|
export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
146
119
|
const time = notTicks(to, "the trim time");
|
|
@@ -157,7 +130,7 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
157
130
|
delta = to - before.end;
|
|
158
131
|
}
|
|
159
132
|
else {
|
|
160
|
-
//
|
|
133
|
+
// Trim the head, then slide the clip back to its original start.
|
|
161
134
|
delta = before.start - to;
|
|
162
135
|
edited = shift(clip, delta);
|
|
163
136
|
}
|
|
@@ -180,9 +153,8 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
180
153
|
}));
|
|
181
154
|
}
|
|
182
155
|
/**
|
|
183
|
-
* Removes a clip and its transitions
|
|
184
|
-
*
|
|
185
|
-
* matte, and when a track in `syncTracks` has content in that time.
|
|
156
|
+
* Removes a clip and its transitions and closes the gap ({@link rippleDeleteSpan}). Refused for a
|
|
157
|
+
* matte source, and when a sync track has content in that span.
|
|
186
158
|
*/
|
|
187
159
|
export function rippleDelete(project, clipId, options = {}) {
|
|
188
160
|
const found = locate(project, clipId);
|
|
@@ -205,7 +177,6 @@ export function rippleDelete(project, clipId, options = {}) {
|
|
|
205
177
|
.map((transition) => transition.timeline_range.start >= range.start
|
|
206
178
|
? shiftTransition(transition, delta)
|
|
207
179
|
: transition);
|
|
208
|
-
// The time the clip frees must be empty on the tracks that close it too.
|
|
209
180
|
for (const other of syncTracksOf(project, options.syncTracks, track.id))
|
|
210
181
|
if (occupies(other, gap))
|
|
211
182
|
return failure("sync_conflict", `track ${other.id} has content in the time the delete closes`);
|
|
@@ -215,11 +186,9 @@ export function rippleDelete(project, clipId, options = {}) {
|
|
|
215
186
|
return finish(replaceTrack(synced.project, { ...track, clips, transitions }));
|
|
216
187
|
}
|
|
217
188
|
/**
|
|
218
|
-
* The
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* `undefined` for an unknown clip. A host moving its own timeline items (markers) with the delete
|
|
222
|
-
* moves those from `start` on back by its length.
|
|
189
|
+
* The span {@link rippleDelete} closes: the part of the clip's span no other clip on its track
|
|
190
|
+
* shares. Empty when fully covered; `undefined` for an unknown clip. Hosts can use it to move their
|
|
191
|
+
* own timeline items, such as markers.
|
|
223
192
|
*/
|
|
224
193
|
export function rippleDeleteSpan(project, clipId) {
|
|
225
194
|
const found = locate(project, clipId);
|
|
@@ -241,10 +210,8 @@ function aloneSpan(track, clip) {
|
|
|
241
210
|
return { start, end: Math.max(start, end) };
|
|
242
211
|
}
|
|
243
212
|
/**
|
|
244
|
-
* Moves the cut between
|
|
245
|
-
*
|
|
246
|
-
* span what they did. Refused unless the clips meet, when a transition joins them, and when the cut
|
|
247
|
-
* would empty either.
|
|
213
|
+
* Moves the cut between adjacent clips `leftId` and `rightId` to `at`, each keeping its speed.
|
|
214
|
+
* Refused unless they meet, when a transition joins them, or when either would become empty.
|
|
248
215
|
*/
|
|
249
216
|
export function rollTrim(project, leftId, rightId, at) {
|
|
250
217
|
const time = notTicks(at, "the cut");
|
|
@@ -279,10 +246,7 @@ export function rollTrim(project, leftId, rightId, at) {
|
|
|
279
246
|
: candidate),
|
|
280
247
|
}));
|
|
281
248
|
}
|
|
282
|
-
/**
|
|
283
|
-
* How far {@link slip} may move a clip's source window, in source ticks: to the source's start one
|
|
284
|
-
* way and to its recorded end the other (unbounded without one).
|
|
285
|
-
*/
|
|
249
|
+
/** Source-tick range {@link slip} allows, bounded by the source's start and recorded end. */
|
|
286
250
|
export function slipLimits(project, clipId) {
|
|
287
251
|
const found = locate(project, clipId);
|
|
288
252
|
if (!found.ok)
|
|
@@ -298,9 +262,8 @@ export function slipLimits(project, clipId) {
|
|
|
298
262
|
};
|
|
299
263
|
}
|
|
300
264
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* composition stay. Refused past the source's start or recorded end.
|
|
265
|
+
* Moves a clip's source window (or a frozen clip's instant) by `delta` source ticks, leaving its
|
|
266
|
+
* timeline placement unchanged. Refused past the source's start or recorded end.
|
|
304
267
|
*/
|
|
305
268
|
export function slip(project, clipId, delta) {
|
|
306
269
|
const time = notTicks(delta, "the slip");
|
|
@@ -326,11 +289,9 @@ export function slip(project, clipId, delta) {
|
|
|
326
289
|
}));
|
|
327
290
|
}
|
|
328
291
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* there, a loop's start); refused (`in_transition`) for a clip in a transition, which slide never
|
|
333
|
-
* moves.
|
|
292
|
+
* Timeline-tick range {@link slide} allows, limited by neighbours becoming empty, reading outside
|
|
293
|
+
* their source or uncovering a transition, and by content across a gap. Only 0 when a neighbour's
|
|
294
|
+
* edge cannot move; refused (`in_transition`) for a clip in a transition.
|
|
334
295
|
*/
|
|
335
296
|
export function slideLimits(project, clipId) {
|
|
336
297
|
const found = locate(project, clipId);
|
|
@@ -347,7 +308,7 @@ export function slideLimits(project, clipId) {
|
|
|
347
308
|
const edges = transitionsOf(track, left.id).map((t) => t.timeline_range);
|
|
348
309
|
if (edges.some((t) => t.end >= left.timeline_range.end))
|
|
349
310
|
return { ok: true, min: 0, max: 0 };
|
|
350
|
-
//
|
|
311
|
+
// The left neighbour's end may not pass back over its transitions.
|
|
351
312
|
min = Math.max(min, left.timeline_range.start + 1 - range.start, ...edges.map((t) => t.end - range.start));
|
|
352
313
|
const room = extensionRoom(project, left, "end");
|
|
353
314
|
if (room !== undefined)
|
|
@@ -366,12 +327,9 @@ export function slideLimits(project, clipId) {
|
|
|
366
327
|
return { ok: true, min, max };
|
|
367
328
|
}
|
|
368
329
|
/**
|
|
369
|
-
* Moves a clip by `delta
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* gap the clip moves into or leaves. The clip keeps its source window, keyframes (moved with it),
|
|
373
|
-
* and composition. Refused in a transition, when a neighbour would be empty or read outside its
|
|
374
|
-
* source, and past the content across a gap.
|
|
330
|
+
* Moves a clip by `delta`, trimming the adjacent neighbours so the total span is unchanged; a side
|
|
331
|
+
* without an adjacent clip is a gap. The clip keeps its source window and composition. Refused
|
|
332
|
+
* within the limits described by {@link slideLimits}.
|
|
375
333
|
*/
|
|
376
334
|
export function slide(project, clipId, delta) {
|
|
377
335
|
const time = notTicks(delta, "the slide");
|
|
@@ -407,10 +365,9 @@ export function slide(project, clipId, delta) {
|
|
|
407
365
|
}));
|
|
408
366
|
}
|
|
409
367
|
/**
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* passes. Refused when the clip's end is in a transition.
|
|
368
|
+
* Sets a clip's timeline length to `duration`. Forward and reversed clips change speed to fit the
|
|
369
|
+
* same source window; frozen clips hold longer or shorter; loops play more or fewer passes.
|
|
370
|
+
* Refused when the clip's end is in a transition.
|
|
414
371
|
*/
|
|
415
372
|
export function retime(project, clipId, duration, options = {}) {
|
|
416
373
|
const found = locate(project, clipId);
|
|
@@ -485,10 +442,8 @@ export function retime(project, clipId, duration, options = {}) {
|
|
|
485
442
|
}));
|
|
486
443
|
}
|
|
487
444
|
/**
|
|
488
|
-
*
|
|
489
|
-
* `
|
|
490
|
-
* its right part is `splitId`. Refused (`needs_id`) when more than one clip is across `at`, as
|
|
491
|
-
* overlapping audio clips can be.
|
|
445
|
+
* Inserts `clip` at `at`, pushing later content on the track and `syncTracks` by its length. A clip
|
|
446
|
+
* across `at` is split first, its right part becoming `splitId`; `needs_id` when more than one is.
|
|
492
447
|
*/
|
|
493
448
|
export function insert(project, trackId, clip, at, options = {}) {
|
|
494
449
|
const placed = placeAt(project, trackId, clip, at);
|
|
@@ -523,11 +478,10 @@ export function insert(project, trackId, clip, at, options = {}) {
|
|
|
523
478
|
}));
|
|
524
479
|
}
|
|
525
480
|
/**
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
* both edges.
|
|
481
|
+
* Places `clip` at `at`, replacing whatever the track shows there. Clips inside are removed, clips
|
|
482
|
+
* across an edge are trimmed, and a clip across both is split (right part `splitId`). Refused where
|
|
483
|
+
* a transition or matte source would be cut, and (`needs_id`) when more than one clip spans both
|
|
484
|
+
* edges.
|
|
531
485
|
*/
|
|
532
486
|
export function overwrite(project, trackId, clip, at, options = {}) {
|
|
533
487
|
const placed = placeAt(project, trackId, clip, at);
|
|
@@ -573,7 +527,7 @@ export function overwrite(project, trackId, clip, at, options = {}) {
|
|
|
573
527
|
clips.push(placed.clip);
|
|
574
528
|
return finish(replaceTrack(edited, { ...track, clips }));
|
|
575
529
|
}
|
|
576
|
-
/**
|
|
530
|
+
/** Places `clip` after the track's last clip, or at 0. */
|
|
577
531
|
export function append(project, trackId, clip) {
|
|
578
532
|
const track = project.timeline.tracks.find((t) => t.id === trackId);
|
|
579
533
|
if (!track)
|
|
@@ -581,10 +535,7 @@ export function append(project, trackId, clip) {
|
|
|
581
535
|
const end = Math.max(0, ...(track.clips ?? []).map((c) => c.timeline_range.end));
|
|
582
536
|
return overwrite(project, trackId, clip, end);
|
|
583
537
|
}
|
|
584
|
-
/**
|
|
585
|
-
* `clip` placed at `at` on track `trackId`, keeping its length, after the checks every placement
|
|
586
|
-
* makes.
|
|
587
|
-
*/
|
|
538
|
+
/** Places `clip` at `at` after the checks every placement makes. */
|
|
588
539
|
function placeAt(project, trackId, clip, at) {
|
|
589
540
|
const track = project.timeline.tracks.find((t) => t.id === trackId);
|
|
590
541
|
if (!track)
|
|
@@ -622,8 +573,8 @@ function occupies(track, range) {
|
|
|
622
573
|
(track.captions?.cues ?? []).some((c) => meets(c.timeline_range)));
|
|
623
574
|
}
|
|
624
575
|
/**
|
|
625
|
-
*
|
|
626
|
-
*
|
|
576
|
+
* Shifts content from `pivot` on by `delta` on tracks `ids` other than `edited`; refuses when one
|
|
577
|
+
* has content across `pivot`.
|
|
627
578
|
*/
|
|
628
579
|
function rippleSyncTracks(project, ids, edited, pivot, delta) {
|
|
629
580
|
if (delta === 0)
|
|
@@ -659,10 +610,8 @@ function rippleSyncTracks(project, ids, edited, pivot, delta) {
|
|
|
659
610
|
return { ok: true, project: result };
|
|
660
611
|
}
|
|
661
612
|
/**
|
|
662
|
-
* Whether
|
|
663
|
-
*
|
|
664
|
-
* content apart before the edit would overlap or change order. Content that already overlapped
|
|
665
|
-
* (audio clips may) is left as it was. `except` is the edited clip, which the edit itself shortens.
|
|
613
|
+
* Whether shifting content from `pivot` on by `delta` would make previously separate content
|
|
614
|
+
* overlap or reorder. Pre-existing overlaps are ignored; `except` is the edited clip.
|
|
666
615
|
*/
|
|
667
616
|
function pullsOnto(track, pivot, delta, except) {
|
|
668
617
|
if (delta >= 0)
|
|
@@ -683,7 +632,7 @@ function pullsOnto(track, pivot, delta, except) {
|
|
|
683
632
|
return spans.some((r) => {
|
|
684
633
|
if (r.start < pivot)
|
|
685
634
|
return false;
|
|
686
|
-
//
|
|
635
|
+
// Find the first end after the landing point; it collides if that end is not after `r.start`.
|
|
687
636
|
let low = 0;
|
|
688
637
|
let high = ends.length;
|
|
689
638
|
while (low < high) {
|
|
@@ -699,24 +648,22 @@ function pullsOnto(track, pivot, delta, except) {
|
|
|
699
648
|
function pulledOnto(track) {
|
|
700
649
|
return failure("sync_conflict", `track ${track.id} has content the edit would pull onto content that stays`);
|
|
701
650
|
}
|
|
702
|
-
/** Moves a clip to start at `to
|
|
651
|
+
/** Moves a clip to start at `to`. Refused while in a transition. */
|
|
703
652
|
export function move(project, clipId, to) {
|
|
704
653
|
const moved = relocate(project, { clip: clipId, to });
|
|
705
654
|
return moved.ok ? finish(moved.project) : moved;
|
|
706
655
|
}
|
|
707
656
|
/**
|
|
708
|
-
* Moves a clip to another track,
|
|
709
|
-
*
|
|
657
|
+
* Moves a clip to another track, at `to` or its current start. Refused while in a transition or
|
|
658
|
+
* onto an incompatible track.
|
|
710
659
|
*/
|
|
711
660
|
export function moveToTrack(project, clipId, trackId, to) {
|
|
712
661
|
const moved = relocate(project, { clip: clipId, track: trackId, to });
|
|
713
662
|
return moved.ok ? finish(moved.project) : moved;
|
|
714
663
|
}
|
|
715
664
|
/**
|
|
716
|
-
* Moves several clips at once
|
|
717
|
-
*
|
|
718
|
-
* as one whatever order its moves come in. Refused for a clip listed twice (`duplicate_id`), and
|
|
719
|
-
* wherever one of the moves alone is refused.
|
|
665
|
+
* Moves several clips at once. Only the final result is checked, so the order of moves does not
|
|
666
|
+
* matter. Refused for a clip listed twice (`duplicate_id`) or wherever a single move would be.
|
|
720
667
|
*/
|
|
721
668
|
export function moveClips(project, moves) {
|
|
722
669
|
const moved = new Set();
|
|
@@ -733,7 +680,7 @@ export function moveClips(project, moves) {
|
|
|
733
680
|
}
|
|
734
681
|
return finish(edited);
|
|
735
682
|
}
|
|
736
|
-
/**
|
|
683
|
+
/** Moves one clip without validating the whole project. */
|
|
737
684
|
function relocate(project, { clip: clipId, to, track: trackId }) {
|
|
738
685
|
const time = notTicks(to, "the move target");
|
|
739
686
|
if (time)
|
|
@@ -786,21 +733,18 @@ function locate(project, clipId) {
|
|
|
786
733
|
function failure(code, message) {
|
|
787
734
|
return { ok: false, error: { code, message } };
|
|
788
735
|
}
|
|
789
|
-
/**
|
|
736
|
+
/** Refuses a provided time argument that is not whole ticks. */
|
|
790
737
|
function notTicks(value, what) {
|
|
791
738
|
if (value === undefined || Number.isSafeInteger(value))
|
|
792
739
|
return undefined;
|
|
793
740
|
return failure("invalid_time", `${what} ${value} is not a whole number of ticks`);
|
|
794
741
|
}
|
|
795
|
-
/**
|
|
742
|
+
/** Nesting depth of {@link deferValidation}. */
|
|
796
743
|
let deferring = 0;
|
|
797
744
|
/**
|
|
798
|
-
* Runs `run
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
* keeps. For a batch of edits valid only as a whole, such as an editor transaction, which then pays
|
|
802
|
-
* for one validation instead of one per edit. `run` is synchronous; nested calls and a throw end
|
|
803
|
-
* the deferral where they began.
|
|
745
|
+
* Runs `run` with {@link validateProject} skipped after each edit. Edits still apply their own
|
|
746
|
+
* checks (`sync_conflict`, `outside_source`, ...); the caller validates the final project. `run` is
|
|
747
|
+
* synchronous and may nest.
|
|
804
748
|
*/
|
|
805
749
|
export function deferValidation(run) {
|
|
806
750
|
deferring += 1;
|
|
@@ -827,15 +771,14 @@ function finish(project) {
|
|
|
827
771
|
}
|
|
828
772
|
return { ok: true, project };
|
|
829
773
|
}
|
|
830
|
-
/**
|
|
774
|
+
/** Source length in ticks from its fingerprint, if recorded. */
|
|
831
775
|
function sourceLength(project, sourceId) {
|
|
832
776
|
const source = project.sources.find((candidate) => candidate.id === sourceId);
|
|
833
777
|
return source?.fingerprint?.duration_ticks ?? undefined;
|
|
834
778
|
}
|
|
835
779
|
/**
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
* shorten a clip that already reads past a source found shorter than it was.
|
|
780
|
+
* Refuses a `range` outside the source. With `before`, only an edge that moves further outside is
|
|
781
|
+
* refused, so a clip already past a shorter source can still be shortened.
|
|
839
782
|
*/
|
|
840
783
|
function outsideSource(project, sourceId, range, before) {
|
|
841
784
|
const length = sourceLength(project, sourceId);
|
|
@@ -848,9 +791,8 @@ function outsideSource(project, sourceId, range, before) {
|
|
|
848
791
|
return undefined;
|
|
849
792
|
}
|
|
850
793
|
/**
|
|
851
|
-
*
|
|
852
|
-
*
|
|
853
|
-
* `after` where the content after it starts.
|
|
794
|
+
* Adjacent clips (`left`, `right`) and the nearest content edges on either side (`before`,
|
|
795
|
+
* `after`).
|
|
854
796
|
*/
|
|
855
797
|
function neighbours(track, clip) {
|
|
856
798
|
const range = clip.timeline_range;
|
|
@@ -874,17 +816,14 @@ function neighbours(track, clip) {
|
|
|
874
816
|
after,
|
|
875
817
|
};
|
|
876
818
|
}
|
|
877
|
-
/**
|
|
878
|
-
* How many timeline ticks `clip` can grow at `edge` before it reads outside its source, at its
|
|
879
|
-
* speed; `undefined` when unbounded.
|
|
880
|
-
*/
|
|
819
|
+
/** Timeline ticks `clip` can grow at `edge` before leaving its source; `undefined` if unbounded. */
|
|
881
820
|
function extensionRoom(project, clip, edge) {
|
|
882
821
|
const map = clip.time_map ?? { type: "forward" };
|
|
883
822
|
if (map.type === "freeze" || map.type === "loop")
|
|
884
823
|
return undefined;
|
|
885
824
|
const source = clip.source_range;
|
|
886
825
|
const timeline = clip.timeline_range;
|
|
887
|
-
//
|
|
826
|
+
// A reversed clip's end reads its source start.
|
|
888
827
|
const readsStart = (edge === "start") === (map.type === "forward");
|
|
889
828
|
const available = readsStart
|
|
890
829
|
? source.start
|
|
@@ -894,13 +833,10 @@ function extensionRoom(project, clip, edge) {
|
|
|
894
833
|
})();
|
|
895
834
|
if (available === undefined)
|
|
896
835
|
return undefined;
|
|
897
|
-
//
|
|
836
|
+
// floor(available * T / S).
|
|
898
837
|
return stretched(available, timeline.end - timeline.start, source.end - source.start);
|
|
899
838
|
}
|
|
900
|
-
/**
|
|
901
|
-
* `value` with every keyframe time `t` of every animated value in it moved to `start + floor((t -
|
|
902
|
-
* start) * to / from)`: stretched from `start` by `to / from`.
|
|
903
|
-
*/
|
|
839
|
+
/** Maps every keyframe time `t` to `start + floor((t - start) * to / from)`. */
|
|
904
840
|
function stretchKeyframes(value, start, to, from) {
|
|
905
841
|
if (Array.isArray(value))
|
|
906
842
|
return value.map((item) => stretchKeyframes(item, start, to, from));
|
|
@@ -923,12 +859,11 @@ function stretchKeyframes(value, start, to, from) {
|
|
|
923
859
|
stretchKeyframes(field, start, to, from),
|
|
924
860
|
]));
|
|
925
861
|
}
|
|
926
|
-
/**
|
|
862
|
+
/** Largest term a composition time scale may hold. */
|
|
927
863
|
const MAX_SCALE_TERM = 0xffff_ffff;
|
|
928
864
|
/**
|
|
929
|
-
* `scale * from / to` in lowest terms
|
|
930
|
-
*
|
|
931
|
-
* fraction of a tick.
|
|
865
|
+
* `scale * from / to` in lowest terms, or the closest convergent whose terms fit
|
|
866
|
+
* {@link MAX_SCALE_TERM}.
|
|
932
867
|
*/
|
|
933
868
|
function rescaled(scale, from, to) {
|
|
934
869
|
let num = BigInt(scale.num) * BigInt(from);
|
|
@@ -984,27 +919,21 @@ function replaceClip(project, track, clip) {
|
|
|
984
919
|
function offset(range, delta) {
|
|
985
920
|
return { start: range.start + delta, end: range.end + delta };
|
|
986
921
|
}
|
|
987
|
-
/**
|
|
988
|
-
* A clip moved by `delta` on the timeline. Keyframe times are timeline times, so its animations
|
|
989
|
-
* move with it. Its composition keeps its own time, and so is left as it is.
|
|
990
|
-
*/
|
|
922
|
+
/** Moves a clip and its keyframes by `delta`; the composition keeps its own time. */
|
|
991
923
|
function shift(clip, delta) {
|
|
992
924
|
return {
|
|
993
925
|
...shiftKeyframes(clip, delta),
|
|
994
926
|
timeline_range: offset(clip.timeline_range, delta),
|
|
995
927
|
};
|
|
996
928
|
}
|
|
997
|
-
/**
|
|
929
|
+
/** Moves a transition and its keyframes by `delta`. */
|
|
998
930
|
function shiftTransition(transition, delta) {
|
|
999
931
|
return {
|
|
1000
932
|
...shiftKeyframes(transition, delta),
|
|
1001
933
|
timeline_range: offset(transition.timeline_range, delta),
|
|
1002
934
|
};
|
|
1003
935
|
}
|
|
1004
|
-
/**
|
|
1005
|
-
* `value` with the time of every keyframe of every animated value in it moved by `delta`: whatever
|
|
1006
|
-
* fields are animated, now or later.
|
|
1007
|
-
*/
|
|
936
|
+
/** Moves every keyframe time in `value` by `delta`, whatever fields are animated. */
|
|
1008
937
|
function shiftKeyframes(value, delta) {
|
|
1009
938
|
if (delta === 0)
|
|
1010
939
|
return value;
|
|
@@ -1038,9 +967,8 @@ function shiftTransitions(track, from, delta) {
|
|
|
1038
967
|
: transition);
|
|
1039
968
|
}
|
|
1040
969
|
/**
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
* is negative for a time before the clip, where a trim extends it.
|
|
970
|
+
* `floor(elapsed * S / T)` in exact integer arithmetic, matching the engine. `elapsed` may be
|
|
971
|
+
* negative for a trim that extends the clip.
|
|
1044
972
|
*/
|
|
1045
973
|
function stretched(elapsed, source, timeline) {
|
|
1046
974
|
const numerator = BigInt(elapsed) * BigInt(source);
|
|
@@ -1049,7 +977,7 @@ function stretched(elapsed, source, timeline) {
|
|
|
1049
977
|
// BigInt division truncates toward zero; below zero, floor is one less.
|
|
1050
978
|
return Number(numerator % denominator < 0n ? quotient - 1n : quotient);
|
|
1051
979
|
}
|
|
1052
|
-
/**
|
|
980
|
+
/** Source ranges of a clip's two halves at `at`, or `undefined` for a loop. */
|
|
1053
981
|
function splitSource(clip, at) {
|
|
1054
982
|
const timeline = clip.timeline_range;
|
|
1055
983
|
const source = clip.source_range;
|
|
@@ -1080,9 +1008,8 @@ function splitSource(clip, at) {
|
|
|
1080
1008
|
}
|
|
1081
1009
|
}
|
|
1082
1010
|
/**
|
|
1083
|
-
* Clip `clipId` with
|
|
1084
|
-
*
|
|
1085
|
-
* timeline's start.
|
|
1011
|
+
* Clip `clipId` with `edge` moved to `to` at its speed, or a refusal. With `ripple`, a start trim
|
|
1012
|
+
* slides back afterwards, so `to` may precede the timeline start.
|
|
1086
1013
|
*/
|
|
1087
1014
|
function trimmedClip(project, clipId, edge, to, ripple = false) {
|
|
1088
1015
|
const found = locate(project, clipId);
|
|
@@ -1127,10 +1054,7 @@ function trimmedClip(project, clipId, edge, to, ripple = false) {
|
|
|
1127
1054
|
},
|
|
1128
1055
|
};
|
|
1129
1056
|
}
|
|
1130
|
-
/**
|
|
1131
|
-
* A composition reference for a clip whose start moved `delta` ticks later (earlier when negative):
|
|
1132
|
-
* its offset moves by `delta * scale`, rounded down as the engine maps composition time.
|
|
1133
|
-
*/
|
|
1057
|
+
/** Advances a composition offset by `delta * scale`, rounded down as the engine does. */
|
|
1134
1058
|
function advance(reference, delta) {
|
|
1135
1059
|
if (delta === 0)
|
|
1136
1060
|
return reference;
|
|
@@ -1139,16 +1063,12 @@ function advance(reference, delta) {
|
|
|
1139
1063
|
return { ...reference, offset };
|
|
1140
1064
|
}
|
|
1141
1065
|
/**
|
|
1142
|
-
* `
|
|
1143
|
-
*
|
|
1144
|
-
*
|
|
1145
|
-
*
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1148
|
-
* definition drawn twice in it is copied once. Composition sources are Library items, shown as
|
|
1149
|
-
* media are, and stay shared. `from` holds the compositions to copy, by default the project's own;
|
|
1150
|
-
* a host pasting a clip whose composition the project no longer has passes those it kept. Returns
|
|
1151
|
-
* the copy's id, and the id of each copy by its original's.
|
|
1066
|
+
* Copies composition `id` and every group definition it draws (recursively) so clip `clipId` can
|
|
1067
|
+
* be edited independently. Copies take the first free id of `<root>~<clipId>`, `<root>~<clipId>~2`
|
|
1068
|
+
* and so on, where `<root>` is the original's id up to its first `~` after the first character, so
|
|
1069
|
+
* repeated splits do not grow ids. Composition sources stay shared. `from` supplies the
|
|
1070
|
+
* compositions to copy (default: the project's), for pasting a clip whose composition was removed.
|
|
1071
|
+
* Returns the copy's id and a map from original to copy ids.
|
|
1152
1072
|
*/
|
|
1153
1073
|
export function copyComposition(project, id, clipId, from = project.compositions ?? []) {
|
|
1154
1074
|
const originals = new Map(from.map((composition) => [composition.id, composition]));
|
|
@@ -1198,9 +1118,8 @@ export function copyComposition(project, id, clipId, from = project.compositions
|
|
|
1198
1118
|
};
|
|
1199
1119
|
}
|
|
1200
1120
|
/**
|
|
1201
|
-
*
|
|
1202
|
-
* start would move.
|
|
1203
|
-
* edge's timeline time, as a split cuts it, so the edge the trim leaves stays exactly in place.
|
|
1121
|
+
* Source range of a clip trimmed to `start..end` at its own speed, or `undefined` when a loop's
|
|
1122
|
+
* start would move. Edges are mapped as a split maps them, so the untouched edge stays exact.
|
|
1204
1123
|
*/
|
|
1205
1124
|
function trimmedSource(clip, start, end) {
|
|
1206
1125
|
const timeline = clip.timeline_range;
|
|
@@ -1208,7 +1127,6 @@ function trimmedSource(clip, start, end) {
|
|
|
1208
1127
|
const length = timeline.end - timeline.start;
|
|
1209
1128
|
const sourceLength = source.end - source.start;
|
|
1210
1129
|
const map = clip.time_map ?? { type: "forward" };
|
|
1211
|
-
// The source instant `elapsed` timeline ticks past the clip's start.
|
|
1212
1130
|
const at = (elapsed) => source.start + stretched(elapsed, sourceLength, length);
|
|
1213
1131
|
switch (map.type) {
|
|
1214
1132
|
case "forward":
|
|
@@ -1217,7 +1135,7 @@ function trimmedSource(clip, start, end) {
|
|
|
1217
1135
|
end: at(end - timeline.start),
|
|
1218
1136
|
};
|
|
1219
1137
|
case "reverse":
|
|
1220
|
-
//
|
|
1138
|
+
// Reversed: the timeline end plays the source start.
|
|
1221
1139
|
return { start: at(timeline.end - end), end: at(timeline.end - start) };
|
|
1222
1140
|
case "freeze":
|
|
1223
1141
|
return source;
|