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.
Files changed (123) hide show
  1. package/README.md +5 -4
  2. package/THIRD_PARTY_NOTICES.md +4 -0
  3. package/dist/abort.d.ts +12 -0
  4. package/dist/abort.js +48 -0
  5. package/dist/active-clock.d.ts +35 -0
  6. package/dist/active-clock.js +99 -0
  7. package/dist/assets.d.ts +51 -22
  8. package/dist/assets.js +8 -12
  9. package/dist/audio-layout.d.ts +52 -74
  10. package/dist/audio-layout.js +114 -148
  11. package/dist/audio-timeline.d.ts +89 -117
  12. package/dist/audio-timeline.js +102 -118
  13. package/dist/audio-worker.d.ts +12 -21
  14. package/dist/audio-worker.js +8 -13
  15. package/dist/audio-worklet-processor.js +45 -58
  16. package/dist/audio-worklet.d.ts +45 -76
  17. package/dist/audio-worklet.js +44 -79
  18. package/dist/audio.d.ts +15 -23
  19. package/dist/audio.js +9 -13
  20. package/dist/builder.d.ts +45 -63
  21. package/dist/builder.js +49 -45
  22. package/dist/capabilities.d.ts +99 -16
  23. package/dist/capabilities.js +2 -2
  24. package/dist/captions.d.ts +45 -22
  25. package/dist/captions.js +60 -15
  26. package/dist/chroma-siting.d.ts +24 -41
  27. package/dist/chroma-siting.js +38 -71
  28. package/dist/containers.d.ts +41 -30
  29. package/dist/containers.js +59 -27
  30. package/dist/decoder-fallback.d.ts +13 -0
  31. package/dist/decoder-fallback.js +38 -0
  32. package/dist/decoder-order.d.ts +24 -39
  33. package/dist/decoder-order.js +28 -42
  34. package/dist/edit.d.ts +77 -154
  35. package/dist/edit.js +98 -180
  36. package/dist/effects.d.ts +125 -176
  37. package/dist/effects.js +7 -9
  38. package/dist/export-destination.d.ts +25 -41
  39. package/dist/export-destination.js +20 -32
  40. package/dist/export-failure.d.ts +34 -59
  41. package/dist/export-failure.js +54 -48
  42. package/dist/export-metrics.d.ts +116 -0
  43. package/dist/export-metrics.js +74 -0
  44. package/dist/export-retry.d.ts +46 -29
  45. package/dist/export-retry.js +86 -51
  46. package/dist/exporter.d.ts +67 -116
  47. package/dist/exporter.js +133 -133
  48. package/dist/extensions.d.ts +69 -115
  49. package/dist/extensions.js +55 -82
  50. package/dist/frame-intake.d.ts +92 -0
  51. package/dist/frame-intake.js +114 -0
  52. package/dist/frame-supply.d.ts +96 -162
  53. package/dist/frame-supply.js +181 -171
  54. package/dist/frames.d.ts +23 -0
  55. package/dist/frames.js +34 -0
  56. package/dist/generated/project-schema.d.ts +712 -485
  57. package/dist/generated/project-schema.js +55 -2
  58. package/dist/generated/project-shape.js +276 -16
  59. package/dist/geometry.d.ts +28 -34
  60. package/dist/geometry.js +18 -23
  61. package/dist/gpu-recovery.d.ts +92 -0
  62. package/dist/gpu-recovery.js +135 -0
  63. package/dist/hdr-frames.d.ts +82 -67
  64. package/dist/hdr-frames.js +112 -49
  65. package/dist/index.d.ts +6 -0
  66. package/dist/index.js +6 -0
  67. package/dist/json-text.d.ts +13 -23
  68. package/dist/json-text.js +10 -20
  69. package/dist/layout-values.d.ts +14 -22
  70. package/dist/layout-values.js +18 -21
  71. package/dist/layout.d.ts +48 -63
  72. package/dist/layout.js +37 -37
  73. package/dist/loudness.d.ts +27 -32
  74. package/dist/loudness.js +19 -23
  75. package/dist/media.d.ts +85 -237
  76. package/dist/media.js +133 -287
  77. package/dist/mediabunny.d.ts +178 -246
  78. package/dist/mediabunny.js +781 -583
  79. package/dist/paint.d.ts +23 -0
  80. package/dist/paint.js +37 -0
  81. package/dist/physical-frames.d.ts +5 -17
  82. package/dist/physical-frames.js +4 -11
  83. package/dist/player.d.ts +56 -47
  84. package/dist/player.js +155 -40
  85. package/dist/presented-frames.d.ts +2 -7
  86. package/dist/presented-frames.js +3 -8
  87. package/dist/project.d.ts +74 -118
  88. package/dist/project.js +384 -445
  89. package/dist/rate-control.d.ts +9 -23
  90. package/dist/rate-control.js +7 -18
  91. package/dist/renderer-choice.d.ts +41 -0
  92. package/dist/renderer-choice.js +82 -0
  93. package/dist/repacked-bytes.d.ts +0 -2
  94. package/dist/repacked-bytes.js +2 -5
  95. package/dist/robustness.d.ts +25 -37
  96. package/dist/robustness.js +71 -54
  97. package/dist/sha256.d.ts +5 -13
  98. package/dist/sha256.js +9 -24
  99. package/dist/text.d.ts +97 -71
  100. package/dist/text.js +33 -70
  101. package/dist/video-frames.d.ts +7 -25
  102. package/dist/video-frames.js +12 -29
  103. package/dist/waveform.d.ts +5 -11
  104. package/dist/waveform.js +4 -9
  105. package/dist/worker-error.d.ts +5 -20
  106. package/dist/worker-error.js +8 -25
  107. package/dist/worker.d.ts +82 -95
  108. package/dist/worker.js +235 -143
  109. package/package.json +26 -2
  110. package/wasm/alpha2_audio_worklet.wasm +0 -0
  111. package/wasm/alpha2_extensions.d.ts +26 -47
  112. package/wasm/alpha2_extensions.js +26 -47
  113. package/wasm/alpha2_extensions_bg.wasm +0 -0
  114. package/wasm/alpha2_wasm.d.ts +501 -587
  115. package/wasm/alpha2_wasm.js +661 -616
  116. package/wasm/alpha2_wasm_bg.wasm +0 -0
  117. package/wasm/alpha2_wasm_bg.wasm.d.ts +22 -12
  118. package/wasm/rust-crate-licenses.md +2 -2
  119. package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline1.js +1 -0
  120. package/wasm/snippets/alpha2-wasm-070d94113471ef0a/inline2.js +82 -0
  121. package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
  122. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline0.js +0 -0
  123. /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline3.js +0 -0
