@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +91 -3
  5. package/dist/browser/chunks/chunk-DD3KHRUL.js +2 -0
  6. package/dist/browser/chunks/chunk-DD3KHRUL.js.map +7 -0
  7. package/dist/browser/index.js +2 -0
  8. package/dist/browser/index.js.map +7 -0
  9. package/dist/browser/kit.js +2 -0
  10. package/dist/browser/kit.js.map +7 -0
  11. package/dist/browser/manifest.json +13 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +3 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/kit.d.ts +13 -0
  17. package/dist/kit.d.ts.map +1 -0
  18. package/dist/kit.js +11 -0
  19. package/dist/kit.js.map +1 -0
  20. package/dist/nodes.d.ts +16 -0
  21. package/dist/nodes.d.ts.map +1 -0
  22. package/dist/nodes.js +17 -0
  23. package/dist/nodes.js.map +1 -0
  24. package/dist/waveform/envelope.d.ts +120 -0
  25. package/dist/waveform/envelope.d.ts.map +1 -0
  26. package/dist/waveform/envelope.js +126 -0
  27. package/dist/waveform/envelope.js.map +1 -0
  28. package/dist/waveform/full-waveform.d.ts +118 -0
  29. package/dist/waveform/full-waveform.d.ts.map +1 -0
  30. package/dist/waveform/full-waveform.js +146 -0
  31. package/dist/waveform/full-waveform.js.map +1 -0
  32. package/dist/waveform/index.d.ts +23 -0
  33. package/dist/waveform/index.d.ts.map +1 -0
  34. package/dist/waveform/index.js +19 -0
  35. package/dist/waveform/index.js.map +1 -0
  36. package/dist/waveform/live-waveform.d.ts +129 -0
  37. package/dist/waveform/live-waveform.d.ts.map +1 -0
  38. package/dist/waveform/live-waveform.js +149 -0
  39. package/dist/waveform/live-waveform.js.map +1 -0
  40. package/dist/waveform/shared.d.ts +98 -0
  41. package/dist/waveform/shared.d.ts.map +1 -0
  42. package/dist/waveform/shared.js +149 -0
  43. package/dist/waveform/shared.js.map +1 -0
  44. package/package.json +72 -3
  45. package/registry.json +28 -0
  46. package/src/index.ts +2 -0
  47. package/src/kit.ts +22 -0
  48. package/src/nodes.ts +17 -0
  49. package/src/waveform/envelope.ts +176 -0
  50. package/src/waveform/full-waveform.ts +188 -0
  51. package/src/waveform/index.ts +30 -0
  52. package/src/waveform/live-waveform.ts +206 -0
  53. package/src/waveform/shared.ts +197 -0
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@motionscript/audio",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.10",
4
+ "type": "module",
5
+ "description": "Waveform components for Motion Script: a full recording drawn as bars, and a live meter that moves with playback. Both draw a loudness envelope the host supplies.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/motionscript-dev/motionscript.git",
9
+ "directory": "packages/components/audio"
10
+ },
11
+ "homepage": "https://motionscript.dev",
12
+ "bugs": {
13
+ "url": "https://github.com/motionscript-dev/motionscript/issues"
14
+ },
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "NOTICE",
20
+ "dist",
21
+ "src",
22
+ "registry.json",
23
+ "CHANGELOG.md",
24
+ "!dist/**/*.tsbuildinfo",
25
+ "!src/**/tests/**",
26
+ "!src/**/*.test.ts",
27
+ "!src/**/*.test.tsx",
28
+ "!src/**/*.fixtures.ts"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ },
38
+ "./kit": {
39
+ "types": "./dist/kit.d.ts",
40
+ "default": "./dist/kit.js"
41
+ }
42
+ },
43
+ "keywords": [
44
+ "motion-script",
45
+ "motion script",
46
+ "audio",
47
+ "waveform",
48
+ "animation"
49
+ ],
50
+ "license": "Apache-2.0",
51
+ "author": "Motionscript",
52
+ "peerDependencies": {
53
+ "@motionscript/sdk": "^0.1.0-alpha.10"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^25.6.2",
57
+ "eslint": "^9.39.4",
58
+ "eslint-import-resolver-typescript": "^4.4.4",
59
+ "eslint-plugin-import-x": "^4.16.1",
60
+ "tsc-alias": "^1.8.16",
61
+ "typescript": "^6.0.3",
62
+ "typescript-eslint": "^8.48.0",
63
+ "vitest": "^4.1.5",
64
+ "@motionscript/core": "0.1.0-alpha.10",
65
+ "@motionscript/sdk": "0.1.0-alpha.10"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && node ../../../scripts/build-browser.mjs",
69
+ "dev": "tsc -p tsconfig.build.json --watch & tsc-alias -p tsconfig.build.json --resolve-full-paths -w",
70
+ "clean": "rimraf --glob dist .turbo *.tsbuildinfo",
71
+ "test": "vitest",
72
+ "lint": "eslint .",
73
+ "typecheck": "tsc -p tsconfig.json --noEmit"
74
+ }
6
75
  }
