@motionscript/audio 0.0.0-stage → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +91 -3
- package/dist/browser/chunks/chunk-DD3KHRUL.js +2 -0
- package/dist/browser/chunks/chunk-DD3KHRUL.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/kit.d.ts +13 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.js +11 -0
- package/dist/kit.js.map +1 -0
- package/dist/nodes.d.ts +16 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +17 -0
- package/dist/nodes.js.map +1 -0
- package/dist/waveform/envelope.d.ts +120 -0
- package/dist/waveform/envelope.d.ts.map +1 -0
- package/dist/waveform/envelope.js +126 -0
- package/dist/waveform/envelope.js.map +1 -0
- package/dist/waveform/full-waveform.d.ts +118 -0
- package/dist/waveform/full-waveform.d.ts.map +1 -0
- package/dist/waveform/full-waveform.js +146 -0
- package/dist/waveform/full-waveform.js.map +1 -0
- package/dist/waveform/index.d.ts +23 -0
- package/dist/waveform/index.d.ts.map +1 -0
- package/dist/waveform/index.js +19 -0
- package/dist/waveform/index.js.map +1 -0
- package/dist/waveform/live-waveform.d.ts +129 -0
- package/dist/waveform/live-waveform.d.ts.map +1 -0
- package/dist/waveform/live-waveform.js +149 -0
- package/dist/waveform/live-waveform.js.map +1 -0
- package/dist/waveform/shared.d.ts +98 -0
- package/dist/waveform/shared.d.ts.map +1 -0
- package/dist/waveform/shared.js +149 -0
- package/dist/waveform/shared.js.map +1 -0
- package/package.json +72 -3
- package/registry.json +28 -0
- package/src/index.ts +2 -0
- package/src/kit.ts +22 -0
- package/src/nodes.ts +17 -0
- package/src/waveform/envelope.ts +176 -0
- package/src/waveform/full-waveform.ts +188 -0
- package/src/waveform/index.ts +30 -0
- package/src/waveform/live-waveform.ts +206 -0
- package/src/waveform/shared.ts +197 -0
package/dist/kit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kit.js","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEhF,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAA","sourcesContent":["/**\n * What the two waveform nodes share, importable without copying it.\n *\n * A registry item copies `envelope.ts` and `shared.ts` beside its node: they\n * hold no class and no registered state, so a fork owning its own copy splits\n * no identity. This is the same surface for a host that samples envelopes or\n * lays bars out itself, and for a fork that keeps only its node file.\n */\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./waveform/envelope\"\nexport type { AudioEnvelope, EnvelopeBar } from \"./waveform/envelope\"\nexport {\n VOICE_PALETTE,\n WAVEFORM_ALIGNMENTS,\n WAVEFORM_STYLES,\n clamp01,\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceColor,\n} from \"./waveform/shared\"\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./waveform/shared\"\n"]}
|
package/dist/nodes.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FullWaveform } from "./waveform/full-waveform.js";
|
|
2
|
+
import { LiveWaveform } from "./waveform/live-waveform.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every node type this package publishes.
|
|
5
|
+
*
|
|
6
|
+
* A host registers these by handing the array to an engine —
|
|
7
|
+
* `new Engine(platform, { nodes: NODES })` — which reads each component's key.
|
|
8
|
+
* Defining a component only *declares* that key: nothing is registered by
|
|
9
|
+
* importing a module, so a registry holds exactly what its owner asked for.
|
|
10
|
+
*
|
|
11
|
+
* Listing the component **values** is also what survives bundling: this package
|
|
12
|
+
* declares `sideEffects: false`, and a document names a node type by string, so
|
|
13
|
+
* an import kept only for its side effect is exactly what gets shaken out.
|
|
14
|
+
*/
|
|
15
|
+
export declare const NODES: (typeof FullWaveform | typeof LiveWaveform)[];
|
|
16
|
+
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,KAAK,EAAE,CAAC,OAAO,YAAY,GAAG,OAAO,YAAY,CAAC,EAAiC,CAAC"}
|
package/dist/nodes.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FullWaveform } from "./waveform/full-waveform.js";
|
|
2
|
+
import { LiveWaveform } from "./waveform/live-waveform.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every node type this package publishes.
|
|
5
|
+
*
|
|
6
|
+
* A host registers these by handing the array to an engine —
|
|
7
|
+
* `new Engine(platform, { nodes: NODES })` — which reads each component's key.
|
|
8
|
+
* Defining a component only *declares* that key: nothing is registered by
|
|
9
|
+
* importing a module, so a registry holds exactly what its owner asked for.
|
|
10
|
+
*
|
|
11
|
+
* Listing the component **values** is also what survives bundling: this package
|
|
12
|
+
* declares `sideEffects: false`, and a document names a node type by string, so
|
|
13
|
+
* an import kept only for its side effect is exactly what gets shaken out.
|
|
14
|
+
*/
|
|
15
|
+
// Typed by name, so the declaration names each component rather than spelling out its type through core.
|
|
16
|
+
export const NODES = [FullWaveform, LiveWaveform];
|
|
17
|
+
//# sourceMappingURL=nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,yGAAyG;AACzG,MAAM,CAAC,MAAM,KAAK,GAAkD,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC","sourcesContent":["import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n/**\n * Every node type this package publishes.\n *\n * A host registers these by handing the array to an engine —\n * `new Engine(platform, { nodes: NODES })` — which reads each component's key.\n * Defining a component only *declares* that key: nothing is registered by\n * importing a module, so a registry holds exactly what its owner asked for.\n *\n * Listing the component **values** is also what survives bundling: this package\n * declares `sideEffects: false`, and a document names a node type by string, so\n * an import kept only for its side effect is exactly what gets shaken out.\n */\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\nexport const NODES: (typeof FullWaveform | typeof LiveWaveform)[] = [FullWaveform, LiveWaveform];\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of a recording, as the waveform nodes draw it.
|
|
3
|
+
*
|
|
4
|
+
* ## How an envelope reaches a node: the host supplies it
|
|
5
|
+
*
|
|
6
|
+
* Nothing in the engine, and nothing in this kit, decodes audio. A waveform node
|
|
7
|
+
* does not read a `sound` node's `src`, declares no audio asset and is not tied
|
|
8
|
+
* to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`
|
|
9
|
+
* prop. Decoding a file into an envelope is the host's job, done once per file
|
|
10
|
+
* before the document is built. Where the recording sits on the audio lane is
|
|
11
|
+
* the author's timing too, which is why `FullWaveform.follow` is opt-in.
|
|
12
|
+
*
|
|
13
|
+
* ### The JSON form
|
|
14
|
+
*
|
|
15
|
+
* A document holds the envelope as plain JSON, because a prop value in a
|
|
16
|
+
* document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of
|
|
17
|
+
* it; `ArrayLike<number>` also accepts the plain arrays a document stores:
|
|
18
|
+
*
|
|
19
|
+
* ```json
|
|
20
|
+
* {
|
|
21
|
+
* "magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
|
|
22
|
+
* "duration": 6,
|
|
23
|
+
* "speaker": [0, 0, 0, 1, 1, -1],
|
|
24
|
+
* "speakers": 2
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`
|
|
29
|
+
* seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice
|
|
30
|
+
* index per bucket, `-1` for "nobody". `speakers` is the voice count, `0` when
|
|
31
|
+
* `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable
|
|
32
|
+
* (`JSON.stringify` writes an object of indices), so a host that holds the typed
|
|
33
|
+
* form converts with `Array.from` before storing it in a document.
|
|
34
|
+
*
|
|
35
|
+
* ## Why the data is baked rather than listened to
|
|
36
|
+
*
|
|
37
|
+
* A scene has to render identically in the preview and in a headless export,
|
|
38
|
+
* and an export has no audio device, no `AudioContext` and no playback to
|
|
39
|
+
* analyse. So a "live" visualiser cannot read a Web Audio analyser: what it
|
|
40
|
+
* reads is a *pre-computed envelope*, indexed by the scene clock. The picture is
|
|
41
|
+
* then a pure function of time, which is what makes scrubbing backwards, jumping
|
|
42
|
+
* to frame 900, and rendering out of order all produce the same frame.
|
|
43
|
+
*
|
|
44
|
+
* The decode happens in the host, once per file, and arrives here through the
|
|
45
|
+
* build — the same arrangement a chart's rows and a protein's atoms already use,
|
|
46
|
+
* and for the same reason: the build is synchronous and cannot await a fetch.
|
|
47
|
+
*
|
|
48
|
+
* ## Why magnitude rather than min/max
|
|
49
|
+
*
|
|
50
|
+
* An editor's waveform is drawn from per-bucket minima *and* maxima, because an
|
|
51
|
+
* editor is a measuring instrument. These nodes are neither — they are a bar
|
|
52
|
+
* chart of loudness that happens to be shaped like a recording — and audio is
|
|
53
|
+
* near enough symmetric that a mirrored magnitude is indistinguishable at the
|
|
54
|
+
* size a node draws. Half the numbers, and one array to reason about.
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* A decoded recording, reduced to a uniform grid of loudness — plus, when the
|
|
58
|
+
* host knows it, who is talking in each bucket.
|
|
59
|
+
*
|
|
60
|
+
* The speaker track is **not** something a decoder can produce; it comes from a
|
|
61
|
+
* diarized transcript and is folded in by the host before the build. It lives
|
|
62
|
+
* here rather than in a parallel structure because every reader of it is also a
|
|
63
|
+
* reader of the magnitudes at the same index, and two arrays that must stay the
|
|
64
|
+
* same length are better as one object than as two arguments.
|
|
65
|
+
*/
|
|
66
|
+
export interface AudioEnvelope {
|
|
67
|
+
/**
|
|
68
|
+
* Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A
|
|
69
|
+
* `Float32Array`, or the plain `number[]` a document stores.
|
|
70
|
+
*/
|
|
71
|
+
magnitude: ArrayLike<number>;
|
|
72
|
+
/** The decoded length in seconds. */
|
|
73
|
+
duration: number;
|
|
74
|
+
/**
|
|
75
|
+
* Which voice is speaking in each bucket, as an index into the recording's
|
|
76
|
+
* own numbering, or `-1` for "nobody identified". Parallel to
|
|
77
|
+
* {@link magnitude}, or `null` when the track was never diarized.
|
|
78
|
+
*/
|
|
79
|
+
speaker: ArrayLike<number> | null;
|
|
80
|
+
/** How many distinct voices the diarizer found. Zero when it did not run. */
|
|
81
|
+
speakers: number;
|
|
82
|
+
}
|
|
83
|
+
/** The envelope of a track that hasn't loaded — or isn't there. */
|
|
84
|
+
export declare const EMPTY_ENVELOPE: AudioEnvelope;
|
|
85
|
+
/** One drawn bar: how loud, and whose. */
|
|
86
|
+
export interface EnvelopeBar {
|
|
87
|
+
/** 0…1. */
|
|
88
|
+
magnitude: number;
|
|
89
|
+
/** The voice index, or -1. */
|
|
90
|
+
speaker: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Resamples `[from, to)` seconds of an envelope down to `bars` columns.
|
|
94
|
+
*
|
|
95
|
+
* Peak-preserving rather than averaging, which is the whole difference between
|
|
96
|
+
* a waveform and a blur: averaging a hundred buckets into one column flattens
|
|
97
|
+
* every transient, and transients are what makes a drawn recording read as
|
|
98
|
+
* speech rather than as noise. The speaker of a column is the speaker of its
|
|
99
|
+
* *loudest* bucket, on the same reasoning — a column straddling a turn belongs
|
|
100
|
+
* to whoever is actually audible in it.
|
|
101
|
+
*
|
|
102
|
+
* A window past either end of the recording yields silent, unattributed
|
|
103
|
+
* columns rather than clamping onto the nearest real one. That matters for the
|
|
104
|
+
* live visualiser, which is handed a window centred on the playhead and would
|
|
105
|
+
* otherwise smear the first bucket across the whole run-up to a track's start.
|
|
106
|
+
*/
|
|
107
|
+
export declare function sampleEnvelope(envelope: AudioEnvelope, from: number, to: number, bars: number): EnvelopeBar[];
|
|
108
|
+
/**
|
|
109
|
+
* The same window, with everything that isn't `voice` silenced.
|
|
110
|
+
*
|
|
111
|
+
* The point of the speaker filter, and the reason it silences rather than
|
|
112
|
+
* *drops*: a podcast visualiser filtered to one host should go quiet while the
|
|
113
|
+
* other one talks, not compress their turn out of existence. Keeping the bars
|
|
114
|
+
* and zeroing them is what makes the picture read as "this person is not
|
|
115
|
+
* speaking right now" instead of as a jump cut.
|
|
116
|
+
*
|
|
117
|
+
* `voice` of `null` returns the bars untouched, which is the unfiltered node.
|
|
118
|
+
*/
|
|
119
|
+
export declare function forSpeaker(bars: EnvelopeBar[], voice: number | null): EnvelopeBar[];
|
|
120
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAC5B,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;IACjC,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,aAK5B,CAAA;AAED,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,WAAW;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,WAAW,EAAE,CAkCf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EAAE,EACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,WAAW,EAAE,CAKf"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of a recording, as the waveform nodes draw it.
|
|
3
|
+
*
|
|
4
|
+
* ## How an envelope reaches a node: the host supplies it
|
|
5
|
+
*
|
|
6
|
+
* Nothing in the engine, and nothing in this kit, decodes audio. A waveform node
|
|
7
|
+
* does not read a `sound` node's `src`, declares no audio asset and is not tied
|
|
8
|
+
* to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`
|
|
9
|
+
* prop. Decoding a file into an envelope is the host's job, done once per file
|
|
10
|
+
* before the document is built. Where the recording sits on the audio lane is
|
|
11
|
+
* the author's timing too, which is why `FullWaveform.follow` is opt-in.
|
|
12
|
+
*
|
|
13
|
+
* ### The JSON form
|
|
14
|
+
*
|
|
15
|
+
* A document holds the envelope as plain JSON, because a prop value in a
|
|
16
|
+
* document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of
|
|
17
|
+
* it; `ArrayLike<number>` also accepts the plain arrays a document stores:
|
|
18
|
+
*
|
|
19
|
+
* ```json
|
|
20
|
+
* {
|
|
21
|
+
* "magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
|
|
22
|
+
* "duration": 6,
|
|
23
|
+
* "speaker": [0, 0, 0, 1, 1, -1],
|
|
24
|
+
* "speakers": 2
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`
|
|
29
|
+
* seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice
|
|
30
|
+
* index per bucket, `-1` for "nobody". `speakers` is the voice count, `0` when
|
|
31
|
+
* `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable
|
|
32
|
+
* (`JSON.stringify` writes an object of indices), so a host that holds the typed
|
|
33
|
+
* form converts with `Array.from` before storing it in a document.
|
|
34
|
+
*
|
|
35
|
+
* ## Why the data is baked rather than listened to
|
|
36
|
+
*
|
|
37
|
+
* A scene has to render identically in the preview and in a headless export,
|
|
38
|
+
* and an export has no audio device, no `AudioContext` and no playback to
|
|
39
|
+
* analyse. So a "live" visualiser cannot read a Web Audio analyser: what it
|
|
40
|
+
* reads is a *pre-computed envelope*, indexed by the scene clock. The picture is
|
|
41
|
+
* then a pure function of time, which is what makes scrubbing backwards, jumping
|
|
42
|
+
* to frame 900, and rendering out of order all produce the same frame.
|
|
43
|
+
*
|
|
44
|
+
* The decode happens in the host, once per file, and arrives here through the
|
|
45
|
+
* build — the same arrangement a chart's rows and a protein's atoms already use,
|
|
46
|
+
* and for the same reason: the build is synchronous and cannot await a fetch.
|
|
47
|
+
*
|
|
48
|
+
* ## Why magnitude rather than min/max
|
|
49
|
+
*
|
|
50
|
+
* An editor's waveform is drawn from per-bucket minima *and* maxima, because an
|
|
51
|
+
* editor is a measuring instrument. These nodes are neither — they are a bar
|
|
52
|
+
* chart of loudness that happens to be shaped like a recording — and audio is
|
|
53
|
+
* near enough symmetric that a mirrored magnitude is indistinguishable at the
|
|
54
|
+
* size a node draws. Half the numbers, and one array to reason about.
|
|
55
|
+
*/
|
|
56
|
+
/** The envelope of a track that hasn't loaded — or isn't there. */
|
|
57
|
+
export const EMPTY_ENVELOPE = {
|
|
58
|
+
magnitude: new Float32Array(0),
|
|
59
|
+
duration: 0,
|
|
60
|
+
speaker: null,
|
|
61
|
+
speakers: 0,
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Resamples `[from, to)` seconds of an envelope down to `bars` columns.
|
|
65
|
+
*
|
|
66
|
+
* Peak-preserving rather than averaging, which is the whole difference between
|
|
67
|
+
* a waveform and a blur: averaging a hundred buckets into one column flattens
|
|
68
|
+
* every transient, and transients are what makes a drawn recording read as
|
|
69
|
+
* speech rather than as noise. The speaker of a column is the speaker of its
|
|
70
|
+
* *loudest* bucket, on the same reasoning — a column straddling a turn belongs
|
|
71
|
+
* to whoever is actually audible in it.
|
|
72
|
+
*
|
|
73
|
+
* A window past either end of the recording yields silent, unattributed
|
|
74
|
+
* columns rather than clamping onto the nearest real one. That matters for the
|
|
75
|
+
* live visualiser, which is handed a window centred on the playhead and would
|
|
76
|
+
* otherwise smear the first bucket across the whole run-up to a track's start.
|
|
77
|
+
*/
|
|
78
|
+
export function sampleEnvelope(envelope, from, to, bars) {
|
|
79
|
+
const count = Math.max(0, Math.floor(bars));
|
|
80
|
+
const out = new Array(count);
|
|
81
|
+
for (let i = 0; i < count; i++)
|
|
82
|
+
out[i] = { magnitude: 0, speaker: -1 };
|
|
83
|
+
const buckets = envelope.magnitude.length;
|
|
84
|
+
if (count === 0 || buckets === 0 || envelope.duration <= 0)
|
|
85
|
+
return out;
|
|
86
|
+
const perSecond = buckets / envelope.duration;
|
|
87
|
+
const span = (to - from) / count;
|
|
88
|
+
for (let i = 0; i < count; i++) {
|
|
89
|
+
const start = (from + span * i) * perSecond;
|
|
90
|
+
const end = (from + span * (i + 1)) * perSecond;
|
|
91
|
+
// At least one bucket per column, so a window zoomed in past the grid draws
|
|
92
|
+
// the sample it is standing on rather than an empty band.
|
|
93
|
+
const first = Math.floor(start);
|
|
94
|
+
const last = Math.max(first, Math.ceil(end) - 1);
|
|
95
|
+
let loudest = 0;
|
|
96
|
+
let speaker = -1;
|
|
97
|
+
for (let b = first; b <= last; b++) {
|
|
98
|
+
if (b < 0 || b >= buckets)
|
|
99
|
+
continue;
|
|
100
|
+
const value = envelope.magnitude[b];
|
|
101
|
+
if (value < loudest)
|
|
102
|
+
continue;
|
|
103
|
+
loudest = value;
|
|
104
|
+
speaker = envelope.speaker ? envelope.speaker[b] : -1;
|
|
105
|
+
}
|
|
106
|
+
out[i] = { magnitude: loudest, speaker };
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The same window, with everything that isn't `voice` silenced.
|
|
112
|
+
*
|
|
113
|
+
* The point of the speaker filter, and the reason it silences rather than
|
|
114
|
+
* *drops*: a podcast visualiser filtered to one host should go quiet while the
|
|
115
|
+
* other one talks, not compress their turn out of existence. Keeping the bars
|
|
116
|
+
* and zeroing them is what makes the picture read as "this person is not
|
|
117
|
+
* speaking right now" instead of as a jump cut.
|
|
118
|
+
*
|
|
119
|
+
* `voice` of `null` returns the bars untouched, which is the unfiltered node.
|
|
120
|
+
*/
|
|
121
|
+
export function forSpeaker(bars, voice) {
|
|
122
|
+
if (voice === null)
|
|
123
|
+
return bars;
|
|
124
|
+
return bars.map((bar) => bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker });
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingUR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,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 * ## How an envelope reaches a node: the host supplies it\n *\n * Nothing in the engine, and nothing in this kit, decodes audio. A waveform node\n * does not read a `sound` node's `src`, declares no audio asset and is not tied\n * to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`\n * prop. Decoding a file into an envelope is the host's job, done once per file\n * before the document is built. Where the recording sits on the audio lane is\n * the author's timing too, which is why `FullWaveform.follow` is opt-in.\n *\n * ### The JSON form\n *\n * A document holds the envelope as plain JSON, because a prop value in a\n * document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of\n * it; `ArrayLike<number>` also accepts the plain arrays a document stores:\n *\n * ```json\n * {\n * \"magnitude\": [0, 0.25, 0.5, 1, 0.5, 0],\n * \"duration\": 6,\n * \"speaker\": [0, 0, 0, 1, 1, -1],\n * \"speakers\": 2\n * }\n * ```\n *\n * `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`\n * seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice\n * index per bucket, `-1` for \"nobody\". `speakers` is the voice count, `0` when\n * `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable\n * (`JSON.stringify` writes an object of indices), so a host that holds the typed\n * form converts with `Array.from` before storing it in a document.\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 host, once per file, and arrives here through the\n * build — the same arrangement a chart's rows and a protein's atoms already use,\n * and for the same reason: the build is 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 * host 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 host 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 /**\n * Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A\n * `Float32Array`, or the plain `number[]` a document stores.\n */\n magnitude: ArrayLike<number>\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: ArrayLike<number> | 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,118 @@
|
|
|
1
|
+
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps } from "@motionscript/sdk";
|
|
2
|
+
import { type AudioEnvelope } from "./envelope.js";
|
|
3
|
+
/**
|
|
4
|
+
* A **waveform overview**: the whole recording's shape, drawn at once.
|
|
5
|
+
*
|
|
6
|
+
* The picture every audio editor opens with, and the one a podcast clip puts
|
|
7
|
+
* under its caption — a static silhouette of the file, with a played portion
|
|
8
|
+
* that advances. It answers "how long is this and where are the loud parts",
|
|
9
|
+
* which is a question about the *file*, not about the moment; its sibling
|
|
10
|
+
* {@link LiveWaveform} answers the other one.
|
|
11
|
+
*
|
|
12
|
+
* ## Progress is authored, not assumed
|
|
13
|
+
*
|
|
14
|
+
* `follow` is off by default, and that default is the considered one. A
|
|
15
|
+
* scene has no idea where the recording it is drawing sits on the video's audio
|
|
16
|
+
* lane — a clip is placed, trimmed and sped up out there, and none of that is
|
|
17
|
+
* visible from in here. So the honest default is that the fill is *animation*:
|
|
18
|
+
* the author sweeps it with a command, the same as any other tween, and it lands
|
|
19
|
+
* wherever they put it. `follow` is the shortcut for the common arrangement
|
|
20
|
+
* where the node appears exactly as the track starts, and it says so by being a
|
|
21
|
+
* switch someone has to turn on rather than a behaviour that quietly disagrees
|
|
22
|
+
* with the mix.
|
|
23
|
+
*
|
|
24
|
+
* ## Voices instead of progress
|
|
25
|
+
*
|
|
26
|
+
* With `byVoice` on, the played/ahead split is replaced by one colour per
|
|
27
|
+
* speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
|
|
28
|
+
* floor, where the turns are, how long each one ran. It replaces the progress
|
|
29
|
+
* colours rather than combining with them, because a bar cannot mean two things
|
|
30
|
+
* at once and "played, and also Grace" is a legend nobody can hold in their
|
|
31
|
+
* head.
|
|
32
|
+
*/
|
|
33
|
+
export declare const FullWaveform: import("@motionscript/sdk").Component<"fullWaveform", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
34
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
35
|
+
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
36
|
+
/** How many columns the whole file is drawn as. */
|
|
37
|
+
readonly bars: 120;
|
|
38
|
+
/** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
|
|
39
|
+
readonly gap: 0.3;
|
|
40
|
+
/** Corner radius of a bar, capped at half its width. */
|
|
41
|
+
readonly radius: 2;
|
|
42
|
+
/** How much of the file reads as played, `0`–`1`. Tweenable. */
|
|
43
|
+
readonly progress: 0;
|
|
44
|
+
/** Drive `progress` from the node's own clock instead of the prop. */
|
|
45
|
+
readonly follow: false;
|
|
46
|
+
/** Multiplies every magnitude — a quiet track pulled up to fill its box. */
|
|
47
|
+
readonly gain: 1;
|
|
48
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
49
|
+
readonly floor: 0.015;
|
|
50
|
+
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
51
|
+
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
52
|
+
readonly byVoice: false;
|
|
53
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
54
|
+
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
55
|
+
/** The bars ahead of the playhead. */
|
|
56
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
57
|
+
/** …and the bars behind it. */
|
|
58
|
+
readonly playedFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
59
|
+
}>, {
|
|
60
|
+
readonly sweep: unknown;
|
|
61
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
62
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
63
|
+
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
64
|
+
/** How many columns the whole file is drawn as. */
|
|
65
|
+
readonly bars: 120;
|
|
66
|
+
/** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
|
|
67
|
+
readonly gap: 0.3;
|
|
68
|
+
/** Corner radius of a bar, capped at half its width. */
|
|
69
|
+
readonly radius: 2;
|
|
70
|
+
/** How much of the file reads as played, `0`–`1`. Tweenable. */
|
|
71
|
+
readonly progress: 0;
|
|
72
|
+
/** Drive `progress` from the node's own clock instead of the prop. */
|
|
73
|
+
readonly follow: false;
|
|
74
|
+
/** Multiplies every magnitude — a quiet track pulled up to fill its box. */
|
|
75
|
+
readonly gain: 1;
|
|
76
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
77
|
+
readonly floor: 0.015;
|
|
78
|
+
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
79
|
+
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
80
|
+
readonly byVoice: false;
|
|
81
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
82
|
+
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
83
|
+
/** The bars ahead of the playhead. */
|
|
84
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
85
|
+
/** …and the bars behind it. */
|
|
86
|
+
readonly playedFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
87
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
88
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
89
|
+
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
90
|
+
/** How many columns the whole file is drawn as. */
|
|
91
|
+
readonly bars: 120;
|
|
92
|
+
/** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
|
|
93
|
+
readonly gap: 0.3;
|
|
94
|
+
/** Corner radius of a bar, capped at half its width. */
|
|
95
|
+
readonly radius: 2;
|
|
96
|
+
/** How much of the file reads as played, `0`–`1`. Tweenable. */
|
|
97
|
+
readonly progress: 0;
|
|
98
|
+
/** Drive `progress` from the node's own clock instead of the prop. */
|
|
99
|
+
readonly follow: false;
|
|
100
|
+
/** Multiplies every magnitude — a quiet track pulled up to fill its box. */
|
|
101
|
+
readonly gain: 1;
|
|
102
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
103
|
+
readonly floor: 0.015;
|
|
104
|
+
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
105
|
+
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
106
|
+
readonly byVoice: false;
|
|
107
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
108
|
+
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
109
|
+
/** The bars ahead of the playhead. */
|
|
110
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
111
|
+
/** …and the bars behind it. */
|
|
112
|
+
readonly playedFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
113
|
+
}>, {
|
|
114
|
+
readonly sweep: unknown;
|
|
115
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
116
|
+
export type FullWaveform = NodeOf<typeof FullWaveform>;
|
|
117
|
+
export type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>;
|
|
118
|
+
//# 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,EAKL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAGX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EACjC,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAc/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,YAAY;IAGrB,0EAA0E;;IAE1E,mDAAmD;;IAEnD,8EAA8E;;IAE9E,wDAAwD;;IAExD,gEAAgE;;IAEhE,sEAAsE;;IAEtE,4EAA4E;;IAE5E,gEAAgE;;;IAGhE,8EAA8E;;IAE9E,0EAA0E;;IAE1E,sCAAsC;;IAEtC,+BAA+B;;;;;IAvB/B,0EAA0E;;IAE1E,mDAAmD;;IAEnD,8EAA8E;;IAE9E,wDAAwD;;IAExD,gEAAgE;;IAEhE,sEAAsE;;IAEtE,4EAA4E;;IAE5E,gEAAgE;;;IAGhE,8EAA8E;;IAE9E,0EAA0E;;IAE1E,sCAAsC;;IAEtC,+BAA+B;;;IAvB/B,0EAA0E;;IAE1E,mDAAmD;;IAEnD,8EAA8E;;IAE9E,wDAAwD;;IAExD,gEAAgE;;IAEhE,sEAAsE;;IAEtE,4EAA4E;;IAE5E,gEAAgE;;;IAGhE,8EAA8E;;IAE9E,0EAA0E;;IAE1E,sCAAsC;;IAEtC,+BAA+B;;;;2BAwBjC,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA;AACtD,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Types, component2d, easeInOut, fillOps, } from "@motionscript/sdk";
|
|
2
|
+
import { EMPTY_ENVELOPE, sampleEnvelope } from "./envelope.js";
|
|
3
|
+
import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./shared.js";
|
|
4
|
+
/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */
|
|
5
|
+
const paint = (initial) => Types.custom(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp });
|
|
6
|
+
/**
|
|
7
|
+
* A **waveform overview**: the whole recording's shape, drawn at once.
|
|
8
|
+
*
|
|
9
|
+
* The picture every audio editor opens with, and the one a podcast clip puts
|
|
10
|
+
* under its caption — a static silhouette of the file, with a played portion
|
|
11
|
+
* that advances. It answers "how long is this and where are the loud parts",
|
|
12
|
+
* which is a question about the *file*, not about the moment; its sibling
|
|
13
|
+
* {@link LiveWaveform} answers the other one.
|
|
14
|
+
*
|
|
15
|
+
* ## Progress is authored, not assumed
|
|
16
|
+
*
|
|
17
|
+
* `follow` is off by default, and that default is the considered one. A
|
|
18
|
+
* scene has no idea where the recording it is drawing sits on the video's audio
|
|
19
|
+
* lane — a clip is placed, trimmed and sped up out there, and none of that is
|
|
20
|
+
* visible from in here. So the honest default is that the fill is *animation*:
|
|
21
|
+
* the author sweeps it with a command, the same as any other tween, and it lands
|
|
22
|
+
* wherever they put it. `follow` is the shortcut for the common arrangement
|
|
23
|
+
* where the node appears exactly as the track starts, and it says so by being a
|
|
24
|
+
* switch someone has to turn on rather than a behaviour that quietly disagrees
|
|
25
|
+
* with the mix.
|
|
26
|
+
*
|
|
27
|
+
* ## Voices instead of progress
|
|
28
|
+
*
|
|
29
|
+
* With `byVoice` on, the played/ahead split is replaced by one colour per
|
|
30
|
+
* speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
|
|
31
|
+
* floor, where the turns are, how long each one ran. It replaces the progress
|
|
32
|
+
* colours rather than combining with them, because a bar cannot mean two things
|
|
33
|
+
* at once and "played, and also Grace" is a legend nobody can hold in their
|
|
34
|
+
* head.
|
|
35
|
+
*/
|
|
36
|
+
export const FullWaveform = component2d({
|
|
37
|
+
key: "fullWaveform",
|
|
38
|
+
state: {
|
|
39
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
40
|
+
envelope: Types.custom(EMPTY_ENVELOPE),
|
|
41
|
+
/** How many columns the whole file is drawn as. */
|
|
42
|
+
bars: 120,
|
|
43
|
+
/** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
|
|
44
|
+
gap: 0.3,
|
|
45
|
+
/** Corner radius of a bar, capped at half its width. */
|
|
46
|
+
radius: 2,
|
|
47
|
+
/** How much of the file reads as played, `0`–`1`. Tweenable. */
|
|
48
|
+
progress: 0,
|
|
49
|
+
/** Drive `progress` from the node's own clock instead of the prop. */
|
|
50
|
+
follow: false,
|
|
51
|
+
/** Multiplies every magnitude — a quiet track pulled up to fill its box. */
|
|
52
|
+
gain: 1,
|
|
53
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
54
|
+
floor: 0.015,
|
|
55
|
+
align: Types.custom("center"),
|
|
56
|
+
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
57
|
+
byVoice: false,
|
|
58
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
59
|
+
voiceColors: Types.custom([]),
|
|
60
|
+
/** The bars ahead of the playhead. */
|
|
61
|
+
fill: paint("#5b5b7a"),
|
|
62
|
+
/** …and the bars behind it. */
|
|
63
|
+
playedFill: paint("#6366f1"),
|
|
64
|
+
},
|
|
65
|
+
// Nothing declares a component's paints but itself: `fill` and `playedFill` both.
|
|
66
|
+
load: (loader, state) => {
|
|
67
|
+
loader.fill(state.fill);
|
|
68
|
+
loader.fill(state.playedFill);
|
|
69
|
+
},
|
|
70
|
+
commands: {
|
|
71
|
+
/**
|
|
72
|
+
* Fill the waveform in, left to right — the node's one command, since
|
|
73
|
+
* everything else about it is expressible as an ordinary `to`. Eased in-out
|
|
74
|
+
* unless it is given an easing of its own.
|
|
75
|
+
*/
|
|
76
|
+
sweep: (timeline, state) => {
|
|
77
|
+
const ease = timeline.easing ? null : easeInOut();
|
|
78
|
+
const from = state.progress;
|
|
79
|
+
return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }));
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
render: (ctx, state) => {
|
|
83
|
+
drawBars(ctx, state);
|
|
84
|
+
ctx.children();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
function drawBars(ctx, s) {
|
|
88
|
+
const { width, height } = ctx.size;
|
|
89
|
+
if (width <= 0 || height <= 0)
|
|
90
|
+
return;
|
|
91
|
+
const count = Math.max(1, Math.round(s.bars));
|
|
92
|
+
const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count);
|
|
93
|
+
const boxes = layOutBars(sampled, {
|
|
94
|
+
width,
|
|
95
|
+
height,
|
|
96
|
+
gap: s.gap,
|
|
97
|
+
align: s.align,
|
|
98
|
+
gain: s.gain,
|
|
99
|
+
floor: s.floor,
|
|
100
|
+
});
|
|
101
|
+
if (boxes.length === 0)
|
|
102
|
+
return;
|
|
103
|
+
// One draw per colour rather than per bar — see {@link paintBars}. The key
|
|
104
|
+
// is a string because it has to be comparable; the paint it stands for is
|
|
105
|
+
// resolved after the grouping.
|
|
106
|
+
const edge = played(ctx, s) * boxes.length;
|
|
107
|
+
const groups = groupByPaint(boxes, (i) => s.byVoice
|
|
108
|
+
? `voice:${sampled[i].speaker}`
|
|
109
|
+
: i < edge
|
|
110
|
+
? "played"
|
|
111
|
+
: "ahead");
|
|
112
|
+
for (const [key, run] of groups) {
|
|
113
|
+
const graphics = paintBars(run, paintFor(s, key), s.radius);
|
|
114
|
+
if (graphics)
|
|
115
|
+
ctx.draw(graphics);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Where the fill has reached, from whichever source is in charge. */
|
|
119
|
+
function played(ctx, s) {
|
|
120
|
+
if (!s.follow)
|
|
121
|
+
return clamp01(s.progress);
|
|
122
|
+
const length = s.envelope.duration;
|
|
123
|
+
if (length <= 0)
|
|
124
|
+
return 0;
|
|
125
|
+
return clamp01(ctx.time.elapsed / length);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The paint a group takes.
|
|
129
|
+
*
|
|
130
|
+
* A voice's colour is a **colour string**, never one of the node's two fill
|
|
131
|
+
* props, and that is deliberate: a voice is identified by hue, so a gradient
|
|
132
|
+
* or an image there would defeat the only thing the colour is for. It also
|
|
133
|
+
* means these paints declare no assets, which is why `load` only has to account
|
|
134
|
+
* for the two real fill props.
|
|
135
|
+
*/
|
|
136
|
+
function paintFor(s, key) {
|
|
137
|
+
if (key === "played")
|
|
138
|
+
return s.playedFill;
|
|
139
|
+
if (key === "ahead")
|
|
140
|
+
return s.fill;
|
|
141
|
+
const voice = Number(key.slice("voice:".length));
|
|
142
|
+
if (!Number.isFinite(voice) || voice < 0)
|
|
143
|
+
return s.fill;
|
|
144
|
+
return s.voiceColors[voice] ?? voiceColor(voice);
|
|
145
|
+
}
|
|
146
|
+
//# 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,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,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;AAEjB,sHAAsH;AACtH,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE,CAChC,KAAK,CAAC,MAAM,CAAuB,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAE/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE;QACL,0EAA0E;QAC1E,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAgB,cAAc,CAAC;QACrD,mDAAmD;QACnD,IAAI,EAAE,GAAG;QACT,8EAA8E;QAC9E,GAAG,EAAE,GAAG;QACR,wDAAwD;QACxD,MAAM,EAAE,CAAC;QACT,gEAAgE;QAChE,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AM,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;QAC3D,IAAI,QAAQ;YAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,SAAS,MAAM,CAAC,GAAkB,EAAE,CAAY;IAC9C,IAAI,CAAC,CAAC,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAA;IAClC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IACzB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,QAAQ,CAAC,CAAY,EAAE,GAAW;IACzC,IAAI,GAAG,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,UAAU,CAAA;IACzC,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,CAAC,CAAC,IAAI,CAAA;IAElC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,IAAI,CAAA;IACvD,OAAO,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC","sourcesContent":["import {\n Types,\n component2d,\n easeInOut,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\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\n/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */\nconst paint = (initial: string) =>\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\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 * `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 `byVoice` on, the played/ahead split is replaced by one colour per\n * speaking voice, at a size 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 */\nexport const FullWaveform = component2d({\n key: \"fullWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many columns the whole file is drawn as. */\n bars: 120,\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: 0.3,\n /** Corner radius of a bar, capped at half its width. */\n radius: 2,\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: 0,\n /** Drive `progress` from the node's own clock instead of the prop. */\n follow: false,\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: 1,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.015,\n align: Types.custom<WaveformAlignment>(\"center\"),\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n /** The bars ahead of the playhead. */\n fill: paint(\"#5b5b7a\"),\n /** …and the bars behind it. */\n playedFill: paint(\"#6366f1\"),\n },\n // Nothing declares a component's paints but itself: `fill` and `playedFill` both.\n load: (loader, state) => {\n loader.fill(state.fill)\n loader.fill(state.playedFill)\n },\n commands: {\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`. Eased in-out\n * unless it is given an easing of its own.\n */\n sweep: (timeline, state) => {\n const ease = timeline.easing ? null : easeInOut()\n const from = state.progress\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\n },\n },\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type FullWaveform = NodeOf<typeof FullWaveform>\nexport type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>\n\ninterface FullState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly progress: number\n readonly follow: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n readonly playedFill: FillResolved[]\n}\n\nfunction drawBars(ctx: RenderContext, s: FullState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.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 = played(ctx, s) * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n s.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, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\n/** Where the fill has reached, from whichever source is in charge. */\nfunction played(ctx: RenderContext, s: FullState): number {\n if (!s.follow) return clamp01(s.progress)\n const length = s.envelope.duration\n if (length <= 0) return 0\n return clamp01(ctx.time.elapsed / length)\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 `load` only has to account\n * for the two real fill props.\n */\nfunction paintFor(s: FullState, key: string): Fill {\n if (key === \"played\") return s.playedFill\n if (key === \"ahead\") return s.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return s.fill\n return s.voiceColors[voice] ?? voiceColor(voice)\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
|