diff --git a/tools/video/beings.js b/tools/video/beings.js new file mode 100644 index 00000000..daf9e970 --- /dev/null +++ b/tools/video/beings.js @@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * (JIANT 0.8.0) the beings of the design studies (firmware/src/ui_being.c, ported to the canvas, with organelles): + * the palette, the heat ramp, the genomes, organism(); for the films (tools/video/tutorial.html) */ +/* ---------------------------------------------------------------- palette: JIANT + heat_col + the plates' inks --- */ +const C = { text: "#f4f1ea", dim: "#6e6a78", mid: "#a39fae", faint: "#2a2633", rule: "#1c1a22", + violet: "#b870ff", orange: "#ff7a00", cyan: "#3fd6dc", yellow: "#ffd400", red: "#f72831", pink: "#ff5aa8", + green: "#7ccf5a", navy: "#060a2e", blue: "#1b2fd8" }; +const H = [[0, 208, 255], [90, 60, 255], [181, 48, 230], [247, 40, 49], [255, 121, 0], [255, 212, 0], [255, 255, 255]]; +function heat(v, a = 1) { + v = Math.max(0, Math.min(256, v)); + const k = Math.min(5, Math.floor(v * 6 / 257)), m = (v * 6 - k * 256) / 256, p = H[k], q = H[k + 1]; + const c = p.map((x, j) => Math.round(x + (q[j] - x) * m)); + return a < 1 ? `rgba(${c},${a})` : `rgb(${c})`; +} +const clamp = (v, a, b) => Math.max(a, Math.min(b, v)); +const TAU = Math.PI * 2; +const hash = (n) => { n = Math.imul(n ^ 0x9e3779b9, 2654435761); n ^= n >>> 15; return (n >>> 0) / 4294967296; }; + +/* ---------------------------------------------------------------- the beings: ui_being.c, ported, + organelles --- */ +const G = { + rad: [6, 18, 16, 3, 22, 0, 6], amo: [3, 5, 14, 2, 26, 3, 2], dia: [4, 6, 10, 4, 18, 0, 1], cil: [10, 30, 8, 5, 20, 1, 10], + spo: [5, 9, 12, 3, 19, 2, 4], wor: [2, 4, 16, 2, 30, 1, 3], pol: [8, 12, 12, 6, 17, 0, 8], hyd: [3, 7, 15, 3, 21, 4, 5], + drm: [12, 0, 10, 3, 18, 0, 6], +}; +const LANE = [["BD", [3, 0, 2, 2, 16, 0, 2]], ["SD", [12, 0, 14, 3, 16, 0, 6]], ["CP", [5, 0, 8, 5, 18, 2, 3]], ["CH", [22, 0, 6, 4, 16, 0, 10]], + ["OH", [18, 0, 12, 4, 16, 1, 8]], ["TM", [4, 0, 4, 3, 17, 0, 2]], ["RS", [4, 0, 9, 4, 16, 0, 1]], ["CB", [5, 0, 16, 5, 16, 0, 5]]]; +const gen = (a) => ({ k0: a[0], kk: a[1], ss: a[2], lob: a[3], ax: a[4], tw: a[5], sh: a[6] }); +const laneF = (ga, l) => ({ spikes: ga[0], len: ga[2] * 6, wob: 40, lob: ga[3], nuc: l === 2 ? 3 : 1, sep: 160 }); +/* one isotherm's points (bg_outline). f.m blends in a second species (f.lobB, f.spikesB, gB): the organ transforming. + tum: tumours, bumps {a, h, w} on every isotherm */ +function iso(g, f, cx, cy, r, outer, t, tum, nv) { + const pts = [], m = f.m || 0, gB = f.gB || g, ax = g.ax + (gB.ax - g.ax) * m, sh = g.sh + (gB.sh - g.sh) * m, tw = g.tw + (gB.tw - g.tw) * m; + for (let i = 0; i <= nv; i++) { + const th = (i % nv) / nv * TAU; + const wA = 0.28 * Math.sin(f.lob * th + t) + 0.12 * Math.sin((f.lob + 2) * th - 2 * t); + const wB = m ? 0.28 * Math.sin(f.lobB * th + t) + 0.12 * Math.sin((f.lobB + 2) * th - 2 * t) : 0; + let rr = r + (r * f.wob / 256) * (wA * (1 - m) + wB * m); + if (outer) { + const sp = (k) => { const c2 = Math.sin(k * th / 2 + tw * 3000 / 65536 * TAU + Math.PI / 2); return c2 > 0 ? Math.pow(c2, sh) : 0; }; + const p = sp(f.spikes) * (1 - m) + (m ? sp(f.spikesB) * m : 0); + rr += (r * f.len / 256) * p * 26 / 16; + rr += (r * f.ripple / 256) * Math.sin(th * 18 + 3 * t) / 14; + if (f.fray) rr += ((hash(i % nv + Math.floor(t * 7) * 977) * 256 - 128) * (r * f.fray / 256)) / 1800; + } + for (const u of tum) { const d = Math.atan2(Math.sin(th - u.a), Math.cos(th - u.a)); rr += r * u.h * Math.exp(-((d / u.w) ** 2)); } + pts.push([cx + rr * Math.cos(th) * ax / 16, cy + rr * Math.sin(th), rr, th]); + } + return pts; +} +function path(ctx, pts) { ctx.beginPath(); pts.forEach((p, i) => (i ? ctx.lineTo(p[0], p[1]) : ctx.moveTo(p[0], p[1]))); ctx.closePath(); } +function ring(ctx, x, y, r, col) { ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r), 0, TAU); ctx.strokeStyle = col; ctx.stroke(); } +function hatch(ctx, ang, gap, col, x, y, s) { /* parallel lines through the current clip, around x y */ + ctx.strokeStyle = col; ctx.lineWidth = 1; ctx.beginPath(); + const c = Math.cos(ang), sn = Math.sin(ang); + for (let k = -s; k <= s; k += gap) { ctx.moveTo(x + k * -sn - s * c, y + k * c - s * sn); ctx.lineTo(x + k * -sn + s * c, y + k * c + s * sn); } + ctx.stroke(); +} +function star(ctx, x, y, r, n, col, a0 = 0) { + ctx.strokeStyle = col; ctx.lineWidth = 1; ctx.beginPath(); + for (let k = 0; k < n; k++) { const a = a0 + k / n * TAU; ctx.moveTo(x, y); ctx.lineTo(x + Math.cos(a) * r, y + Math.sin(a) * r); } + ctx.stroke(); ctx.fillStyle = col; ctx.beginPath(); ctx.arc(x, y, Math.max(1, r * 0.22), 0, TAU); ctx.fill(); +} +/* the organism. o.style: "thermal" (the firmware's lines), "plate" (Auzoux: pellicle, cilia, vacuoles), "pet" + (filled isotherms), "ghost" (an ancestor, cream and dim), "dim" (muted). o.ex excitement, o.tum tumours, + o.voices food vacuoles, o.beat 0..1 the contractile vacuole */ +function organism(ctx, ga, f0, cx, cy, r, en, t, o = {}) { + const g = gen(ga), E = en * 256, f = { sep: 0, fray: 0, ripple: 0, ...f0 }, st = o.style || "thermal"; + if (f.gB && !f.gB.ax) f.gB = gen(f.gB); + if (o.ex) { + const e = E * 0.4; + f.wob = clamp(f.wob + e * o.ex / 4, 0, 256); f.len = clamp(f.len + e * o.ex / 3, 0, 420); + f.ripple = clamp(f.ripple + e * o.ex / 3, 0, 256); f.fray = clamp(f.fray + e * o.ex / 6, 0, 256); + } + r += r * E * 30 / 65536; + const SC = [256, 180, 112, 52], HT = [28, 90, 150, 206], tum = o.tum || [], nv = o.nv || 96; + const isos = SC.map((s, i) => iso(g, f, cx, cy, r * s / 256, !i, t, tum, i ? nv / 2 : nv)); + const nuc = []; + for (let n = 0; n < f.nuc; n++) { + const a = t + n * TAU / f.nuc, d = f.nuc > 1 ? r * (24 + f.sep * 40 / 256) / 100 : 0; + nuc.push([cx + d * Math.cos(a) * g.ax / 16, cy + d * Math.sin(a) * 0.7]); + } + ctx.lineWidth = 1; + if (st === "dim") { path(ctx, isos[0]); ctx.setLineDash([2, 2]); ctx.strokeStyle = o.col || C.dim; ctx.stroke(); ctx.setLineDash([]); return { r, isos, nuc, out: isos[0], f }; } + if (st === "pet") { + const gr = ctx.createRadialGradient(cx, cy, r * 0.6, cx, cy, r * 2.1); + gr.addColorStop(0, "rgba(27,47,216,.75)"); gr.addColorStop(0.6, "rgba(20,30,150,.35)"); gr.addColorStop(1, "rgba(6,10,46,0)"); + ctx.fillStyle = gr; ctx.beginPath(); ctx.ellipse(cx, cy, r * 2.1 * g.ax / 16, r * 2.1, 0, 0, TAU); ctx.fill(); + ctx.save(); ctx.filter = `blur(${o.blur ?? 1}px)`; + const PH = [10, 70, 140, 200]; + isos.forEach((p, i) => { path(ctx, p); ctx.fillStyle = heat(PH[i] + E * 50 / 256); ctx.fill(); }); + nuc.forEach(([x, y]) => { ctx.fillStyle = heat(236 + E * 20 / 256); ctx.beginPath(); ctx.arc(x, y, r * 0.13, 0, TAU); ctx.fill(); }); + tum.forEach((u) => { const p = atAngle(isos[1], u.a); ctx.fillStyle = heat(220); ctx.beginPath(); ctx.arc(p[0], p[1], r * u.h * 0.6, 0, TAU); ctx.fill(); }); + ctx.restore(); + return { r, isos, nuc, out: isos[0], f }; + } + const ghost = st === "ghost"; + isos.forEach((p, i) => { + path(ctx, p); + ctx.strokeStyle = ghost ? (i ? "rgba(244,241,234,.22)" : "rgba(244,241,234,.5)") : st === "plate" && !i ? C.text : heat(HT[i] + E * 40 / 256); + ctx.stroke(); + }); + if (st === "plate") { + const out = isos[0]; + path(ctx, iso(g, f, cx, cy, r * 0.9, true, t, tum, nv)); ctx.strokeStyle = "rgba(244,241,234,.45)"; ctx.stroke(); /* the pellicle, doubled */ + ctx.strokeStyle = "rgba(244,241,234,.55)"; ctx.beginPath(); /* the cilia, beating */ + for (let i = 0; i < out.length - 1; i += 2) { + const [x, y] = out[i], [x2, y2] = out[i + 1], nx = y2 - y, ny = -(x2 - x), l = Math.hypot(nx, ny) || 1; + const len = (1.6 + 1.2 * Math.sin(i * 0.45 - t * 7)) * (1 + f.fray / 200) * (r > 14 ? 1.3 : 0.8); + ctx.moveTo(x, y); ctx.lineTo(x + nx / l * len, y + ny / l * len); + } + ctx.stroke(); + for (let k = 0; k < 14; k++) { /* granules */ + const a = hash(k * 31 + 7) * TAU, d = r * 0.45 * Math.sqrt(hash(k * 17 + 3)); + ctx.fillStyle = k % 3 ? "rgba(255,122,0,.8)" : "rgba(255,212,0,.8)"; ctx.fillRect(cx + Math.cos(a + t * 0.1) * d * g.ax / 16, cy + Math.sin(a + t * 0.1) * d, 1, 1); + } + const nvc = o.voices ?? 1; /* food vacuoles: a voice each */ + for (let k = 0; k < nvc; k++) { + const a = -t * 0.3 + k * TAU / Math.max(nvc, 1) + 1, d = r * 0.3, x = cx + Math.cos(a) * d * g.ax / 16, y = cy + Math.sin(a) * d * 0.8, rv = r * 0.12 + 0.6; + ring(ctx, x, y, rv, C.pink); ctx.fillStyle = C.red; ctx.fillRect(x - 0.5, y - 0.5, 1.5, 1.5); + } + const b = o.beat ?? 0, sx = cx + r * 0.42 * g.ax / 16, sy = cy - r * 0.18; /* the contractile vacuole */ + star(ctx, sx, sy, r * (0.1 + 0.12 * (1 - b)), 6, C.orange, t * 0.4); + o.cv = [sx, sy]; + } + tum.forEach((u) => { /* tumours: hot hatched nodules */ + const p = atAngle(isos[0], u.a), q = atAngle(isos[1], u.a), x = (p[0] + q[0]) / 2, y = (p[1] + q[1]) / 2, rt = Math.max(1.5, r * u.h * 0.55); + ctx.save(); ctx.beginPath(); ctx.arc(x, y, rt, 0, TAU); ctx.clip(); hatch(ctx, 0.8, 2, C.red, x, y, rt + 2); ctx.restore(); + ring(ctx, x, y, rt, C.orange); ctx.fillStyle = heat(240); ctx.fillRect(x - 0.5, y - 0.5, 1.5, 1.5); + }); + nuc.forEach(([x, y]) => { ring(ctx, x, y, r * 0.15, ghost ? "rgba(244,241,234,.5)" : st === "plate" ? C.cyan : heat(214 + E * 42 / 256)); ring(ctx, x, y, r * 0.06, ghost ? C.dim : heat(240)); }); + return { r, isos, nuc, out: isos[0], f, cv: o.cv }; +} +const tipOf = (pts) => pts.reduce((m, p) => (p[2] > m[2] ? p : m), pts[0]); +function atAngle(pts, a) { let best = pts[0], bd = 9; for (const p of pts) { const d = Math.abs(Math.atan2(Math.sin(p[3] - a), Math.cos(p[3] - a))); if (d < bd) { bd = d; best = p; } } return best; } + +/* ---------------------------------------------------------------- the song --- */ +const TR = [ + { n: "ACID", eng: "ANALOG", sp: "RADIOLARIA", ab: "RAD", id: "D732", g: G.rad, f: { spikes: 24, len: 98, wob: 66, lob: 3, nuc: 2, ripple: 202 }, db: "-6.0", lv: 0.78, pan: -0.31, pat: 0xB2B2, amp: 0.9, tau: 0.16, v: 1 }, + { n: "PAD", eng: "PHASE", sp: "AMOEBA", ab: "AMO", id: "S209", g: G.amo, f: { spikes: 5, len: 140, wob: 150, lob: 2, nuc: 1 }, db: "-14", lv: 0.55, pan: 0.2, pat: 0x8080, amp: 0.55, tau: 0.9, v: 4 }, + { n: "PULS", eng: "FM6", sp: "POLLEN", ab: "POL", id: "R078", g: G.pol, f: { spikes: 14, len: 110, wob: 80, lob: 6, nuc: 3, sep: 90 }, db: "-24", lv: 0.3, pan: 0.6, pat: 0x5555, amp: 0.5, tau: 0.1, mute: true, v: 2 }, + { n: "DRUM", eng: "DRUM-X", sp: "COLONY", ab: "COL", id: "F802", g: G.drm, f: { spikes: 12, len: 120, wob: 60, lob: 3, nuc: 1 }, db: "-1.0", lv: 0.92, pan: 0, pat: 0x8888, amp: 1, tau: 0.14, v: 1 }, + { n: "BRAS", eng: "VOICE", sp: "HYDRA", ab: "HYD", id: "V763", g: G.hyd, f: { spikes: 6, len: 160, wob: 90, lob: 3, nuc: 2, sep: 120 }, db: "-4.0", lv: 0.7, pan: -0.7, pat: 0x2424, amp: 0.75, tau: 0.35, v: 3 }, + { n: "FULL", eng: "WHEEL", sp: "CILIATE", ab: "CIL", id: "E940", g: G.cil, f: { spikes: 30, len: 80, wob: 70, lob: 5, nuc: 1 }, db: "-4.0", lv: 0.66, pan: 0.45, pat: 0x0A0A, amp: 0.7, tau: 0.22, v: 2 }, +]; +const STEP = 60 / 124 / 4; diff --git a/tools/video/capture_tutorial.c b/tools/video/capture_tutorial.c new file mode 100644 index 00000000..6354e342 --- /dev/null +++ b/tools/video/capture_tutorial.c @@ -0,0 +1,446 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * (JIANT 0.8.0) the tutorial film's footage (tools/video/tutorial.html, in Spanish): a dark, evolving, spacious but + * percussive piece in F minor at 116 BPM played by the real engines (TECHNO RAW drums, a REESE bass, a DARK PAD, a + * PD LEAD with its filter envelope and a dotted delay, an FM PLUCK arpeggio, METAL hits in the reverb), arranged by the + * voice-over's chapters (tools/video/tutorial_voice.py: plan.txt, "seconds chapter cue" a line), while the screen goes + * to what each line talks about. Writes audio.wav (the music alone: the voice is mixed in after), screen.rgb, + * frames.txt (HOME shown, each track's peak) and scenes.txt (its header: what film_prep.py reads). + * cc -O2 -w -Ibuild/gen -Ifirmware/src -Itests -o build/tut/capture_tutorial tools/video/capture_tutorial.c -lm + * build/tut/capture_tutorial build/tut */ +#define UI_TEST_NO_MAIN 1 +#define FELUCCA_VERSION "v0.8.0" +#define PF_MS 900u +#define UI_NO_DRIFT 0 +#include "ui_test.c" + +#define FPS 30u +#define BPM 116u +#define BEAT_S (60.0 / BPM) +#define SPLASH_S 4.0 +enum { T_DRUM, T_BASS, T_PAD, T_LEAD, T_ARP, T_METAL }; +static FILE *wav, *rgb, *cap, *frm; +static uint32_t nsamp; +static double SECS; + +/* ---- the plan: the voice-over's lines (their start, chapter, cue) */ +#define NPLAN 128 +static struct { double t; char ch[16]; int cue; } plan[NPLAN]; +static uint32_t nplan; +static void plan_read(const char *dir) +{ + char p[512], id[16]; + double t; + int cue; + snprintf(p, sizeof p, "%s/plan.txt", dir); + FILE *f = fopen(p, "r"); + if (!f) { fprintf(stderr, "no %s (tools/video/tutorial_voice.py first)\n", p); exit(1); } + while (fscanf(f, "%lf %15s %d", &t, id, &cue) == 3) { + if (!strcmp(id, "end")) { SECS = t; continue; } + if (nplan < NPLAN) { plan[nplan].t = t; strcpy(plan[nplan].ch, id); plan[nplan].cue = cue; nplan++; } + } + fclose(f); +} +static const char *chapter_at(double t) /* the chapter whose first line has begun (the intro before) */ +{ + const char *c = "intro"; + uint32_t i; + for (i = 0; i < nplan && plan[i].t <= t + 1.2; i++) c = plan[i].ch; /* (the music turns a little ahead) */ + return c; +} +static int is(const char *a, const char *b) { return !strcmp(a, b); } + +/* ---- the sounds and the notes */ +static uint32_t eng_of(const char *name) +{ + uint32_t e; + for (e = 0; e < NENGINES; e++) if (str_eq(ENGINES[e]->name, name)) return e; + return 0; +} +static uint32_t pre_of(uint32_t e, const char *name) +{ + uint32_t i; + for (i = 0; i < ENGINES[e]->npresets; i++) if (str_eq(ENGINES[e]->presets[i].name, name)) return i; + return 0; +} +static void sound(uint32_t k, const char *eng, const char *pre) +{ + uint32_t e = eng_of(eng); + set_engine_of(&trk[k], e); + apply_preset_to(&trk[k], pre_of(e, pre)); + trk[k].engine = trk[k].eng_req; +} +static void put(uint32_t k, uint32_t i, uint32_t n, const uint8_t *notes, uint32_t time, uint32_t flags) +{ + step_t *s = &trk[k].step[i]; + uint32_t j; + s->n = (uint8_t)n; + for (j = 0; j < 4u; j++) s->note[j] = j < n ? notes[j] : 0; + s->time = (uint8_t)time; + s->flags = (uint8_t)flags; + s->vel = n ? 100 : 0; + s->comp = s->carg = 0; + s->probability = 0; +} +static void line(uint32_t k, uint32_t at, uint8_t note, uint32_t len, uint32_t flags) /* a note held len steps */ +{ + uint32_t i; + for (i = 0; i < len && at + i < 64u; i++) put(k, at + i, i ? 0u : 1u, ¬e, i ? ST_TIE : ST_NOTE, i ? 0u : flags); +} +static void rests(uint32_t k) { uint32_t i; for (i = 0; i < 64u; i++) put(k, i, 0, 0, ST_REST, 0); } +static void drums(const char *const rows[8]) /* BD SD CP CH OH TM RS CB: 'x' a hit, 'X' accented */ +{ + static const uint8_t NOTE[8] = {36, 38, 39, 42, 46, 45, 37, 56}; + uint32_t i, l; + for (i = 0; i < 16u; i++) { + uint8_t n[4]; uint32_t c = 0, acc = 0; + for (l = 0; l < 8u; l++) + if (rows[l] && rows[l][i] != '.' && c < 4u) { n[c++] = NOTE[l]; acc |= rows[l][i] == 'X'; } + put(T_DRUM, i, c, n, c ? ST_NOTE : ST_REST, acc ? SF_ACCENT : 0u); + step_to_grid(&trk[T_DRUM].step[i]); + } +} +static const char *const D_SPARSE[8] = {"X.......x.......", 0, 0, "..x...x...x...x.", 0, 0, "..........x.....", 0}; +static const char *const D_GROOVE[8] = {"X...x...X...x...", 0, "....x.......x...", "..x...x...x...x.", "..............x.", 0, + "...x......x..x..", 0}; +static const char *const D_DRIVE[8] = {"X...x...X...x.x.", 0, "....X.......X...", "x.xxx.xxx.xxx.xx", "..x.......x.....", + ".............x.x", "...x..x....x..x.", "......x.......x."}; +/* F minor: A Fm Dbmaj7 Abmaj7 Eb7, B Fm7 Bbm7 Dbmaj7 C7 (the dominant's E: the tension) */ +static const uint8_t ROOT[2][4] = {{41, 37, 44, 39}, {41, 46, 37, 36}}; +static const uint8_t CHORD[2][4][4] = {{{65, 68, 72, 75}, {61, 65, 68, 72}, {56, 60, 63, 67}, {63, 67, 70, 73}}, + {{65, 68, 72, 75}, {58, 61, 65, 68}, {61, 65, 68, 72}, {60, 64, 67, 70}}}; +static void pad(int pr) +{ + uint32_t b, i; + for (b = 0; b < 4u; b++) + for (i = 0; i < 16u; i++) + put(T_PAD, b * 16u + i, i ? 0u : 3u, CHORD[pr][b], i ? (i < 15u ? ST_TIE : ST_REST) : ST_NOTE, 0); +} +static void bass(int pr, int big) /* syncopated, or long and deep (the drops) */ +{ + static const uint8_t NORM[][3] = {{0, 0, 3}, {3, 12, 1}, {6, 0, 1}, {8, 0, 2}, {10, 12, 1}, {12, 0, 1}, {14, 7, 1}}; + static const uint8_t BIG[][3] = {{0, 0, 6}, {8, 0, 3}, {11, 0, 1}, {12, 12, 2}, {14, 10, 2}}; + uint32_t b, j; + rests(T_BASS); + for (b = 0; b < 4u; b++) { + if (big) for (j = 0; j < sizeof BIG / sizeof BIG[0]; j++) line(T_BASS, b * 16u + BIG[j][0], (uint8_t)(ROOT[pr][b] + BIG[j][1]), BIG[j][2], j ? 0u : SF_ACCENT); + else for (j = 0; j < sizeof NORM / sizeof NORM[0]; j++) line(T_BASS, b * 16u + NORM[j][0], (uint8_t)(ROOT[pr][b] + NORM[j][1]), NORM[j][2], j ? 0u : SF_ACCENT); + } +} +static void lead(int alt) /* a phrase with room: notes with their tails, rests between */ +{ + static const uint8_t A[][2] = {{72, 3}, {0, 1}, {75, 2}, {77, 2}, {75, 3}, {0, 1}, {72, 4}, + {73, 6}, {72, 2}, {68, 6}, {0, 2}, + {67, 3}, {0, 1}, {68, 2}, {72, 2}, {75, 6}, {0, 2}, + {70, 4}, {73, 4}, {72, 6}, {0, 2}}; + static const uint8_t B[][2] = {{77, 6}, {0, 2}, {80, 2}, {79, 2}, {77, 4}, + {77, 3}, {0, 1}, {73, 4}, {72, 6}, {0, 2}, + {73, 2}, {72, 2}, {68, 4}, {65, 6}, {0, 2}, + {67, 4}, {70, 4}, {72, 8}}; + const uint8_t (*L)[2] = alt ? B : A; + uint32_t n = alt ? sizeof B / sizeof B[0] : sizeof A / sizeof A[0], j, p = 0; + rests(T_LEAD); + for (j = 0; j < n; j++) { if (L[j][0]) line(T_LEAD, p, L[j][0], L[j][1], 0); p += L[j][1]; } +} +static void arp(int pr) /* 16ths up two octaves, every fourth left out: air */ +{ + uint32_t b, i; + for (b = 0; b < 4u; b++) + for (i = 0; i < 16u; i++) { + uint8_t n = (uint8_t)(CHORD[pr][b][i % 4u] + 12u * ((i / 4u) % 2u) - 12u); + int on = i % 4u != 3u; + put(T_ARP, b * 16u + i, on ? 1u : 0u, &n, on ? ST_NOTE : ST_REST, i % 8u == 0u ? SF_ACCENT : 0u); + } +} +static void metal(void) +{ + uint32_t i; + rests(T_METAL); + for (i = 0; i < 64u; i++) { + uint8_t n = (uint8_t)(i % 32u == 14u ? 70 : 63); + if (i % 16u == 6u || i % 32u == 14u || i == 59u) put(T_METAL, i, 1, &n, ST_NOTE, i % 32u == 14u ? SF_ACCENT : 0u); + } +} + +static void mute(uint32_t k, int m) { trk[k].p[P_MUTE] = (int16_t)m; } +static void pad_sound(void) /* the space: slow, wide, a cathedral (again after the browsing) */ +{ + track_t *t = &trk[T_PAD]; + int16_t m = t->p[P_MUTE]; + sound(T_PAD, "ANALOG", "DARK PAD"); + t->p[P_ROOT] = 5; t->p[P_SCALE] = 0; t->p[P_SLEN] = 64; t->p[P_MUTE] = m; + t->p[P_LEVEL] = 76; t->p[P_ATK] = 70; t->p[P_REL] = 100; t->p[P_SUS] = 100; + t->p[P_FCUT] = 64; t->p[P_FRES] = 30; t->p[P_LRATE] = 10; t->p[P_LD_FLT] = 22; + t->p[P_CHOR] = 80; t->p[P_REV] = 118; t->p[P_DLY] = 10; t->p[P_APDEP] = 30; t->p[P_APRATE] = 12; +} +static void song_build(void) +{ + uint32_t k; + ui_power_on(); + settings.palette = UI_JIANT_INDEX; palette_set(UI_JIANT_INDEX); + ui_rec_prefs |= PREF_SIX >> 8; rp_apply(); + song.g[G_BPM] = BPM; + song.master_q12 = 4096; + sound(T_DRUM, "DRUM", "TECHNO RAW"); + sound(T_BASS, "ANALOG", "REESE"); + sound(T_PAD, "ANALOG", "DARK PAD"); + sound(T_LEAD, "PHASE", "PD LEAD"); + sound(T_ARP, "FM6", "FM PLUCK"); + sound(T_METAL, "NOISE", "METAL"); + for (k = 0; k < NTRK; k++) { + track_defaults_steps(&trk[k]); + trk[k].p[P_ROOT] = 5; trk[k].p[P_SCALE] = 0; /* F, chromatic: the chords as written */ + trk[k].p[P_SLEN] = 64; + trk[k].p[P_MUTE] = 1; + } + trk[T_DRUM].p[P_SLEN] = 16; + drums(D_SPARSE); bass(0, 0); pad(0); lead(0); arp(0); metal(); + { track_t *t = &trk[T_BASS]; /* big: mono, the envelope biting a low filter, a slow sweep */ + t->p[P_VOICE] = V_MONO; t->p[P_LEVEL] = 104; t->p[P_FCUT] = 58; t->p[P_FRES] = 34; + t->p[P_ATK] = 0; t->p[P_DEC] = 46; t->p[P_SUS] = 70; t->p[P_REL] = 26; t->p[P_ED_FLT] = 30; + t->p[P_LRATE] = 6; t->p[P_LD_FLT] = 10; t->p[P_DIST] = 22; t->p[P_DTYPE] = 5; t->p[P_CHOR] = 20; t->p[P_GLIDE] = 10; } + pad_sound(); + { track_t *t = &trk[T_LEAD]; /* the lead: its envelope on the filter, a dotted delay */ + t->p[P_LEVEL] = 88; t->p[P_ATK] = 4; t->p[P_DEC] = 54; t->p[P_SUS] = 46; t->p[P_REL] = 70; + t->p[P_FTYPE] = 0; t->p[P_FCUT] = 70; t->p[P_FRES] = 44; t->p[P_ED_FLT] = 40; t->p[P_GLIDE] = 14; + t->p[P_LRATE] = 30; t->p[P_LD_PIT] = 2; t->p[P_DLY] = 70; t->p[P_REV] = 92; t->p[P_PAN] = 10; } + { track_t *t = &trk[T_ARP]; /* the pluck: short, bright, to the left, into the delay */ + t->p[P_LEVEL] = 92; t->p[P_SGATE] = 30; t->p[P_REL] = 30; t->p[P_DLY] = 50; t->p[P_REV] = 60; t->p[P_PAN] = -22; + t->p[P_FTYPE] = 0; t->p[P_FCUT] = 84; t->p[P_LRATE] = 4; t->p[P_LD_FLT] = 26; } + { track_t *t = &trk[T_METAL]; /* the metal: hits far away in the reverb */ + t->p[P_LEVEL] = 127; t->p[P_SGATE] = 70; t->p[P_REV] = 110; t->p[P_DLY] = 40; t->p[P_PAN] = 24; } + trk[T_DRUM].p[P_LEVEL] = 106; trk[T_DRUM].p[P_REV] = 24; + dx_snd[2] = (uint8_t)(3u << 6 | 48u); /* the clap and the rim into the reverb, the cowbell the delay */ + dx_snd[6] = (uint8_t)(3u << 6 | 40u); + dx_snd[7] = (uint8_t)(2u << 6 | 40u); + song.g[G_RTYPE] = 2; song.g[G_RSIZE] = 116; song.g[G_DTIME] = 3; song.g[G_DFDBK] = 50; /* SHIMMER, a dotted delay */ + song.g[G_CDEPTH] = 80; song.g[G_CRATE] = 20; + song.g[G_CLIP] = 20; song.g[G_PUNCH] = 50; song.g[G_DUCK] = 30; + for (k = 0; k < 4u; k++) project_save(k); + ui.msg_t = 0; ui.msg[0] = ui.msg2[0] = 0; + transport_req = 1; +} + +/* ---- the arrangement: what plays in each chapter, set on the bar */ +static const char *arr_ch = ""; +static int arr_pr = -1, arr_big = -1, arr_alt = -1; +static const char *const *arr_dr; +static void arrange(uint32_t bar, double t) +{ + const char *c = chapter_at(t); + int on[6] = {0}, pr = 0, big = 0, alt = 0; + const char *const *dr = D_GROOVE; + on[T_PAD] = 1; + if (is(c, "intro")) { on[T_METAL] = bar >= 4u; dr = D_SPARSE; } + else if (is(c, "install")) { on[T_DRUM] = on[T_METAL] = 1; dr = D_SPARSE; } + else if (is(c, "panel")) { on[T_DRUM] = on[T_BASS] = on[T_METAL] = 1; dr = D_SPARSE; } + else if (is(c, "screen")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = 1; } + else if (is(c, "home")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = on[T_METAL] = 1; pr = 1; } + else if (is(c, "layers")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = 1; } + else if (is(c, "engines")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = on[T_LEAD] = 1; } + else if (is(c, "signal")) { on[T_DRUM] = on[T_BASS] = on[T_LEAD] = on[T_METAL] = 1; dr = D_DRIVE; big = 1; pr = 1; alt = 1; } + else if (is(c, "drumx")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = 1; dr = D_DRIVE; big = 1; } + else if (is(c, "seq")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = on[T_LEAD] = on[T_METAL] = 1; } + else if (is(c, "mod")) { on[T_LEAD] = on[T_ARP] = on[T_METAL] = 1; pr = 1; alt = 1; } + else if (is(c, "fx")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = on[T_LEAD] = on[T_METAL] = 1; dr = D_DRIVE; big = 1; } + else if (is(c, "gen")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = 1; } + else if (is(c, "arrange")) { on[T_DRUM] = on[T_BASS] = on[T_ARP] = on[T_LEAD] = 1; dr = D_DRIVE; pr = 1; alt = 1; } + else if (is(c, "usb")) { on[T_DRUM] = on[T_BASS] = on[T_LEAD] = on[T_METAL] = 1; } + else if (is(c, "web")) { on[T_DRUM] = on[T_BASS] = on[T_METAL] = 1; dr = D_SPARSE; } + else if (is(c, "outro")) { on[T_LEAD] = on[T_METAL] = 1; pr = 1; alt = 1; } + if (!is(c, arr_ch) || pr != arr_pr) { /* (rewritten on a chapter's bar: the 4-bar phrase restarts) */ + if (pr != arr_pr) { pad(pr); arp(pr); } + if (pr != arr_pr || big != arr_big) bass(pr, big); + if (alt != arr_alt) lead(alt); + if (dr != arr_dr) drums(dr); + arr_ch = c; arr_pr = pr; arr_big = big; arr_alt = alt; arr_dr = dr; + } + { uint32_t k; + for (k = 0; k < NTRK; k++) if (!(ui.menu && k == T_DRUM)) mute(k, !on[k]); + } + /* the slow movement: the pad's filter breathing over minutes, the bass opening in the drops */ + trk[T_PAD].p[P_FCUT] = (int16_t)(60 + 16 * sin(t / 37.0)); + trk[T_BASS].p[P_FCUT] = (int16_t)((big ? 66 : 56) + 8 * sin(t / 23.0)); + trk[T_LEAD].p[P_ED_FLT] = (int16_t)(36 + 14 * sin(t / 29.0)); +} + +/* ---- the screen: each line's action */ +static void page(uint32_t sel, const char *title) { song.sel = (uint8_t)sel; go_title(title); } +static void home(uint32_t sel) { song.sel = (uint8_t)sel; go_home(); } +static void hold_btn(uint32_t label, int on) +{ + if (on) { fm1_in.buttons |= 1u << panel.btn[label]; host_pressed |= 1u << panel.btn[label]; } + else fm1_in.buttons &= ~(1u << panel.btn[label]); +} +static void enc_turn(uint32_t role, int32_t s) { host_enc[panel.enc[role]] += s * panel.dir[role]; } +static int held = -1; /* the button held for a layer's map, let go on the next line */ +static void hold_layer(uint32_t b) { hold_btn(b, 1); held = (int)b; } +static void let_go(void) /* (and no layer left latched: FX LOCKED, the macros' LATCH) */ +{ + if (held >= 0) hold_btn((uint32_t)held, 0); + if (held >= 0 || fx_lock || perf_latch_on || ui.layer) { fx_lock = 0; perf_latch_on = 0; ui.layer = 0; ui.ly = 0; ui.force = 1; } + held = -1; +} +static uint32_t pad_pre; +static void menu_open(uint32_t row) +{ + if (!ui.menu) hold(B_HOME); + ui.menu_sel = (uint8_t)row; + ui.force = 1; +} +static void tut_menu_close(void) { menu_put(MI_SERIAL, 0u); ui.menu = 0; ui.force = 1; } +static void act(const char *c, int cue) +{ + let_go(); + perf_press(PF_R16, 0); + if (ui.menu && !is(c, "usb")) tut_menu_close(); + if (ui.confirm && !is(c, "gen")) { ui.confirm = 0; ui.force = 1; } + if (is(c, "intro")) home(cue % 2 ? T_LEAD : T_PAD); + else if (is(c, "install")) home(T_DRUM); + else if (is(c, "panel")) { + if (cue == 0) home(T_PAD); + if (cue == 2) page(T_PAD, "FILTER"); + if (cue == 3) page(T_LEAD, "ENV"); + } else if (is(c, "screen")) { + if (cue <= 2) page(T_BASS, "FILTER"); + if (cue == 3) page(T_BASS, "MIXER"); + } else if (is(c, "home")) home(T_BASS); + else if (is(c, "layers")) { + if (cue == 0) page(T_ARP, "EDIT 1"); + if (cue == 1) { home(T_ARP); hold_layer(B_GLO); } + if (cue == 2) hold_layer(B_FX); + } else if (is(c, "engines")) { + static const uint32_t K[5] = {T_BASS, T_ARP, T_LEAD, T_METAL, T_PAD}; + if (cue == 4) { pad_pre = 1; page(T_PAD, "PRESETS"); } + else page(K[cue], cue == 1 ? "OPERATOR" : "EDIT 1"); + } else if (is(c, "signal")) { + static const char *const P[5] = {"EDIT 1", "FILTER", "DIST", "FX", "MASTER"}; + page(T_LEAD, P[cue]); + } else if (is(c, "drumx")) { + if (cue == 0) page(T_DRUM, "EDIT 1"); + if (cue == 2) { page(T_DRUM, "SOUND"); dx_ui_lane = 1; } + } else if (is(c, "seq")) { + static const char *const P[5] = {"PATTERN", "STEP", "STEP", "COMP", "PLAYHEADS"}; + page(cue == 2 ? T_DRUM : cue == 0 ? T_ARP : T_LEAD, P[cue]); + if (cue == 3) { trk[T_LEAD].step[0].comp = CP_WALK; trk[T_LEAD].step[0].carg = CP_WARG(0, 0, 1); ui.cursor = 0; ui.bank = 0; } + if (cue == 4) { trk[T_LEAD].step[0].comp = 0; trk[T_LEAD].step[0].carg = 0; } + } else if (is(c, "mod")) { + if (cue == 0) page(T_PAD, "LFO"); + if (cue == 1) { /* two routes: the LFO on the cutoff, the noise on the pan */ + trk[T_PAD].p[P_M1SRC] = MS_LFO; trk[T_PAD].p[P_M1DST] = MD_CUT; trk[T_PAD].p[P_M1AMT] = 30; + trk[T_PAD].p[P_M1SRC + 3] = MS_NOISE; trk[T_PAD].p[P_M1DST + 3] = MD_PAN; trk[T_PAD].p[P_M1AMT + 3] = 40; + page(T_PAD, "MOD"); + } + if (cue == 2) { home(T_LEAD); hold_layer(B_LFO); } + } else if (is(c, "fx")) { + if (cue == 0) page(T_LEAD, "DLY"); + if (cue == 1) page(T_LEAD, "SLICER"); + if (cue == 2) { home(T_DRUM); hold_layer(B_FX); } + if (cue == 3) page(T_DRUM, "PUNCH"); + } else if (is(c, "gen")) { + if (cue == 0) { home(T_LEAD); confirm_open(CF_DICE_ALL, song.sel); gen_open(); } + if (cue == 1) { ui.confirm = 0; page(T_ARP, "STEP"); } + if (cue == 2) { home(T_ARP); hold_layer(B_GLO); } + } else if (is(c, "arrange")) { + if (cue == 0) page(T_LEAD, "PROJECT"); + if (cue == 1) { + chain_config.count = 3; + chain_config.row[0] = (chain_row_t){0, 8}; chain_config.row[1] = (chain_row_t){1, 8}; chain_config.row[2] = (chain_row_t){0, 4}; + page(T_LEAD, "ARRANGE"); ui.song_row = 1; + } + if (cue == 2) { home(T_LEAD); hold_layer(B_SAVE); } + } else if (is(c, "usb")) { + if (cue == 0) { menu_open(MI_SERIAL); menu_put(MI_SERIAL, 2u); } + if (cue == 1) { menu_put(MI_SERIAL, 3u); ui.force = 1; } + if (cue == 2) { menu_put(MI_SERIAL, 0u); ui.menu_sel = MI_MIDIOUT; ui.force = 1; } + } else if (is(c, "web")) home(T_BASS); + else if (is(c, "outro")) home(T_LEAD); +} +/* within a line: the knob being turned, the keys being played */ +static void during(const char *c, int cue, double dt, uint32_t f) +{ + if (is(c, "panel") && cue == 1 && f % 20u == 0u && dt < 6.0) enc_turn(EN_ALGO, 1); + if (is(c, "panel") && cue == 2 && dt > 1.0 && dt < 5.0 && f % 3u == 0u) enc_turn(EN_K2, dt < 3.0 ? 1 : -1); + if (is(c, "screen") && cue == 1 && dt < 4.0 && f % 4u == 0u) enc_turn(EN_K2, dt < 2.0 ? 1 : -1); + if (is(c, "drumx") && cue == 1 && f % 3u == 0u && dt < 8.0) enc_turn(EN_K1, dt < 4.0 ? 2 : -2); + if (is(c, "engines") && cue == 4 && f % 45u == 0u && dt > 1.0 && dt < 6.0) enc_turn(EN_PRESET, 1); + if (is(c, "engines") && cue == 4 && dt > 9.0 && pad_pre) { pad_sound(); pad_pre = 0; } /* (the pad as it was) */ + if (is(c, "fx") && cue == 2 && dt > 3.0 && dt < 7.0) perf_press(PF_R16, fmod(dt, 1.0) < 0.5); + if (is(c, "fx") && cue == 2 && dt >= 7.0) perf_press(PF_R16, 0); + if (is(c, "usb") && cue == 1 && dt > 4.5 && dt < 4.6) { menu_put(MI_SERIAL, 4u); ui.force = 1; } + if (is(c, "home") && cue == 2 && dt > 2.0 && dt < 5.0) mute(T_METAL, 1); +} + +static void put_screen(void) +{ + static uint8_t buf[240u * 240u * 3u]; + uint32_t i; + for (i = 0; i < 240u * 240u; i++) { + uint16_t c = swap16(host_screen[i]); + buf[3u * i] = (uint8_t)((c >> 11) * 255u / 31u); + buf[3u * i + 1u] = (uint8_t)(((c >> 5) & 63u) * 255u / 63u); + buf[3u * i + 2u] = (uint8_t)((c & 31u) * 255u / 31u); + } + fwrite(buf, 1, sizeof buf, rgb); +} +int main(int argc, char **argv) +{ + char p[512]; + const char *dir = argc > 1 ? argv[1] : "build/tut"; + uint32_t f, total, nwav, k, bar_done = 0xFFFFFFFFu, pi = 0; + const char *cur = "intro"; + int cue = -1; + double cue_t = 0; + plan_read(dir); + total = (uint32_t)(FPS * SECS); nwav = (uint32_t)(FS * SECS); + snprintf(p, sizeof p, "%s/audio.wav", dir); wav = fopen(p, "wb"); + snprintf(p, sizeof p, "%s/screen.rgb", dir); rgb = fopen(p, "wb"); + snprintf(p, sizeof p, "%s/scenes.txt", dir); cap = fopen(p, "w"); + snprintf(p, sizeof p, "%s/frames.txt", dir); frm = fopen(p, "w"); + if (!wav || !rgb || !cap || !frm) { fprintf(stderr, "cannot write in %s\n", dir); return 1; } + wav_hdr(wav, nwav); + fprintf(cap, "# %u fps, %u BPM, %u bars, splash %.4f s, end %.4f s, beat %.6f s\n", FPS, BPM, (uint32_t)(SECS / BEAT_S / 4.0), + SPLASH_S, SECS, BEAT_S); + song_build(); + for (f = 0; f < total; f++) { + double t = (double)f / FPS; + uint32_t want = (uint32_t)((uint64_t)(f + 1u) * FS / FPS), bar = (uint32_t)(t / (4.0 * BEAT_S)); + if (bar != bar_done) { bar_done = bar; arrange(bar, t); } + while (pi < nplan && plan[pi].t <= t) { /* a line begins: its action */ + cur = plan[pi].ch; cue = plan[pi].cue; cue_t = plan[pi].t; + if (t >= SPLASH_S) act(cur, cue); + pi++; + } + if (t >= SPLASH_S && cue >= 0) during(cur, cue, t - cue_t, f); + while (nsamp < want && nsamp < nwav) { + int32_t o[2 * CTL]; + int16_t s[2 * CTL]; + uint32_t i, n = CTL; + mix_block(o, CTL); + for (i = 1; i < CTL; i += 2u) + scope_buf[scope_w++ & (SCOPE_N - 1u)] = (int16_t)clamp(o[2u * i], -32768, 32767); + if (nsamp + n > nwav) n = nwav - nsamp; + for (i = 0; i < 2u * n; i++) s[i] = (int16_t)clamp(o[i], -32768, 32767); + fwrite(s, 2, 2u * n, wav); + nsamp += n; + } + if ((f & 7u) == 0u) mutate_poll(); + fprintf(frm, "%d", t >= SPLASH_S && ui.home && !ui.menu && !ui.confirm); + for (k = 0; k < NTRK; k++) fprintf(frm, " %d", trk[k].p[P_MUTE] ? 0 : (int)trk[k].peak); + fprintf(frm, "\n"); + host_ticks += 1000000u / FPS; fm1_ms += 1000u / FPS; + if (t < SPLASH_S) { + if (f == 0) { spl_anim = 1; draw_splash(); } + splash_write((uint32_t)(t * 1000.0)); + } else { + static int first = 1; + if (first) { ui.force = 1; first = 0; act(cur, cue < 0 ? 0 : cue); } + ui_input(); + ui_draw(); + } + for (k = 0; k < NTRK; k++) trk[k].peak = 0; + put_screen(); + } + fclose(wav); fclose(rgb); fclose(cap); fclose(frm); + printf("%u frames, %u samples, %.1f s\n", total, nsamp, SECS); + return 0; +} diff --git a/tools/video/film.mjs b/tools/video/film.mjs index a02395c1..7f4a720c 100644 --- a/tools/video/film.mjs +++ b/tools/video/film.mjs @@ -3,6 +3,7 @@ // directory (tools/video/capture_dark.c + film_prep.py), piped as JPEG to ffmpeg with the audio: // NODE_PATH=$(npm root -g) node tools/video/film.mjs build/video5/feat feat out.mp4 // NODE_PATH=$(npm root -g) node tools/video/film.mjs build/video5/feat feat preview 100,400,900 -> preview-*.jpg +// film "tutorial": tools/video/tutorial.html (the tutorial, in Spanish: capture_tutorial.c, tutorial_voice.py; AUDIO= the mix) // film "promo": tools/video/promo.html (the presentation film, tools/video/capture_promo.c); "update": update.html (the // news of a release, in Spanish, tools/video/capture_update.c); "story": stories.html (1080 x 1920) // The fonts (the landing's: Michroma, IBM Plex Mono, Instrument Sans, VT323) come from build/video5/fonts. @@ -33,20 +34,24 @@ await page.route("http://film/**", async r => { if (p === "/data.json") return r.fulfill({ path: path.join(dir, "data.json"), contentType: "application/json" }); if (p === "/version") return r.fulfill({ body: ver, contentType: "text/plain" }); if (p.startsWith("/fonts/")) return r.fulfill({ path: path.join(FONTS, path.basename(p)) }); - return r.fulfill({ path: path.join(root, film === "promo" ? "tools/video/promo.html" : film === "update" ? "tools/video/update.html" : film === "plate" ? "tools/video/plate.html" : film.startsWith("story") ? "tools/video/stories.html" : "tools/video/film.html"), contentType: "text/html" }); + if (p.startsWith("/afonts/")) return r.fulfill({ path: path.join(root, "assets/fonts", path.basename(p)) }); // (the tutorial: Chakra Petch) + if (p === "/timeline.json") return r.fulfill({ path: path.join(dir, "timeline.json"), contentType: "application/json" }); + if (p.endsWith(".js")) return r.fulfill({ path: path.join(root, "tools/video", path.basename(p)), contentType: "text/javascript" }); + return r.fulfill({ path: path.join(root, film === "promo" ? "tools/video/promo.html" : film === "update" ? "tools/video/update.html" : film === "plate" ? "tools/video/plate.html" : film === "tutorial" ? "tools/video/tutorial.html" : film.startsWith("story") ? "tools/video/stories.html" : "tools/video/film.html"), contentType: "text/html" }); }); await page.goto("http://film/film.html"); const n = await page.evaluate(f => boot(f), film); if (out === "preview") { - const want = (list || "60").split(",").map(Number); - const last = Math.max(...want); - for (let f = Math.max(0, Math.min(...want) - 90); f <= last; f++) { // (from a little before: the beings swim) + const want = (list || "60").split(",").map(Number), pre = +(process.env.PREVIEW_PRE || 90); + const todo = new Set(); + for (const w of want) for (let f = Math.max(0, w - pre); f <= w; f++) todo.add(f); // (from a little before: the beings swim) + for (const f of [...todo].sort((a, b) => a - b)) { const d = await page.evaluate(([f]) => frameJpeg(f, .9), [f]); if (want.includes(f)) fs.writeFileSync(path.join(dir, `preview-${String(f).padStart(5, "0")}.jpg`), Buffer.from(d.split(",")[1], "base64")); } } else { const ff = spawn("ffmpeg", ["-y", "-loglevel", "error", "-f", "image2pipe", "-framerate", "30", "-c:v", "mjpeg", "-i", "-", - "-i", path.join(dir, "audio.wav"), "-c:v", "libx264", "-preset", "medium", "-crf", "20", "-pix_fmt", "yuv420p", + "-i", process.env.AUDIO || path.join(dir, "audio.wav"), "-c:v", "libx264", "-preset", "medium", "-crf", "20", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "256k", "-shortest", "-movflags", "+faststart", out], { stdio: ["pipe", "inherit", "inherit"] }); const t0 = Date.now(); for (let f = 0; f < n; f++) { diff --git a/tools/video/tutorial.html b/tools/video/tutorial.html new file mode 100644 index 00000000..fdbecb85 --- /dev/null +++ b/tools/video/tutorial.html @@ -0,0 +1,15 @@ + + +
+ + + + + diff --git a/tools/video/tutorial_body.js b/tools/video/tutorial_body.js new file mode 100644 index 00000000..d8aefda8 --- /dev/null +++ b/tools/video/tutorial_body.js @@ -0,0 +1,572 @@ +/* SPDX-License-Identifier: GPL-3.0-only + * (JIANT 0.8.0) the tutorial film, drawn frame by frame (tools/video/film.mjs "tutorial"): black, Chakra Petch, the + * heat palette and the beings (tutorial.html carries their code, from the design studies), the FM-1's real screen at + * three times its size on the right, each chapter's animated graphic on the left, the voice-over's words as subtitles, + * a thin bar of the chapters at the foot. data.json: film_prep.py's (the music's levels, each track's peak); + * timeline.json: tools/video/tutorial_voice.py's (the chapters, each line's words, cue and time). */ +const W = 1920, H2 = 1080, FPS = 30, BEAT = 60 / 116; +const cv = document.getElementById('cv'), X = cv.getContext('2d'); +const scr = document.createElement('canvas'); scr.width = scr.height = 240; const sx = scr.getContext('2d'); const simg = sx.createImageData(240, 240); +let D, TL, VER = 'v0.8.0'; +const FONT = '"Chakra Petch", sans-serif'; +const ease = (u) => { u = clamp(u, 0, 1); return u < .5 ? 4 * u * u * u : 1 - Math.pow(-2 * u + 2, 3) / 2; }; +const fade = (t, a, b) => clamp((t - a) / (b - a), 0, 1); +function T(s, x, y, size, w = 500, col = C.text, al = 'left', ls = 0) { + X.font = `${w} ${size}px ${FONT}`; X.fillStyle = col; X.textAlign = al; X.textBaseline = 'alphabetic'; + if (ls && X.letterSpacing !== undefined) X.letterSpacing = ls + 'px'; + X.fillText(s, x, y); + if (ls && X.letterSpacing !== undefined) X.letterSpacing = '0px'; + return X.measureText(s).width; +} +function rr(x, y, w, h, r, stroke, fill, lw = 1.5) { + X.beginPath(); X.roundRect(x, y, w, h, r); + if (fill) { X.fillStyle = fill; X.fill(); } + if (stroke) { X.strokeStyle = stroke; X.lineWidth = lw; X.stroke(); } +} +function heatRule(x, y, w, h = 2, a = 0, b = 0.86) { + const g = X.createLinearGradient(x, 0, x + w, 0); + for (let i = 0; i <= 6; i++) g.addColorStop(i / 6, heat((a + (b - a) * i / 6) * 256)); + X.fillStyle = g; X.fillRect(x, y, w, h); +} +function arrow(x1, y1, x2, y2, col, lw = 1.5, head = 8) { + X.strokeStyle = col; X.fillStyle = col; X.lineWidth = lw; + X.beginPath(); X.moveTo(x1, y1); X.lineTo(x2, y2); X.stroke(); + const a = Math.atan2(y2 - y1, x2 - x1); + X.beginPath(); X.moveTo(x2, y2); X.lineTo(x2 - head * Math.cos(a - .4), y2 - head * Math.sin(a - .4)); + X.lineTo(x2 - head * Math.cos(a + .4), y2 - head * Math.sin(a + .4)); X.closePath(); X.fill(); +} +function node(x, y, w, h, label, on, sub) { + rr(x, y, w, h, 6, on ? C.orange : C.faint, on ? 'rgba(255,122,0,.08)' : '#08070b', on ? 2 : 1.2); + T(label, x + w / 2, y + h / 2 + (sub ? -2 : 8), 22, 600, on ? C.text : C.mid, 'center'); + if (sub) T(sub, x + w / 2, y + h / 2 + 22, 14, 500, on ? C.orange : C.dim, 'center'); +} +const SP = { ANALOG: [G.rad, { spikes: 24, len: 98, wob: 66, lob: 3, nuc: 2, ripple: 160 }], FM6: [G.pol, { spikes: 14, len: 110, wob: 80, lob: 6, nuc: 3, sep: 90 }], + PHASE: [G.amo, { spikes: 5, len: 140, wob: 150, lob: 2, nuc: 1 }], LOFI: [G.dia, { spikes: 8, len: 90, wob: 50, lob: 4, nuc: 1 }], + VOICE: [G.hyd, { spikes: 6, len: 160, wob: 90, lob: 3, nuc: 2, sep: 120 }], WHEEL: [G.cil, { spikes: 30, len: 80, wob: 70, lob: 5, nuc: 1 }], + NOISE: [G.spo, { spikes: 16, len: 70, wob: 110, lob: 5, nuc: 1, ripple: 120 }], DRUM: [G.drm, { spikes: 12, len: 120, wob: 60, lob: 3, nuc: 1 }], + PAD: [G.rad, { spikes: 8, len: 60, wob: 140, lob: 2, nuc: 1 }] }; +/* the film's six tracks (capture_tutorial.c) */ +const TRK = [['DRUM-X', 'BATERÍA', 'DRUM'], ['ANALOG', 'BAJO', 'ANALOG'], ['ANALOG', 'PAD', 'PAD'], ['PHASE', 'LEAD', 'PHASE'], ['FM6', 'ARPEGIO', 'FM6'], ['NOISE', 'METAL', 'NOISE']]; +const sm = new Float32Array(6); +function en(f, k) { const v = D.trk[Math.min(f, D.n - 1)] ? D.trk[Math.min(f, D.n - 1)][k] : 0; return clamp(v, 0, 1.3); } +function being(sp, x, y, r, e, t, o = {}) { const [g, f] = SP[sp]; organism(X, g, f, x, y, r, e, t, { ex: 3, nv: 80, ...o }); } + +/* ---- where we are */ +function at(t) { + const chs = TL.chapters; + let ci = 0; + for (let i = 0; i < chs.length; i++) if (t >= chs[i].start - 0.6) ci = i; + const ch = chs[ci]; + let li = 0; + for (let i = 0; i < ch.lines.length; i++) if (t >= ch.lines[i].start - 0.15) li = i; + const ln = ch.lines[li]; + return { ci, ch, li, ln, cue: t < ch.lines[0].start - 0.15 ? 0 : ln.cue, ct: t - ch.start, lt: t - ln.start, ld: ln.end - ln.start }; +} +/* the subtitle: the line in chunks at its commas and stops, each its share of the line's time */ +function subtitle(t, A) { + const { ln } = A; + if (t > ln.end + 0.5 || t < ln.start - 0.1) return; + const parts = ln.text.match(/[^.,:;?¿!]+[.,:;?!]*/g).map((s) => s.trim()).filter(Boolean); + const chunks = []; let cur = ''; + for (const p of parts) { if ((cur + ' ' + p).trim().length > 74 && cur) { chunks.push(cur); cur = p; } else cur = (cur + ' ' + p).trim(); } + if (cur) chunks.push(cur); + const tot = chunks.reduce((a, c) => a + c.length, 0), u = clamp((t - ln.start) / (ln.end - ln.start), 0, 0.999) * tot; + let acc = 0, s = chunks[0]; + for (const c of chunks) { if (u < acc + c.length) { s = c; break; } acc += c.length; } + X.globalAlpha = fade(t, ln.start - 0.1, ln.start + 0.15) * (1 - fade(t, ln.end + 0.25, ln.end + 0.5)); + T(s, W / 2, 1000, 34, 500, C.text, 'center'); + X.globalAlpha = 1; +} +/* the FM-1's screen, three times its size, sharp */ +const SX = 1080, SY = 128, SS = 720; +function screen(f, a) { + X.globalAlpha = a; + rr(SX - 14, SY - 14, SS + 28, SS + 28, 10, '#2b2833', '#030304', 1.5); + X.imageSmoothingEnabled = false; X.drawImage(scr, SX, SY, SS, SS); X.imageSmoothingEnabled = true; + T('FM-1', SX - 14, SY + SS + 50, 18, 600, C.mid); + T(`JIANT ${VER} · LA PANTALLA REAL, EN TIEMPO REAL`, SX + 50, SY + SS + 50, 16, 500, C.dim); + X.globalAlpha = 1; +} +function mark(x, y, w, h, a = 1) { /* a region of the real screen, in 240-pixel units */ + X.globalAlpha = a; rr(SX + x * 3 - 4, SY + y * 3 - 4, w * 3 + 8, h * 3 + 8, 6, C.orange, null, 2.5); X.globalAlpha = 1; +} + +/* ---------------------------------------------------------------- the graphics: one a chapter --- */ +const GX = 120, GY = 300, GW = 860, GH = 560; +const Gr = {}; +Gr.install = (A, t, f) => { + const cards = [['1', 'INSTALADOR WEB', 'juanjiant-bit.github.io/JIANT · Chrome o Edge'], ['2', 'CABLE USB DE DATOS', 'directo a la computadora, sin hub'], + ['3', 'INSTALL', 'no desenchufes mientras escribe']]; + cards.forEach((c, i) => { + const y = GY + i * 140, on = A.cue === 0 ? i < 2 : A.cue === 1 ? i === 2 : false, a = fade(A.ct, 0.3 + i * 0.35, 0.9 + i * 0.35); + X.globalAlpha = a; + rr(GX, y, GW, 116, 8, on ? C.orange : C.faint, '#07060a', on ? 2 : 1.2); + T(c[0], GX + 44, y + 76, 54, 600, on ? heat(170) : C.faint, 'center'); + T(c[1], GX + 100, y + 52, 30, 600, on ? C.text : C.mid); + T(c[2], GX + 100, y + 86, 19, 500, C.dim); + if (i === 2 && A.cue >= 1) { + const p = A.cue === 1 ? ease(A.lt / A.ld) : 1; + rr(GX + 560, y + 50, 260, 10, 5, C.faint, null, 1); heatRule(GX + 560, y + 50, 260 * p, 10, 0, p * 0.9); + T(p >= 1 ? 'LISTO' : Math.round(p * 100) + ' %', GX + 820, y + 90, 18, 600, p >= 1 ? C.orange : C.mid, 'right'); + } + X.globalAlpha = 1; + }); + if (A.cue === 2) { + const a = fade(A.lt, 0, 0.4); X.globalAlpha = a; + rr(GX, GY + 430, GW, 100, 8, C.violet, 'rgba(184,112,255,.07)', 2); + T('¿VENÍS DE OTRO FIRMWARE CUSTOM?', GX + 30, GY + 470, 24, 600, C.text); + T('primero: Return to official V15 first (también guarda un backup)', GX + 30, GY + 505, 19, 500, C.violet); + X.globalAlpha = 1; + } +}; +Gr.panel = (A, t, f) => { + const bx = GX, by = GY + 10, bw = GW, bh = 520; + rr(bx, by, bw, bh, 22, '#2b2833', '#060508', 1.5); + const encs = [['ALGORITHM', 'la pista'], ['PRESETS', 'los sonidos'], ['SELECT', 'las páginas']]; + encs.forEach((e, i) => { + const x = bx + 90 + i * 150, y = by + 95, on = A.cue === 0 || (A.cue === 1 && Math.floor(A.lt / (A.ld / 3)) === i); + X.lineWidth = on ? 3 : 1.5; X.strokeStyle = on ? C.orange : C.faint; X.beginPath(); X.arc(x, y, 38, 0, TAU); X.stroke(); + const ang = t * (on ? 2.2 : 0.3) + i; + X.beginPath(); X.moveTo(x + 22 * Math.cos(ang), y + 22 * Math.sin(ang)); X.lineTo(x + 34 * Math.cos(ang), y + 34 * Math.sin(ang)); X.stroke(); + T(e[0], x, y + 66, 16, 600, on ? C.text : C.mid, 'center'); + if (A.cue === 1 && on) T(e[1], x, y + 90, 18, 500, C.orange, 'center'); + }); + const kv = A.cue === 2 ? (A.lt < A.ld / 2 ? (A.lt * 3) % 1 : 0.5 + 0.08 * Math.sin(A.lt * 2)) : 0.3; + for (let i = 0; i < 4; i++) { + const x = bx + 560 + i * 74, y = by + 95, on = A.cue === 2; + X.lineWidth = on ? 3 : 1.5; X.strokeStyle = on ? C.orange : C.faint; X.beginPath(); X.arc(x, y, 26, 0, TAU); X.stroke(); + const ang = Math.PI * 0.75 + (on ? kv : 0.3 + i * 0.1) * Math.PI * 1.5; + X.beginPath(); X.moveTo(x, y); X.lineTo(x + 22 * Math.cos(ang), y + 22 * Math.sin(ang)); X.stroke(); + T('K' + (i + 1), x, y + 52, 15, 600, on ? C.text : C.mid, 'center'); + } + if (A.cue === 2) T(A.lt < A.ld / 2 ? 'RÁPIDO: TODO EL RANGO' : 'DESPACIO: AJUSTE FINO', bx + 670, by + 190, 18, 600, C.orange, 'center'); + const btn = ['HOME', 'ENV', 'LFO', 'FX', 'SCL', 'EDIT', 'GLO', 'SAVE', 'ARP', 'SEQ', 'PLAY', 'REC']; + btn.forEach((b, i) => { + const x = bx + 34 + i * 67, y = by + 240, k = A.cue === 3 ? Math.floor(A.lt / (A.ld * 0.55 / 9)) : -1; + const on = A.cue === 3 && i >= 1 && i <= 9 && k >= i - 1; + rr(x, y, 58, 34, 5, on ? C.orange : C.faint, on ? 'rgba(255,122,0,.1)' : null, on ? 2 : 1.2); + T(b, x + 29, y + 23, 14, 600, on ? C.text : b === 'PLAY' ? C.violet : b === 'REC' ? C.red : C.mid, 'center'); + }); + const kx = bx + 40, ky = by + 320, kw = (bw - 80) / 16; + const lit = A.cue === 3 && A.lt > A.ld * 0.55; + for (let i = 0; i < 16; i++) { + const on = lit && Math.floor(t * 4.6 + i * 3) % 7 === 0; + rr(kx + i * kw + 2, ky, kw - 4, 170, 4, on ? C.orange : '#2b2833', on ? 'rgba(255,122,0,.18)' : '#0b0a0e', 1.2); + } + [0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14].forEach((i, j) => { + const on = lit && Math.floor(t * 4.6 + j * 5) % 9 === 0; + rr(kx + (i + 1) * kw - kw * 0.3, ky, kw * 0.6, 100, 3, on ? C.orange : '#3a3644', on ? '#3a1d05' : '#141218', 1); + }); + T(lit ? '27 TECLAS: TOCAN LA PISTA ELEGIDA' : 'ESQUEMA DEL PANEL', bx + bw / 2, by + bh - 14, 16, 600, lit ? C.orange : C.dim, 'center'); +}; +Gr.screen = (A, t, f) => { + const R = [['ENCABEZADO', 'reproducción · tempo · carga · batería', 0, 0, 240, 22], ['TARJETAS', 'una por perilla: KNOB 1–4', 0, 22, 240, 40], + ['GRÁFICO', 'la criatura, la envolvente, los pasos…', 0, 62, 240, 152], ['PIE', 'la página y dónde estás', 0, 214, 240, 26]]; + const sel = A.cue === 0 ? [0] : A.cue === 1 ? [1] : A.cue === 2 ? [2, 3] : []; + const mx = GX + 20, my = GY + 10, ms = 1.55; + R.forEach((r, i) => { + const on = sel.includes(i); + rr(mx + r[2] * ms, my + r[3] * ms, r[4] * ms, r[5] * ms, 3, on ? C.orange : C.faint, on ? 'rgba(255,122,0,.07)' : null, on ? 2 : 1.2); + T(r[0], mx + 400, my + (r[3] + r[5] / 2) * ms + 2, 20, 600, on ? C.text : C.dim); + T(r[1], mx + 400, my + (r[3] + r[5] / 2) * ms + 26, 15, 500, on ? C.orange : C.faint); + if (on) { mark(r[2], r[3], r[4], r[5], 0.5 + 0.5 * Math.sin(t * 4) ** 2); X.globalAlpha = .35; arrow(mx + 372, my + (r[3] + r[5] / 2) * ms - 6, SX - 24, SY + (r[3] + r[5] / 2) * 3, C.orange, 1, 7); X.globalAlpha = 1; } + }); + if (A.cue === 1) { for (let k = 0; k < 4; k++) rr(mx + k * 60 * ms + 4, my + 22 * ms + 4, 60 * ms - 8, 40 * ms - 8, 3, k === 1 ? C.orange : C.faint, null, k === 1 ? 2 : 1); } + if (A.cue === 3) { + const y = GY + 430, a = fade(A.lt, 0, .5); X.globalAlpha = a; + heatRule(GX, y, GW, 18, 0, 1); + T('POCO', GX, y + 48, 18, 600, C.cyan); T('MUCHO', GX + GW, y + 48, 18, 600, C.text, 'right'); + rr(GX, y + 76, 26, 26, 4, null, C.violet); T('SELECCIONADO', GX + 38, y + 96, 18, 600, C.text); + rr(GX + 300, y + 76, 26, 26, 4, null, C.orange); T('ACTIVO', GX + 338, y + 96, 18, 600, C.text); + X.globalAlpha = 1; + } +}; +Gr.home = (A, t, f) => { + for (let k = 0; k < 6; k++) { + const col = k % 3, row = Math.floor(k / 3), x = GX + 140 + col * 290, y = GY + 130 + row * 270; + const e = en(f, k), sel = A.cue === 2 && k === 1, muted = e < 0.01; + sm[k] += (e - sm[k]) * 0.35; + being(TRK[k][2], x, y, (sel ? 64 : 46) * (1 + sm[k] * 0.35), sm[k], t * 0.8 + k * 1.7, muted ? { style: 'dim' } : {}); + T('T' + (k + 1), x - 110, y - 96, 18, 600, sel ? C.orange : C.mid); + T(TRK[k][0], x, y + 118, 19, 600, muted ? C.dim : C.text, 'center'); + T(muted ? 'MUTEADA' : TRK[k][1], x, y + 142, 15, 500, muted ? C.faint : C.dim, 'center'); + } +}; +Gr.layers = (A, t, f) => { + const half = GW / 2 - 20; + const L = (x, title, on) => { X.globalAlpha = on ? 1 : .35; T(title, x, GY + 30, 30, 600, on ? C.text : C.mid); X.globalAlpha = 1; }; + L(GX, 'TOCAR', A.cue === 0); L(GX + half + 40, 'MANTENER', A.cue >= 1); + { /* tap: a ripple, the pages flip */ + const on = A.cue === 0, ph = (t % 1.4) / 1.4; X.globalAlpha = on ? 1 : .35; + rr(GX, GY + 70, 120, 56, 8, C.orange, 'rgba(255,122,0,.1)', 2); T('EDIT', GX + 60, GY + 106, 20, 600, C.text, 'center'); + if (on) { X.globalAlpha = (1 - ph) * .8; X.strokeStyle = C.orange; X.lineWidth = 2; X.beginPath(); X.roundRect(GX - ph * 30, GY + 70 - ph * 30, 120 + ph * 60, 56 + ph * 60, 12); X.stroke(); X.globalAlpha = 1; } + const pages = ['EDIT 1', 'EDIT 2', 'FILTER', 'VOICE'], k = on ? Math.floor(t / 1.4) % 4 : 0; + pages.forEach((p, i) => { const d = (i - k + 4) % 4; X.globalAlpha = (on ? 1 : .35) * (1 - d * .28); rr(GX + d * 18, GY + 170 + d * 18, 300, 190, 8, d ? C.faint : C.orange, '#07060a', d ? 1 : 2); if (!d) T(p, GX + 24, GY + 214, 24, 600, C.text); }); + X.globalAlpha = 1; + } + { /* hold: the bar fills, the map of the keys */ + const x0 = GX + half + 40, on = A.cue >= 1; X.globalAlpha = on ? 1 : .35; + const fx = A.cue === 2 && A.lt > A.ld * 0.45, name = A.cue === 2 ? (fx ? 'FX' : 'GLO') : 'GLO'; + rr(x0, GY + 70, 120, 56, 8, C.violet, 'rgba(184,112,255,.1)', 2); T(name, x0 + 60, GY + 106, 20, 600, C.text, 'center'); + const hp = on ? clamp((A.lt % 6) / 0.6, 0, 1) : 0; rr(x0 + 140, GY + 92, 220, 10, 5, C.faint, null, 1); X.fillStyle = C.violet; X.fillRect(x0 + 140, GY + 92, 220 * hp, 10); + T('0,4 s', x0 + 372, GY + 102, 14, 500, C.dim); + const keys = fx ? ['RPT 1/8', 'RPT 1/16', 'RPT 1/32', 'LPF', 'HPF', 'OCT−', 'OCT+', '1/2 T'] : ['SOLO 1', 'SOLO 2', 'SOLO 3', 'SOLO 4', 'SOLO 5', 'SOLO 6', 'UNMUTE', 'TAP']; + const blk = fx ? ['MUTE', 'MUTE', 'MUTE', 'MUTE', 'MUTE', 'MUTE'] : ['MUTE 1', 'MUTE 2', 'MUTE 3', 'MUTE 4', 'MUTE 5', 'MUTE 6']; + const kw = (half - 10) / 8; + keys.forEach((s, i) => { + const lit = on && hp >= 1 && (fx ? Math.floor(t * 3) % 8 === i : false); + rr(x0 + i * kw, GY + 250, kw - 6, 150, 4, lit ? C.orange : '#2b2833', lit ? 'rgba(255,122,0,.15)' : '#0b0a0e', 1.2); + X.save(); X.translate(x0 + i * kw + kw / 2 - 3, GY + 390); X.rotate(-Math.PI / 2); T(s, 0, 5, 13, 600, hp >= 1 ? C.text : C.dim); X.restore(); + }); + [0, 1, 2, 3, 4, 5].forEach((i) => { + const lit = on && hp >= 1 && !fx && Math.floor(t * 1.2) % 6 === i; + rr(x0 + (i + 1) * kw - kw * 0.32 - 3, GY + 250, kw * 0.6, 84, 3, lit ? C.violet : '#3a3644', lit ? '#2a1640' : '#141218', 1); + if (hp >= 1) T(blk[i].replace('MUTE ', ''), x0 + (i + 1) * kw - 3, GY + 238, 12, 600, lit ? C.violet : C.dim, 'center'); + }); + if (hp >= 1) T(fx ? 'cada tecla, un efecto momentáneo' : 'teclas negras: mutes · blancas: solos', x0, GY + 450, 18, 500, fx ? C.orange : C.violet); + T('soltás: volvés a donde estabas', x0, GY + 480, 16, 500, C.dim); + X.globalAlpha = 1; + } +}; +Gr.engines = (A, t, f) => { + const E = [['ANALOG', 'dos osciladores, filtro por voz'], ['FM6', 'seis operadores, 32 algoritmos'], ['PHASE', 'distorsión de fase'], + ['LOFI', 'chip · bytebeat · floatbeat'], ['VOICE', 'voz por formantes'], ['WHEEL', 'órgano con rotativo'], + ['NOISE', 'ruido coloreado y metálico'], ['DRUM', 'DRUM-X: batería sintetizada']]; + const hi = [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2], [3, 4, 5], [6, 7], []][A.cue] || []; + E.forEach((e, i) => { + const col = i % 4, row = Math.floor(i / 4), x = GX + 105 + col * 216, y = GY + 110 + row * 250; + const on = hi.includes(i), a = A.cue === 4 ? .55 : on ? 1 : .28; + X.globalAlpha = a; + const pulse = 0.35 + 0.35 * Math.max(0, Math.sin(t * TAU / (BEAT * 2) + i)); + being(e[0], x, y, on ? 46 : 38, on ? pulse : 0.15, t * 0.7 + i * 2.1); + T(e[0] === 'DRUM' ? 'DRUM-X' : e[0], x, y + 104, 20, 600, on ? C.text : C.mid, 'center'); + if (on && A.cue) T(e[1], x, y + 128, 14, 500, C.orange, 'center'); + X.globalAlpha = 1; + }); + if (A.cue === 4) { + const a = fade(A.lt, 0, .5); X.globalAlpha = a; + rr(GX, GY + 470, GW / 2 - 20, 80, 8, C.violet, 'rgba(184,112,255,.07)', 2); + T('PRESETS', GX + 24, GY + 505, 22, 600, C.text); T('una lista con todos los motores', GX + 24, GY + 533, 16, 500, C.violet); + rr(GX + GW / 2 + 20, GY + 470, GW / 2 - 20, 80, 8, C.orange, 'rgba(255,122,0,.07)', 2); + T('EDIT + SELECT', GX + GW / 2 + 44, GY + 505, 22, 600, C.text); T('el sonido, a los dados', GX + GW / 2 + 44, GY + 533, 16, 500, C.orange); + X.globalAlpha = 1; + } +}; +Gr.signal = (A, t, f) => { + const y = GY + 230, nw = 128, nh = 66; + const N = [['MOTOR', 'la voz', GX], ['FILTRO', 'LP HP BP COMB', GX + 172], ['DIST', '6 tipos · AMP', GX + 344], ['NIVEL', 'y PANEO', GX + 516]]; + const on = (i) => (A.cue === 1 && i <= 1) || (A.cue === 2 && i === 2) || (A.cue === 3 && i === 3) || A.cue === 0; + N.forEach((n, i) => { node(n[2], y, nw, nh, n[0], on(i), n[1]); if (i) arrow(n[2] - 44, y + nh / 2, n[2] - 4, y + nh / 2, C.mid, 1.5, 7); }); + const ml = A.cue === 1 || A.cue === 0; + node(GX + 172, y - 150, nw, 56, 'ENV · LFO', ml); + X.setLineDash([5, 5]); arrow(GX + 236, y - 92, GX + 236, y - 6, ml ? C.violet : C.faint, 1.5, 7); X.setLineDash([]); + if (ml) { X.strokeStyle = C.violet; X.lineWidth = 2; X.beginPath(); for (let i = 0; i <= 60; i++) { const xx = GX + 186 + i * 1.65, yy = y - 128 + 8 * Math.sin(i / 6 + t * 3); i ? X.lineTo(xx, yy) : X.moveTo(xx, yy); } X.stroke(); } + const busOn = A.cue === 3 || A.cue === 0; + ['CHORUS', 'DELAY', 'REVERB'].forEach((b, i) => { + const by = y - 110 + i * 110; node(GX + 700, by + 8, 150, 50, b, busOn); + X.globalAlpha = busOn ? 1 : .4; arrow(GX + 644, y + nh / 2, GX + 696, by + 33, busOn ? C.mid : C.faint, 1.2, 6); X.globalAlpha = 1; + }); + T('ENVÍOS · COMPARTIDOS', GX + 775, y - 128, 14, 600, busOn ? C.orange : C.dim, 'center'); + const mOn = A.cue === 4 || A.cue === 0; + node(GX + 300, y + 200, 300, 70, 'MASTER', mOn, 'limitador · CLIP · PUNCH · DUCK'); + X.globalAlpha = mOn ? 1 : .4; arrow(GX + 580, y + nh, GX + 500, y + 196, C.mid, 1.4, 7); arrow(GX + 775, y + 168, GX + 604, y + 228, C.mid, 1.4, 7); X.globalAlpha = 1; + /* the sound travelling: a dot a beat along the chain */ + const ph = (t / BEAT) % 1, px = GX + nw / 2 + ph * 516, k = clamp(1 - ph, 0, 1); + X.fillStyle = heat(80 + 170 * k); X.beginPath(); X.arc(px, y + nh / 2, 6 + 4 * k, 0, TAU); X.fill(); + if (A.cue === 2) { /* the curve of the distortion */ + X.strokeStyle = C.orange; X.lineWidth = 2; X.beginPath(); + for (let i = 0; i <= 80; i++) { const u = i / 40 - 1, v = Math.tanh(u * (2.5 + 1.5 * Math.sin(t))); const xx = GX + 344 + 14 + i * 1.25, yy = y + nh + 70 - v * 40; i ? X.lineTo(xx, yy) : X.moveTo(xx, yy); } + X.stroke(); T('SOFT · HARD · FOLD · CRUSH · RECT · AMP', GX + 408, y + nh + 140, 14, 600, C.orange, 'center'); + } +}; +const DRIVE = ['X...x...X...x.x.', '', '....X.......X...', 'x.xxx.xxx.xxx.xx', '..x.......x.....', '.............x.x', '...x..x....x..x.', '......x.......x.']; +Gr.drumx = (A, t, f) => { + const cx = GX + 300, cy = GY + 250, R = 180, step = Math.floor(t / (BEAT / 4)) % 16, frac = (t / (BEAT / 4)) % 1; + const names = ['BD', 'SD', 'CP', 'CH', 'OH', 'TM', 'RS', 'CB'], full = ['bombo', 'redoblante', 'clap', 'hat cerrado', 'hat abierto', 'tom', 'rim', 'cowbell']; + const morph = A.cue === 1 ? 0.5 + 0.5 * Math.sin(A.lt * 0.9 - Math.PI / 2) : 0.2; + names.forEach((n, i) => { + const a = i / 8 * TAU - Math.PI / 2, x = cx + R * Math.cos(a), y = cy + R * Math.sin(a); + const hit = DRIVE[i][step] && DRIVE[i][step] !== '.' && en(f, 0) > 0.02, e = hit ? 1 - frac : 0; + const g = LANE[i][1], ff = { ...laneF(g, i), m: morph, lobB: g[3] + 2, spikesB: g[0] + 6, gB: gen(G.cil) }; + organism(X, g, ff, x, y, 30 * (1 + e * 0.4), e * 0.9, t + i, { ex: 4, nv: 64 }); + T(n, x, y + 62, 17, 600, hit && e > .5 ? C.orange : C.text, 'center'); + T(full[i], x, y + 80, 12, 500, C.dim, 'center'); + }); + T('8 SONIDOS', cx, cy + 6, 22, 600, C.mid, 'center'); T('sin samples', cx, cy + 30, 14, 500, C.dim, 'center'); + const sx0 = GX + 600, sy0 = GY + 120; + X.globalAlpha = A.cue >= 1 ? 1 : .35; + T('MORPH', sx0 + 120, sy0 - 10, 22, 600, C.text, 'center'); + rr(sx0, sy0 + 20, 240, 8, 4, C.faint, null, 1); heatRule(sx0, sy0 + 20, 240 * morph, 8, 0, 0.8); + X.fillStyle = C.orange; X.beginPath(); X.arc(sx0 + 240 * morph, sy0 + 24, 11, 0, TAU); X.fill(); + T('A', sx0 - 20, sy0 + 31, 22, 600, C.text, 'center'); T('B', sx0 + 260, sy0 + 31, 22, 600, C.text, 'center'); + T('todo el kit, de un lado al otro', sx0 + 120, sy0 + 70, 15, 500, C.dim, 'center'); + X.globalAlpha = A.cue === 2 ? 1 : .3; + const kits = ['DRUM-X', '909 CLUB', '808 BOOM', 'LOFI DUST', 'INDUSTRIAL', 'ACOUSTIC', 'DUB ROOTS', 'TECHNO RAW', 'BREAKS']; + kits.forEach((k, i) => { const on = A.cue === 2 && Math.floor(A.lt * 1.6) % 9 === i; rr(sx0, sy0 + 120 + i * 36, 240, 30, 4, on ? C.orange : C.faint, on ? 'rgba(255,122,0,.1)' : null, on ? 2 : 1); T(k, sx0 + 14, sy0 + 141 + i * 36, 15, 600, on ? C.text : C.mid); }); + X.globalAlpha = 1; +}; +Gr.seq = (A, t, f) => { + const s16 = t / (BEAT / 4); + if (A.cue === 0 || A.cue === 2) { + const lens = [16, 12, 10], cols = [heat(30), heat(110), heat(190)]; + lens.forEach((L, r) => { + const y = GY + 60 + r * 130, cw = GW / 16, pos = Math.floor(s16) % L; + T('LEN ' + L, GX, y - 14, 16, 600, C.mid); + for (let i = 0; i < 16; i++) { + const inL = i < L, hit = inL && (i * (r + 3)) % 5 < 2, cur = i === pos; + rr(GX + i * cw + 3, y, cw - 6, 70, 4, cur ? C.orange : inL ? '#2b2833' : '#121016', hit ? (cur ? C.orange : cols[r]) : null, cur ? 2 : 1); + } + }); + T(A.cue === 2 ? 'REC + PLAY: GRABÁS EN VIVO' : 'CADA PISTA, SU LARGO: GIRAN UNAS CONTRA OTRAS', GX, GY + 480, 20, 600, A.cue === 2 ? C.red : C.orange); + if (A.cue === 2 && (t * 2) % 1 < .5) { X.fillStyle = C.red; X.beginPath(); X.arc(GX + GW - 20, GY + 473, 10, 0, TAU); X.fill(); } + } else if (A.cue === 1) { + const rows = 14, cw = GW / 16, rh = 30, y0 = GY + 40, pos = Math.floor(s16) % 16; + for (let r = 0; r < rows; r++) { X.fillStyle = r % 2 ? '#0a090d' : '#0e0d12'; X.fillRect(GX, y0 + r * rh, GW, rh); } + const notes = [[0, 3, 9], [4, 2, 6], [6, 2, 5], [8, 3, 6], [12, 4, 9], [12, 4, 5], [12, 4, 2]]; + notes.forEach(([s, l, r]) => { const on = pos >= s && pos < s + l; rr(GX + s * cw + 2, y0 + r * rh + 3, l * cw - 4, rh - 6, 4, null, on ? C.orange : heat(60 + r * 10)); }); + X.fillStyle = C.text; X.fillRect(GX + pos * cw, y0, 2, rows * rh); + T('ACC', GX + 2, y0 + rows * rh + 28, 14, 600, C.violet); T('SLD', GX + 6 * cw, y0 + rows * rh + 28, 14, 600, C.violet); + T('PIANO ROLL · HASTA 4 NOTAS POR PASO', GX, GY + 520, 20, 600, C.orange); + } else if (A.cue === 3) { + const cw = GW / 16, y = GY + 150, pos = Math.floor(s16) % 16, loop = Math.floor(s16 / 16); + const comp = { 2: 'PROB 50%', 5: 'RATCH ×3', 8: 'ECHO', 11: 'ARP', 14: 'WALK ↑' }; + for (let i = 0; i < 16; i++) { + const cur = i === pos; rr(GX + i * cw + 3, y, cw - 6, 70, 4, cur ? C.orange : '#2b2833', i % 3 === 2 ? heat(120) : null, cur ? 2 : 1); + if (comp[i]) { X.save(); X.translate(GX + i * cw + cw / 2, y - 16); T(comp[i], 0, 0, 14, 600, C.violet, 'center'); X.restore(); arrow(GX + i * cw + cw / 2, y - 10, GX + i * cw + cw / 2, y - 2, C.violet, 1, 5); } + } + const wn = loop % 5; T('vuelta ' + (loop % 5 + 1), GX + 14 * cw - 20, y + 120, 14, 500, C.dim); + for (let k = 0; k < 5; k++) rr(GX + 14 * cw + 6, y + 250 - k * 26, cw - 12, 20, 3, null, k === wn ? C.orange : '#1d1a24'); + T('COMPONENTES POR PASO', GX, GY + 520, 20, 600, C.orange); + } else { + const cw = GW / 16, y = GY + 120; + for (let i = 0; i < 16; i++) rr(GX + i * cw + 3, y, cw - 6, 70, 4, '#2b2833', i % 4 === 0 ? heat(90) : i % 3 === 1 ? heat(160) : null, 1); + const heads = [[1, C.orange, 'x1'], [0.5, C.violet, 'x½'], [-1, C.cyan, '◀'], [2, C.yellow, 'x2']]; + heads.forEach(([r, col, lb], k) => { const p = ((s16 * r) % 16 + 16) % 16; X.fillStyle = col; X.fillRect(GX + p * cw, y - 10 - k * 8, cw, 4); T(lb, GX + GW + 8, y - 4 - k * 8, 12, 600, col); }); + T('PLAYHEADS: CABEZALES EXTRA', GX, y + 140, 20, 600, C.orange); + const m = (t / (BEAT * 16)) % 1; being('LOFI', GX + 120, GY + 420, 50, .3 + .4 * m, t, { tum: [] }); + T('MUTATE: CADA TANTOS COMPASES', GX + 220, GY + 430, 20, 600, C.violet); + } +}; +Gr.mod = (A, t, f) => { + const S = ['ENV', 'LFO', 'VELOCIDAD', 'MSEQ', 'RUIDO'], Dd = ['AFINACIÓN', 'FILTRO', 'FORMA', 'AMPLITUD', 'DELAY', 'REVERB']; + if (A.cue < 2) { + const routes = A.cue === 0 ? [[0, 1], [1, 0], [1, 1], [0, 3], [1, 2]] : [[0, 1], [1, 0], [2, 3], [3, 4], [4, 5], [1, 2]]; + S.forEach((s, i) => { const on = routes.some((r) => r[0] === i); node(GX, GY + 30 + i * 100, 190, 60, s, on); }); + Dd.forEach((d, i) => { const on = routes.some((r) => r[1] === i); node(GX + GW - 210, GY + 10 + i * 88, 210, 56, d, on, i >= 4 ? 'efectos' : ''); }); + routes.forEach(([a, b], k) => { + const x1 = GX + 190, y1 = GY + 60 + a * 100, x2 = GX + GW - 214, y2 = GY + 38 + b * 88; + X.strokeStyle = b >= 4 ? C.violet : heat(60 + k * 30); X.lineWidth = 1.8; X.beginPath(); X.moveTo(x1, y1); X.bezierCurveTo(x1 + 200, y1, x2 - 200, y2, x2, y2); X.stroke(); + const u = (t * 0.6 + k * 0.23) % 1, bx = (1 - u) ** 3 * x1 + 3 * (1 - u) ** 2 * u * (x1 + 200) + 3 * (1 - u) * u * u * (x2 - 200) + u ** 3 * x2; + const by = (1 - u) ** 3 * y1 + 3 * (1 - u) ** 2 * u * y1 + 3 * (1 - u) * u * u * y2 + u ** 3 * y2; + X.fillStyle = C.text; X.beginPath(); X.arc(bx, by, 4, 0, TAU); X.fill(); + }); + T(A.cue === 0 ? 'ENV Y LFO EN CADA PISTA' : 'MATRIZ MOD: 4 RUTAS MÁS POR PISTA', GX, GY + 550, 20, 600, C.orange); + } else { + const P = ['CUT', 'RES', 'DECAY', 'DLY', 'REV', 'DRIVE', 'PAN', 'SPEED', 'FOLD', 'TONE', 'MIX', 'WIDE']; + for (let m = 0; m < 4; m++) { + const x = GX + 100 + m * 220, y = GY + 140, v = 0.5 + 0.45 * Math.sin(t * (0.7 + m * 0.3) + m); + X.lineWidth = 3; X.strokeStyle = C.orange; X.beginPath(); X.arc(x, y, 44, 0, TAU); X.stroke(); + const ang = Math.PI * 0.75 + v * Math.PI * 1.5; X.beginPath(); X.moveTo(x, y); X.lineTo(x + 38 * Math.cos(ang), y + 38 * Math.sin(ang)); X.stroke(); + T('M' + (m + 1), x, y + 80, 22, 600, C.text, 'center'); + for (let j = 0; j < 3; j++) { + const px = x - 70 + j * 70, py = y + 270; X.globalAlpha = .4 + .6 * v; X.strokeStyle = heat(60 + m * 50); X.lineWidth = 1.5; + X.beginPath(); X.moveTo(x, y + 96); X.lineTo(px, py - 26); X.stroke(); X.globalAlpha = 1; + rr(px - 32, py - 24, 64, 30, 4, C.faint, null, 1); T(P[m * 3 + j], px, py - 3, 13, 600, C.mid, 'center'); + } + } + T('LFO MANTENIDO: LAS PERILLAS SON M1–M4', GX, GY + 550, 20, 600, C.orange); + } +}; +Gr.fx = (A, t, f) => { + const box = (i, title, on) => { const x = GX + (i % 2) * (GW / 2 + 10), y = GY + Math.floor(i / 2) * 270; X.globalAlpha = on ? 1 : .3; rr(x, y, GW / 2 - 10, 250, 8, on ? C.orange : C.faint, '#07060a', on ? 2 : 1.2); T(title, x + 20, y + 36, 22, 600, C.text); return [x, y]; }; + if (A.cue <= 1) { + let [x, y] = box(0, 'DELAY', A.cue === 0); + for (let k = 0; k < 7; k++) { const ph = ((t / (BEAT * 0.75)) - k) ; const a = Math.max(0, 1 - k * 0.15); X.fillStyle = heat(220 - k * 28, a); X.beginPath(); X.arc(x + 50 + k * 56, y + 140, 14 * a + 3 * Math.max(0, 1 - (ph % 1)), 0, TAU); X.fill(); } + T('analógico o digital · pitch · ping pong', x + 20, y + 225, 14, 500, C.dim); + [x, y] = box(1, 'REVERB', A.cue === 0); + for (let k = 0; k < 60; k++) { const hx = hash(k * 7), hy = hash(k * 13 + 5), d = (t * 0.1 + hx) % 1; X.fillStyle = heat(30 + hy * 180, 0.6 * (1 - d)); X.beginPath(); X.arc(x + 30 + hx * 360, y + 70 + hy * 110 - d * 20, 2 + 3 * d, 0, TAU); X.fill(); } + ['ROOM', 'SPRING', 'SHIMMER', 'RESO', 'CLOUD'].forEach((m, i) => { const on = A.cue === 0 && Math.floor(A.lt * 1.2) % 5 === i; rr(x + 18 + i * 82, y + 196, 76, 30, 4, on ? C.orange : C.faint, null, on ? 2 : 1); T(m, x + 56 + i * 82, y + 217, 12, 600, on ? C.text : C.mid, 'center'); }); + [x, y] = box(2, 'CHORUS', A.cue === 1); + for (let l = 0; l < 2; l++) { X.strokeStyle = l ? C.violet : C.cyan; X.lineWidth = 2; X.beginPath(); for (let i = 0; i <= 100; i++) { const xx = x + 20 + i * 3.8, yy = y + 140 + 40 * Math.sin(i / 9 + t * 2 + l * (1 + Math.sin(t))); i ? X.lineTo(xx, yy) : X.moveTo(xx, yy); } X.stroke(); } + [x, y] = box(3, 'SLICER', A.cue === 1); + const pat = [1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1], st = Math.floor(t / (BEAT / 4)) % 16; + pat.forEach((p, i) => rr(x + 20 + i * 24, y + 90, 18, 100, 3, i === st ? C.orange : C.faint, p ? (i === st ? C.orange : heat(130)) : null, 1)); + X.globalAlpha = 1; + } else { + const keys = ['RPT 1/8', 'RPT 1/16', 'RPT 1/32', 'LPF', 'HPF', 'OCT−', 'OCT+', '1/2 T', 'DEC−', 'DEC+', 'STUT 8', 'STUT 16']; + const kw = GW / keys.length, playing = A.cue === 2 && A.lt > 3 && A.lt < 7; + keys.forEach((k, i) => { + const lit = (playing && i === 1 && (A.lt % 1) < .5) || (A.cue === 3 && Math.floor(t * 2) % 12 === i && i % 3 === 0); + rr(GX + i * kw + 2, GY + 40, kw - 4, 200, 4, lit ? C.orange : '#2b2833', lit ? 'rgba(255,122,0,.2)' : '#0b0a0e', 1.2); + X.save(); X.translate(GX + i * kw + kw / 2 + 5, GY + 230); X.rotate(-Math.PI / 2); T(k, 0, 0, 14, 600, lit ? C.text : C.mid); X.restore(); + }); + T('FX MANTENIDO: LAS TECLAS SON EFECTOS', GX, GY + 290, 20, 600, C.orange); + if (A.cue === 3) { + const cx = GX + 650, cy = GY + 420, r = 100, p = (t / (BEAT * 16)) % 1; + for (let i = 0; i < 16; i++) { const a = i / 16 * TAU - Math.PI / 2; X.fillStyle = [6, 7, 12].includes(i) ? C.orange : '#1d1a24'; X.beginPath(); X.arc(cx + r * Math.cos(a), cy + r * Math.sin(a), 9, 0, TAU); X.fill(); } + const a = p * TAU - Math.PI / 2; X.strokeStyle = C.text; X.lineWidth = 2; X.beginPath(); X.moveTo(cx, cy); X.lineTo(cx + (r - 18) * Math.cos(a), cy + (r - 18) * Math.sin(a)); X.stroke(); + T('EL CARRIL DE PUNCH-IN', GX, GY + 400, 22, 600, C.text); T('lo que tocaste se repite con el tema', GX, GY + 432, 16, 500, C.dim); + } + } +}; +Gr.gen = (A, t, f) => { + if (A.cue === 0) { + const gs = ['ELECTRO', 'EBM', 'ITALO', 'SYNTHPOP', 'DARKWAVE', 'POST PUNK', 'MOTORIK', 'SHOEGAZE', 'DISCO', 'TRAP']; + const k = Math.floor(A.lt * 3) % gs.length, stop = A.lt > A.ld * 0.35; + gs.forEach((g, i) => { const on = (stop ? 5 : k) === i; rr(GX + (i % 5) * 172, GY + 20 + Math.floor(i / 5) * 50, 162, 40, 4, on ? C.orange : C.faint, on ? 'rgba(255,122,0,.12)' : null, on ? 2 : 1); T(g, GX + (i % 5) * 172 + 81, GY + 46 + Math.floor(i / 5) * 50, 14, 600, on ? C.text : C.mid, 'center'); }); + if (stop) { + arrow(GX + GW / 2, GY + 140, GX + GW / 2, GY + 190, C.orange, 2, 9); T('OCT+', GX + GW / 2 + 20, GY + 172, 16, 600, C.orange); + ['MOTORES', 'SONIDOS', 'PARTES', 'ESCALA', 'TEMPO', 'EFECTOS'].forEach((c, i) => { const a = fade(A.lt, A.ld * 0.4 + i * 0.35, A.ld * 0.4 + i * 0.35 + 0.3); X.globalAlpha = a; node(GX + (i % 3) * 290, GY + 220 + Math.floor(i / 3) * 100, 270, 70, c, true); X.globalAlpha = 1; }); + } + } else if (A.cue === 1) { + ['SEQ', 'LFO', 'FX'].forEach((p, i) => { + const x = GX + 80 + i * 280, y = GY + 160, a = t * 3 + i * 1.3, s = 60; + X.save(); X.translate(x, y); X.rotate(Math.sin(a) * 0.4); rr(-s / 2, -s / 2, s, s, 10, C.orange, 'rgba(255,122,0,.08)', 2); + const v = (Math.floor(t * 4 + i * 2) % 6) + 1, P = { 1: [[0, 0]], 2: [[-1, -1], [1, 1]], 3: [[-1, -1], [0, 0], [1, 1]], 4: [[-1, -1], [1, -1], [-1, 1], [1, 1]], 5: [[-1, -1], [1, -1], [0, 0], [-1, 1], [1, 1]], 6: [[-1, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [1, 1]] }; + P[v].forEach(([dx, dy]) => { X.fillStyle = C.text; X.beginPath(); X.arc(dx * 15, dy * 15, 5, 0, TAU); X.fill(); }); X.restore(); + T(p + ' + SELECT', x, y + 80, 20, 600, C.text, 'center'); + }); + T('LOS DADOS, PARTE POR PARTE', GX, GY + 400, 22, 600, C.orange); T('con OK para quedártelo o CANCEL para volver', GX, GY + 432, 16, 500, C.dim); + } else { + const cx = GX + 200, cy = GY + 220, a0 = -Math.PI * 0.2, a1 = a0 + Math.PI * 1.6 * ease((A.lt % 2.4) / 1.6); + X.strokeStyle = C.violet; X.lineWidth = 6; X.beginPath(); X.arc(cx, cy, 90, a0, a1); X.stroke(); + arrow(cx + 90 * Math.cos(a1), cy + 90 * Math.sin(a1), cx + 90 * Math.cos(a1 + .2), cy + 90 * Math.sin(a1 + .2), C.violet, 6, 18); + T('DESHACER', GX + 380, GY + 210, 40, 600, C.text); T('GLO mantenido + G4 · otra vez: rehacer', GX + 380, GY + 250, 18, 500, C.violet); + } +}; +Gr.arrange = (A, t, f) => { + if (A.cue === 0) { + T('PROYECTO', GX, GY + 30, 18, 600, C.mid); + for (let p = 0; p < 8; p++) rr(GX + 120 + p * 58, GY + 8, 46, 32, 4, p === 0 ? C.orange : C.faint, p === 0 ? 'rgba(255,122,0,.12)' : null, p === 0 ? 2 : 1), T(String(p + 1), GX + 143 + p * 58, GY + 30, 16, 600, p === 0 ? C.text : C.dim, 'center'); + ['A', 'B', 'C', 'D'].forEach((s, i) => { + const x = GX + i * 218, y = GY + 90, full = i < 2 && A.lt > i * 2.5; + rr(x, y, 200, 260, 8, full ? C.orange : C.faint, '#07060a', full ? 2 : 1.2); T(s, x + 100, y + 70, 60, 600, full ? C.text : C.faint, 'center'); + if (full) for (let r = 0; r < 6; r++) for (let c = 0; c < 8; c++) if (hash(i * 97 + r * 13 + c) > .55) rr(x + 24 + c * 20, y + 110 + r * 22, 14, 14, 2, null, heat(40 + r * 35)); + T(i === 0 ? 'una idea' : i === 1 ? 'su variación' : '', x + 100, y + 240, 15, 500, C.dim, 'center'); + }); + } else if (A.cue === 1) { + const rows = [['A', 8], ['B', 8], ['A', 4], ['B', 8]], tot = 28, wpx = GW / tot, p = ((t - TL.chapters[A.ci].lines[1].start) / (BEAT * 4)) % tot; + let x = GX; + rows.forEach(([s, b], i) => { const on = p >= (x - GX) / wpx && p < (x - GX) / wpx + b; rr(x + 2, GY + 120, b * wpx - 4, 140, 6, on ? C.orange : C.faint, on ? 'rgba(255,122,0,.1)' : '#07060a', on ? 2 : 1.2); T(s, x + b * wpx / 2, GY + 205, 44, 600, on ? C.text : C.mid, 'center'); T(b + ' compases', x + b * wpx / 2, GY + 290, 14, 500, C.dim, 'center'); x += b * wpx; }); + X.fillStyle = C.text; X.fillRect(GX + p * wpx, GY + 100, 2, 180); + T('ARRANGE: SECCIONES EN FILAS', GX, GY + 380, 22, 600, C.orange); + } else { + const kw = GW / 8; + ['A', 'B', 'C', 'D', 'STORE A', 'STORE B', 'STORE C', 'STORE D'].forEach((k, i) => { + const lit = i < 4 && Math.floor(A.lt / 1.5) % 4 === i; + rr(GX + i * kw + 2, GY + 80, kw - 4, 220, 4, lit ? C.orange : '#2b2833', lit ? 'rgba(255,122,0,.2)' : '#0b0a0e', 1.2); + T(k, GX + i * kw + kw / 2, GY + 280, i < 4 ? 26 : 13, 600, lit ? C.text : C.mid, 'center'); + }); + T('SAVE MANTENIDO: LAS SECCIONES EN VIVO', GX, GY + 360, 22, 600, C.orange); T('entran en el compás siguiente', GX, GY + 392, 16, 500, C.dim); + } +}; +Gr.usb = (A, t, f) => { + const fmx = GX, fmy = GY + 180; + rr(fmx, fmy, 200, 120, 10, C.text, '#07060a', 2); T('FM-1', fmx + 100, fmy + 70, 30, 600, C.text, 'center'); + if (A.cue <= 1) { + const n = A.cue === 1 ? 10 : 8, lab = ['T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'FX L', 'FX R', 'MIC', 'MIC']; + const lx = GX + 360, lw = GW - 360; + rr(lx, GY + 40, lw, 400, 10, C.faint, '#07060a', 1.2); T(A.cue === 1 ? 'EL CELULAR · 10 CANALES' : 'TU DAW · 8 CANALES', lx + 20, GY + 74, 18, 600, C.mid); + arrow(fmx + 210, fmy + 50, lx - 10, fmy + 50, C.orange, 2, 9); + for (let i = 0; i < n; i++) { + const v = i < 6 ? en(f, i) : i < 8 ? clamp(D.rms[f] * 0.8, 0, 1) : A.cue === 1 ? clamp(0.3 + 0.5 * Math.abs(Math.sin(t * 5.3) * Math.sin(t * 1.7)), 0, 1) : 0; + const bw2 = (lw - 40) / n, x = lx + 20 + i * bw2, segs = 16, lit = Math.round(clamp(v, 0, 1) * segs); + for (let s = 0; s < segs; s++) rr(x + 4, GY + 400 - s * 18, bw2 - 8, 13, 2, null, s < lit ? heat(30 + s * 13) : '#151319'); + T(lab[i], x + bw2 / 2, GY + 428, 13, 600, i >= 8 ? C.violet : C.mid, 'center'); + } + if (A.cue === 1) { + const px = fmx + 40, py = fmy + 220; rr(px, py, 70, 130, 12, C.violet, null, 2); T('MIC', px + 35, py + 72, 14, 600, C.violet, 'center'); + for (let k = 0; k < 3; k++) { X.globalAlpha = 1 - ((t * 1.5 + k / 3) % 1); X.strokeStyle = C.violet; X.beginPath(); X.arc(px + 35, py - 10, 14 + ((t * 1.5 + k / 3) % 1) * 30, Math.PI * 1.15, Math.PI * 1.85); X.stroke(); X.globalAlpha = 1; } + arrow(px + 80, py + 40, fmx + 150, fmy + 126, C.violet, 2, 9); + T('STEMS+IN · NUEVO EN 0.8.0', lx, GY + 500, 20, 600, C.violet); T('tu voz por los efectos de la última pista, en su propio canal', lx, GY + 530, 15, 500, C.dim); + } else T('USB › STEMS · las 6 pistas por separado + los efectos', GX + 360, GY + 500, 18, 600, C.orange); + } else { + ['USB', 'BLUETOOTH', 'TRS'].forEach((m, i) => { node(GX + 300 + i * 190, GY + 200, 170, 70, m, true, 'MIDI'); arrow(fmx + 210, fmy + 60, GX + 296 + i * 190, GY + 235, C.mid, 1.2, 6); }); + const ph = (t / BEAT) % 1; X.fillStyle = heat(250 * (1 - ph)); X.beginPath(); X.arc(GX + 300, GY + 380, 12 + 8 * (1 - ph), 0, TAU); X.fill(); + T('CLOCK: EN TEMPO CON OTROS EQUIPOS', GX + 330, GY + 388, 20, 600, C.orange); + } +}; +Gr.web = (A, t, f) => { + const C3 = [['EMULADOR', 'JIANT en el navegador'], ['INSTALADOR', 'Chrome o Edge, por USB'], ['EDITOR', 'sonidos, bancos y backups']]; + C3.forEach((c, i) => { const on = A.cue === 0, a = fade(A.ct, 0.3 + i * 0.5, 0.8 + i * 0.5); X.globalAlpha = a * (on ? 1 : .35); rr(GX, GY + i * 120, GW, 100, 8, on ? C.orange : C.faint, '#07060a', on ? 2 : 1.2); T(c[0], GX + 30, GY + i * 120 + 48, 28, 600, C.text); T(c[1], GX + 30, GY + i * 120 + 80, 17, 500, C.dim); X.globalAlpha = 1; }); + T('juanjiant-bit.github.io/JIANT', GX, GY + 400, 24, 600, C.violet); + if (A.cue === 1) { + const zx = GX + 560, zy = GY + 380; rr(zx, zy, 200, 150, 10, C.orange, 'rgba(255,122,0,.07)', 2); T('STEMS.ZIP', zx + 100, zy + 136, 16, 600, C.orange, 'center'); + ['T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'MIX'].forEach((s, i) => { const u = clamp((A.lt - i * 0.4) / 0.6, 0, 1); if (u <= 0) return; const y = zy - 80 + ease(u) * 120; X.globalAlpha = u < 1 ? 1 : .7; rr(zx + 14 + (i % 4) * 46, y + Math.floor(i / 4) * 10, 40, 26, 3, null, heat(40 + i * 30)); T(s, zx + 34 + (i % 4) * 46, y + 18 + Math.floor(i / 4) * 10, 11, 600, '#000', 'center'); X.globalAlpha = 1; }); + } +}; +/* the intro and the outro: the ecosystem, the name */ +function eco(f, t, cx, cy, R, grow) { + for (let k = 0; k < 6; k++) { + const a = k / 6 * TAU - Math.PI / 2 + t * 0.03, x = cx + R * Math.cos(a) + 10 * Math.sin(t * 0.3 + k), y = cy + R * 0.62 * Math.sin(a) + 8 * Math.sin(t * 0.27 + k * 2); + const e = en(f, k); sm[k] += (e - sm[k]) * 0.3; + being(TRK[k][2], x, y, 44 * grow * (1 + sm[k] * 0.4), sm[k], t * 0.8 + k * 1.9, e < 0.01 ? { style: 'ghost' } : {}); + } +} +function intro(A, t, f) { + const grow = ease(t / 3.2); + eco(f, t, W / 2, 360, 320, grow); + const a0 = fade(t, 4.2, 5.4); + X.globalAlpha = a0; T('JIANT', W / 2, 760, 130, 600, C.text, 'center', 24); heatRule(W / 2 - 300, 792, 600, 3); + X.globalAlpha = fade(t, TL.chapters[0].lines[1].start, TL.chapters[0].lines[1].start + .6) * (A.ci === 0 ? 1 : 0); + T('6 PISTAS · 8 MOTORES · SECUENCIADOR · EFECTOS', W / 2, 846, 24, 500, C.mid, 'center', 3); + if (A.ci === 0 && A.cue >= 2) { + X.globalAlpha = fade(A.lt, 0, .6) * (A.cue === 2 ? 1 : 1 - fade(A.lt, 0, .5)); + X.fillStyle = '#000'; X.fillRect(W / 2 - 420, 822, 840, 40); + rr(W / 2 - 380, 826, 760, 124, 12, C.orange, 'rgba(255,122,0,.06)', 2); + T('GRACIAS A QUIENES APOYAN EL PROYECTO', W / 2, 872, 24, 600, C.text, 'center'); + T('ko-fi.com/juanjiant', W / 2, 922, 32, 600, C.orange, 'center'); + } + if (A.ci === 0 && A.cue === 3) { X.globalAlpha = fade(A.lt, 0.2, .8); X.fillStyle = '#000'; X.fillRect(W / 2 - 420, 822, 840, 40); T('TUTORIAL · EL SISTEMA COMPLETO', W / 2, 900, 28, 600, C.violet, 'center', 4); } + X.globalAlpha = 1; +} +function outro(A, t, f) { + const end = TL.end, out = 1 - fade(t, end - 3.5, end - 0.5); + X.globalAlpha = out; + eco(f, t, W / 2, 330, 320, 1); + T('GRACIAS', W / 2, 730, 110, 600, C.text, 'center', 18); heatRule(W / 2 - 260, 762, 520, 3); + X.globalAlpha = out * fade(A.ct, 2, 3); + T('ko-fi.com/juanjiant', W / 2 - 230, 840, 30, 600, C.orange, 'center'); T('cafecito.app/juanjiant', W / 2 + 230, 840, 30, 600, C.violet, 'center'); + T('juanjiant-bit.github.io/JIANT', W / 2, 894, 24, 500, C.mid, 'center'); + X.globalAlpha = out * fade(A.ct, 8, 9); + T('la música: tocada por JIANT en el FM-1 · la voz: sintetizada', W / 2, 944, 18, 500, C.dim, 'center'); + X.globalAlpha = 1; +} + +/* ---------------------------------------------------------------- a frame --- */ +async function render(f) { + const t = f / FPS, A = at(t); + await rgbFrame(f); + X.fillStyle = '#000'; X.fillRect(0, 0, W, H2); + const g = A.ch.g, full = g === 'intro' || g === 'outro'; + if (g === 'intro') intro(A, t, f); + else if (g === 'outro') outro(A, t, f); + else { + const a = fade(A.ct, -0.3, 0.5) * (1 - fade(t, A.ch.end - 0.4, A.ch.end + 0.2) * (A.ci + 1 < TL.chapters.length && TL.chapters[A.ci + 1].g === 'outro' ? 1 : 0)); + screen(f, fade(A.ct + (A.ci === 1 ? 0 : 5), 0, 1)); + X.globalAlpha = a; + T(A.ch.k + ' / 15', GX, 150, 20, 600, heat(30 + A.ci * 13)); + const tw = T(A.ch.title, GX, 222, 62, 600, C.text, 'left', 2); + heatRule(GX, 246, Math.min(tw, 860) * ease(A.ct / 1.0), 2); + X.save(); X.translate(0, (1 - ease(A.ct / 0.6)) * 14); + Gr[g](A, t, f); + X.restore(); + X.globalAlpha = 1; + } + subtitle(t, A); + /* the chapters at the foot */ + const chs = TL.chapters.filter((c) => c.k), x0 = 120, w0 = W - 240; + if (!full) chs.forEach((c, i) => { const w = w0 / chs.length, on = c.id === A.ch.id; X.fillStyle = on ? heat(30 + i * 13) : '#1a1820'; X.fillRect(x0 + i * w + 2, 1058, w - 4, on ? 4 : 2); }); +} +async function rgbFrame(f) { + const b = new Uint8Array(await (await fetch('scr/' + f)).arrayBuffer()), d = simg.data; + for (let i = 0, j = 0; i < 57600; i++, j += 3) { d[i * 4] = b[j]; d[i * 4 + 1] = b[j + 1]; d[i * 4 + 2] = b[j + 2]; d[i * 4 + 3] = 255; } + sx.putImageData(simg, 0, 0); +} +async function boot(film) { + D = await (await fetch('data.json')).json(); TL = await (await fetch('timeline.json')).json(); + VER = (await (await fetch('version')).text()).trim(); + await document.fonts.load(`600 40px ${FONT}`); await document.fonts.load(`500 40px ${FONT}`); + return Math.min(D.n, Math.round(TL.end * FPS)); +} +async function frameJpeg(f, q) { await render(f); return cv.toDataURL('image/jpeg', q || .92); } diff --git a/tools/video/tutorial_script.py b/tools/video/tutorial_script.py new file mode 100644 index 00000000..f46e5e48 --- /dev/null +++ b/tools/video/tutorial_script.py @@ -0,0 +1,156 @@ +# SPDX-License-Identifier: GPL-3.0-only +# (JIANT 0.8.0) the tutorial film's script, in Spanish: each chapter its number, title, the graphic tools/video/tutorial.html +# draws beside the FM-1's screen, the screen's action (tools/video/capture_tutorial.c, by the chapter's number) and the +# voice-over's lines. A line is (the words shown, cue): the cue is a step of the chapter's graphic (0, 1, 2 ...). What the +# voice says is the shown text through SAY (the names spelt out as they are said). +CHAPTERS = [ + dict(id='intro', k='', title='JIANT', g='intro', lines=[ + ("Hola. Esto es JIANT.", 0), + ("Un firmware libre que convierte al FM-1 en un instrumento completo: seis pistas, ocho motores de síntesis, " + "un secuenciador profundo y efectos, todo dentro de este pequeño teclado.", 1), + ("Antes de empezar, gracias de corazón a todas las personas que apoyan el proyecto en Ko-fi. " + "Gracias a ustedes, JIANT sigue creciendo.", 2), + ("En este tutorial vamos a recorrer el sistema completo, paso a paso.", 3), + ]), + dict(id='install', k='01', title='INSTALAR', g='install', lines=[ + ("Primero, la instalación. Abrí el instalador web en Chrome o en Edge, " + "y conectá el FM-1 directo a la computadora, con un cable USB de datos.", 0), + ("Apretá Install y esperá a que termine, sin desenchufar.", 1), + ("Si venís de otro firmware custom, volvé primero al oficial con el botón del instalador.", 2), + ]), + dict(id='panel', k='02', title='EL PANEL', g='panel', lines=[ + ("Este es el panel. Arriba hay tres encoders.", 0), + ("ALGORITHM elige la pista. PRESETS recorre los sonidos. Y SELECT recorre las páginas de la sección donde estás.", 1), + ("Las cuatro perillas controlan las cuatro tarjetas de la pantalla. " + "Si las girás rápido barren todo el rango; despacio, ajustan fino.", 2), + ("Los botones abren las páginas: ENV, LFO, FX, SCL, EDIT, GLO, SAVE, ARP y SEQ. " + "Y las veintisiete teclas tocan la pista elegida.", 3), + ]), + dict(id='screen', k='03', title='LA PANTALLA', g='screen', lines=[ + ("La pantalla tiene siempre el mismo orden. Arriba, el encabezado: " + "la reproducción, el tempo, la carga del procesador y la batería.", 0), + ("Debajo, cuatro tarjetas, una por perilla. El valor que estás girando se enciende en naranja.", 1), + ("Al medio, el gráfico de la página. Y abajo, el nombre de la página y dónde estás.", 2), + ("Los colores funcionan como una cámara térmica: frío es poco, caliente es mucho. " + "Violeta es lo seleccionado; naranja, lo activo.", 3), + ]), + dict(id='home', k='04', title='HOME', g='home', lines=[ + ("Apretá HOME y llegás al ecosistema: una criatura por pista.", 0), + ("Cada especie corresponde a un motor, y su forma sale de sus cuatro perillas. " + "Cuando la pista suena, la criatura se hincha y se calienta con su propio audio.", 1), + ("La pista elegida se dibuja más grande. Una pista muteada se apaga.", 2), + ]), + dict(id='layers', k='05', title='TOCAR Y MANTENER', g='layers', lines=[ + ("Toda la navegación tiene dos gestos. Tocar un botón abre sus páginas; tocarlo otra vez pasa a la siguiente.", 0), + ("Mantenerlo abre su capa: mientras lo sostenés, las teclas y las perillas cambian de función, " + "y un mapa te muestra qué hace cada una. Soltás, y volvés a donde estabas.", 1), + ("Por ejemplo, mantené GLO para mutear pistas con las teclas negras, o mantené FX para tocar efectos en vivo.", 2), + ]), + dict(id='engines', k='06', title='OCHO MOTORES', g='engines', lines=[ + ("JIANT tiene ocho motores, todos de síntesis, sin samples. Cualquier motor puede ir en cualquier pista.", 0), + ("ANALOG: dos osciladores con filtro por voz. FM6: síntesis FM de seis operadores, con treinta y dos algoritmos. " + "PHASE: distorsión de fase.", 1), + ("LOFI: sonidos de chip, bytebeat y floatbeat. VOICE: una voz por formantes. " + "WHEEL: un órgano de drawbars con parlante rotativo.", 2), + ("NOISE: ruido coloreado y metálico. Y DRUM-X, la batería sintetizada.", 3), + ("Girá PRESETS para recorrer los sonidos de todos los motores en una sola lista. " + "Y si querés algo nuevo, mantené EDIT y girá SELECT: el sonido se tira a los dados.", 4), + ]), + dict(id='signal', k='07', title='EL CAMINO DEL SONIDO', g='signal', lines=[ + ("Así viaja el sonido dentro de una pista.", 0), + ("El motor genera la voz. El filtro la esculpe: pasa bajos, pasa altos, pasa banda o peine. " + "La envolvente y el LFO la mueven en el tiempo.", 1), + ("Después pasa por la distorsión de la pista, con seis tipos, entre ellos un emulador de amplificador.", 2), + ("El nivel y el paneo la ubican en la mezcla, y tres envíos la mandan al chorus, al delay y a la reverb, " + "que comparten todas las pistas.", 3), + ("Al final, el master: un limitador siempre activo, con clip, punch y ducking.", 4), + ]), + dict(id='drumx', k='08', title='DRUM-X', g='drumx', lines=[ + ("DRUM-X es una batería de ocho sonidos generados en tiempo real: " + "bombo, redoblante, clap, dos hi-hats, tom, rim y cowbell.", 0), + ("Cada sonido tiene dos lados, A y B. La perilla MORPH lleva todo el kit de un lado al otro: " + "es la perilla para tocar en vivo.", 1), + ("Hay nueve kits de fábrica, de la 909 y la 808 a industrial y acústico. Y cada sonido se edita a fondo: " + "afinación, ruido, capas, realimentación, y su propio envío a un efecto.", 2), + ]), + dict(id='seq', k='09', title='EL SECUENCIADOR', g='seq', lines=[ + ("Cada pista tiene su propio secuenciador de sesenta y cuatro pasos, con su largo, su división, su swing y su gate. " + "Patrones de distinto largo giran unos contra otros.", 0), + ("En una pista melódica, la página STEP es un piano roll: cada paso guarda hasta cuatro notas, con acento y slide.", 1), + ("Podés escribir paso a paso, o grabar en vivo con REC y PLAY.", 2), + ("Y cada paso puede llevar componentes: probabilidad, ratchets, ecos, arpegios, " + "o notas que caminan por la escala vuelta a vuelta.", 3), + ("Con PLAYHEADS, hasta tres cabezales más leen el mismo patrón a otra velocidad, o al revés. " + "Y MUTATE transforma el sonido y el patrón cada tantos compases.", 4), + ]), + dict(id='mod', k='10', title='MODULACIÓN', g='mod', lines=[ + ("La modulación le da vida. Cada pista tiene una envolvente y un LFO, " + "con sus destinos: afinación, filtro, forma y amplitud.", 0), + ("La matriz MOD suma cuatro rutas más por pista, con fuentes como la velocidad, " + "el secuenciador de modulación o el ruido, y destinos que llegan hasta los efectos.", 1), + ("Y las cuatro macros: mantené LFO, y las perillas pasan a ser M1 a M4, que mueven muchos parámetros a la vez.", 2), + ]), + dict(id='fx', k='11', title='EFECTOS', g='fx', lines=[ + ("Los efectos. Un delay analógico o digital, con pitch y ping pong. " + "Una reverb con cinco modelos, entre ellos SHIMMER, RESO afinada a la escala, y CLOUD, granular.", 0), + ("Un chorus estéreo, y el SLICER, que corta el audio en ritmos sobre las pistas que elijas.", 1), + ("Y en vivo: mantené FX, y cada tecla es un efecto momentáneo. Repeticiones, filtros, octavas, stutters.", 2), + ("Todo lo que tocás se puede grabar en un carril que se repite con el tema.", 3), + ]), + dict(id='gen', k='12', title='GENERADOR Y DADOS', g='gen', lines=[ + ("¿Sin ideas? En HOME girá SELECT y se abre el generador. Elegí un género, apretá OCT más, " + "y aparece un tema entero: motores, sonidos, partes, escala, tempo y efectos.", 0), + ("Los dados funcionan en cada parte: mantené SEQ, LFO o FX, y girá SELECT para variar solo eso.", 1), + ("Y si te arrepentís, mantené GLO y apretá la tecla G4: deshacer.", 2), + ]), + dict(id='arrange', k='13', title='GUARDAR Y ARMAR TEMAS', g='arrange', lines=[ + ("Para guardar, cada proyecto tiene cuatro secciones, de la A a la D. Guardá una idea en A, y una variación en B.", 0), + ("En la página ARRANGE encadenás secciones en filas, cada una con su largo en compases. " + "Apretá PLAY, y el tema se reproduce en orden.", 1), + ("Y en vivo, mantené SAVE: las teclas disparan secciones en el compás siguiente.", 2), + ]), + dict(id='usb', k='14', title='USB Y MIDI', g='usb', lines=[ + ("El FM-1 también es una interfaz de audio USB. En el modo STEMS manda ocho canales: " + "las seis pistas por separado y los efectos, directo a tu DAW.", 0), + ("Con IN+OUT, la computadora o el celular suenan a través del FM-1. " + "Y el nuevo modo STEMS+IN junta las dos cosas: grabás los stems, y tu voz pasa por los efectos de la última pista.", 1), + ("Además, MIDI por USB, por Bluetooth y por TRS, con clock para sincronizarte con otros equipos.", 2), + ]), + dict(id='web', k='15', title='EN LA WEB', g='web', lines=[ + ("En la web hay tres herramientas: el emulador, que corre JIANT en el navegador; el instalador; " + "y el editor, para manejar sonidos, bancos y backups desde la computadora.", 0), + ("Desde el emulador también podés renderizar los stems de una canción de tu backup, más rápido que en tiempo real.", 1), + ]), + dict(id='outro', k='', title='GRACIAS', g='outro', lines=[ + ("Eso es JIANT. El manual completo, en español y en inglés, está en la página del proyecto.", 0), + ("Si este trabajo resuena con vos, podés apoyarlo en Ko-fi, o en Cafecito desde Argentina.", 1), + ("Gracias por mirar, y gracias otra vez a quienes lo hacen posible. Nos vemos en la próxima.", 2), + ]), +] + +# how the voice says what the screen spells (the order matters: the longer names first) +SAY = [ + ('STEMS+IN', 'stems más in'), ('IN+OUT', 'in más out'), ('FM-1', 'efe eme uno'), ('FM6', 'efe eme seis'), + ('DRUM-X', 'drum equis'), ('M1 a M4', 'eme uno a eme cuatro'), ('Ko-fi', 'Kofi'), ('JIANT', 'Jiant'), + ('USB', 'u ese be'), ('LFO', 'ele efe o'), ('FX', 'efe equis'), ('SCL', 'escala'), ('ENV', 'envolvente'), + ('GLO', 'glo'), ('SEQ', 'sec'), ('DAW', 'dau'), ('TRS', 'te erre ese'), ('MIDI', 'midi'), ('G4', 'ge cuatro'), + ('OCT más', 'octava más'), ('MOD', 'mod'), ('STEP', 'step'), ('PLAYHEADS', 'pleijeds'), ('MUTATE', 'miuteit'), + ('PRESETS', 'presets'), ('SELECT', 'selec'), ('ALGORITHM', 'álgoritm'), ('HOME', 'jom'), ('SAVE', 'seiv'), + ('EDIT', 'edit'), ('ARP', 'arp'), ('REC', 'rec'), ('PLAY', 'plei'), ('Install', 'instol'), ('ARRANGE', 'arreinch'), + ('SLICER', 'slaicer'), ('SHIMMER', 'shimer'), ('CLOUD', 'claud'), ('RESO', 'reso'), ('MORPH', 'morf'), + ('ANALOG', 'análog'), ('PHASE', 'feis'), ('LOFI', 'lo fai'), ('VOICE', 'vois'), ('WHEEL', 'uil'), + ('NOISE', 'nois'), ('STEMS', 'stems'), ('bytebeat', 'baitbit'), ('floatbeat', 'floutbit'), ('drawbars', 'drobars'), + ('hi-hats', 'jai jats'), ('cowbell', 'caubel'), ('ratchets', 'rachets'), ('stutters', 'státers'), + ('ping pong', 'ping pong'), ('custom', 'castom'), ('Chrome', 'crom'), ('Edge', 'edch'), ('808', 'ocho cero ocho'), + ('909', 'nueve cero nueve'), ('Bluetooth', 'blutuz'), ('slide', 'slaid'), ('swing', 'suing'), ('gate', 'geit'), + ('clock', 'clok'), ('backups', 'bakaps'), ('Cafecito', 'cafecito'), ('punch', 'panch'), ('ducking', 'daking'), + ('clip', 'clip'), ('chorus', 'corus'), ('delay', 'dilei'), ('pitch', 'pich'), ('stems', 'stems'), + ('rim', 'rim'), ('tom', 'tom'), ('clap', 'clap'), +] + + +def say(text): + import re + for a, b in SAY: + text = re.sub(r'(? build/tut/voice.wav (24 kHz mono), build/tut/timeline.json, build/tut/plan.txt (capture_tutorial.c's chapters) +import json, os, sys +from pathlib import Path +import numpy as np +import soundfile as sf +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from tutorial_script import CHAPTERS, say +from kokoro_onnx import Kokoro + +D = Path(sys.argv[1]); D.mkdir(parents=True, exist_ok=True) +VOICE = sys.argv[2] if len(sys.argv) > 2 else 'em_alex' +SPEED = float(sys.argv[3]) if len(sys.argv) > 3 else 0.94 +KD = Path(os.environ.get('KOKORO', Path.home() / 'tts')) +k = Kokoro(str(KD / 'kokoro.onnx'), str(KD / 'voices.bin')) +SR = 24000 +LEAD, LINE_GAP, CH_GAP, TAIL = 4.0, 0.55, 2.2, 9.0 # (the intro's beings form first; the outro breathes after) +out, t, chapters = [np.zeros(int(LEAD * SR), np.float32)], LEAD, [] +for ci, c in enumerate(CHAPTERS): + ch = dict(id=c['id'], k=c['k'], title=c['title'], g=c['g'], start=t, lines=[]) + for text, cue in c['lines']: + a, sr = k.create(say(text), voice=VOICE, speed=SPEED, lang='es') + assert sr == SR + a = a.astype(np.float32) + nz = np.nonzero(np.abs(a) > 0.004)[0] # (the model's own silence at both ends trimmed) + if len(nz): a = a[max(0, nz[0] - 240): nz[-1] + 1200] + ch['lines'].append(dict(text=text, cue=cue, start=round(t, 3), end=round(t + len(a) / SR, 3))) + out.append(a); t += len(a) / SR + out.append(np.zeros(int(LINE_GAP * SR), np.float32)); t += LINE_GAP + print(f'{c["id"]:8s} {t:7.2f} {text[:60]}') + gap = CH_GAP if ci + 1 < len(CHAPTERS) else TAIL + out.append(np.zeros(int(gap * SR), np.float32)); t += gap + ch['end'] = round(t, 3) + chapters.append(ch) +v = np.concatenate(out) +v = v / (np.abs(v).max() + 1e-9) * 0.89 +sf.write(D / 'voice.wav', v, SR) +json.dump(dict(end=round(t, 3), voice=VOICE, chapters=chapters), open(D / 'timeline.json', 'w'), ensure_ascii=False, indent=1) +with open(D / 'plan.txt', 'w') as f: # capture_tutorial.c: "seconds chapter cue" a line + f.write(f'{t:.3f} end 0\n') + for ch in chapters: + for ln in ch['lines']: + f.write(f'{ln["start"]:.3f} {ch["id"]} {ln["cue"]}\n') +print(D / 'voice.wav', f'{t:.1f} s')