launch-film 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launch-film",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A launch film from a website or an App Store page: its real logo, colors, fonts and screens, rendered locally with Chrome and ffmpeg.",
5
5
  "license": "MIT",
6
6
  "author": "Emin Budak",
@@ -33,10 +33,10 @@
33
33
  ],
34
34
  "repository": {
35
35
  "type": "git",
36
- "url": "git+https://github.com/EminBudak/launch-film.git"
36
+ "url": "git+https://github.com/MakersMCP/launch-film.git"
37
37
  },
38
- "homepage": "https://github.com/EminBudak/launch-film#readme",
38
+ "homepage": "https://github.com/MakersMCP/launch-film#readme",
39
39
  "bugs": {
40
- "url": "https://github.com/EminBudak/launch-film/issues"
40
+ "url": "https://github.com/MakersMCP/launch-film/issues"
41
41
  }
42
42
  }
@@ -7,18 +7,18 @@ description: Make a 20 to 40 second launch film (an MP4 at 1920x1080 with music
7
7
 
8
8
  A launch film made from the product itself: its logo cut from its own page, its colors and typefaces, its real screens in a browser window or a phone, and the words its site already uses. You plan the film as a short JSON file, render it, check it, and hand over the MP4, with launch pictures when the user wants them.
9
9
 
10
- The tool is the `launch-film` npm package. It needs Node 22 or newer, Chrome or Chromium, and ffmpeg. Check them first:
10
+ The tool is the `launch-film` npm package. It needs Node 22 or newer, Chrome or Chromium, and ffmpeg and ffprobe 4.4 or newer. Check them first:
11
11
 
12
12
  ```bash
13
- npx -y launch-film@latest doctor
13
+ npx -y launch-film@0.3.0 doctor
14
14
  ```
15
15
 
16
- If ffmpeg is missing, tell the user how to install it (`brew install ffmpeg` on a Mac, `sudo apt install ffmpeg` on Debian or Ubuntu) and stop.
16
+ If ffmpeg or ffprobe is missing, cannot be started or is older than 4.4, tell the user how to install ffmpeg, which comes with ffprobe (`brew install ffmpeg` on a Mac, `sudo apt install ffmpeg` on Ubuntu 22.04, Debian 12 or newer), and stop. doctor also starts Chrome once: if it finds no Chrome, or says that Chrome could not start its sandbox or did not start, tell the user what it says and stop. Each program's line says what is wrong with it. A command that cannot start ffmpeg, ffprobe or Chrome stops before any work with a message that starts `launch-film needs ffmpeg` (or ffprobe, or Chrome) and names the setting or the PATH entry that gave it, what is wrong with it and how to point to one that works. A message that starts `launch-film could not run its stand-ins` or `launch-film cannot put its stand-ins` (the temp folder cannot hold the programs that keep a page from starting one of the machine's, or the machine was too busy to run them), `launch-film cannot start Chrome from the temp folder` (the temp folder's path is too long for Chrome), or `launch-film could not start` says what to do as well. Pass any of these on to the user and stop.
17
17
 
18
18
  ## 1. Get the brand and a first plan
19
19
 
20
20
  ```bash
21
- npx -y launch-film@latest plan <url> --out film/<name>
21
+ npx -y launch-film@0.3.0 plan <url> --out film/<name>
22
22
  ```
23
23
 
24
24
  Give the product's website, or its App Store or Google Play listing (then the listing's icon, screenshots and rating are used, with the colors, fonts and logo of the site it names). Not a social profile: easybrandkit refuses those.
@@ -31,21 +31,21 @@ Then read, in this order:
31
31
  - `film/<name>/words.json`: the page's title, description, headings and the line under each heading.
32
32
  - `film/<name>/film.json`: the plan.
33
33
 
34
- If the brand looks wrong (a cookie wall, a login page, no logo), tell the user what you got and ask for the logo file or the right page. Do not go on with a wrong brand. If the site answered easybrandkit with a bot check, there is no kit: ask the user for the logo file and the main colors instead of guessing.
34
+ If the brand looks wrong (a cookie wall, a login page, no logo), tell the user what you got and ask for the logo file or the right page. A note that the page tried to open an address that is not a web address, such as mailto:, means the site asked the browser to start a program: on Linux none was started, and on a Mac or Windows the note says a program may have opened, so tell the user. Do not go on with a wrong brand. If the site answered easybrandkit with a bot check, there is no kit: ask the user for the logo file and the main colors instead of guessing.
35
35
 
36
- If launch-film says easybrandkit could not be fetched, npx could not download it (no network, or a registry without it): tell the user they can install it with `npm install -g easybrandkit`, and use `--easybrandkit <path to easybrandkit's scripts/easybrandkit.js>` when they have a copy.
36
+ If launch-film says easybrandkit could not be fetched, npx could not download it (no network, or a registry without it): tell the user they can install it with `npm install -g easybrandkit`, and use `--easybrandkit <path to easybrandkit's skills/easybrandkit/scripts/easybrandkit.js>` when they have a copy.
37
37
 
38
38
  ## 2. Pick a look
39
39
 
40
40
  ```bash
41
- npx -y launch-film@latest looks
41
+ npx -y launch-film@0.3.0 looks
42
42
  ```
43
43
 