@@ -1,13 +1,13 @@
1
+ import { throwIfAborted } from "./abort.js";
1
2
  import { encodeMasterAudio } from "./audio-timeline.js";
2
- /** The live delay of every node {@link Alpha2AudioWorkletHost.create} made. */
3
+ /** Live delay of each node created by {@link Alpha2AudioWorkletHost.create}. */
3
4
  const delays = new WeakMap();
4
- /** The delay of a node this module did not make: none. */
5
5
  const NO_DELAY = Object.freeze({ latencySamples: 0 });
6
6
  /** URL of the processor module distributed with the alpha2 package. */
7
7
  export const alpha2AudioWorkletProcessorUrl = new URL("./audio-worklet-processor.js", import.meta.url);
8
8
  /** URL of the C-ABI DSP wasm module distributed with the alpha2 package. */
9
9
  export const alpha2AudioWorkletWasmUrl = new URL("../wasm/alpha2_audio_worklet.wasm", import.meta.url);
10
- /** Fetches the packaged DSP bytes for transfer into the AudioWorklet realm. */
10
+ /** Fetches the packaged DSP wasm bytes. */
11
11
  export async function loadAlpha2AudioWorkletWasm(url = alpha2AudioWorkletWasmUrl) {
12
12
  const response = await fetch(url);
13
13
  if (!response.ok) {
@@ -18,13 +18,11 @@ export async function loadAlpha2AudioWorkletWasm(url = alpha2AudioWorkletWasmUrl
18
18
  /** Browser host for the C-ABI DSP wasm module; no wasm-bindgen glue is used. */
19
19
  export class Alpha2AudioWorkletHost {
20
20
  /**
21
- * Adds the processor module to `context`, creates the node and starts the DSP module in it from
22
- * a copy of `wasm` (the caller's buffer is not detached). Resolves once the processor reports
23
- * ready; later errors go to `options.onError`.
21
+ * Adds the processor module, creates the node and starts the DSP module from a copy of `wasm`.
22
+ * Resolves once the processor is ready; later errors go to `options.onError`.
24
23
  *
25
- * Rejects when the module cannot be added, the processor fails or reports an error while
26
- * starting, it is not ready within 5 seconds, or `options.signal` aborts. A node that fails to
27
- * start is disposed.
24
+ * Rejects (and disposes the node) when the module cannot be added, the processor fails while
25
+ * starting, it is not ready within 5 seconds, or `options.signal` aborts.
28
26
  *
29
27
  * @throws RangeError When `options.projectSampleRate` is not a positive integer.
30
28
  */
@@ -45,13 +43,12 @@ export class Alpha2AudioWorkletHost {
45
43
  outputChannelCount: options.outputChannelCount
46
44
  ? [...options.outputChannelCount]
47
45
  : Array.from({ length: numberOfOutputs }, () => channels),
48
- // Mix the input to the module's channels by WebAudio's speaker rules; the default "max"
49
- // would pass a mono source as one channel.
46
+ // Up-mix by speaker rules; the default "max" would pass mono through as one channel.
50
47
  channelCount: channels,
51
48
  channelCountMode: "explicit",
52
49
  channelInterpretation: "speakers",
53
50
  });
54
- // Listening before the processor starts, so the delay it reports on starting is not missed.
51
+ // Listen before starting so the initial latency report is not missed.
55
52
  const untrack = trackLatency(node);
56
53
  try {
57
54
  await initializeNode(node, payload, channels, projectSampleRate, options.signal);
@@ -66,8 +63,7 @@ export class Alpha2AudioWorkletHost {
66
63
  return node;
67
64
  }
68
65
  catch (error) {
69
- // The processor may still be starting; without this it would finish and run until the
70
- // context closes.
66
+ // The processor may still be starting and would otherwise run until the context closes.
71
67
  disposeAudioWorklet(node);
72
68
  untrack();
73
69
  node.port.close();
@@ -75,26 +71,18 @@ export class Alpha2AudioWorkletHost {
75
71
  }
76
72
  }
77
73
  /**
78
- * The node's delay, live, in samples at the context's rate: the samples its master chain holds
79
- * its input back by (the lookahead of the master's compressors; the limiter has none), and, while
80
- * it converts a ring at the project's rate to the context's, the source samples the converter
81
- * reads past the one it plays (16 to 18 at the usual rates), so its output is that much behind
82
- * what it takes from the ring or its input. Zero without either (an engine-mixed node at the
83
- * project's rate), and for a node `create` did not make.
74
+ * The node's live output delay in context-rate samples: master compressor lookahead plus, when
75
+ * resampling ring audio, the converter's lookahead (16 to 18 samples at common rates). Zero for an
76
+ * engine-mixed node at the project rate and for nodes `create` did not make.
84
77
  *
85
- * The engine reads ahead by its own latency, so its mix is never late; the worklet cannot read
86
- * ahead of live input. The value follows each configuration once the processor has installed it,
87
- * which it reports on its port; pass the object to `AudioPlaybackClock` so the clock says
88
- * what is being heard.
78
+ * The returned object updates as configurations are applied; pass it to `AudioPlaybackClock` so
79
+ * the clock reports what is being heard.
89
80
  */
90
81
  static latency(node) {
91
82
  return delays.get(node) ?? NO_DELAY;
92
83
  }
93
84
  }
94
- /**
95
- * Keeps the delay the processor reports for {@link Alpha2AudioWorkletHost.latency}. Returns what
96
- * stops it, for a node that failed to start.
97
- */
85
+ /** Tracks the processor's reported delay; returns a function that stops tracking. */
98
86
  function trackLatency(node) {
99
87
  const delay = { latencySamples: 0 };
100
88
  delays.set(node, delay);
@@ -108,7 +96,7 @@ function trackLatency(node) {
108
96
  delays.delete(node);
109
97
  };
110
98
  }
111
- /** Keeps the node's error channels open for as long as it runs. */
99
+ /** Forwards the running node's errors to `report`. */
112
100
  function reportErrors(node, report) {
113
101
  node.addEventListener("processorerror", () => {
114
102
  report(new Error("AudioWorklet processor threw; the node has stopped"));
@@ -168,19 +156,14 @@ function initializeNode(node, wasm, channels, sourceRate, signal) {
168
156
  }
169
157
  });
170
158
  }
171
- /** Makes a transferable, tightly bounded copy without detaching caller data. */
159
+ /** Copies the bytes so the transfer does not detach the caller's buffer. */
172
160
  function copyWasmBytes(source) {
173
161
  if (source instanceof ArrayBuffer)
174
162
  return source.slice(0);
175
163
  return new Uint8Array(source.buffer, source.byteOffset, source.byteLength).slice().buffer;
176
164
  }
177
- function throwIfAborted(signal) {
178
- if (signal?.aborted === true) {
179
- throw signal.reason ?? new DOMException("Aborted", "AbortError");
180
- }
181
- }
182
165
  const requests = new WeakMap();
183
- /** The node's requests, listening for their answers from the first one on. */
166
+ /** Request state for `node`, created with its answer listener on first use. */
184
167
  function requestsOf(node) {
185
168
  const existing = requests.get(node);
186
169
  if (existing !== undefined)
@@ -204,7 +187,7 @@ function requestsOf(node) {
204
187
  node.port.start();
205
188
  return created;
206
189
  }
207
- /** Rejects every request the node has not answered, and every later one, with `reason`. */
190
+ /** Rejects pending and future requests with `reason`. */
208
191
  function closeRequests(node, reason) {
209
192
  const state = requests.get(node);
210
193
  if (state === undefined) {
@@ -218,9 +201,8 @@ function closeRequests(node, reason) {
218
201
  request.reject(reason);
219
202
  }
220
203
  /**
221
- * Posts `message` to the node's processor. Resolves once the processor has applied it, so the
222
- * quantum after the promise resolves runs with it; rejects with why the processor could not apply
223
- * it, or when the node is disposed or its processor throws first.
204
+ * Posts `message` and resolves once the processor has applied it, so the next quantum uses it.
205
+ * Rejects with the processor's refusal, or when the node is disposed or its processor throws.
224
206
  */
225
207
  function request(node, message) {
226
208
  const state = requestsOf(node);
@@ -240,33 +222,27 @@ function request(node, message) {
240
222
  });
241
223
  }
242
224
  /**
243
- * Points the node at a shared audio ring instead of its WebAudio input.
244
- *
245
- * Pass `undefined` to return the node to input processing. Both sides must agree to clear the ring
246
- * at a seek.
225
+ * Points the node at a shared audio ring instead of its WebAudio input; `undefined` switches back.
226
+ * Both sides must agree to clear the ring at a seek.
247
227
  *
248
- * Resolves once the processor plays from the ring (and {@link Alpha2AudioWorkletHost.latency}
249
- * includes a conversion's delay): the processor takes messages between render quanta, so a quantum
250
- * rendered before then plays the input. Await it before an `OfflineAudioContext`'s
251
- * `startRendering()`, whose first quanta may otherwise render without the ring. Rejects when the
252
- * node is disposed or its processor throws before it answers.
228
+ * Resolves once the processor plays from the ring and {@link Alpha2AudioWorkletHost.latency} is
229
+ * updated. Await it before `OfflineAudioContext.startRendering()`, or the first quanta may render
230
+ * without the ring. Rejects when the node is disposed or its processor throws first.
253
231
  */
254
232
  export function useAudioRing(node, ring) {
255
233
  return request(node, { type: "alpha2-ring", ring });
256
234
  }
257
235
  /**
258
- * Installs a project master bus in the running worklet, as an edit: the effects it keeps, and those
259
- * it changes in place, keep their history, so moving a master control does not restart the reverb's
260
- * tail or empty the compressor's lookahead.
236
+ * Installs a project master bus in the running worklet as an edit. Kept and changed effects keep
237
+ * their state, so adjusting a control does not cut a reverb tail or reset compressor lookahead.
261
238
  *
262
- * The worklet applies the master as the engine does (effects, then gain, then limiter), except the
263
- * loudness normalization a host sets on the engine, which the master bus does not carry.
239
+ * Applied as the engine does (effects, gain, limiter), without the engine's loudness normalization
240
+ * gain, which the master bus does not carry.
264
241
  *
265
- * Resolves once the processor runs the new master, with {@link Alpha2AudioWorkletHost.latency}
266
- * already its delay. Rejects with a `RangeError`, posting nothing, for a keyframed master gain
267
- * ({@link encodeMasterAudio}); with the processor's reason when it refuses the record (the chain it
268
- * was running keeps running); and when the node is disposed or its processor throws before it
269
- * answers.
242
+ * Resolves once the new master runs and {@link Alpha2AudioWorkletHost.latency} reflects it.
243
+ * Rejects with a `RangeError` for a keyframed master gain (nothing is posted), with the processor's
244
+ * reason when it refuses the record (the old chain keeps running), or when the node is disposed or
245
+ * its processor throws first.
270
246
  */
271
247
  export function configureMasterAudio(node, master) {
272
248
  let config;
@@ -279,11 +255,8 @@ export function configureMasterAudio(node, master) {
279
255
  return request(node, { type: "alpha2-config", config });
280
256
  }
281
257
  /**
282
- * Configures the worklet as a transparent transport for engine-mixed audio.
283
- *
284
- * `renderAudio` has already applied the project master gain, effects, and limiter. Ring-buffer
285
- * preview must therefore bypass the worklet master chain or preview would process it twice while
286
- * offline export processes it once.
258
+ * Makes the worklet a transparent transport for engine-mixed audio, since `renderAudio` has already
259
+ * applied the master chain.
287
260
  *
288
261
  * Resolves once the processor is transparent; rejects as {@link configureMasterAudio} does.
289
262
  */
@@ -294,33 +267,25 @@ export function configureEngineMixedAudio(node) {
294
267
  });
295
268
  }
296
269
  /**
297
- * Clears the worklet's DSP history and transport position. Resolves once the processor has cleared
298
- * them; rejects when the node is disposed or its processor throws before it answers.
270
+ * Clears the worklet's DSP state and transport position. Rejects when the node is disposed or its
271
+ * processor throws first.
299
272
  */
300
273
  export function resetAudioWorklet(node) {
301
274
  return request(node, { type: "alpha2-reset" });
302
275
  }
303
276
  /**
304
- * Stops the node for good and disconnects it.
277
+ * Permanently stops and disconnects the node.
305
278
  *
306
- * A processor runs until its `AudioContext` closes unless it is told to stop: disconnecting alone
307
- * leaves it processing every quantum and holding its DSP module's memory. This frees the module and
308
- * retires the processor, including one still starting. Call it for every node a host stops using
309
- * while the context lives on. A configuration the processor has not answered yet, and any made
310
- * afterwards, rejects.
279
+ * Disconnecting alone leaves the processor running and holding DSP memory until the context
280
+ * closes, so call this for every node no longer used. Pending and later configuration requests
281
+ * reject.
311
282
  */
312
283
  export function disposeAudioWorklet(node) {
313
284
  closeRequests(node, new Error("the AudioWorklet node was disposed"));
314
285
  node.port.postMessage({ type: "alpha2-dispose" });
315
286
  node.disconnect();
316
287
  }
317
- /**
318
- * The reason a signal carries, as an `Error` a caller can reject with.
319
- *
320
- * `AbortSignal.reason` is typed `any` and a caller may abort with a value that is not an `Error`,
321
- * which would reject without a stack. An `Error` passes through untouched, so an `AbortError` keeps
322
- * its name.
323
- */
288
+ /** The signal's reason as an `Error`; non-`Error` reasons become an `AbortError`. */
324
289
  function abortError(signal) {
325
290
  const reason = signal?.reason;
326
291
  if (reason instanceof Error)
package/dist/audio.d.ts CHANGED
@@ -1,42 +1,34 @@
1
1
  import type { BrowserAudioBlock } from "./media.js";
2
- /**
3
- * Where {@link renderOfflineAudio} delivers rendered audio, owned by the host
4
- * (an encoder, a file writer, a test collector).
5
- */
2
+ /** Host-owned destination for {@link renderOfflineAudio} output. */
6
3
  export interface BrowserAudioBlockSink {
7
4
  /**
8
- * Takes the next block, in timeline order. The next block is not rendered
9
- * until the returned promise settles; a rejection aborts the render.
5
+ * Takes the next block in timeline order. The next block is not rendered until the promise
6
+ * settles; a rejection aborts the render.
10
7
  */
11
8
  writeAudio(block: BrowserAudioBlock): Promise<void>;
12
9
  /** Called once after the last block was written. */
13
10
  finish(): Promise<void>;
14
11
  /**
15
- * Called once instead of `finish` when rendering, writing, or finishing
16
- * fails or is aborted; `reason` is the error the render rejects with.
12
+ * Called once instead of `finish` when the render fails or is aborted; `reason` is the error the
13
+ * render rejects with.
17
14
  */
18
15
  abort(reason: Error): Promise<void> | void;
19
16
  }
20
17
  /**
21
- * Renders `frameCount` frames of the project's audio starting at project-rate
22
- * sample `startSample`. Every channel of the returned block must hold exactly
23
- * `frameCount` samples.
18
+ * Renders `frameCount` frames starting at project-rate sample `startSample`. Every channel of the
19
+ * returned block must hold exactly `frameCount` samples.
24
20
  */
25
21
  export type OfflineAudioRenderer = (startSample: bigint, frameCount: number) => Promise<BrowserAudioBlock>;
26
22
  /**
27
- * Renders `totalFrames` frames through `render` into `sink`, in blocks whose
28
- * sizes cycle through `blockSizes`, so a schedule of irregular block sizes is
29
- * reproduced exactly on every run.
23
+ * Renders `totalFrames` frames through `render` into `sink`, one block at a time, with block
24
+ * sizes cycling through `blockSizes`.
30
25
  *
31
- * Blocks are rendered and written one at a time. On success the sink's
32
- * `finish` is awaited; on any failure, including `signal` aborting before the
33
- * promise resolves (during the last block or `finish` included), the sink's
34
- * `abort` is awaited with the error and the promise rejects with it
35
- * (`signal.reason`, or an `AbortError`, for an abort). An `abort` that throws
36
- * does not replace that error ({@link recordCleanupFailure}).
26
+ * On success the sink's `finish` is awaited. On any failure, including `signal` aborting before
27
+ * the promise resolves, the sink's `abort` is awaited and the promise rejects with the error
28
+ * (`signal.reason` or an `AbortError` for an abort). An error thrown by `abort` does not replace it.
37
29
  *
38
- * @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or
39
- * holds a size that is not a positive safe integer (before the sink is
40
- * touched), or `render` returns a block of the wrong length.
30
+ * @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or holds a size that is
31
+ * not a positive safe integer (checked before the sink is touched), or `render` returns a block
32
+ * of the wrong length.
41
33
  */
42
34
  export declare function renderOfflineAudio(totalFrames: bigint, blockSizes: readonly number[], render: OfflineAudioRenderer, sink: BrowserAudioBlockSink, signal?: AbortSignal): Promise<void>;
package/dist/audio.js CHANGED
@@ -1,19 +1,15 @@
1
1
  import { recordCleanupFailure } from "./export-failure.js";
2
2
  /**
3
- * Renders `totalFrames` frames through `render` into `sink`, in blocks whose
4
- * sizes cycle through `blockSizes`, so a schedule of irregular block sizes is
5
- * reproduced exactly on every run.
3
+ * Renders `totalFrames` frames through `render` into `sink`, one block at a time, with block
4
+ * sizes cycling through `blockSizes`.
6
5
  *
7
- * Blocks are rendered and written one at a time. On success the sink's
8
- * `finish` is awaited; on any failure, including `signal` aborting before the
9
- * promise resolves (during the last block or `finish` included), the sink's
10
- * `abort` is awaited with the error and the promise rejects with it
11
- * (`signal.reason`, or an `AbortError`, for an abort). An `abort` that throws
12
- * does not replace that error ({@link recordCleanupFailure}).
6
+ * On success the sink's `finish` is awaited. On any failure, including `signal` aborting before
7
+ * the promise resolves, the sink's `abort` is awaited and the promise rejects with the error
8
+ * (`signal.reason` or an `AbortError` for an abort). An error thrown by `abort` does not replace it.
13
9
  *
14
- * @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or
15
- * holds a size that is not a positive safe integer (before the sink is
16
- * touched), or `render` returns a block of the wrong length.
10
+ * @throws RangeError When `totalFrames` is negative, `blockSizes` is empty or holds a size that is
11
+ * not a positive safe integer (checked before the sink is touched), or `render` returns a block
12
+ * of the wrong length.
17
13
  */
18
14
  export async function renderOfflineAudio(totalFrames, blockSizes, render, sink, signal) {
19
15
  if (totalFrames < 0n ||
@@ -23,7 +19,7 @@ export async function renderOfflineAudio(totalFrames, blockSizes, render, sink,
23
19
  }
24
20
  let position = 0n;
25
21
  let block = 0;
26
- // Checked around each block and on each side of `finish`, so a late cancel never reports success.
22
+ // Also checked after `finish`, so a late cancel never reports success.
27
23
  const throwIfAborted = () => {
28
24
  if (signal?.aborted === true)
29
25
  throw signal.reason ?? new DOMException("Aborted", "AbortError");
package/dist/builder.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * A fluent builder for project documents: sources, tracks, clips, and caption cues, with times in
3
- * seconds (or exact ticks) and ids generated deterministically.
2
+ * Fluent builder for project documents. Times are seconds or exact ticks; ids are deterministic.
4
3
  *
5
4
  * ```ts
6
5
  * const project = new ProjectBuilder({ name: "Intro", width: 1920, height: 1080, frameRate: 30 });
@@ -9,31 +8,30 @@
9
8
  * const document = project.build(); // passes validateProject, or throws
10
9
  * ```
11
10
  */
12
- import type { TextStyle, Clip, ClipEffect, ClipTransition, CompositionNode, Generator, Project, Rgb, Track } from "./generated/project-schema.js";
13
- /** An exact time in ticks, where seconds would round. */
11
+ import type { TextContent, TextStyle, TextStylePatch, Clip, ClipEffect, ClipTransition, CompositionNode, Generator, Project, Rgb, Track } from "./generated/project-schema.js";
12
+ /** An exact time in ticks. */
14
13
  export interface Ticks {
15
14
  readonly ticks: number;
16
15
  }
17
16
  /** Seconds, or exact {@link ticks}. */
18
17
  export type Time = number | Ticks;
19
- /** `count` ticks: an exact time. Throws a `RangeError` unless `count` is a safe integer. */
18
+ /**
19
+ * An exact time of `count` ticks.
20
+ *
21
+ * @throws RangeError Unless `count` is a safe integer.
22
+ */
20
23
  export declare function ticks(count: number): Ticks;
21
24
  /**
22
- * A time in ticks: seconds rounded to the nearest tick ({@link secondsToTicks}).
25
+ * Converts to ticks, rounding seconds to the nearest tick.
23
26
  *
24
- * @throws RangeError For seconds that are not finite.
27
+ * @throws RangeError For non-finite seconds.
25
28
  */
26
29
  export declare function toTicks(time: Time): number;
27
- /** What a generated id names. */
28
30
  export type IdKind = "source" | "track" | "clip" | "composition";
29
- /**
30
- * Makes ids: called with what the id names, in build order. A builder skips an id it already holds
31
- * of that kind, given explicitly or generated, and calls again.
32
- */
31
+ /** Called in build order; the builder calls again when an id of that kind is already taken. */
33
32
  export type IdGenerator = (kind: IdKind) => string;
34
- /** `source-1`, `track-1`, `clip-1`, ..., counted per kind. */
33
+ /** Generates `source-1`, `track-1`, `clip-1` and so on, counted per kind. */
35
34
  export declare function sequentialIds(): IdGenerator;
36
- /** The settings a {@link ProjectBuilder} starts from. */
37
35
  export interface ProjectBuilderOptions {
38
36
  readonly name: string;
39
37
  /** Project id (default `project`). */
@@ -47,15 +45,11 @@ export interface ProjectBuilderOptions {
47
45
  };
48
46
  /** Audio sample rate (default 48 000). */
49
47
  readonly sampleRate?: number;
50
- /** Canvas color behind every track (the engine's default when absent). */
48
+ /** Canvas color behind every track. */
51
49
  readonly background?: Rgb;
52
- /**
53
- * How generated ids are made (default {@link sequentialIds}). An id the builder already holds
54
- * is skipped, so explicit ids such as `clip-2` and generated ones mix freely.
55
- */
50
+ /** Default {@link sequentialIds}. Ids already taken are skipped, so explicit ids mix freely. */
56
51
  readonly ids?: IdGenerator;
57
52
  }
58
- /** A clip to place: where on the timeline, how long, and from where in the source. */
59
53
  export interface ClipOptions {
60
54
  readonly source: string;
61
55
  /** Timeline start. */
@@ -63,77 +57,69 @@ export interface ClipOptions {
63
57
  readonly duration: Time;
64
58
  /** Source start (default 0). */
65
59
  readonly sourceIn?: Time;
66
- /**
67
- * Source duration (default `duration`: untouched speed). Twice `duration` plays twice as fast.
68
- */
60
+ /** Source duration (default `duration`). Twice `duration` plays twice as fast. */
69
61
  readonly sourceDuration?: Time;
70
- /** An explicit id instead of a generated one. */
62
+ /** Time-stretches instead of resampling at non-unit speed (sets `audio.preserve_pitch`). */
63
+ readonly preservePitch?: boolean;
71
64
  readonly id?: string;
72
65
  /**
73
- * Effects applied in order to the clip's picture: a composition of the clip node through one
74
- * effect node each, added for this clip. The clip has one composition, so this and a
75
- * `with.composition` together are refused.
66
+ * Effects applied in order, added as a composition chain for this clip. Cannot be combined with
67
+ * `with.composition`.
76
68
  */
77
69
  readonly effects?: readonly ClipEffect[];
78
- /** Any other clip fields: visual, composition, blend mode, masks, and so on. */
70
+ /** Any other clip fields, such as visual, blend mode or masks. */
79
71
  readonly with?: Partial<Omit<Clip, "id" | "source_id" | "timeline_range" | "source_range">>;
80
72
  }
81
- /** A cue to show on a caption track. */
82
73
  export interface CueOptions {
83
74
  readonly at: Time;
84
75
  readonly duration: Time;
85
- readonly text: string;
76
+ /** A string or runs. A run's `time` is in ticks from the cue start (for karaoke timing). */
77
+ readonly text: TextContent;
78
+ /** A track style with this name applies when the cue names no `style`. */
79
+ readonly speaker?: string;
80
+ /** Name of a track style, applied over the track's base style. */
81
+ readonly style?: string;
86
82
  }
87
- /**
88
- * Builds one project document. Nothing is checked until {@link ProjectBuilder.build}
89
- * validates the whole document.
90
- */
83
+ /** Builds one project document. Validation happens only in {@link ProjectBuilder.build}. */
91
84
  export declare class ProjectBuilder {
92
85
  #private;
93
86
  constructor(options: ProjectBuilderOptions);
94
- /** Adds a media source the host resolves; returns its id. */
87
+ /** Adds a host-resolved media source and returns its id. */
95
88
  source(kind: "video" | "audio" | "image", locator: string, options?: {
96
89
  readonly id?: string;
97
90
  readonly hasAudio?: boolean;
98
91
  }): string;
99
92
  /**
100
- * Each media source's id mapped to its locator: the `assets` a native export (`@alpha2-sh/node`)
101
- * reads, when the locators are file paths. A relative path resolves against the exporting
102
- * process's working directory. Sources added to the built document by hand are not in it.
93
+ * Source ids mapped to locators, usable as the `assets` of a native export (`@alpha2-sh/node`)
94
+ * when locators are file paths. Relative paths resolve against the exporting process's working
95
+ * directory.
103
96
  */
104
97
  assets(): Record<string, string>;
105
- /** Adds a source the engine draws itself; returns its id. */
98
+ /** Adds a generated source and returns its id. */
106
99
  generated(generator: Generator, options?: {
107
100
  readonly id?: string;
108
101
  }): string;
109
- /**
110
- * Adds a composition graph for clips to show (with `ClipOptions.with`'s `composition`); returns
111
- * its id.
112
- */
102
+ /** Adds a composition graph for clips to reference via `with.composition`; returns its id. */
113
103
  composition(nodes: readonly CompositionNode[], output: string | null, options?: {
114
104
  readonly id?: string;
115
105
  }): string;
116
- /** Adds a visual track, drawn over the tracks added before it. */
106
+ /** Adds a visual track, drawn over earlier tracks. */
117
107
  videoTrack(options?: {
118
108
  readonly id?: string;
119
109
  readonly name?: string;
120
110
  }): TrackBuilder;
121
- /** Adds an audio track. */
122
111
  audioTrack(options?: {
123
112
  readonly id?: string;
124
113
  readonly name?: string;
125
114
  }): TrackBuilder;
126
- /** Adds a caption track in `style` (the defaults where absent). */
115
+ /** Adds a caption track. Cues pick from the named `styles` by `style` or `speaker`. */
127
116
  captionTrack(options?: {
128
117
  readonly id?: string;
129
118
  readonly name?: string;
130
119
  readonly style?: TextStyle;
120
+ readonly styles?: Readonly<Record<string, TextStylePatch>>;
131
121
  }): CaptionTrackBuilder;
132
- /**
133
- * The document.
134
- *
135
- * @throws {RangeError} Listing every problem when it does not validate.
136
- */
122
+ /** @throws {RangeError} Listing every problem when the document does not validate. */
137
123
  build(): Project;
138
124
  }
139
125
  /** Clips and transitions of one visual or audio track. */
@@ -141,22 +127,19 @@ export declare class TrackBuilder {
141
127
  #private;
142
128
  /** @internal */
143
129
  constructor(id: string, name: string, kind: "video" | "audio", clipId: (explicit: string | undefined) => string, chain: (effects: readonly ClipEffect[]) => string);
144
- /** The track's id. */
145
130
  get id(): string;
146
131
  /**
147
- * Places a clip; returns its id. With `effects`, a composition chaining them
148
- * is added to the project and the clip shows it.
132
+ * Places a clip and returns its id. `effects` adds a composition chaining them.
149
133
  *
150
- * @throws RangeError For `effects` together with a `with.composition`, or a
151
- * time that is not finite; nothing is added then.
134
+ * @throws RangeError For `effects` with `with.composition`, or a non-finite time; nothing is
135
+ * added then.
152
136
  */
153
137
  clip(options: ClipOptions): string;
154
138
  /**
155
- * A transition from `from` to `to` over the time the two clips overlap, which must be where they
156
- * meet.
139
+ * Adds a transition from `from` to `to` over the time the two clips overlap.
157
140
  *
158
- * @throws RangeError When either clip is not on this track. An overlap that
159
- * is not valid is reported by {@link ProjectBuilder.build}.
141
+ * @throws RangeError When either clip is not on this track. An invalid overlap is reported by
142
+ * {@link ProjectBuilder.build}.
160
143
  */
161
144
  transition(from: string, to: string, effect: ClipTransition["effect"], easing?: ClipTransition["easing"]): this;
162
145
  /** @internal */
@@ -166,10 +149,9 @@ export declare class TrackBuilder {
166
149
  export declare class CaptionTrackBuilder {
167
150
  #private;
168
151
  /** @internal */
169
- constructor(id: string, name: string, style: TextStyle);
170
- /** The track's id. */
152
+ constructor(id: string, name: string, style: TextStyle, styles: Readonly<Record<string, TextStylePatch>>);
171
153
  get id(): string;
172
- /** Shows `text` from `at` for `duration`. Cues may be added in any order. */
154
+ /** Adds a cue. Cues may be added in any order. */
173
155
  cue(options: CueOptions): this;
174
156
  /** @internal */
175
157
  build(): Track;