package/registry.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "kit": {
3
+ "barrel": "src/kit.ts",
4
+ "specifier": "@motionscript/audio/kit"
5
+ },
6
+ "items": [
7
+ {
8
+ "name": "full-waveform",
9
+ "description": "A whole recording drawn as bars, with a played portion that advances.",
10
+ "root": "src/waveform",
11
+ "files": [
12
+ "envelope.ts",
13
+ "full-waveform.ts",
14
+ "shared.ts"
15
+ ]
16
+ },
17
+ {
18
+ "name": "live-waveform",
19
+ "description": "A visualiser whose bars move with the recording as it plays, coloured by voice.",
20
+ "root": "src/waveform",
21
+ "files": [
22
+ "envelope.ts",
23
+ "live-waveform.ts",
24
+ "shared.ts"
25
+ ]
26
+ }
27
+ ]
28
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./waveform"
2
+ export { NODES } from "./nodes";
package/src/kit.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * What the two waveform nodes share, importable without copying it.
3
+ *
4
+ * A registry item copies `envelope.ts` and `shared.ts` beside its node: they
5
+ * hold no class and no registered state, so a fork owning its own copy splits
6
+ * no identity. This is the same surface for a host that samples envelopes or
7
+ * lays bars out itself, and for a fork that keeps only its node file.
8
+ */
9
+ export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./waveform/envelope"
10
+ export type { AudioEnvelope, EnvelopeBar } from "./waveform/envelope"
11
+ export {
12
+ VOICE_PALETTE,
13
+ WAVEFORM_ALIGNMENTS,
14
+ WAVEFORM_STYLES,
15
+ clamp01,
16
+ groupByPaint,
17
+ layOutBars,
18
+ livePaintKey,
19
+ paintBars,
20
+ voiceColor,
21
+ } from "./waveform/shared"
22
+ export type { BarBox, WaveformAlignment, WaveformStyle } from "./waveform/shared"
package/src/nodes.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { FullWaveform } from "./waveform/full-waveform";
2
+ import { LiveWaveform } from "./waveform/live-waveform";
3
+
4
+ /**
5
+ * Every node type this package publishes.
6
+ *
7
+ * A host registers these by handing the array to an engine —
8
+ * `new Engine(platform, { nodes: NODES })` — which reads each component's key.
9
+ * Defining a component only *declares* that key: nothing is registered by
10
+ * importing a module, so a registry holds exactly what its owner asked for.
11
+ *
12
+ * Listing the component **values** is also what survives bundling: this package
13
+ * declares `sideEffects: false`, and a document names a node type by string, so
14
+ * an import kept only for its side effect is exactly what gets shaken out.
15
+ */
16
+ // Typed by name, so the declaration names each component rather than spelling out its type through core.
17
+ export const NODES: (typeof FullWaveform | typeof LiveWaveform)[] = [FullWaveform, LiveWaveform];
@@ -0,0 +1,176 @@
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
+ /**
58
+ * A decoded recording, reduced to a uniform grid of loudness — plus, when the
59
+ * host knows it, who is talking in each bucket.
60
+ *
61
+ * The speaker track is **not** something a decoder can produce; it comes from a
62
+ * diarized transcript and is folded in by the host before the build. It lives
63
+ * here rather than in a parallel structure because every reader of it is also a
64
+ * reader of the magnitudes at the same index, and two arrays that must stay the
65
+ * same length are better as one object than as two arguments.
66
+ */
67
+ export interface AudioEnvelope {
68
+ /**
69
+ * Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A
70
+ * `Float32Array`, or the plain `number[]` a document stores.
71
+ */
72
+ magnitude: ArrayLike<number>
73
+ /** The decoded length in seconds. */
74
+ duration: number
75
+ /**
76
+ * Which voice is speaking in each bucket, as an index into the recording's
77
+ * own numbering, or `-1` for "nobody identified". Parallel to
78
+ * {@link magnitude}, or `null` when the track was never diarized.
79
+ */
80
+ speaker: ArrayLike<number> | null
81
+ /** How many distinct voices the diarizer found. Zero when it did not run. */
82
+ speakers: number
83
+ }
84
+
85
+ /** The envelope of a track that hasn't loaded — or isn't there. */
86
+ export const EMPTY_ENVELOPE: AudioEnvelope = {
87
+ magnitude: new Float32Array(0),
88
+ duration: 0,
89
+ speaker: null,
90
+ speakers: 0,
91
+ }
92
+
93
+ /** One drawn bar: how loud, and whose. */
94
+ export interface EnvelopeBar {
95
+ /** 0…1. */
96
+ magnitude: number
97
+ /** The voice index, or -1. */
98
+ speaker: number
99
+ }
100
+
101
+ /**
102
+ * Resamples `[from, to)` seconds of an envelope down to `bars` columns.
103
+ *
104
+ * Peak-preserving rather than averaging, which is the whole difference between
105
+ * a waveform and a blur: averaging a hundred buckets into one column flattens
106
+ * every transient, and transients are what makes a drawn recording read as
107
+ * speech rather than as noise. The speaker of a column is the speaker of its
108
+ * *loudest* bucket, on the same reasoning — a column straddling a turn belongs
109
+ * to whoever is actually audible in it.
110
+ *
111
+ * A window past either end of the recording yields silent, unattributed
112
+ * columns rather than clamping onto the nearest real one. That matters for the
113
+ * live visualiser, which is handed a window centred on the playhead and would
114
+ * otherwise smear the first bucket across the whole run-up to a track's start.
115
+ */
116
+ export function sampleEnvelope(
117
+ envelope: AudioEnvelope,
118
+ from: number,
119
+ to: number,
120
+ bars: number
121
+ ): EnvelopeBar[] {
122
+ const count = Math.max(0, Math.floor(bars))
123
+ const out: EnvelopeBar[] = new Array(count)
124
+ for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }
125
+
126
+ const buckets = envelope.magnitude.length
127
+ if (count === 0 || buckets === 0 || envelope.duration <= 0) return out
128
+
129
+ const perSecond = buckets / envelope.duration
130
+ const span = (to - from) / count
131
+
132
+ for (let i = 0; i < count; i++) {
133
+ const start = (from + span * i) * perSecond
134
+ const end = (from + span * (i + 1)) * perSecond
135
+
136
+ // At least one bucket per column, so a window zoomed in past the grid draws
137
+ // the sample it is standing on rather than an empty band.
138
+ const first = Math.floor(start)
139
+ const last = Math.max(first, Math.ceil(end) - 1)
140
+
141
+ let loudest = 0
142
+ let speaker = -1
143
+ for (let b = first; b <= last; b++) {
144
+ if (b < 0 || b >= buckets) continue
145
+ const value = envelope.magnitude[b]
146
+ if (value < loudest) continue
147
+ loudest = value
148
+ speaker = envelope.speaker ? envelope.speaker[b] : -1
149
+ }
150
+
151
+ out[i] = { magnitude: loudest, speaker }
152
+ }
153
+
154
+ return out
155
+ }
156
+
157
+ /**
158
+ * The same window, with everything that isn't `voice` silenced.
159
+ *
160
+ * The point of the speaker filter, and the reason it silences rather than
161
+ * *drops*: a podcast visualiser filtered to one host should go quiet while the
162
+ * other one talks, not compress their turn out of existence. Keeping the bars
163
+ * and zeroing them is what makes the picture read as "this person is not
164
+ * speaking right now" instead of as a jump cut.
165
+ *
166
+ * `voice` of `null` returns the bars untouched, which is the unfiltered node.
167
+ */
168
+ export function forSpeaker(
169
+ bars: EnvelopeBar[],
170
+ voice: number | null
171
+ ): EnvelopeBar[] {
172
+ if (voice === null) return bars
173
+ return bars.map((bar) =>
174
+ bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }
175
+ )
176
+ }
@@ -0,0 +1,188 @@
1
+ import {
2
+ Types,
3
+ component2d,
4
+ easeInOut,
5
+ fillOps,
6
+ type Fill,
7
+ type FillResolved,
8
+ type NodeOf,
9
+ type RenderContext,
10
+ // Named so the emitted declaration reaches these through the sdk, not core.
11
+ type Node2D as _Node2D,
12
+ type Node2DProps as _Node2DProps,
13
+ } from "@motionscript/sdk"
14
+
15
+ import { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from "./envelope"
16
+ import {
17
+ clamp01,
18
+ groupByPaint,
19
+ layOutBars,
20
+ paintBars,
21
+ voiceColor,
22
+ type WaveformAlignment,
23
+ } from "./shared"
24
+
25
+ /** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */
26
+ const paint = (initial: string) =>
27
+ Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })
28
+
29
+ /**
30
+ * A **waveform overview**: the whole recording's shape, drawn at once.
31
+ *
32
+ * The picture every audio editor opens with, and the one a podcast clip puts
33
+ * under its caption — a static silhouette of the file, with a played portion
34
+ * that advances. It answers "how long is this and where are the loud parts",
35
+ * which is a question about the *file*, not about the moment; its sibling
36
+ * {@link LiveWaveform} answers the other one.
37
+ *
38
+ * ## Progress is authored, not assumed
39
+ *
40
+ * `follow` is off by default, and that default is the considered one. A
41
+ * scene has no idea where the recording it is drawing sits on the video's audio
42
+ * lane — a clip is placed, trimmed and sped up out there, and none of that is
43
+ * visible from in here. So the honest default is that the fill is *animation*:
44
+ * the author sweeps it with a command, the same as any other tween, and it lands
45
+ * wherever they put it. `follow` is the shortcut for the common arrangement
46
+ * where the node appears exactly as the track starts, and it says so by being a
47
+ * switch someone has to turn on rather than a behaviour that quietly disagrees
48
+ * with the mix.
49
+ *
50
+ * ## Voices instead of progress
51
+ *
52
+ * With `byVoice` on, the played/ahead split is replaced by one colour per
53
+ * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
54
+ * floor, where the turns are, how long each one ran. It replaces the progress
55
+ * colours rather than combining with them, because a bar cannot mean two things
56
+ * at once and "played, and also Grace" is a legend nobody can hold in their
57
+ * head.
58
+ */
59
+ export const FullWaveform = component2d({
60
+ key: "fullWaveform",
61
+ state: {
62
+ /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
63
+ envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),
64
+ /** How many columns the whole file is drawn as. */
65
+ bars: 120,
66
+ /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
67
+ gap: 0.3,
68
+ /** Corner radius of a bar, capped at half its width. */
69
+ radius: 2,
70
+ /** How much of the file reads as played, `0`–`1`. Tweenable. */
71
+ progress: 0,
72
+ /** Drive `progress` from the node's own clock instead of the prop. */
73
+ follow: false,
74
+ /** Multiplies every magnitude — a quiet track pulled up to fill its box. */
75
+ gain: 1,
76
+ /** How much of the box a silent bar still occupies, `0`–`1`. */
77
+ floor: 0.015,
78
+ align: Types.custom<WaveformAlignment>("center"),
79
+ /** Colour each voice's turns rather than splitting on played / not played. */
80
+ byVoice: false,
81
+ /** A colour per voice index. Short or empty falls back to the palette. */
82
+ voiceColors: Types.custom<string[]>([]),
83
+ /** The bars ahead of the playhead. */
84
+ fill: paint("#5b5b7a"),
85
+ /** …and the bars behind it. */
86
+ playedFill: paint("#6366f1"),
87
+ },
88
+ // Nothing declares a component's paints but itself: `fill` and `playedFill` both.
89
+ load: (loader, state) => {
90
+ loader.fill(state.fill)
91
+ loader.fill(state.playedFill)
92
+ },
93
+ commands: {
94
+ /**
95
+ * Fill the waveform in, left to right — the node's one command, since
96
+ * everything else about it is expressible as an ordinary `to`. Eased in-out
97
+ * unless it is given an easing of its own.
98
+ */
99
+ sweep: (timeline, state) => {
100
+ const ease = timeline.easing ? null : easeInOut()
101
+ const from = state.progress
102
+ return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))
103
+ },
104
+ },
105
+ render: (ctx, state) => {
106
+ drawBars(ctx, state)
107
+ ctx.children()
108
+ },
109
+ })
110
+
111
+ export type FullWaveform = NodeOf<typeof FullWaveform>
112
+ export type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>
113
+
114
+ interface FullState {
115
+ readonly envelope: AudioEnvelope
116
+ readonly bars: number
117
+ readonly gap: number
118
+ readonly radius: number
119
+ readonly progress: number
120
+ readonly follow: boolean
121
+ readonly gain: number
122
+ readonly floor: number
123
+ readonly align: WaveformAlignment
124
+ readonly byVoice: boolean
125
+ readonly voiceColors: string[]
126
+ readonly fill: FillResolved[]
127
+ readonly playedFill: FillResolved[]
128
+ }
129
+
130
+ function drawBars(ctx: RenderContext, s: FullState): void {
131
+ const { width, height } = ctx.size
132
+ if (width <= 0 || height <= 0) return
133
+
134
+ const count = Math.max(1, Math.round(s.bars))
135
+ const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)
136
+ const boxes = layOutBars(sampled, {
137
+ width,
138
+ height,
139
+ gap: s.gap,
140
+ align: s.align,
141
+ gain: s.gain,
142
+ floor: s.floor,
143
+ })
144
+ if (boxes.length === 0) return
145
+
146
+ // One draw per colour rather than per bar — see {@link paintBars}. The key
147
+ // is a string because it has to be comparable; the paint it stands for is
148
+ // resolved after the grouping.
149
+ const edge = played(ctx, s) * boxes.length
150
+ const groups = groupByPaint(boxes, (i) =>
151
+ s.byVoice
152
+ ? `voice:${sampled[i].speaker}`
153
+ : i < edge
154
+ ? "played"
155
+ : "ahead"
156
+ )
157
+
158
+ for (const [key, run] of groups) {
159
+ const graphics = paintBars(run, paintFor(s, key), s.radius)
160
+ if (graphics) ctx.draw(graphics)
161
+ }
162
+ }
163
+
164
+ /** Where the fill has reached, from whichever source is in charge. */
165
+ function played(ctx: RenderContext, s: FullState): number {
166
+ if (!s.follow) return clamp01(s.progress)
167
+ const length = s.envelope.duration
168
+ if (length <= 0) return 0
169
+ return clamp01(ctx.time.elapsed / length)
170
+ }
171
+
172
+ /**
173
+ * The paint a group takes.
174
+ *
175
+ * A voice's colour is a **colour string**, never one of the node's two fill
176
+ * props, and that is deliberate: a voice is identified by hue, so a gradient
177
+ * or an image there would defeat the only thing the colour is for. It also
178
+ * means these paints declare no assets, which is why `load` only has to account
179
+ * for the two real fill props.
180
+ */
181
+ function paintFor(s: FullState, key: string): Fill {
182
+ if (key === "played") return s.playedFill
183
+ if (key === "ahead") return s.fill
184
+
185
+ const voice = Number(key.slice("voice:".length))
186
+ if (!Number.isFinite(voice) || voice < 0) return s.fill
187
+ return s.voiceColors[voice] ?? voiceColor(voice)
188
+ }
@@ -0,0 +1,30 @@
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"
16
+ export type { FullWaveformProps } from "./full-waveform"
17
+ export { LiveWaveform } from "./live-waveform"
18
+ export type { LiveWaveformProps } from "./live-waveform"
19
+ export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./envelope"
20
+ export type { AudioEnvelope, EnvelopeBar } from "./envelope"
21
+ export {
22
+ VOICE_PALETTE,
23
+ WAVEFORM_ALIGNMENTS,
24
+ WAVEFORM_STYLES,
25
+ groupByPaint,
26
+ layOutBars,
27
+ paintBars,
28
+ voiceColor,
29
+ } from "./shared"
30
+ export type { BarBox, WaveformAlignment, WaveformStyle } from "./shared"