44
44
  The plan already picked one from the brand: `launch` (dark stage, depth, one bright accent) for dark sites and developer tools, `aurora` (frosted glass over soft color) for vivid consumer and AI products, `gridline` (Swiss grid on paper) for light B2B sites, `pop` (full color fields, stickers) for consumer apps, `journal` (serif headlines on warm paper) for editorial brands. Change `"look"` in film.json if the user asked for a style or another one fits better.
45
45
 
46
46
  ## 3. Write the scenes
47
47
 
48
- film.json holds `look`, `aspect` (`16:9` or `9:16`) and `clips`, played in order. Each clip has a `kind` and a length in `bars` of the look's music (one bar is about 2 seconds; cuts land on the beat). You may give `seconds` instead.
48
+ film.json holds `look`, `aspect` (`16:9` or `9:16`), `music` and `clips`, played in order. `music` is `true` for the look's own bed, `false` for none, `{ "volume": 0.55 }` for the bed at another level (0 to 2), or the path of a track, from film.json's folder or absolute, at least as long as the film. Each clip has a `kind` and a length in `bars` of the look's music (one bar is about 2 seconds; cuts land on the beat). You may give `seconds` instead.
49
49
 
50
50
  | kind | what it shows | fields |
51
51
  | --- | --- | --- |
@@ -56,7 +56,7 @@ film.json holds `look`, `aspect` (`16:9` or `9:16`) and `clips`, played in order
56
56
  | `scroll` | a tall page scrolling in a window | `image` |
57
57
  | `logo` | the logo close with the site's address | `logo` (an easybrandkit logo file) or `icon` (an app icon), `site` |
58
58
 
59
- A scene object has a `type` and its words. List every type and its fields with `npx -y launch-film@latest types`; icon names come from `npx -y launch-film@latest icons <word>`. The ones a launch film uses most:
59
+ A scene object has a `type` and its words. List every type and its fields with `npx -y launch-film@0.3.0 types`; icon names come from `npx -y launch-film@0.3.0 icons <word>`. The ones a launch film uses most:
60
60
 
61
61
  ```json
62
62
  { "type": "opener", "title": "Acme Notes", "text": "Notes that think with you" }
@@ -79,24 +79,26 @@ Words between asterisks are set in the accent color. Rules for the words:
79
79
  ## 4. Render
80
80
 
81
81
  ```bash
82
- npx -y launch-film@latest render film/<name>/film.json
82
+ npx -y launch-film@0.3.0 render film/<name>/film.json
83
83
  ```
84
84
 
85
- Clips render two at a time; a 30 second film takes one to three minutes. The film is `film/<name>/film.mp4`. If a clip fails, the message names it: fix film.json and render again.
85
+ Clips render two at a time; a 30 second film takes one to three minutes. The film is `film/<name>/film.mp4`. If a clip fails, the message names it: fix film.json and render again. When it says that Chrome did not answer in time or that the page did not load, the machine was too busy: render again with `--jobs 1`. When it says that the system ran out of memory, after "Chrome's page crashed", "Chrome could not capture frame", "Chrome was stopped by SIGKILL" or "ffmpeg was stopped by SIGKILL", render again with `--jobs 1` too, which needs less. When it says that Chrome could not start its sandbox, tell the user what the message says to do, and stop.
86
+
87
+ A run that fails or is stopped changes nothing in the folder: the last good plan, brand, film, frames, stills and check stay. Fix the cause and run it again. An earlier file the user made read-only is not replaced: the run names it and stops. That does not hold inside `brand/`: a plan replaces that folder whole, so a plan given a kit with `--brand` takes read-only files there away with the rest. A frames, stills or check folder that is a link takes the new files in the folder it leads to. An earlier file that is a link is replaced by a plain file, and what it led to is left alone; a new file has the mode a new file gets on that system, not the one the earlier file was given.
86
88
 
87
89
  ## 5. Check the film before you hand it over
88
90
 
89
91
  You can't watch the film or hear it, so measure it:
90
92
 
91
93
  ```bash
92
- npx -y launch-film@latest check film/<name>/film.mp4 --expect 1920x1080@25 --seconds 20-40 --lufs -14
94
+ npx -y launch-film@0.3.0 check film/<name>/film.mp4 --expect 1920x1080@25 --seconds 20-40 --lufs -14
93
95
  ```
94
96
 
95
- launch-film renders at 25 fps, 1920x1080 (1080x1920 for 9:16). `--seconds 20-40` is the range a launch film keeps to; when the user asked for a length, give that instead (`--seconds 30` allows half a second either way). Clips last whole bars, so a film planned for 30 seconds can come out two seconds short: to hit a length exactly, give the last clip `seconds` in place of `bars` and render again. `--lufs -14` is the loudness YouTube, X and most social apps play at. If the user has music cues from another tool, add `--cues cues.json` to see whether the cuts land on the beat.
97
+ launch-film renders at 25 fps, 1920x1080 (1080x1920 for 9:16). `--seconds 20-40` is the range a launch film keeps to; when the user asked for a length, give that instead (`--seconds 30` allows half a second either way). Clips last whole bars, so a film planned for 30 seconds can come out two seconds short: to hit a length exactly, give the last clip `seconds` in place of `bars` and render again. `--lufs -14` is the loudness YouTube, X and most social apps play at, and a render brings the film's sound to it. If the user has music cues from another tool, add `--cues cues.json` to see whether the cuts land on the beat.
96
98
 
97
99
  Read `film/<name>/check/CHECK.md` first. It says PASS or FAIL and why, for each check: size, frame rate, length, black, still and silent stretches, loudness, true peak, clipping and cuts on the beat. A warning is something to look at, not always a fault: a title that rests or an end card is a hold, and you can pass the stretches you meant with `--allow 27-30`.
98
100
 
99
- Then look, because a measurement can't read words. Open `check/sheet.png` (a frame from each shot) and `check/wave.png` (the sound over time, with the cuts). For two stills a clip, run `npx -y launch-film@latest frames film/<name>/film.mp4` and open `frames/sheet.jpg`. Check:
101
+ Then look, because a measurement can't read words. Open `check/sheet.png` (a frame from each shot) and `check/wave.png` (the sound over time, with the cuts). For two stills a clip, run `npx -y launch-film@0.3.0 frames film/<name>/film.mp4` and open `frames/sheet.jpg`. Check:
100
102
 
101
103
  - every word is whole, inside the frame and spelled as written;
102
104
  - no text lies on other text or runs out of its card;
@@ -109,20 +111,22 @@ Fix what you find in film.json and render again. If the loudness or the peaks fa
109
111
  ## 6. Launch pictures, when the user wants them
110
112
 
111
113
  ```bash
