rushes 0.2.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/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +10 -0
- package/.mcp.json +8 -0
- package/AGENTS.md +110 -0
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/cli/demo.js +339 -0
- package/dist/cli/doctor.js +307 -0
- package/dist/cli/index.js +11 -0
- package/dist/cli/main.js +469 -0
- package/dist/core/batches.js +58 -0
- package/dist/core/errors.js +37 -0
- package/dist/core/exportNotes.js +132 -0
- package/dist/core/ids.js +42 -0
- package/dist/core/media.js +128 -0
- package/dist/core/notes.js +117 -0
- package/dist/core/paths.js +17 -0
- package/dist/core/project.js +200 -0
- package/dist/core/schema.js +220 -0
- package/dist/core/script.js +113 -0
- package/dist/core/store.js +132 -0
- package/dist/core/tabs.js +24 -0
- package/dist/mcp/client.js +50 -0
- package/dist/mcp/ensure.js +69 -0
- package/dist/mcp/stdio.js +47 -0
- package/dist/mcp/tools.js +191 -0
- package/dist/server/app.js +710 -0
- package/dist/server/assets.js +234 -0
- package/dist/server/files.js +170 -0
- package/dist/server/lock.js +148 -0
- package/dist/server/loudness.js +331 -0
- package/dist/server/proxy.js +575 -0
- package/dist/server/reveal.js +71 -0
- package/dist/server/start.js +125 -0
- package/dist/server/watch.js +133 -0
- package/dist/setup/env.js +42 -0
- package/dist/setup/harnesses.js +93 -0
- package/dist/setup/setup.js +92 -0
- package/package.json +54 -0
- package/skills/rushes/SKILL.md +30 -0
- package/web-dist/assets/figtree-latin-400-normal-BD4aNku5.woff +0 -0
- package/web-dist/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
- package/web-dist/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
- package/web-dist/assets/figtree-latin-500-normal-B_yy1phn.woff +0 -0
- package/web-dist/assets/figtree-latin-600-normal-BM_oTo4n.woff +0 -0
- package/web-dist/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
- package/web-dist/assets/figtree-latin-700-normal-BCCt2T1q.woff +0 -0
- package/web-dist/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-400-normal-CXAzuTZb.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-400-normal-Gbh-3PTk.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-500-normal-BOEJvrb_.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-500-normal-Du0rIuHj.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-600-normal-CQqsimlV.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-600-normal-DJlfifZj.woff2 +0 -0
- package/web-dist/assets/figtree-latin-ext-700-normal-BoDi4KL2.woff +0 -0
- package/web-dist/assets/figtree-latin-ext-700-normal-CS4sQkGV.woff2 +0 -0
- package/web-dist/assets/index-BjDIT_wL.css +1 -0
- package/web-dist/assets/index-DF6Rl-Ac.js +3 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- package/web-dist/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- package/web-dist/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- package/web-dist/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/web-dist/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- package/web-dist/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- package/web-dist/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- package/web-dist/index.html +14 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { stat } from "node:fs/promises";
|
|
4
|
+
import { RushesError } from "../core/errors.js";
|
|
5
|
+
import { probe } from "../core/media.js";
|
|
6
|
+
import { fromManifestPath } from "../core/paths.js";
|
|
7
|
+
/** Grace period between SIGTERM and SIGKILL when a run is aborted. */
|
|
8
|
+
const KILL_GRACE_MS = 2_000;
|
|
9
|
+
/**
|
|
10
|
+
* Spawns ffmpeg with an argument array -- never through a shell (global constraints). The
|
|
11
|
+
* locale is pinned to `C` so ffmpeg's own text (decimal points, "LUFS"/"dBFS"/"-inf") is never
|
|
12
|
+
* localised out from under `parseEbur128`. When `signal` aborts (the timeout in
|
|
13
|
+
* `runWithTimeout` firing), the child is sent SIGTERM, then SIGKILL after a grace period if it's
|
|
14
|
+
* still alive -- a timed-out ffmpeg must never keep running in the background.
|
|
15
|
+
*/
|
|
16
|
+
export const defaultRunner = (args, signal) => new Promise((resolve) => {
|
|
17
|
+
let stderr = "";
|
|
18
|
+
const child = spawn("ffmpeg", args, {
|
|
19
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
20
|
+
env: { ...process.env, LC_ALL: "C" },
|
|
21
|
+
});
|
|
22
|
+
const onData = (d) => {
|
|
23
|
+
stderr += d.toString();
|
|
24
|
+
};
|
|
25
|
+
child.stderr.on("data", onData);
|
|
26
|
+
let killTimer;
|
|
27
|
+
const onAbort = () => {
|
|
28
|
+
child.kill("SIGTERM");
|
|
29
|
+
killTimer = setTimeout(() => {
|
|
30
|
+
// Still alive past the grace period (SIGTERM ignored or still shutting down): escalate.
|
|
31
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
32
|
+
child.kill("SIGKILL");
|
|
33
|
+
}, KILL_GRACE_MS);
|
|
34
|
+
};
|
|
35
|
+
signal?.addEventListener("abort", onAbort);
|
|
36
|
+
const cleanup = () => {
|
|
37
|
+
child.stderr.off("data", onData);
|
|
38
|
+
signal?.removeEventListener("abort", onAbort);
|
|
39
|
+
if (killTimer)
|
|
40
|
+
clearTimeout(killTimer);
|
|
41
|
+
};
|
|
42
|
+
// ENOENT (ffmpeg not on PATH) and any other spawn failure both just mean "not available".
|
|
43
|
+
child.on("error", () => {
|
|
44
|
+
cleanup();
|
|
45
|
+
resolve({ code: 1, stderr });
|
|
46
|
+
});
|
|
47
|
+
child.on("close", (code) => {
|
|
48
|
+
cleanup();
|
|
49
|
+
resolve({ code: code ?? 1, stderr });
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
// "Detect it once per server": keyed by the runner's own identity, so the one shared
|
|
53
|
+
// defaultRunner (and whichever single fake a test or a server instance injects) is probed at
|
|
54
|
+
// most once for its lifetime, while two different runners -- two tests' two fakes, say -- never
|
|
55
|
+
// share a result.
|
|
56
|
+
const availability = new WeakMap();
|
|
57
|
+
export function ffmpegAvailable(run = defaultRunner) {
|
|
58
|
+
let cached = availability.get(run);
|
|
59
|
+
if (!cached) {
|
|
60
|
+
cached = run(["-version"]).then((r) => r.code === 0, () => false);
|
|
61
|
+
availability.set(run, cached);
|
|
62
|
+
}
|
|
63
|
+
return cached;
|
|
64
|
+
}
|
|
65
|
+
function voiceSource(project, picks) {
|
|
66
|
+
// §18.4: the newest round (lane) with a pick; takes are never mixed.
|
|
67
|
+
const voice = project.lanes.filter((l) => l.stage === "voice");
|
|
68
|
+
for (let i = voice.length - 1; i >= 0; i--) {
|
|
69
|
+
const pickedId = picks.lanes[voice[i].id];
|
|
70
|
+
const variant = pickedId ? voice[i].variants.find((v) => v.id === pickedId) : undefined;
|
|
71
|
+
if (variant)
|
|
72
|
+
return { kind: "variant", variant };
|
|
73
|
+
}
|
|
74
|
+
return { kind: "none" };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The files and offsets a mix of `lanes` is made from (§17.6, §18.4) -- exactly what the Mix tab
|
|
78
|
+
* plays:
|
|
79
|
+
* - voice: the pick of the newest round (voice lane) that has one. With no round picked, there is
|
|
80
|
+
* no voice input at all -- takes are never mixed, however many a script section has.
|
|
81
|
+
* - music: the picked variant of each music lane, at 0;
|
|
82
|
+
* - sfx: the picked variant of each sfx lane, at 0.
|
|
83
|
+
*
|
|
84
|
+
* A music or sfx lane with nothing picked is left out, never stood in for by its first variant:
|
|
85
|
+
* Mix plays only explicit picks, so the readout must measure only them. A manifest entry whose
|
|
86
|
+
* file is missing from disk is left out too, rather than handed to ffmpeg.
|
|
87
|
+
*/
|
|
88
|
+
export function mixInputs(project, picks, lanes, root) {
|
|
89
|
+
const want = new Set(lanes);
|
|
90
|
+
const out = [];
|
|
91
|
+
const add = (file, offset, stage) => {
|
|
92
|
+
const abs = fromManifestPath(root, file);
|
|
93
|
+
if (existsSync(abs))
|
|
94
|
+
out.push({ file: abs, offset, stage, gainDb: picks.levels[stage] ?? 0 });
|
|
95
|
+
};
|
|
96
|
+
if (want.has("voice")) {
|
|
97
|
+
const voice = voiceSource(project, picks);
|
|
98
|
+
if (voice.kind === "variant")
|
|
99
|
+
add(voice.variant.file, 0, "voice");
|
|
100
|
+
}
|
|
101
|
+
for (const stage of ["music", "sfx"]) {
|
|
102
|
+
if (!want.has(stage))
|
|
103
|
+
continue;
|
|
104
|
+
for (const lane of project.lanes) {
|
|
105
|
+
if (lane.stage !== stage)
|
|
106
|
+
continue;
|
|
107
|
+
const pickedId = picks.lanes[lane.id];
|
|
108
|
+
const variant = pickedId ? lane.variants.find((v) => v.id === pickedId) : undefined;
|
|
109
|
+
if (variant)
|
|
110
|
+
add(variant.file, 0, stage);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
function inputArgs(inputs) {
|
|
116
|
+
return inputs.flatMap((i) => ["-i", i.file]);
|
|
117
|
+
}
|
|
118
|
+
function filterComplex(inputs) {
|
|
119
|
+
// §19.6: each input's level is applied (volume=<db>dB) before the mix, right after its delay, so
|
|
120
|
+
// the readout measures the mix exactly as Mix plays it.
|
|
121
|
+
const delays = inputs.map((inp, i) => `[${i}]adelay=${Math.round(inp.offset * 1000)}:all=1,volume=${inp.gainDb}dB[a${i}]`);
|
|
122
|
+
const labels = inputs.map((_, i) => `[a${i}]`).join("");
|
|
123
|
+
return `${delays.join(";")};${labels}amix=inputs=${inputs.length}:normalize=0,ebur128=peak=true`;
|
|
124
|
+
}
|
|
125
|
+
/** The ffmpeg argument array that mixes `inputs` down at their offsets and measures loudness over all of it. */
|
|
126
|
+
export function loudnessArgs(inputs) {
|
|
127
|
+
return ["-nostats", ...inputArgs(inputs), "-filter_complex", filterComplex(inputs), "-f", "null", "-"];
|
|
128
|
+
}
|
|
129
|
+
/** As `loudnessArgs`, but stops measuring at `seconds` -- used to compare a lane against the VO's own span. */
|
|
130
|
+
function loudnessArgsTrimmed(inputs, seconds) {
|
|
131
|
+
return ["-nostats", ...inputArgs(inputs), "-filter_complex", filterComplex(inputs), "-t", seconds.toFixed(3), "-f", "null", "-"];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Pulls the integrated loudness (LUFS) and true peak (dBTP) out of an `ebur128=peak=true`
|
|
135
|
+
* summary block. ffmpeg prints `-inf` for either value on a fully silent mix (observed in the
|
|
136
|
+
* wild for "Peak:", and documented for "I:" too on a track with no measurable blocks at all) --
|
|
137
|
+
* returned here as `-Infinity`, a real (if non-finite) number, rather than `null`: `null` means
|
|
138
|
+
* "couldn't find this in the output at all", `-Infinity` means "ffmpeg measured it, and it's
|
|
139
|
+
* silence". `measureMix` is the layer that turns `-Infinity` into the public `silent` flag.
|
|
140
|
+
*/
|
|
141
|
+
export function parseEbur128(stderr) {
|
|
142
|
+
const integrated = stderr.match(/Integrated loudness:\s*I:\s*(-inf|-?\d+(?:\.\d+)?)\s*LUFS/);
|
|
143
|
+
const truePeak = stderr.match(/True peak:\s*Peak:\s*(-inf|-?\d+(?:\.\d+)?)\s*dBFS/);
|
|
144
|
+
const toNumber = (m) => (m ? (m[1] === "-inf" ? -Infinity : Number(m[1])) : null);
|
|
145
|
+
return { integrated: toNumber(integrated), truePeak: toNumber(truePeak) };
|
|
146
|
+
}
|
|
147
|
+
export class LoudnessTimeoutError extends RushesError {
|
|
148
|
+
constructor(ms) {
|
|
149
|
+
super(`ffmpeg didn't finish within ${ms} ms`, 504, "loudness_timeout");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** `null` when `n` isn't a real, finite measurement (ffmpeg's `-inf`, or no reading at all). */
|
|
153
|
+
function finite(n) {
|
|
154
|
+
return n !== null && Number.isFinite(n) ? n : null;
|
|
155
|
+
}
|
|
156
|
+
/** Runs `run(args)` racing a `timeoutMs` clock. On timeout, aborts the signal passed to `run` --
|
|
157
|
+
* `defaultRunner` uses that to SIGTERM (then SIGKILL) the ffmpeg process -- and rejects with a
|
|
158
|
+
* `LoudnessTimeoutError` (504) rather than leaving the run abandoned in the background. */
|
|
159
|
+
async function runWithTimeout(run, args, timeoutMs) {
|
|
160
|
+
const controller = new AbortController();
|
|
161
|
+
let timer;
|
|
162
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
163
|
+
timer = setTimeout(() => {
|
|
164
|
+
controller.abort();
|
|
165
|
+
reject(new LoudnessTimeoutError(timeoutMs));
|
|
166
|
+
}, timeoutMs);
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
return await Promise.race([run(args, controller.signal), timeout]);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const probeDuration = async (file) => (await probe(file)).duration;
|
|
176
|
+
function voSpan(project, picks, root) {
|
|
177
|
+
const voice = voiceSource(project, picks);
|
|
178
|
+
if (voice.kind === "variant")
|
|
179
|
+
return { kind: "variant", file: fromManifestPath(root, voice.variant.file) };
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
async function voSpanSeconds(span, durationOf) {
|
|
183
|
+
if (span === null)
|
|
184
|
+
return null;
|
|
185
|
+
try {
|
|
186
|
+
const d = await durationOf(span.file);
|
|
187
|
+
return d !== null && Number.isFinite(d) && d > 0 ? d : null;
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const NOT_MEASURED = { integrated: null, truePeak: null, musicUnderVo: null, silent: false };
|
|
194
|
+
// Keyed by runner identity, same reasoning as `availability` above: one cache per server, capped
|
|
195
|
+
// at 50 entries. A real LRU -- both a hit and a set move the entry to the end of the Map's
|
|
196
|
+
// iteration order, so eviction (when over the cap) always drops the one actually least recently
|
|
197
|
+
// touched, not just the one least recently written.
|
|
198
|
+
const CACHE_LIMIT = 50;
|
|
199
|
+
const mixCaches = new WeakMap();
|
|
200
|
+
function cacheGet(run, key) {
|
|
201
|
+
const cache = mixCaches.get(run);
|
|
202
|
+
const value = cache?.get(key);
|
|
203
|
+
if (cache && value !== undefined) {
|
|
204
|
+
cache.delete(key);
|
|
205
|
+
cache.set(key, value);
|
|
206
|
+
}
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
function cacheSet(run, key, value) {
|
|
210
|
+
let cache = mixCaches.get(run);
|
|
211
|
+
if (!cache) {
|
|
212
|
+
cache = new Map();
|
|
213
|
+
mixCaches.set(run, cache);
|
|
214
|
+
}
|
|
215
|
+
cache.delete(key);
|
|
216
|
+
cache.set(key, value);
|
|
217
|
+
if (cache.size > CACHE_LIMIT) {
|
|
218
|
+
const oldest = cache.keys().next().value;
|
|
219
|
+
if (oldest !== undefined)
|
|
220
|
+
cache.delete(oldest);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Sorted (abs path, mtime, offset) for every input, plus the lanes asked for -- or `null` when a
|
|
225
|
+
* file's `stat` fails (it existed a moment ago for `mixInputs`' own check, but could have been
|
|
226
|
+
* removed since). `null` means "don't cache this one", never a thrown error: a loudness request
|
|
227
|
+
* racing a file deletion must still get an answer, not a 500. A picked round's span is its own
|
|
228
|
+
* file's length (§18.4), already covered by that file's path and mtime among the inputs; `span`
|
|
229
|
+
* distinguishes only whether one is in play at all, so a pick appearing or disappearing (with the
|
|
230
|
+
* same files otherwise) still gets its own cache entry.
|
|
231
|
+
*/
|
|
232
|
+
async function cacheKey(inputs, lanes, span) {
|
|
233
|
+
const stats = [];
|
|
234
|
+
for (const i of inputs) {
|
|
235
|
+
try {
|
|
236
|
+
stats.push({ file: i.file, offset: i.offset, gainDb: i.gainDb, mtimeMs: (await stat(i.file)).mtimeMs });
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
stats.sort((a, b) => a.file.localeCompare(b.file) || a.offset - b.offset);
|
|
243
|
+
return JSON.stringify({ lanes: [...lanes].sort(), inputs: stats, span: span === null ? "none" : "variant" });
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Mixes the picked files for `lanes` and measures loudness: `integrated` (LUFS) and `truePeak`
|
|
247
|
+
* (dBTP) over the whole mix, plus `musicUnderVo` -- the music's level relative to the VO, each
|
|
248
|
+
* measured alone over the VO's own span -- whenever both a voice and a music lane are present
|
|
249
|
+
* among the inputs. Runs at most three ffmpeg invocations, each through `run`; each is aborted,
|
|
250
|
+
* and its process killed, if it runs past `timeoutMs`, rather than left running in the
|
|
251
|
+
* background. Results are cached per `run`, by the inputs' paths, mtimes and offsets plus the
|
|
252
|
+
* lanes asked for and the VO span (skipped when a file can't be stat'ed any more, and never for a
|
|
253
|
+
* run ffmpeg failed: a nonzero exit with nothing parsed, as an older ffmpeg without
|
|
254
|
+
* `amix normalize` gives). Two requests for the same key while one is measuring share that one
|
|
255
|
+
* run rather than starting a second ffmpeg chain. Returns `{ available: false, ... }` without
|
|
256
|
+
* touching the filesystem further when ffmpeg isn't on PATH.
|
|
257
|
+
*/
|
|
258
|
+
export async function measureMix(project, picks, lanes, root, run = defaultRunner, timeoutMs = 60_000, durationOf = probeDuration) {
|
|
259
|
+
if (!(await ffmpegAvailable(run)))
|
|
260
|
+
return { available: false, ...NOT_MEASURED };
|
|
261
|
+
const inputs = mixInputs(project, picks, lanes, root);
|
|
262
|
+
if (inputs.length === 0)
|
|
263
|
+
return { available: true, ...NOT_MEASURED };
|
|
264
|
+
const span = voSpan(project, picks, root);
|
|
265
|
+
const key = await cacheKey(inputs, lanes, span);
|
|
266
|
+
if (key === null)
|
|
267
|
+
return (await measure(inputs, span, run, timeoutMs, durationOf)).result;
|
|
268
|
+
const cached = cacheGet(run, key);
|
|
269
|
+
if (cached)
|
|
270
|
+
return cached;
|
|
271
|
+
let flights = inFlight.get(run);
|
|
272
|
+
if (!flights) {
|
|
273
|
+
flights = new Map();
|
|
274
|
+
inFlight.set(run, flights);
|
|
275
|
+
}
|
|
276
|
+
const running = flights.get(key);
|
|
277
|
+
if (running)
|
|
278
|
+
return running;
|
|
279
|
+
const flight = measure(inputs, span, run, timeoutMs, durationOf).then(({ result, failed }) => {
|
|
280
|
+
if (!failed)
|
|
281
|
+
cacheSet(run, key, result);
|
|
282
|
+
return result;
|
|
283
|
+
});
|
|
284
|
+
flights.set(key, flight);
|
|
285
|
+
const done = () => {
|
|
286
|
+
if (flights.get(key) === flight)
|
|
287
|
+
flights.delete(key);
|
|
288
|
+
};
|
|
289
|
+
flight.then(done, done);
|
|
290
|
+
return flight;
|
|
291
|
+
}
|
|
292
|
+
// The measurement running for each cache key right now, per runner: a second request for the same
|
|
293
|
+
// mix while the first is still measuring waits on it instead of spawning its own ffmpeg chain.
|
|
294
|
+
const inFlight = new WeakMap();
|
|
295
|
+
/** The ffmpeg runs behind one reading. `failed`: a run exited nonzero with nothing parsed, so don't cache it. */
|
|
296
|
+
async function measure(inputs, span, run, timeoutMs, durationOf) {
|
|
297
|
+
let failed = false;
|
|
298
|
+
const reading = async (args) => {
|
|
299
|
+
const r = await runWithTimeout(run, args, timeoutMs);
|
|
300
|
+
const parsed = parseEbur128(r.stderr);
|
|
301
|
+
if (r.code !== 0 && parsed.integrated === null && parsed.truePeak === null)
|
|
302
|
+
failed = true;
|
|
303
|
+
return parsed;
|
|
304
|
+
};
|
|
305
|
+
const full = await reading(loudnessArgs(inputs));
|
|
306
|
+
// Either reading hitting -inf means there's nothing there to measure -- treat the whole
|
|
307
|
+
// full-mix reading as silence rather than keeping a merely-finite other field (ffmpeg's own
|
|
308
|
+
// integrated-loudness gate floors at -70 LUFS even when the true peak is genuinely -inf), which
|
|
309
|
+
// would otherwise show a stray number next to `silent: true` that looks like it contradicts it.
|
|
310
|
+
const silent = full.integrated === -Infinity || full.truePeak === -Infinity;
|
|
311
|
+
const voiceInputs = inputs.filter((i) => i.stage === "voice");
|
|
312
|
+
const musicInputs = inputs.filter((i) => i.stage === "music");
|
|
313
|
+
let musicUnderVo = null;
|
|
314
|
+
if (voiceInputs.length > 0 && musicInputs.length > 0) {
|
|
315
|
+
const seconds = await voSpanSeconds(span, durationOf);
|
|
316
|
+
if (seconds !== null) {
|
|
317
|
+
const vo = finite((await reading(loudnessArgs(voiceInputs))).integrated);
|
|
318
|
+
const music = finite((await reading(loudnessArgsTrimmed(musicInputs, seconds))).integrated);
|
|
319
|
+
if (vo !== null && music !== null)
|
|
320
|
+
musicUnderVo = music - vo;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const result = {
|
|
324
|
+
available: true,
|
|
325
|
+
integrated: silent ? null : finite(full.integrated),
|
|
326
|
+
truePeak: silent ? null : finite(full.truePeak),
|
|
327
|
+
musicUnderVo,
|
|
328
|
+
silent,
|
|
329
|
+
};
|
|
330
|
+
return { result, failed };
|
|
331
|
+
}
|