xevol 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xevol",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Xevol is a tool to consume, remix, make, publish, and offer systems, products, and workflows.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,12 @@
1
+ # Starter film
2
+
3
+ A 9-second code-drawn film: a title, three points, an end card, and a soundtrack mixed in the cloud.
4
+
5
+ xevol film render . --brand <brand> --draft --wait # a cheap review cut
6
+ xevol film render . --brand <brand> --wait # a final, with text and master checks
7
+ xevol film render . --brand <brand> --format wide --wait # 1920x1080
8
+
9
+ Edit `COPY`, the colours and `T` in `film.html`. Keep `window.DUR`, render.json `"duration"` and `DUR` in
10
+ `scripts/mix.py` equal. For a voice-over, make one with Xevol's `make_voice`, download it to `assets/vo.wav` and set
11
+ `V` in `scripts/mix.py`. Read `xevol film skill` for the craft rules. Font: Onest, SIL Open Font License
12
+ (`assets/fonts/OFL-Onest.txt`).
@@ -0,0 +1,93 @@
1
+ Copyright 2021 The Onest Project Authors (https://github.com/simpals/onest)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -1,8 +1,101 @@
1
1
  <!doctype html>
2
+ <html lang="en">
3
+ <head>
2
4
  <meta charset="utf-8">
3
- <title>Synthetic code film</title>
5
+ <title>Starter film</title>
6
+ <style>
7
+ @font-face { font-family: Onest; src: url(assets/fonts/onest-latin.woff2) format('woff2'); font-weight: 100 900;
8
+ unicode-range: U+0000-00FF, U+2013-2014, U+2018-201E, U+2026; }
9
+ @font-face { font-family: Onest; src: url(assets/fonts/onest-cyrillic-wght-normal.woff2) format('woff2'); font-weight: 100 900;
10
+ unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
11
+ html, body { margin: 0; background: #111; }
12
+ canvas { display: block; }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <canvas id="frame"></canvas>
4
17
  <script>
5
- // A fixture, not a real film: the page contract without any company content.
6
- window.DUR = 2;
7
- window.seek = () => {};
18
+ // A starter code film: a title, three points that appear one by one, and an end card. Replace COPY, the colours
19
+ // and the times; keep the contract: frame t is drawn from t alone (no clocks, no Math.random, no network),
20
+ // window.DUR matches render.json "duration", window.ready resolves when fonts are loaded, window.seek(t) draws.
21
+ // window.CUES lists the picture's sound moments; scripts/mix.py turns them into the soundtrack in the cloud.
22
+ // Tall (1080x1920) by default; `xevol film render . --format wide` renders 1920x1080 (?shape=16x9).
23
+ const WIDE = new URLSearchParams(location.search).get('shape') === '16x9';
24
+ const W = WIDE ? 1920 : 1080, H = WIDE ? 1080 : 1920, DUR = 9;
25
+ const ACCENT = '#5bc0eb', INK = '#111111', WHITE = '#ffffff', GREY = '#a7a7a7';
26
+ const COPY = {
27
+ title: 'Say one thing.',
28
+ sub: 'Then show how.',
29
+ points: ['First, the problem', 'Then, what changes', 'Last, the result'],
30
+ end: 'example.com',
31
+ };
32
+ // When each part appears, in seconds. Text needs about 1 s per short line to be read.
33
+ const T = { title: 0, sub: 1.0, points: [3.0, 4.2, 5.4], end: 7.2 };
34
+ const CUES = [
35
+ {t: T.title, kind: 'swell'},
36
+ ...T.points.map(t => ({t, kind: 'tick'})),
37
+ {t: T.end, kind: 'chime'},
38
+ ];
39
+ window.CUES = CUES; window.DUR = DUR;
40
+
41
+ const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
42
+ const eOut = k => 1 - Math.pow(1 - clamp(k), 3);
43
+ const at = (t, a, d = 0.45) => clamp((t - a) / d);
44
+
45
+ const c = document.getElementById('frame');
46
+ c.width = W; c.height = H;
47
+ const G = c.getContext('2d');
48
+
49
+ function text(s, x, y, size, color, {weight = 700, align = 'left', alpha = 1, rise = 0} = {}) {
50
+ if (alpha <= 0) return;
51
+ G.save();
52
+ G.globalAlpha = alpha;
53
+ G.font = `${weight} ${size}px Onest`;
54
+ G.letterSpacing = `${(size >= 100 ? -0.03 : -0.01) * size}px`;
55
+ G.fillStyle = color; G.textAlign = align; G.textBaseline = 'alphabetic';
56
+ G.fillText(s, x, y + rise);
57
+ G.restore();
58
+ }
59
+
60
+ function draw(t) {
61
+ G.fillStyle = INK; G.fillRect(0, 0, W, H);
62
+ // A slow glow that never stops moving: a held, perfectly still frame reads as a frozen video (master-audit).
63
+ const gy = H * (0.85 - 0.35 * t / DUR), gx = W * (0.35 + 0.3 * t / DUR);
64
+ const glow = G.createRadialGradient(gx, gy, 0, gx, gy, Math.max(W, H) * 0.55);
65
+ glow.addColorStop(0, 'rgba(91,192,235,0.16)'); glow.addColorStop(1, 'rgba(91,192,235,0)');
66
+ G.fillStyle = glow; G.fillRect(0, 0, W, H);
67
+ const x = WIDE ? 160 : 90, s = WIDE ? 0.9 : 1;
68
+
69
+ // Title, then it fades out as the points arrive (fade, do not fly: fast text cannot be read).
70
+ const titleOut = eOut(at(t, 2.5, 0.4));
71
+ const a = eOut(at(t, T.title)) * (1 - titleOut);
72
+ text(COPY.title, x, H * 0.45, 120 * s, WHITE, {weight: 800, alpha: a, rise: (1 - eOut(at(t, T.title))) * 30});
73
+ text(COPY.sub, x, H * 0.45 + 110 * s, 70 * s, ACCENT, {weight: 600, alpha: eOut(at(t, T.sub)) * (1 - titleOut)});
74
+
75
+ // Three points, each lit when it arrives and dimmed when the next one does.
76
+ const pointsOut = eOut(at(t, T.end - 0.3, 0.4));
77
+ COPY.points.forEach((p, i) => {
78
+ const k = eOut(at(t, T.points[i]));
79
+ const next = i < 2 ? eOut(at(t, T.points[i + 1], 0.35)) : 0;
80
+ const y = H * 0.36 + i * 160 * s;
81
+ G.save(); G.globalAlpha = k * (1 - 0.55 * next) * (1 - pointsOut);
82
+ G.fillStyle = ACCENT; G.fillRect(x, y - 54 * s, 12 * s, 64 * s); G.restore();
83
+ text(p, x + 44 * s, y, 66 * s, WHITE, {weight: 700, alpha: k * (1 - 0.55 * next) * (1 - pointsOut), rise: (1 - k) * 24});
84
+ });
85
+
86
+ // End card.
87
+ const e = eOut(at(t, T.end));
88
+ text(COPY.end, W / 2, H * 0.5, 92 * s, WHITE, {weight: 800, align: 'center', alpha: e, rise: (1 - e) * 24});
89
+ G.save(); G.globalAlpha = e; G.fillStyle = ACCENT;
90
+ G.fillRect(W / 2 - 220 * s * e, H * 0.5 + 40 * s, 440 * s * e, 10 * s); G.restore();
91
+ text('Made with xevol film', W / 2, H * 0.5 + 140 * s, 40 * s, GREY, {weight: 500, align: 'center', alpha: eOut(at(t, T.end + 0.4))});
92
+ }
93
+
94
+ window.seek = t => draw(Math.max(0, Math.min(DUR, t)));
95
+ window.ready = (async () => {
96
+ for (const w of [500, 600, 700, 800]) await document.fonts.load(`${w} 100px Onest`, 'Say one thing.');
97
+ draw(0);
98
+ })();
8
99
  </script>
100
+ </body>
101
+ </html>
@@ -1,26 +1,5 @@
1
- {
2
- "width": 1080,
3
- "height": 1920,
4
- "fps": 30,
5
- "sub": 2,
6
- "shutter": 180,
7
- "query": { "shape": "9x16" },
8
- "out": "out/9x16",
9
- "bundle": ["film.html", "assets/**"],
10
- "audio": "out/audio.wav",
11
- "finish": ["scripts/finish.py", "9x16"],
12
- "duration": 2,
13
- "formats": {
14
- "tall": {
15
- "width": 1920,
16
- "height": 1080,
17
- "out": "out/16x9",
18
- "query": { "shape": "16x9" },
19
- "finish": ["scripts/finish.py", "16x9"]
20
- },
21
- "localized": {
22
- "out": "out/{lang}",
23
- "finish": ["scripts/finish.py", "9x16", "{lang}.json"]
24
- }
25
- }
26
- }
1
+ {"width": 1080, "height": 1920, "fps": 30, "sub": 4, "shutter": 180, "duration": 9,
2
+ "out": "out/9x16",
3
+ "bundle": ["film.html", "assets/**"],
4
+ "mix": {"cues": ["--out", "out"], "run": ["scripts/mix.py"], "out": "out/audio.wav"},
5
+ "formats": {"wide": {"width": 1920, "height": 1080, "out": "out/16x9", "query": {"shape": "16x9"}}}}
@@ -0,0 +1,121 @@
1
+ """The starter film's soundtrack, made in the cloud (render.json "mix"): xevol film render runs it, not you.
2
+
3
+ render.mjs . --cues --out out -> out/cues.json (the picture's window.CUES)
4
+ python -I scripts/mix.py -> out/audio.wav, 48 kHz stereo, DUR seconds, about -16 LUFS / -2 dBTP
5
+
6
+ Optional voice-over: put a 48 kHz 16-bit WAV at assets/vo.wav (download one made by Xevol's make_voice) and set V
7
+ to when it starts; the bed ducks under it. Without it the film has music and cue sounds only. One synthesized sound
8
+ per cue kind in SOUNDS. numpy and ffmpeg only; no network. Keep DUR equal to render.json "duration".
9
+ """
10
+ import json
11
+ import os
12
+ import subprocess
13
+ import sys
14
+ import wave
15
+ from pathlib import Path
16
+
17
+ import numpy as np
18
+
19
+ ROOT = Path(os.environ.get('FILM_ROOT') or Path(__file__).resolve().parent.parent)
20
+ OUT = ROOT / 'out'
21
+ SR, DUR, V = 48000, 9.0, 0.4
22
+ N = int(DUR * SR)
23
+ t_all = np.arange(N) / SR
24
+
25
+
26
+ def read_voice():
27
+ with wave.open(str(ROOT / 'assets/vo.wav'), 'rb') as w:
28
+ assert w.getframerate() == SR and w.getsampwidth() == 2, 'vo.wav must be 48 kHz 16-bit'
29
+ y = np.frombuffer(w.readframes(w.getnframes()), np.int16).astype(np.float32) / 32768
30
+ return y.reshape(-1, w.getnchannels()).mean(axis=1)
31
+
32
+
33
+ def env(n, attack, release):
34
+ e = np.ones(n, np.float32)
35
+ a, r = int(attack * SR), int(release * SR)
36
+ e[:a] = np.linspace(0, 1, a) if a else 1
37
+ e[n - r:] *= np.linspace(1, 0, r) ** 2 if r else 1
38
+ return e
39
+
40
+
41
+ def tone(freqs, seconds, decay, level):
42
+ n = int(seconds * SR)
43
+ t = np.arange(n) / SR
44
+ y = sum(np.sin(2 * np.pi * f * t) * (0.6 ** i) for i, f in enumerate(freqs))
45
+ return (y * np.exp(-t / decay) * env(n, 0.004, 0.05) * level).astype(np.float32)
46
+
47
+
48
+ def noise_swell(seconds, level):
49
+ n = int(seconds * SR)
50
+ rng = np.random.default_rng(7) # fixed seed: the same mix every time
51
+ y = rng.standard_normal(n).astype(np.float32)
52
+ k = np.exp(-np.arange(256) / 40); k /= k.sum()
53
+ y = np.convolve(y, k, 'same') # soften the hiss
54
+ shape = np.sin(np.linspace(0, np.pi, n)) ** 2
55
+ return (y * shape * level).astype(np.float32)
56
+
57
+
58
+ SOUNDS = {
59
+ 'swell': lambda: noise_swell(1.2, 0.05),
60
+ 'tick': lambda: tone([1318.5, 2637], 0.35, 0.07, 0.16), # E6, a pluck per lesson part
61
+ 'whoosh': lambda: noise_swell(0.7, 0.08),
62
+ 'chime': lambda: tone([1760, 2637, 3520], 1.6, 0.45, 0.14),
63
+ 'pop': lambda: tone([880, 1760], 0.25, 0.05, 0.14),
64
+ }
65
+
66
+
67
+ def bed():
68
+ # D major, warm and slow: Dmaj7, Bm7, Gmaj7, A, three seconds each, sines with a slow fade between chords.
69
+ chords = [[146.83, 220.0, 277.18, 369.99], [123.47, 185.0, 220.0, 293.66],
70
+ [98.0, 146.83, 246.94, 293.66]]
71
+ y = np.zeros(N, np.float32)
72
+ for i, chord in enumerate(chords):
73
+ a, b = int(i * 3.0 * SR), int(min(DUR, i * 3.0 + 3.6) * SR)
74
+ t = np.arange(b - a) / SR
75
+ part = sum(np.sin(2 * np.pi * f * t) + 0.5 * np.sin(2 * np.pi * f * 1.003 * t) for f in chord)
76
+ y[a:b] += part * env(b - a, 0.8, 0.9) * 0.022
77
+ y[-int(1.2 * SR):] *= np.linspace(1, 0, int(1.2 * SR)) ** 2 # the film fades out
78
+ return y
79
+
80
+
81
+ def main():
82
+ cues = json.loads((OUT / 'cues.json').read_text())['cues']
83
+ voice = np.zeros(N, np.float32)
84
+ if (ROOT / 'assets/vo.wav').exists():
85
+ vo = read_voice()
86
+ a = int(V * SR)
87
+ voice[a:a + len(vo)] = vo[:N - a]
88
+
89
+ # Duck the bed by 7 dB wherever the voice is speaking (a 150 ms envelope follower).
90
+ k = np.ones(int(0.15 * SR), np.float32) / int(0.15 * SR)
91
+ level = np.convolve(np.abs(voice), k, 'same')
92
+ duck = 1 - (1 - 10 ** (-7 / 20)) * np.clip(level / 0.02, 0, 1)
93
+ music = bed() * duck
94
+
95
+ fx = np.zeros(N, np.float32)
96
+ for cue in cues:
97
+ s = SOUNDS[cue['kind']]()
98
+ start = int(float(cue['t']) * SR) - (len(s) // 2 if cue['kind'] in ('swell', 'whoosh') else 0)
99
+ start = max(0, start)
100
+ fx[start:start + len(s)] += s[:N - start]
101
+
102
+ left = voice + music + fx
103
+ right = voice + music * 0.97 + fx
104
+ mix = np.stack([left, right], axis=1)
105
+ raw = OUT / 'mix-raw.wav'
106
+ with wave.open(str(raw), 'wb') as w:
107
+ w.setnchannels(2); w.setsampwidth(2); w.setframerate(SR)
108
+ w.writeframes((np.clip(mix, -1, 1) * 32767).astype(np.int16).tobytes())
109
+ # Loudness to the craft target, then exactly 12.000 s at 48 kHz stereo.
110
+ r = subprocess.run(['ffmpeg', '-v', 'error', '-y', '-i', str(raw), '-af',
111
+ f'loudnorm=I=-16:TP=-2:LRA=11,aresample={SR},apad,atrim=0:{DUR}',
112
+ '-ar', str(SR), '-ac', '2', '-c:a', 'pcm_s16le', str(OUT / 'audio.wav')],
113
+ capture_output=True, text=True)
114
+ if r.returncode:
115
+ sys.exit(f'mix.py: ffmpeg failed: {r.stderr[-800:]}')
116
+ raw.unlink()
117
+ print(f'out/audio.wav: {len(cues)} cues, bed in D, voice {"at " + str(V) + " s" if voice.any() else "none"}, loudnorm -16 LUFS')
118
+
119
+
120
+ if __name__ == '__main__':
121
+ main()
@@ -1 +0,0 @@
1
- synthetic font placeholder
@@ -1 +0,0 @@
1
- synthetic plate
@@ -1 +0,0 @@
1
- not declared in render.json
@@ -1 +0,0 @@
1
- RIFFsynthetic-wav
@@ -1 +0,0 @@
1
- print("synthetic finish")