112
- npx -y launch-film@latest stills film/<name>/film.json --for ph,og,x,play,chrome
114
+ npx -y launch-film@0.3.0 stills film/<name>/film.json --for ph,og,x,play,chrome
113
115
  ```
114
116
 
115
- This makes the pictures a launch needs from the same plan, at the exact size each place asks for, in `film/<name>/stills/`: the Product Hunt gallery (`ph-1.png` to `ph-6.png`, 1270x760) and thumbnail (240x240), `og.png` (1200x630) for link previews, `x.png` (1600x900) for a post on X, `play-feature.png` (1024x500) for Google Play, and the Chrome Web Store tiles (`chrome-small.png` 440x280 and `chrome-marquee.png` 1400x560). Ask for only the ones the user needs with `--for`; a site's address in place of film.json plans the film first.
117
+ This makes the pictures a launch needs from the same plan, at the exact size each place asks for, in `film/<name>/stills/`: the Product Hunt gallery (`ph-1.png` up to `ph-6.png`, 1270x760: the first picture, then one for each scene of the film after it) and thumbnail (240x240), `og.png` (1200x630) for link previews, `x.png` (1600x900) for a post on X, `play-feature.png` (1024x500) for Google Play, and the Chrome Web Store tiles (`chrome-small.png` 440x280 and `chrome-marquee.png` 1400x560). Ask for only the ones the user needs with `--for`; a site's address in place of film.json plans the film first.
116
118
 
117
119
  Read `stills/STILLS.md` and look at every picture with the same list as the frames. The words come from film.json, so fix them there and run `stills` again. Then give the user the folder and say what each file is for.
118
120
 
119
121
  ## Without a plan step
120
122
 
121
- `npx -y launch-film@latest <url>` does steps 1 to 4 in one go with the first plan, and saves the frames. Use it when the user wants a film quickly and has no wishes about the words, and check the MP4 as in step 5 before you hand it over.
123
+ `npx -y launch-film@0.3.0 <url>` does steps 1 to 4 in one go with the first plan, and saves the frames. Use it when the user wants a film quickly and has no wishes about the words, and check the MP4 as in step 5 before you hand it over.
122
124
 
123
125
  ## Options
124
126
 
125
127
  - `--look <name>`, `--seconds <20-40>`, `--aspect 9:16` on `plan` or the one-go command.
126
128
  - `--brand <folder>` uses an easybrandkit folder you already have; `--words <file>` a words.json you already have.
127
- - `--no-music`, `--no-sfx` on the one-go command; or set `"music": false` and `"sfx": false` in film.json.
128
- - `--jobs 1` renders one clip at a time on a slow machine.
129
+ - `--no-music`, `--no-sfx` on `plan` or the one-go command, which write `"music": false` and `"sfx": false` into film.json; for a film already planned, set them in film.json and render again.
130
+ - The cuts fall on bars of the look's own tempo: launch 112 BPM, aurora 96, gridline 120, pop 124, journal 90. A track's beats meet every cut when a bar of the look holds a whole number of the track's beats, with its hit on a cut: four at the look's tempo, two at half of it, eight at twice it, or five for a 120 BPM track in aurora. So when the user has a track of their own, read its tempo first, before you plan the film and before you fit the track (`npx musicfit@latest <track> --analyze`), and plan the film in a look that fits it, or tell the user some cuts will fall between beats.
131
+ - Once the film has rendered, fit the track to it in a folder of its own, with the film's length and the logo close's start from film.timeline.json: `npx musicfit@latest <track> --length 29.333 --hit 24 --fps 25 --out film/<name>/music`. Set `"music"` in film.json to `"music/fitted.wav"` (a path from film.json's folder, or an absolute one) and render again. The track plays in place of the bed at about the bed's level, with its own build and drop, cut at the film's end and faded over the last second, under the sound effects. A track shorter than the film is refused, and the message gives the musicfit command that fits it: the track, the length, the hit and the folder, quoted for the shell. For an earlier fit that the film has outgrown, the command fits the track it was made from again; when that track was not found, the command has a word in quotes such as `'<song.mp3>'` where its path goes: ask the user for it. `check` with `--cues film/<name>/music/cues.json` shows which cuts land on the beat.
132
+ - `--jobs 1` renders one clip at a time, on a slow machine or one short of memory: give it when a render says that Chrome did not answer in time, that the page did not load, or that the system ran out of memory.
package/src/audio.js CHANGED
@@ -4,13 +4,15 @@
4
4
  // recordings and no licences beyond its own: the effects (whooshes, pops,
5
5
  // clicks, hits, sparkles) and a music bed made for the film's own cuts.
6
6
  // Everything is drawn into float buffers at 48 kHz and written as one WAV.
7
+ // A track of the user's own, named in film.json, takes the bed's place.
7
8
  //
8
9
  // The music follows the film: the first clip gets only pads, the groove
9
10
  // starts on the second clip's downbeat, and the logo clip lands on a hit with
10
11
  // the last chord ringing out. Clip lengths are whole bars, so every cut
11
- // falls on a downbeat.
12
+ // falls on a downbeat. What plays before the groove is set a few dB under
13
+ // it (OPENING_UNDER), so a film opens quieter than its body, but with music.
12
14
 
13
- const fs = require("fs");
15
+ const { save } = require("./out");
14
16
 
15
17
  const SR = 48000;
16
18
  const TAU = Math.PI * 2;
@@ -445,6 +447,15 @@ function keysChord(bus, at, seconds, notes, { gain = 0.07 } = {}) {
445
447
  });
446
448
  }
447
449
 
450
+ // How far under the groove the bars before it are set, in dB of their power
451
+ // over both channels. As they are drawn, the pads, keys and arp there sit 8
452
+ // to 16 dB under it, the journal look's keys alone the furthest, and no film
453
+ // played them so: loudnorm's dynamic mode, which set a film's level up to
454
+ // 0.2, lifted a quiet opening. A film's level is now set with one gain
455
+ // (film.js), which keeps the bed as it is drawn, so they are lifted here,
456
+ // by 15.6 dB at most (openingGain).
457
+ const OPENING_UNDER = 4;
458
+
448
459
  // The bed for a film: cuts (clip starts, seconds) after the first start the
449
460
  // groove, the last clip lands on a hit. Returns a Bus.
450
461
  function music({ look = "launch", seconds, cuts = [], seed = 1 }) {
@@ -457,6 +468,10 @@ function music({ look = "launch", seconds, cuts = [], seed = 1 }) {
457
468
  const has = (p) => mood.parts.includes(p);
458
469
  const grooveFrom = cuts.length > 1 ? cuts[1] : bar * 2;
459
470
  const closeAt = cuts.length > 2 ? cuts[cuts.length - 1] : seconds - bar;
471
+ // The pads, keys and arp of the bars before the groove, on a bus of their
472
+ // own, so that they can be lifted (below): as long as their last chord
473
+ // and its reverb ring past the groove's start.
474
+ const opening = new Bus(Math.min(seconds + 2, grooveFrom + bar + 4));
460
475
  const bars = Math.ceil(seconds / bar) + 1;
461
476
  for (let b = 0; b < bars; b++) {
462
477
  const t0 = b * bar;
@@ -467,8 +482,9 @@ function music({ look = "launch", seconds, cuts = [], seed = 1 }) {
467
482
  const chord = chordOf(mood, degree, 0);
468
483
  // Pads and keys hold the harmony throughout; the last chord rings out.
469
484
  const hold = closing ? Math.max(bar, seconds - t0) : bar;
470
- if (has("pad") || has("pad-thin")) padChord(wet, t0, hold, has("pad-thin") ? chord.slice(0, 3) : chord, { gain: has("pad-thin") ? 0.05 : 0.075, cutoff: mood.bright * (groove ? 1 : 0.7) });
471
- if (has("keys")) keysChord(wet, t0, Math.min(hold, bar * 0.95), chord.map((n) => n + 12).slice(0, 3), { gain: 0.06 });
485
+ const harmony = groove || closing ? wet : opening;
486
+ if (has("pad") || has("pad-thin")) padChord(harmony, t0, hold, has("pad-thin") ? chord.slice(0, 3) : chord, { gain: has("pad-thin") ? 0.05 : 0.075, cutoff: mood.bright * (groove ? 1 : 0.7) });
487
+ if (has("keys")) keysChord(harmony, t0, Math.min(hold, bar * 0.95), chord.map((n) => n + 12).slice(0, 3), { gain: 0.06 });
472
488
  if (closing && b === Math.round(closeAt / bar)) {
473
489
  // The hit under the logo.
474
490
  kick(dry, t0, 1.1);
@@ -478,7 +494,7 @@ function music({ look = "launch", seconds, cuts = [], seed = 1 }) {
478
494
  if (!groove) {
479
495
  // Before the groove: a filtered pulse and the arp, quiet.
480
496
  if (!closing && (has("arp") || has("arp-soft"))) {
481
- for (let s = 0; s < 8; s++) pluck(wet, t0 + s * (beat / 2), chord[s % 4] + 12, { gain: 0.035, decay: 0.16, pan: s % 2 ? 0.3 : -0.3 });
497
+ for (let s = 0; s < 8; s++) pluck(opening, t0 + s * (beat / 2), chord[s % 4] + 12, { gain: 0.035, decay: 0.16, pan: s % 2 ? 0.3 : -0.3 });
482
498
  }
483
499
  continue;
484
500
  }
@@ -511,6 +527,14 @@ function music({ look = "launch", seconds, cuts = [], seed = 1 }) {
511
527
  if (grooveFrom > 1.2) dry.mix(riser(Math.min(2, grooveFrom)), grooveFrom - Math.min(2, grooveFrom), 0.25);
512
528
  const out = reverb(wet, { wet: 0.32, size: 0.84 });
513
529
  out.mix(dry, 0, 1);
530
+ // The reverb is linear, so the opening's parts take theirs on their own
531
+ // and are mixed in at the gain that sets them OPENING_UNDER dB under the
532
+ // groove, the riser and the rest of what plays then counted in: from the
533
+ // end of the fade in to the groove, against the groove up to the close
534
+ // (or the film's last second, when the close comes within a beat of it).
535
+ const open = reverb(opening, { wet: 0.32, size: 0.84 });
536
+ const bodyTo = closeAt > grooveFrom + beat ? closeAt : seconds - 1;
537
+ out.mix(open, 0, openingGain(out, open, [Math.min(beat, grooveFrom), grooveFrom], [grooveFrom, bodyTo]));
514
538
  // The whole bed fades in over the first beat and out over the last second.
515
539
  const total = Math.round(seconds * SR);
516
540
  for (let i = 0; i < out.length; i++) {
@@ -522,6 +546,54 @@ function music({ look = "launch", seconds, cuts = [], seed = 1 }) {
522
546
  return { bus: out, beat, bar, bpm: mood.bpm };
523
547
  }
524
548
 
549
+ // The gain that sets `open`, mixed into `out`, OPENING_UNDER dB under the
550
+ // groove over the stretch `[from, to]` of the opening, against `body`, the
551
+ // stretch of the groove. 1 when it is no further under than that already,
552
+ // or when either stretch is too short to say; 6 (15.6 dB) at most.
553
+ function openingGain(out, open, [from, to], [bodyFrom, bodyTo]) {
554
+ if (to - from < 0.5 || bodyTo - bodyFrom < 0.5) return 1;
555
+ const power = (bus, a, b) => {
556
+ const i0 = Math.round(a * SR);
557
+ const i1 = Math.min(bus.length, Math.round(b * SR));
558
+ let sum = 0;
559
+ for (let i = i0; i < i1; i++) sum += bus.L[i] * bus.L[i] + bus.R[i] * bus.R[i];
560
+ return i1 > i0 ? sum / (i1 - i0) : 0;
561
+ };
562
+ const target = power(out, bodyFrom, bodyTo) * 10 ** (-OPENING_UNDER / 10);
563
+ const rest = power(out, from, to);
564
+ const parts = power(open, from, to);
565
+ if (!(parts > 0) || rest + parts >= target) return 1;
566
+ return Math.min(6, Math.sqrt((target - rest) / parts));
567
+ }
568
+
569
+ // ─── the user's own track ──────────────────────────────────────────────────
570
+ // The level the looks' beds are drawn at, so a track takes the bed's place
571
+ // in the mix and the effects sit over it as they sit over a bed.
572
+ const TRACK_LUFS = -14;
573
+
574
+ // The gain that brings a track ({ integrated, peak }, as ebur128 measures
575
+ // it) to the beds' level, held down so its peaks stay at -1 dBFS or under.
576
+ function trackGain({ integrated, peak }) {
577
+ const level = 10 ** ((TRACK_LUFS - integrated) / 20);
578
+ return Number.isFinite(peak) ? Math.min(level, 10 ** ((-1 - peak) / 20)) : level;
579
+ }
580
+
581
+ // A track in the bed's place: the film's length at `gain`, from the film's
582
+ // first frame, faded in over 10 ms so a track cut mid-wave does not click,
583
+ // and out over the last second as the bed is.
584
+ function trackBus({ left, right, seconds, gain = 1 }) {
585
+ const bus = new Bus(seconds);
586
+ const total = Math.min(bus.length, Math.round(seconds * SR));
587
+ const rise = Math.round(0.01 * SR);
588
+ const n = Math.min(total, left.length, right.length);
589
+ for (let i = 0; i < n; i++) {
590
+ const g = gain * Math.min(1, (i + 1) / rise) * Math.min(1, (total - 1 - i) / (SR - 1));
591
+ bus.L[i] = left[i] * g;
592
+ bus.R[i] = right[i] * g;
593
+ }
594
+ return bus;
595
+ }
596
+
525
597
  // ─── the mix ───────────────────────────────────────────────────────────────
526
598
  // Music and effects into one buffer of the film's length; a soft limiter
527
599
  // keeps the peaks under full scale. cues: [{ sfx, at, volume }].
@@ -559,7 +631,7 @@ function writeWav(file, bus) {
559
631
  head.writeUInt16LE(32, 34);
560
632
  head.write("data", 36);
561
633
  head.writeUInt32LE(data.length, 40);
562
- fs.writeFileSync(file, Buffer.concat([head, data]));
634
+ save(file, Buffer.concat([head, data]));
563
635
  }
564
636
 
565
- module.exports = { SR, Bus, MOODS, EFFECTS, effect, music, mixFilm, writeWav };
637
+ module.exports = { SR, Bus, MOODS, EFFECTS, TRACK_LUFS, OPENING_UNDER, effect, music, trackGain, trackBus, mixFilm, writeWav };
package/src/brand.js CHANGED
@@ -6,9 +6,12 @@
6
6
  // next to it). Paths in brand.json are relative to its folder.
7
7
 
8
8
  const fs = require("fs");
9
+ const os = require("os");
9
10
  const path = require("path");
10
11
  const { spawn } = require("child_process");
11
- const { onPath } = require("./chrome");
12
+ const { onPath, withoutOpeners, offTheDesktop } = require("./chrome");
13
+ const { track, tempDir, tempEnv, release, stopping, save } = require("./out");
14
+ const confine = require("./confine");
12
15
 
13
16
  // ─── colour ────────────────────────────────────────────────────────────────
14
17
  const rgb = (hex) => [1, 3, 5].map((k) => parseInt(hex.slice(k, k + 2), 16));
@@ -37,21 +40,45 @@ const normHex = (v) => {
37
40
  // The commands that may run easybrandkit, in the order they are tried: the
38
41
  // one given (a command, or the path of easybrandkit's script), else
39
42
  // LAUNCH_FILM_EASYBRANDKIT, else an easybrandkit installed on PATH, else
40
- // easybrandkit from npm through npx, then from its GitHub repository when
41
- // npm cannot give it.
43
+ // easybrandkit 0.4.1 from npm through npx, then the same release from its
44
+ // GitHub repository when npm cannot give it. The version is pinned, so a run
45
+ // never picks up a newer easybrandkit on its own.
42
46
  function easybrandkitCommands(given = "") {
43
47
  const raw = String(given || process.env.LAUNCH_FILM_EASYBRANDKIT || "").trim();
44
48
  if (raw) {
45
49
  if (/\.(c?js|mjs)$/i.test(raw) && fs.existsSync(raw)) return [[process.execPath, raw]];
46
50
  return [raw.split(" ").filter(Boolean)];
47
51
  }
48
- const installed = onPath(process.platform === "win32" ? "easybrandkit.cmd" : "easybrandkit");
49
- if (installed) return [[installed]];
50
- const npx = process.platform === "win32" ? "npx.cmd" : "npx";
51
- return [[npx, "-y", "easybrandkit@latest"], [npx, "-y", "github:EminBudak/easybrandkit"]];
52
+ const windows = process.platform === "win32";
53
+ const installed = onPath(windows ? "easybrandkit.cmd" : "easybrandkit");
54
+ if (installed) return [windows ? scriptOfInstalled(installed) : [installed]];
55
+ const npx = windows ? scriptOfNpx() : ["npx"];
56
+ return [[...npx, "-y", "easybrandkit@0.4.1"], [...npx, "-y", "github:MakersMCP/easybrandkit#v0.4.1"]];
52
57
  }
53
58
 
54
- const HOW = "Install easybrandkit (npm install -g easybrandkit), or point LAUNCH_FILM_EASYBRANDKIT (or --easybrandkit) at its scripts/easybrandkit.js, or give a kit you already have with --brand.";
59
+ // On Windows npx and an installed easybrandkit are .cmd files. Node starts
60
+ // one only through a shell, and a shell would read the & and % of an address
61
+ // as its own, so the script behind it is run with Node, where it is found
62
+ // next to the .cmd file, as npm puts it.
63
+ function scriptOfInstalled(cmd) {
64
+ const folder = path.join(path.dirname(cmd), "node_modules", "easybrandkit");
65
+ try {
66
+ const { bin } = JSON.parse(fs.readFileSync(path.join(folder, "package.json"), "utf8"));
67
+ const script = path.join(folder, typeof bin === "string" ? bin : bin.easybrandkit);
68
+ if (fs.existsSync(script)) return [process.execPath, script];
69
+ } catch {
70
+ // Not where npm puts it: started as it is, and refused with what to do.
71
+ }
72
+ return [cmd];
73
+ }
74
+
75
+ function scriptOfNpx() {
76
+ const cmd = onPath("npx.cmd");
77
+ const script = cmd ? path.join(path.dirname(cmd), "node_modules", "npm", "bin", "npx-cli.js") : null;
78
+ return script && fs.existsSync(script) ? [process.execPath, script] : ["npx.cmd"];
79
+ }
80
+
81
+ const HOW = "Install easybrandkit (npm install -g easybrandkit), or point LAUNCH_FILM_EASYBRANDKIT (or --easybrandkit) at its skills/easybrandkit/scripts/easybrandkit.js, or give a kit you already have with --brand.";
55
82
 
56
83
  // Runs easybrandkit for a URL into a folder. Resolves the path of brand.json.
57
84
  // The next command is tried only when npx could not fetch easybrandkit; when
@@ -68,9 +95,65 @@ async function runEasybrandkit(url, dir, { log = () => {}, command = "" } = {})
68
95
  }
69
96
  }
70
97
 
98
+ // The Chrome of easybrandkit 0.4.0 and older saves a file a page makes it
99
+ // download, of any size, into the Downloads folder of the user it runs as,
100
+ // where nothing removes it, as launch-film's own Chrome no longer does
101
+ // (chrome.js). 0.4.1, which launch-film runs through npx, refuses downloads,
102
+ // but one on PATH or named by LAUNCH_FILM_EASYBRANDKIT can be older. On Linux
103
+ // Chrome finds that folder in $XDG_CONFIG_HOME/user-dirs.dirs, so easybrandkit
104
+ // is given such a folder in the run's temp folder, `temp`, that names one
105
+ // there: a download goes with the run. The user's own fontconfig settings,
106
+ // which that folder would hide from Chrome, are linked into it.
107
+ function downloadsIn(temp, env) {
108
+ const config = path.join(temp, "config");
109
+ fs.mkdirSync(config);
110
+ const downloads = path.join(temp, "downloads").replace(/["\\]/g, "\\$&");
111
+ save(path.join(config, "user-dirs.dirs"), `XDG_DOWNLOAD_DIR="${downloads}"\n`);
112
+ const fonts = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"), "fontconfig");
113
+ if (fs.existsSync(fonts)) fs.symlinkSync(fonts, path.join(config, "fontconfig"));
114
+ return { ...env, XDG_CONFIG_HOME: config };
115
+ }
116
+
117
+ // easybrandkit runs a Chrome of its own, which a stop or a failure of the
118
+ // run ends with it (out.js, watch). On Linux both get a temp folder of the
119
+ // run's own, so what they leave goes with it, a download among it.
120
+ // easybrandkit's own words name the folder it was given as the user knows it
121
+ // (ownWords): that is the run's copy of the folder's brand/, not a new file.
122
+ // A stop removes the temp folder itself once what uses it has been killed:
123
+ // removed here while Chrome still writes there, the removal's retries would
124
+ // hold the stop up past the moment a supervisor kills the run.
71
125
  function runOnce([cmd, ...pre], url, dir, log) {
72
126
  return new Promise((resolve, reject) => {
73
- const child = spawn(cmd, [...pre, url, "--out", dir], { stdio: ["ignore", "pipe", "pipe"] });
127
+ const temp = process.platform === "linux" ? tempDir("launch-film-brand-") : null;
128
+ const done = () => temp && !stopping() && release(temp);
129
+ // The system short of a file descriptor or a process says so, as a
130
+ // command that cannot start ffmpeg does (programs.js).
131
+ const unstarted = (e) => {
132
+ done();
133
+ const short = require("./programs").short(e, "easybrandkit");
134
+ reject(short ? Object.assign(new Error(short), { short: true }) : new Error(`easybrandkit could not be started (${e.message}). ${HOW}`));
135
+ };
136
+ // The Chrome easybrandkit starts takes its environment, and with it the
137
+ // stand-ins that keep a page from starting a program and the session bus
138
+ // that leads nowhere, which keeps it from the desktop's (chrome.js).
139
+ let env;
140
+ try {
141
+ env = withoutOpeners(temp ? offTheDesktop(downloadsIn(temp, tempEnv(temp)), temp) : process.env);
142
+ } catch (err) {
143
+ done();
144
+ return reject(err);
145
+ }
146
+ let child;
147
+ try {
148
+ child = track(spawn(cmd, [...pre, url, "--out", dir], { stdio: ["ignore", "pipe", "pipe"], env }), { watch: true });
149
+ } catch (e) {
150
+ // A .cmd file on Windows, given without a shell.
151
+ return unstarted(e);
152
+ }
153
+ // Its error listener first: one the system had no file descriptor for
154
+ // has no pipes, and its error comes next (ffmpeg.js run).
155
+ child.on("error", unstarted);
156
+ if (!child.stdout) return;
74
157
  let out = "";
75
158
  child.stdout.on("data", (d) => {
76
159
  out = (out + d).slice(-3000);
@@ -80,16 +163,19 @@ function runOnce([cmd, ...pre], url, dir, log) {
80
163
  out = (out + d).slice(-3000);
81
164
  log(String(d));
82
165
  });
83
- child.on("error", (e) => reject(new Error(`easybrandkit could not be started (${e.message}). ${HOW}`)));
84
166
  child.on("close", (code) => {
167
+ done();
85
168
  if (code === 0 && fs.existsSync(path.join(dir, "brand.json"))) return resolve(path.join(dir, "brand.json"));
86
- const said = out.trim().split("\n").filter(Boolean).slice(-2).join(" ");
169
+ // npm's notices and warnings, as the one npx prints as it ends when a
170
+ // newer npm is out, are not easybrandkit's words: its last two lines
171
+ // are.
172
+ const said = out.trim().split("\n").filter((line) => line.trim() && !/^npm (?:notice|warn)\b/i.test(line)).slice(-2).join(" ");
87
173
  // npm's own error lines mean npx could not fetch easybrandkit (no such
88
174
  // package, no network) before it ran; easybrandkit never prints them.
89
175
  const npm = /^npm (?:error|ERR!) code \S+/m.exec(out) || /^npm (?:error|ERR!) .+/m.exec(out);
90
176
  if (npm) reject(Object.assign(new Error(`easybrandkit could not be fetched (${npm[0].trim()}). ${HOW}`), { unfetched: true }));
91
- else if (/bot check/i.test(out)) reject(new Error(`${said} The brand could not be read: ask for the logo file and the main colors, or give a kit with --brand.`));
92
- else reject(new Error(`easybrandkit failed (exit ${code})${said ? `: ${said}` : ""}`));
177
+ else if (/bot check/i.test(out)) reject(Object.assign(new Error(`${said} The brand could not be read: ask for the logo file and the main colors, or give a kit with --brand.`), { ownWords: true }));
178
+ else reject(Object.assign(new Error(`easybrandkit failed (exit ${code})${said ? `: ${said}` : ""}`), { ownWords: true }));
93
179
  });
94
180
  });
95
181
  }
@@ -97,7 +183,7 @@ function runOnce([cmd, ...pre], url, dir, log) {
97
183
  // A family as Google Fonts names it: "Inter Variable", "InterVariable" and
98
184
  // a framework's hashed "__Inter_d65c78" are all Inter.
99
185
  function familyName(raw) {
100
- let f = String(raw || "").split(",")[0].replace(/["']/g, "").trim();
186
+ let f = String(raw || "").split(",")[0].replace(/["']/g, "").trim().replace(/\s+/g, " ");
101
187
  const hashed = /^__([A-Za-z0-9_]+?)(?:_Fallback)?_[0-9a-f]{5,}$/.exec(f);
102
188
  if (hashed) f = hashed[1].replace(/_/g, " ");
103
189
  f = f.replace(/\s*(Variable|VF|var)$/i, "").replace(/([a-z])Variable$/, "$1").trim();
@@ -115,18 +201,32 @@ function wordsOf(text) {
115
201
  }
116
202
 
117
203
  // brand.json read and put in the shape the film uses. Files that are
118
- // missing are left out with a note.
204
+ // missing are left out with a note. With LAUNCH_FILM_CONFINE set, a file
205
+ // named outside the kit's folder makes the kit one that cannot be read
206
+ // (confine.js).
119
207
  function readBrand(file) {
120
208
  const dir = path.dirname(path.resolve(file));
121
209
  const raw = JSON.parse(fs.readFileSync(file, "utf8"));
210
+ // One that holds null ended the plan in Node's own words, and one that
211
+ // holds a list was planned as a brand with nothing in it.
212
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error(`${path.basename(file)} must hold an object, as easybrandkit's brand.json does`);
122
213
  const notes = [];
