@motionscript/audio 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/dist/browser/chunks/chunk-U5OUQJHQ.js +2 -0
  4. package/dist/browser/chunks/chunk-U5OUQJHQ.js.map +7 -0
  5. package/dist/browser/index.js +2 -0
  6. package/dist/browser/index.js.map +7 -0
  7. package/dist/browser/kit.js +2 -0
  8. package/dist/browser/kit.js.map +7 -0
  9. package/dist/browser/manifest.json +12 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +3 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/kit.d.ts +13 -0
  15. package/dist/kit.d.ts.map +1 -0
  16. package/dist/kit.js +11 -0
  17. package/dist/kit.js.map +1 -0
  18. package/dist/nodes.d.ts +19 -0
  19. package/dist/nodes.d.ts.map +1 -0
  20. package/dist/nodes.js +19 -0
  21. package/dist/nodes.js.map +1 -0
  22. package/dist/waveform/envelope.d.ts +87 -0
  23. package/dist/waveform/envelope.d.ts.map +1 -0
  24. package/dist/waveform/envelope.js +96 -0
  25. package/dist/waveform/envelope.js.map +1 -0
  26. package/dist/waveform/full-waveform.d.ts +104 -0
  27. package/dist/waveform/full-waveform.d.ts.map +1 -0
  28. package/dist/waveform/full-waveform.js +193 -0
  29. package/dist/waveform/full-waveform.js.map +1 -0
  30. package/dist/waveform/index.d.ts +23 -0
  31. package/dist/waveform/index.d.ts.map +1 -0
  32. package/dist/waveform/index.js +19 -0
  33. package/dist/waveform/index.js.map +1 -0
  34. package/dist/waveform/live-waveform.d.ts +99 -0
  35. package/dist/waveform/live-waveform.d.ts.map +1 -0
  36. package/dist/waveform/live-waveform.js +191 -0
  37. package/dist/waveform/live-waveform.js.map +1 -0
  38. package/dist/waveform/shared.d.ts +96 -0
  39. package/dist/waveform/shared.d.ts.map +1 -0
  40. package/dist/waveform/shared.js +150 -0
  41. package/dist/waveform/shared.js.map +1 -0
  42. package/package.json +69 -3
  43. package/registry.json +28 -0
  44. package/src/index.ts +2 -0
  45. package/src/kit.ts +22 -0
  46. package/src/nodes.ts +19 -0
  47. package/src/waveform/envelope.ts +143 -0
  48. package/src/waveform/full-waveform.ts +218 -0
  49. package/src/waveform/index.ts +30 -0
  50. package/src/waveform/live-waveform.ts +221 -0
  51. package/src/waveform/shared.ts +194 -0
  52. package/README.md +0 -4
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The shape of a recording, as the waveform nodes draw it.
3
+ *
4
+ * ## Why the data is baked rather than listened to
5
+ *
6
+ * A scene has to render identically in the preview and in a headless export,
7
+ * and an export has no audio device, no `AudioContext` and no playback to
8
+ * analyse. So a "live" visualiser cannot read a Web Audio analyser: what it
9
+ * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is
10
+ * then a pure function of time, which is what makes scrubbing backwards, jumping
11
+ * to frame 900, and rendering out of order all produce the same frame.
12
+ *
13
+ * The decode happens in the app, once per file, and arrives here through the
14
+ * build (see `SceneAsset.envelope`) — the same arrangement a chart's rows and a
15
+ * protein's atoms already use, and for the same reason: the build is
16
+ * synchronous and cannot await a fetch.
17
+ *
18
+ * ## Why magnitude rather than min/max
19
+ *
20
+ * An editor's waveform is drawn from per-bucket minima *and* maxima, because an
21
+ * editor is a measuring instrument. These nodes are neither — they are a bar
22
+ * chart of loudness that happens to be shaped like a recording — and audio is
23
+ * near enough symmetric that a mirrored magnitude is indistinguishable at the
24
+ * size a node draws. Half the numbers, and one array to reason about.
25
+ */
26
+ /** The envelope of a track that hasn't loaded — or isn't there. */
27
+ export const EMPTY_ENVELOPE = {
28
+ magnitude: new Float32Array(0),
29
+ duration: 0,
30
+ speaker: null,
31
+ speakers: 0,
32
+ };
33
+ /**
34
+ * Resamples `[from, to)` seconds of an envelope down to `bars` columns.
35
+ *
36
+ * Peak-preserving rather than averaging, which is the whole difference between
37
+ * a waveform and a blur: averaging a hundred buckets into one column flattens
38
+ * every transient, and transients are what makes a drawn recording read as
39
+ * speech rather than as noise. The speaker of a column is the speaker of its
40
+ * *loudest* bucket, on the same reasoning — a column straddling a turn belongs
41
+ * to whoever is actually audible in it.
42
+ *
43
+ * A window past either end of the recording yields silent, unattributed
44
+ * columns rather than clamping onto the nearest real one. That matters for the
45
+ * live visualiser, which is handed a window centred on the playhead and would
46
+ * otherwise smear the first bucket across the whole run-up to a track's start.
47
+ */
48
+ export function sampleEnvelope(envelope, from, to, bars) {
49
+ const count = Math.max(0, Math.floor(bars));
50
+ const out = new Array(count);
51
+ for (let i = 0; i < count; i++)
52
+ out[i] = { magnitude: 0, speaker: -1 };
53
+ const buckets = envelope.magnitude.length;
54
+ if (count === 0 || buckets === 0 || envelope.duration <= 0)
55
+ return out;
56
+ const perSecond = buckets / envelope.duration;
57
+ const span = (to - from) / count;
58
+ for (let i = 0; i < count; i++) {
59
+ const start = (from + span * i) * perSecond;
60
+ const end = (from + span * (i + 1)) * perSecond;
61
+ // At least one bucket per column, so a window zoomed in past the grid draws
62
+ // the sample it is standing on rather than an empty band.
63
+ const first = Math.floor(start);
64
+ const last = Math.max(first, Math.ceil(end) - 1);
65
+ let loudest = 0;
66
+ let speaker = -1;
67
+ for (let b = first; b <= last; b++) {
68
+ if (b < 0 || b >= buckets)
69
+ continue;
70
+ const value = envelope.magnitude[b];
71
+ if (value < loudest)
72
+ continue;
73
+ loudest = value;
74
+ speaker = envelope.speaker ? envelope.speaker[b] : -1;
75
+ }
76
+ out[i] = { magnitude: loudest, speaker };
77
+ }
78
+ return out;
79
+ }
80
+ /**
81
+ * The same window, with everything that isn't `voice` silenced.
82
+ *
83
+ * The point of the speaker filter, and the reason it silences rather than
84
+ * *drops*: a podcast visualiser filtered to one host should go quiet while the
85
+ * other one talks, not compress their turn out of existence. Keeping the bars
86
+ * and zeroing them is what makes the picture read as "this person is not
87
+ * speaking right now" instead of as a jump cut.
88
+ *
89
+ * `voice` of `null` returns the bars untouched, which is the unfiltered node.
90
+ */
91
+ export function forSpeaker(bars, voice) {
92
+ if (voice === null)
93
+ return bars;
94
+ return bars.map((bar) => bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker });
95
+ }
96
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AA2BH,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,SAAS,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,CAAC;CACZ,CAAA;AAUD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAuB,EACvB,IAAY,EACZ,EAAU,EACV,IAAY;IAEZ,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAC3C,MAAM,GAAG,GAAkB,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAA;IAEtE,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAA;IACzC,IAAI,KAAK,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,IAAI,CAAC;QAAE,OAAO,GAAG,CAAA;IAEtE,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAA;IAC7C,MAAM,IAAI,GAA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H,MAAM,UAAU,UAAU,CACxB,IAAmB,EACnB,KAAoB;IAEpB,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACtB,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CACrE,CAAA;AACH,CAAC","sourcesContent":["/**\n * The shape of a recording, as the waveform nodes draw it.\n *\n * ## Why the data is baked rather than listened to\n *\n * A scene has to render identically in the preview and in a headless export,\n * and an export has no audio device, no `AudioContext` and no playback to\n * analyse. So a \"live\" visualiser cannot read a Web Audio analyser: what it\n * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is\n * then a pure function of time, which is what makes scrubbing backwards, jumping\n * to frame 900, and rendering out of order all produce the same frame.\n *\n * The decode happens in the app, once per file, and arrives here through the\n * build (see `SceneAsset.envelope`) — the same arrangement a chart's rows and a\n * protein's atoms already use, and for the same reason: the build is\n * synchronous and cannot await a fetch.\n *\n * ## Why magnitude rather than min/max\n *\n * An editor's waveform is drawn from per-bucket minima *and* maxima, because an\n * editor is a measuring instrument. These nodes are neither — they are a bar\n * chart of loudness that happens to be shaped like a recording — and audio is\n * near enough symmetric that a mirrored magnitude is indistinguishable at the\n * size a node draws. Half the numbers, and one array to reason about.\n */\n\n/**\n * A decoded recording, reduced to a uniform grid of loudness — plus, when the\n * app knows it, who is talking in each bucket.\n *\n * The speaker track is **not** something a decoder can produce; it comes from a\n * diarized transcript and is folded in by the app before the build. It lives\n * here rather than in a parallel structure because every reader of it is also a\n * reader of the magnitudes at the same index, and two arrays that must stay the\n * same length are better as one object than as two arguments.\n */\nexport interface AudioEnvelope {\n /** Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. */\n magnitude: Float32Array\n /** The decoded length in seconds. */\n duration: number\n /**\n * Which voice is speaking in each bucket, as an index into the recording's\n * own numbering, or `-1` for \"nobody identified\". Parallel to\n * {@link magnitude}, or `null` when the track was never diarized.\n */\n speaker: Int16Array | null\n /** How many distinct voices the diarizer found. Zero when it did not run. */\n speakers: number\n}\n\n/** The envelope of a track that hasn't loaded — or isn't there. */\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\n magnitude: new Float32Array(0),\n duration: 0,\n speaker: null,\n speakers: 0,\n}\n\n/** One drawn bar: how loud, and whose. */\nexport interface EnvelopeBar {\n /** 0…1. */\n magnitude: number\n /** The voice index, or -1. */\n speaker: number\n}\n\n/**\n * Resamples `[from, to)` seconds of an envelope down to `bars` columns.\n *\n * Peak-preserving rather than averaging, which is the whole difference between\n * a waveform and a blur: averaging a hundred buckets into one column flattens\n * every transient, and transients are what makes a drawn recording read as\n * speech rather than as noise. The speaker of a column is the speaker of its\n * *loudest* bucket, on the same reasoning — a column straddling a turn belongs\n * to whoever is actually audible in it.\n *\n * A window past either end of the recording yields silent, unattributed\n * columns rather than clamping onto the nearest real one. That matters for the\n * live visualiser, which is handed a window centred on the playhead and would\n * otherwise smear the first bucket across the whole run-up to a track's start.\n */\nexport function sampleEnvelope(\n envelope: AudioEnvelope,\n from: number,\n to: number,\n bars: number\n): EnvelopeBar[] {\n const count = Math.max(0, Math.floor(bars))\n const out: EnvelopeBar[] = new Array(count)\n for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }\n\n const buckets = envelope.magnitude.length\n if (count === 0 || buckets === 0 || envelope.duration <= 0) return out\n\n const perSecond = buckets / envelope.duration\n const span = (to - from) / count\n\n for (let i = 0; i < count; i++) {\n const start = (from + span * i) * perSecond\n const end = (from + span * (i + 1)) * perSecond\n\n // At least one bucket per column, so a window zoomed in past the grid draws\n // the sample it is standing on rather than an empty band.\n const first = Math.floor(start)\n const last = Math.max(first, Math.ceil(end) - 1)\n\n let loudest = 0\n let speaker = -1\n for (let b = first; b <= last; b++) {\n if (b < 0 || b >= buckets) continue\n const value = envelope.magnitude[b]\n if (value < loudest) continue\n loudest = value\n speaker = envelope.speaker ? envelope.speaker[b] : -1\n }\n\n out[i] = { magnitude: loudest, speaker }\n }\n\n return out\n}\n\n/**\n * The same window, with everything that isn't `voice` silenced.\n *\n * The point of the speaker filter, and the reason it silences rather than\n * *drops*: a podcast visualiser filtered to one host should go quiet while the\n * other one talks, not compress their turn out of existence. Keeping the bars\n * and zeroing them is what makes the picture read as \"this person is not\n * speaking right now\" instead of as a jump cut.\n *\n * `voice` of `null` returns the bars untouched, which is the unfiltered node.\n */\nexport function forSpeaker(\n bars: EnvelopeBar[],\n voice: number | null\n): EnvelopeBar[] {\n if (voice === null) return bars\n return bars.map((bar) =>\n bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }\n )\n}\n"]}
@@ -0,0 +1,104 @@
1
+ import { Node2D, type AssetScope, type CommandArgs, type Fill, type Node2DProps, type RenderContext2D } from "@motionscript/core";
2
+ import type { Seekable } from "@motionscript/core/component";
3
+ import { type AudioEnvelope } from "./envelope.js";
4
+ import { type WaveformAlignment } from "./shared.js";
5
+ export interface FullWaveformProps extends Node2DProps {
6
+ /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
7
+ envelope: AudioEnvelope;
8
+ /** How many columns the whole file is drawn as. */
9
+ bars: number;
10
+ /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
11
+ gap: number;
12
+ /** Corner radius of a bar, capped at half its width. */
13
+ radius: number;
14
+ /** How much of the file reads as played, `0`–`1`. Tweenable. */
15
+ progress: number;
16
+ /** Drive {@link progress} from the node's own clock instead of the prop. */
17
+ follow: boolean;
18
+ /** Multiplies every magnitude — a quiet track pulled up to fill its box. */
19
+ gain: number;
20
+ /** How much of the box a silent bar still occupies, `0`–`1`. */
21
+ floor: number;
22
+ align: WaveformAlignment;
23
+ /** Colour each voice's turns rather than splitting on played / not played. */
24
+ byVoice: boolean;
25
+ /** A colour per voice index. Short or empty falls back to the palette. */
26
+ voiceColors: string[];
27
+ /** The bars ahead of the playhead. */
28
+ fill: Fill;
29
+ /** …and the bars behind it. */
30
+ playedFill: Fill;
31
+ }
32
+ /**
33
+ * A **waveform overview**: the whole recording's shape, drawn at once.
34
+ *
35
+ * The picture every audio editor opens with, and the one a podcast clip puts
36
+ * under its caption — a static silhouette of the file, with a played portion
37
+ * that advances. It answers "how long is this and where are the loud parts",
38
+ * which is a question about the *file*, not about the moment; its sibling
39
+ * {@link LiveWaveform} answers the other one.
40
+ *
41
+ * ## Progress is authored, not assumed
42
+ *
43
+ * {@link follow} is off by default, and that default is the considered one. A
44
+ * scene has no idea where the recording it is drawing sits on the video's audio
45
+ * lane — a clip is placed, trimmed and sped up out there, and none of that is
46
+ * visible from in here. So the honest default is that the fill is *animation*:
47
+ * the author sweeps it with a command, the same as any other tween, and it lands
48
+ * wherever they put it. `follow` is the shortcut for the common arrangement
49
+ * where the node appears exactly as the track starts, and it says so by being a
50
+ * switch someone has to turn on rather than a behaviour that quietly disagrees
51
+ * with the mix.
52
+ *
53
+ * ## Voices instead of progress
54
+ *
55
+ * With {@link byVoice} on, the played/ahead split is replaced by one colour per
56
+ * speaking voice — the drawing the timeline's clip bars already make, at a size
57
+ * you can read. For a two-hander it is a map of the conversation: who has the
58
+ * floor, where the turns are, how long each one ran. It replaces the progress
59
+ * colours rather than combining with them, because a bar cannot mean two things
60
+ * at once and "played, and also Grace" is a legend nobody can hold in their
61
+ * head.
62
+ */
63
+ export declare class FullWaveform extends Node2D<FullWaveformProps> {
64
+ envelope: AudioEnvelope;
65
+ bars: number;
66
+ gap: number;
67
+ radius: number;
68
+ progress: number;
69
+ follow: boolean;
70
+ gain: number;
71
+ floor: number;
72
+ align: WaveformAlignment;
73
+ byVoice: boolean;
74
+ voiceColors: string[];
75
+ fill: Fill;
76
+ playedFill: Fill;
77
+ /**
78
+ * Fill the waveform in, left to right — the node's one command, since
79
+ * everything else about it is expressible as an ordinary `to`.
80
+ */
81
+ sweep(args: CommandArgs<Record<string, never>> & {
82
+ duration: number;
83
+ }): Seekable;
84
+ /**
85
+ * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
86
+ * paint props it carries — see {@link declarePaints}. `playedFill` is named
87
+ * past the conventional slots, so it is passed explicitly.
88
+ */
89
+ declareAssets(assets: AssetScope): void;
90
+ /** Where the fill has reached, from whichever source is in charge. */
91
+ private get played();
92
+ protected renderSelf(ctx: RenderContext2D): void;
93
+ /**
94
+ * The paint a group takes.
95
+ *
96
+ * A voice's colour is a **colour string**, never one of the node's two fill
97
+ * props, and that is deliberate: a voice is identified by hue, so a gradient
98
+ * or an image there would defeat the only thing the colour is for. It also
99
+ * means these paints declare no assets, which is why {@link declareAssets}
100
+ * only has to account for the two real fill props.
101
+ */
102
+ private paintFor;
103
+ }
104
+ //# sourceMappingURL=full-waveform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"full-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAMN,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,IAAI,EAET,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/E,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,0EAA0E;IAC1E,QAAQ,EAAE,aAAa,CAAA;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAA;IACX,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAA;IACd,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAA;IAChB,4EAA4E;IAC5E,MAAM,EAAE,OAAO,CAAA;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|| function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Node2D, node, command, easeInOut, fillOps, property, } from "@motionscript/core";
8
+ import { declarePaints } from "@motionscript/core/component";
9
+ import { EMPTY_ENVELOPE, sampleEnvelope } from "./envelope.js";
10
+ import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./shared.js";
11
+ /**
12
+ * A **waveform overview**: the whole recording's shape, drawn at once.
13
+ *
14
+ * The picture every audio editor opens with, and the one a podcast clip puts
15
+ * under its caption — a static silhouette of the file, with a played portion
16
+ * that advances. It answers "how long is this and where are the loud parts",
17
+ * which is a question about the *file*, not about the moment; its sibling
18
+ * {@link LiveWaveform} answers the other one.
19
+ *
20
+ * ## Progress is authored, not assumed
21
+ *
22
+ * {@link follow} is off by default, and that default is the considered one. A
23
+ * scene has no idea where the recording it is drawing sits on the video's audio
24
+ * lane — a clip is placed, trimmed and sped up out there, and none of that is
25
+ * visible from in here. So the honest default is that the fill is *animation*:
26
+ * the author sweeps it with a command, the same as any other tween, and it lands
27
+ * wherever they put it. `follow` is the shortcut for the common arrangement
28
+ * where the node appears exactly as the track starts, and it says so by being a
29
+ * switch someone has to turn on rather than a behaviour that quietly disagrees
30
+ * with the mix.
31
+ *
32
+ * ## Voices instead of progress
33
+ *
34
+ * With {@link byVoice} on, the played/ahead split is replaced by one colour per
35
+ * speaking voice — the drawing the timeline's clip bars already make, at a size
36
+ * you can read. For a two-hander it is a map of the conversation: who has the
37
+ * floor, where the turns are, how long each one ran. It replaces the progress
38
+ * colours rather than combining with them, because a bar cannot mean two things
39
+ * at once and "played, and also Grace" is a legend nobody can hold in their
40
+ * head.
41
+ */
42
+ let FullWaveform = class FullWaveform extends Node2D {
43
+ /**
44
+ * Fill the waveform in, left to right — the node's one command, since
45
+ * everything else about it is expressible as an ordinary `to`.
46
+ */
47
+ sweep(args) {
48
+ return this.to({
49
+ data: { progress: 1 },
50
+ duration: args.duration,
51
+ easing: args.easing ?? easeInOut(),
52
+ });
53
+ }
54
+ /**
55
+ * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
56
+ * paint props it carries — see {@link declarePaints}. `playedFill` is named
57
+ * past the conventional slots, so it is passed explicitly.
58
+ */
59
+ declareAssets(assets) {
60
+ super.declareAssets(assets);
61
+ declarePaints(this, assets, { fills: [this.playedFill] });
62
+ }
63
+ /** Where the fill has reached, from whichever source is in charge. */
64
+ get played() {
65
+ if (!this.follow)
66
+ return clamp01(this.progress);
67
+ const length = this.envelope.duration;
68
+ if (length <= 0)
69
+ return 0;
70
+ return clamp01(this.time.elapsed / length);
71
+ }
72
+ renderSelf(ctx) {
73
+ const rect = this.layoutBounds;
74
+ const width = rect?.width ?? 0;
75
+ const height = rect?.height ?? 0;
76
+ if (width <= 0 || height <= 0)
77
+ return;
78
+ const count = Math.max(1, Math.round(this.bars));
79
+ const sampled = sampleEnvelope(this.envelope, 0, this.envelope.duration, count);
80
+ const boxes = layOutBars(sampled, {
81
+ width,
82
+ height,
83
+ gap: this.gap,
84
+ align: this.align,
85
+ gain: this.gain,
86
+ floor: this.floor,
87
+ });
88
+ if (boxes.length === 0)
89
+ return;
90
+ // One draw per colour rather than per bar — see {@link paintBars}. The key
91
+ // is a string because it has to be comparable; the paint it stands for is
92
+ // resolved after the grouping.
93
+ const edge = this.played * boxes.length;
94
+ const groups = groupByPaint(boxes, (i) => this.byVoice
95
+ ? `voice:${sampled[i].speaker}`
96
+ : i < edge
97
+ ? "played"
98
+ : "ahead");
99
+ for (const [key, run] of groups) {
100
+ const graphics = paintBars(run, this.paintFor(key), this.radius);
101
+ if (graphics)
102
+ ctx.draw(graphics);
103
+ }
104
+ }
105
+ /**
106
+ * The paint a group takes.
107
+ *
108
+ * A voice's colour is a **colour string**, never one of the node's two fill
109
+ * props, and that is deliberate: a voice is identified by hue, so a gradient
110
+ * or an image there would defeat the only thing the colour is for. It also
111
+ * means these paints declare no assets, which is why {@link declareAssets}
112
+ * only has to account for the two real fill props.
113
+ */
114
+ paintFor(key) {
115
+ if (key === "played")
116
+ return this.playedFill;
117
+ if (key === "ahead")
118
+ return this.fill;
119
+ const voice = Number(key.slice("voice:".length));
120
+ if (!Number.isFinite(voice) || voice < 0)
121
+ return this.fill;
122
+ return this.voiceColors[voice] ?? voiceColor(voice);
123
+ }
124
+ };
125
+ __decorate([
126
+ property({ default: EMPTY_ENVELOPE })
127
+ ], FullWaveform.prototype, "envelope", void 0);
128
+ __decorate([
129
+ property({ default: 120 })
130
+ ], FullWaveform.prototype, "bars", void 0);
131
+ __decorate([
132
+ property({ default: 0.3 })
133
+ ], FullWaveform.prototype, "gap", void 0);
134
+ __decorate([
135
+ property({ default: 2 })
136
+ ], FullWaveform.prototype, "radius", void 0);
137
+ __decorate([
138
+ property({ default: 0 })
139
+ ], FullWaveform.prototype, "progress", void 0);
140
+ __decorate([
141
+ property({ default: false })
142
+ ], FullWaveform.prototype, "follow", void 0);
143
+ __decorate([
144
+ property({ default: 1 })
145
+ ], FullWaveform.prototype, "gain", void 0);
146
+ __decorate([
147
+ property({ default: 0.015 })
148
+ ], FullWaveform.prototype, "floor", void 0);
149
+ __decorate([
150
+ property({ default: "center" })
151
+ ], FullWaveform.prototype, "align", void 0);
152
+ __decorate([
153
+ property({ default: false })
154
+ ], FullWaveform.prototype, "byVoice", void 0);
155
+ __decorate([
156
+ property({ default: [] })
157
+ ], FullWaveform.prototype, "voiceColors", void 0);
158
+ __decorate([
159
+ property({
160
+ default: "#5b5b7a",
161
+ mapper: fillOps.resolve,
162
+ tween: fillOps.lerp,
163
+ })
164
+ ], FullWaveform.prototype, "fill", void 0);
165
+ __decorate([
166
+ property({
167
+ default: "#6366f1",
168
+ mapper: fillOps.resolve,
169
+ tween: fillOps.lerp,
170
+ })
171
+ ], FullWaveform.prototype, "playedFill", void 0);
172
+ __decorate([
173
+ command()
174
+ ], FullWaveform.prototype, "sweep", null);
175
+ FullWaveform = __decorate([
176
+ node({
177
+ key: "fullWaveform",
178
+ parentKey: "node",
179
+ forkable: true,
180
+ layout: {
181
+ children: "freeform",
182
+ defaultWidthMode: "fixed",
183
+ defaultHeightMode: "fixed",
184
+ acceptsChildren: true,
185
+ },
186
+ seed: {
187
+ width: 900,
188
+ height: 160,
189
+ },
190
+ })
191
+ ], FullWaveform);
192
+ export { FullWaveform };
193
+ //# sourceMappingURL=full-waveform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,GAOT,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAA;AAC/E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GAEX,MAAM,UAAU,CAAA;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAgBI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,MAAyB;IA2BzD;;;OAGG;IAEH,KAAK,CAAC,IAA+D;QACnE,OAAO,IAAI,CAAC,EAAE,CAAC;YACb,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAgC;YACnD,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS,EAAE;SACnC,CAAC,CAAA;IACJ,CAAC;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MAAM,EAAE;YACN,QAAQ,EAAE,UAAU;YACpB,gBAAgB,EAAE,OAAO;YACzB,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,IAAI;SACtB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;SACZ;KACF,CAAC;GACW,YAAY,CAoHxB","sourcesContent":["import {\n Node2D,\n node,\n command,\n easeInOut,\n fillOps,\n property,\n type AssetScope,\n type CommandArgs,\n type Fill,\n type FillResolved,\n type Node2DProps,\n type RenderContext2D,\n} from \"@motionscript/core\"\n\nimport { declarePaints } from \"@motionscript/core/component\"\nimport type { Seekable } from \"@motionscript/core/component\"\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\nexport interface FullWaveformProps extends Node2DProps {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: AudioEnvelope\n /** How many columns the whole file is drawn as. */\n bars: number\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: number\n /** Corner radius of a bar, capped at half its width. */\n radius: number\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: number\n /** Drive {@link progress} from the node's own clock instead of the prop. */\n follow: boolean\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: number\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: number\n align: WaveformAlignment\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: boolean\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: string[]\n /** The bars ahead of the playhead. */\n fill: Fill\n /** …and the bars behind it. */\n playedFill: Fill\n}\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * {@link follow} is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\n * speaking voice — the drawing the timeline's clip bars already make, at a size\n * you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\n@node({\n key: \"fullWaveform\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"freeform\",\n defaultWidthMode: \"fixed\",\n defaultHeightMode: \"fixed\",\n acceptsChildren: true,\n },\n seed: {\n width: 900,\n height: 160,\n },\n})\nexport class FullWaveform extends Node2D<FullWaveformProps> {\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\n @property({ default: 120 }) declare bars: number\n @property({ default: 0.3 }) declare gap: number\n @property({ default: 2 }) declare radius: number\n @property({ default: 0 }) declare progress: number\n @property({ default: false }) declare follow: boolean\n @property({ default: 1 }) declare gain: number\n @property({ default: 0.015 }) declare floor: number\n @property({ default: \"center\" }) declare align: WaveformAlignment\n @property({ default: false }) declare byVoice: boolean\n @property({ default: [] }) declare voiceColors: string[]\n\n @property({\n default: \"#5b5b7a\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n\n @property({\n default: \"#6366f1\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare playedFill: Fill\n\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`.\n */\n @command()\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\n return this.to({\n data: { progress: 1 } as Partial<FullWaveformProps>,\n duration: args.duration,\n easing: args.easing ?? easeInOut(),\n })\n }\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\n * past the conventional slots, so it is passed explicitly.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\n }\n\n /** Where the fill has reached, from whichever source is in charge. */\n private get played(): number {\n if (!this.follow) return clamp01(this.progress)\n const length = this.envelope.duration\n if (length <= 0) return 0\n return clamp01(this.time.elapsed / length)\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const rect = this.layoutBounds\n const width = rect?.width ?? 0\n const height = rect?.height ?? 0\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(this.bars))\n const sampled = sampleEnvelope(\n this.envelope,\n 0,\n this.envelope.duration,\n count\n )\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: this.gap,\n align: this.align,\n gain: this.gain,\n floor: this.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = this.played * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n this.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, this.paintFor(key), this.radius)\n if (graphics) ctx.draw(graphics)\n }\n }\n\n /**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why {@link declareAssets}\n * only has to account for the two real fill props.\n */\n private paintFor(key: string): Fill {\n if (key === \"played\") return this.playedFill\n if (key === \"ahead\") return this.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return this.fill\n return this.voiceColors[voice] ?? voiceColor(voice)\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The waveform family: one subject, two questions.
3
+ *
4
+ * - {@link FullWaveform} draws the **file** — the whole recording's silhouette,
5
+ * with a played portion that advances. "How long is this, and where are the
6
+ * loud parts."
7
+ * - {@link LiveWaveform} draws the **moment** — bars moving with playback, the
8
+ * visualiser a podcast clip puts beside the artwork. "Is anything happening
9
+ * right now, and whose voice is it."
10
+ *
11
+ * Both read the same baked {@link AudioEnvelope}, which is why they cannot
12
+ * disagree about a recording, and why neither listens to anything — see that
13
+ * module for why a scene that has to export cannot use a live analyser.
14
+ */
15
+ export { FullWaveform } from "./full-waveform.js";
16
+ export type { FullWaveformProps } from "./full-waveform.js";
17
+ export { LiveWaveform } from "./live-waveform.js";
18
+ export type { LiveWaveformProps } from "./live-waveform.js";
19
+ export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./envelope.js";
20
+ export type { AudioEnvelope, EnvelopeBar } from "./envelope.js";
21
+ export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, groupByPaint, layOutBars, paintBars, voiceColor, } from "./shared.js";
22
+ export type { BarBox, WaveformAlignment, WaveformStyle } from "./shared.js";
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACvE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The waveform family: one subject, two questions.
3
+ *
4
+ * - {@link FullWaveform} draws the **file** — the whole recording's silhouette,
5
+ * with a played portion that advances. "How long is this, and where are the
6
+ * loud parts."
7
+ * - {@link LiveWaveform} draws the **moment** — bars moving with playback, the
8
+ * visualiser a podcast clip puts beside the artwork. "Is anything happening
9
+ * right now, and whose voice is it."
10
+ *
11
+ * Both read the same baked {@link AudioEnvelope}, which is why they cannot
12
+ * disagree about a recording, and why neither listens to anything — see that
13
+ * module for why a scene that has to export cannot use a live analyser.
14
+ */
15
+ export { FullWaveform } from "./full-waveform.js";
16
+ export { LiveWaveform } from "./live-waveform.js";
17
+ export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./envelope.js";
18
+ export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, groupByPaint, layOutBars, paintBars, voiceColor, } from "./shared.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEvE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAA","sourcesContent":["/**\n * The waveform family: one subject, two questions.\n *\n * - {@link FullWaveform} draws the **file** — the whole recording's silhouette,\n * with a played portion that advances. \"How long is this, and where are the\n * loud parts.\"\n * - {@link LiveWaveform} draws the **moment** — bars moving with playback, the\n * visualiser a podcast clip puts beside the artwork. \"Is anything happening\n * right now, and whose voice is it.\"\n *\n * Both read the same baked {@link AudioEnvelope}, which is why they cannot\n * disagree about a recording, and why neither listens to anything — see that\n * module for why a scene that has to export cannot use a live analyser.\n */\nexport { FullWaveform } from \"./full-waveform\"\nexport type { FullWaveformProps } from \"./full-waveform\"\nexport { LiveWaveform } from \"./live-waveform\"\nexport type { LiveWaveformProps } from \"./live-waveform\"\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./envelope\"\nexport type { AudioEnvelope, EnvelopeBar } from \"./envelope\"\nexport {\n VOICE_PALETTE,\n WAVEFORM_ALIGNMENTS,\n WAVEFORM_STYLES,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n} from \"./shared\"\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./shared\"\n"]}
@@ -0,0 +1,99 @@
1
+ import { Node2D, type AssetScope, type Fill, type Node2DProps, type RenderContext2D } from "@motionscript/core";
2
+ import { type AudioEnvelope } from "./envelope.js";
3
+ import { type WaveformAlignment, type WaveformStyle } from "./shared.js";
4
+ export interface LiveWaveformProps extends Node2DProps {
5
+ /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
6
+ envelope: AudioEnvelope;
7
+ /** How many bars the visualiser is made of. */
8
+ bars: number;
9
+ /** Space between bars, as a fraction of the pitch. */
10
+ gap: number;
11
+ radius: number;
12
+ /** How many seconds of audio are on screen at once. */
13
+ window: number;
14
+ /** Seconds into the file the node's first frame shows. */
15
+ offset: number;
16
+ /** Advance with the scene clock. Off freezes the picture at {@link offset}. */
17
+ playing: boolean;
18
+ /** Multiplies every magnitude before it is clamped. */
19
+ gain: number;
20
+ /** How much of the box a silent bar still occupies, `0`–`1`. */
21
+ floor: number;
22
+ align: WaveformAlignment;
23
+ style: WaveformStyle;
24
+ /**
25
+ * Show only this voice's activity, by index into the recording's own
26
+ * numbering. `-1` — the default — is every voice.
27
+ */
28
+ speaker: number;
29
+ /** Colour each bar by whoever is speaking in it. */
30
+ byVoice: boolean;
31
+ /** A colour per voice index. Short or empty falls back to the palette. */
32
+ voiceColors: string[];
33
+ fill: Fill;
34
+ }
35
+ /**
36
+ * A **live audio visualiser**: bars that move with the recording as it plays.
37
+ *
38
+ * The thing every podcast-to-video tool puts beside the artwork. It is not a
39
+ * picture of the file — that is {@link FullWaveform} — it is a picture of *this
40
+ * moment*, and what it is for is making a static frame of a talking head feel
41
+ * like it is playing.
42
+ *
43
+ * ## "Live" without listening
44
+ *
45
+ * Nothing here reads an audio device. The bars are sampled out of a baked
46
+ * envelope at the node's own elapsed time, which is what makes the visualiser
47
+ * survive the thing it exists for: an **export**, where there is no playback to
48
+ * analyse and frames may be rendered out of order or in parallel. A frame is a
49
+ * pure function of its time, so scrubbing back and forth over the visualiser
50
+ * redraws exactly what it drew the first time — which an analyser node, by
51
+ * construction, cannot promise. See {@link AudioEnvelope}.
52
+ *
53
+ * ## The speaker filter
54
+ *
55
+ * {@link speaker} narrows the node to one voice of a diarized recording, and it
56
+ * is the reason this node knows about transcripts at all. Two visualisers beside
57
+ * two headshots, each filtered to its own host, is a podcast edit that would
58
+ * otherwise be done by hand for every turn — and because the filter *silences*
59
+ * rather than skips (see {@link forSpeaker}), the quiet host visibly stops
60
+ * talking instead of vanishing. Nothing about that requires the words: only who
61
+ * is talking when, which is what the diarizer produces.
62
+ *
63
+ * A filter naming a voice the recording doesn't have draws a resting row rather
64
+ * than everything — a picture of "this person never speaks here", which is
65
+ * true, where falling back to the unfiltered mix would be a silent lie about
66
+ * whose voice you were watching.
67
+ */
68
+ export declare class LiveWaveform extends Node2D<LiveWaveformProps> {
69
+ envelope: AudioEnvelope;
70
+ bars: number;
71
+ gap: number;
72
+ radius: number;
73
+ window: number;
74
+ offset: number;
75
+ playing: boolean;
76
+ gain: number;
77
+ floor: number;
78
+ align: WaveformAlignment;
79
+ style: WaveformStyle;
80
+ speaker: number;
81
+ byVoice: boolean;
82
+ voiceColors: string[];
83
+ fill: Fill;
84
+ declareAssets(assets: AssetScope): void;
85
+ /**
86
+ * The second of the recording the visualiser is showing.
87
+ *
88
+ * Off the node's own clock rather than the scene's, which is what "from the
89
+ * moment this node appeared" means — the same clock motion-script's own
90
+ * `Video` times its picture from, and the same one that makes a node dropped
91
+ * halfway through a scene start its recording at its entrance rather than
92
+ * partway in.
93
+ */
94
+ private get at();
95
+ protected renderSelf(ctx: RenderContext2D): void;
96
+ /** See {@link FullWaveform.paintFor} — a voice is a hue, never a gradient. */
97
+ private paintFor;
98
+ }
99
+ //# sourceMappingURL=live-waveform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIN,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAOL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,0EAA0E;IAC1E,QAAQ,EAAE,aAAa,CAAA;IACvB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAA;IACd,0DAA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