123
- const fileOf = (rel) => {
214
+ const outside = [];
215
+ const lists = [];
216
+ const fileOf = (rel, where) => {
124
217
  if (!rel || typeof rel !== "string") return null;
218
+ const out = confine.outside(dir, rel, path.basename(file));
219
+ if (out) {
220
+ outside.push(`${where} "${confine.said(rel)}" ${out}`);
221
+ return null;
222
+ }
125
223
  const abs = path.resolve(dir, rel);
126
224
  if (!fs.existsSync(abs)) {
127
- notes.push(`${rel} is listed in brand.json but missing`);
225
+ notes.push(`${confine.said(rel)} is listed in brand.json but missing`);
128
226
  return null;
129
227
  }
228
+ const list = confine.listOf(abs);
229
+ if (list) lists.push(`${where} "${confine.said(rel)}" is ${list}`);
130
230
  return abs;
131
231
  };
132
232
  let host = "";
@@ -147,12 +247,12 @@ function readBrand(file) {
147
247
  const dark = colors.filter((c) => luminance(c.hex) < 0.04).map((c) => c.hex);
148
248
  const fonts = raw.fonts && typeof raw.fonts === "object" ? raw.fonts : {};
149
249
  const logos = (Array.isArray(raw.logos) ? raw.logos : [])
150
- .map((l) => ({ file: fileOf(l && l.file), where: String((l && l.where) || ""), kind: String((l && l.kind) || ""), background: normHex(l && l.background), alt: String((l && l.alt) || "") }))
250
+ .map((l, i) => ({ file: fileOf(l && l.file, `logos[${i}].file`), where: String((l && l.where) || ""), kind: String((l && l.kind) || ""), background: normHex(l && l.background), alt: String((l && l.alt) || "") }))
151
251
  .filter((l) => l.file);
152
252
  const screens = (Array.isArray(raw.screenshots) ? raw.screenshots : [])
153
- .map((s) => ({ file: fileOf(s && s.file), width: Number(s && s.width) || 0, height: Number(s && s.height) || 0 }))
253
+ .map((s, i) => ({ file: fileOf(s && s.file, `screenshots[${i}].file`), width: Number(s && s.width) || 0, height: Number(s && s.height) || 0 }))
154
254
  .filter((s) => s.file);
155
- const stores = (Array.isArray(raw.stores) ? raw.stores : []).filter((s) => s && s.ok !== false).map((s) => ({
255
+ const stores = (Array.isArray(raw.stores) ? raw.stores : []).map((s, i) => [s, i]).filter(([s]) => s && s.ok !== false).map(([s, i]) => ({
156
256
  type: String(s.type || ""),
157
257
  url: String(s.url || ""),
158
258
  name: String(s.name || ""),
@@ -160,8 +260,10 @@ function readBrand(file) {
160
260
  description: String(s.description || ""),
161
261
  // A listing names the maker's own site.
162
262
  site: String(s.site || ""),
163
- assets: (Array.isArray(s.assets) ? s.assets : []).map((a) => ({ file: fileOf(a && a.file), kind: String((a && a.kind) || ""), width: Number(a && a.width) || 0, height: Number(a && a.height) || 0 })).filter((a) => a.file),
263
+ assets: (Array.isArray(s.assets) ? s.assets : []).map((a, k) => ({ file: fileOf(a && a.file, `stores[${i}].assets[${k}].file`), kind: String((a && a.kind) || ""), width: Number(a && a.width) || 0, height: Number(a && a.height) || 0 })).filter((a) => a.file),
164
264
  }));
265
+ if (outside.length) throw new Error(`${path.basename(file)} names files outside its folder, which LAUNCH_FILM_CONFINE does not allow: ${outside.join(", ")}`);
266
+ if (lists.length) throw new Error(`${path.basename(file)} names lists of other files where pictures go, whose files ffmpeg would open wherever they are, which LAUNCH_FILM_CONFINE does not allow: ${lists.join(", ")}`);
165
267
  const appStores = stores.filter((s) => /appstore|googleplay|play/i.test(s.type));
166
268
  const phoneScreens = appStores.flatMap((s) => s.assets.filter((a) => /screen/i.test(a.kind) && a.height > a.width));
167
269
  const appIcon = appStores.flatMap((s) => s.assets.filter((a) => /icon/i.test(a.kind)))[0] || null;