@motionscript/audio 0.1.0-alpha.3 → 0.1.0-alpha.6

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 (45) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +92 -0
  5. package/dist/browser/chunks/chunk-DAFIVUTT.js +2 -0
  6. package/dist/browser/chunks/chunk-DAFIVUTT.js.map +7 -0
  7. package/dist/browser/index.js +1 -1
  8. package/dist/browser/index.js.map +3 -3
  9. package/dist/browser/kit.js +1 -1
  10. package/dist/browser/manifest.json +3 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/kit.js.map +1 -1
  13. package/dist/nodes.d.ts +6 -9
  14. package/dist/nodes.d.ts.map +1 -1
  15. package/dist/nodes.js +7 -9
  16. package/dist/nodes.js.map +1 -1
  17. package/dist/waveform/envelope.d.ts +42 -9
  18. package/dist/waveform/envelope.d.ts.map +1 -1
  19. package/dist/waveform/envelope.js +34 -4
  20. package/dist/waveform/envelope.js.map +1 -1
  21. package/dist/waveform/full-waveform.d.ts +61 -75
  22. package/dist/waveform/full-waveform.d.ts.map +1 -1
  23. package/dist/waveform/full-waveform.js +115 -162
  24. package/dist/waveform/full-waveform.js.map +1 -1
  25. package/dist/waveform/index.js.map +1 -1
  26. package/dist/waveform/live-waveform.d.ts +63 -63
  27. package/dist/waveform/live-waveform.d.ts.map +1 -1
  28. package/dist/waveform/live-waveform.js +92 -134
  29. package/dist/waveform/live-waveform.js.map +1 -1
  30. package/dist/waveform/shared.d.ts +10 -8
  31. package/dist/waveform/shared.d.ts.map +1 -1
  32. package/dist/waveform/shared.js +14 -15
  33. package/dist/waveform/shared.js.map +1 -1
  34. package/package.json +7 -6
  35. package/registry.json +28 -28
  36. package/src/index.ts +2 -2
  37. package/src/kit.ts +22 -22
  38. package/src/nodes.ts +17 -19
  39. package/src/waveform/envelope.ts +176 -143
  40. package/src/waveform/full-waveform.ts +188 -218
  41. package/src/waveform/index.ts +30 -30
  42. package/src/waveform/live-waveform.ts +206 -221
  43. package/src/waveform/shared.ts +197 -194
  44. package/dist/browser/chunks/chunk-B3JXGNP6.js +0 -2
  45. package/dist/browser/chunks/chunk-B3JXGNP6.js.map +0 -7
@@ -1,34 +1,5 @@
1
- import { Node2D, type AssetScope, type CommandArgs, type Fill, type Node2DProps, type RenderContext2D } from "@motionscript/sdk";
2
- import type { Seekable } from "@motionscript/sdk/component";
1
+ import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps } from "@motionscript/sdk";
3
2
  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
3
  /**
33
4
  * A **waveform overview**: the whole recording's shape, drawn at once.
34
5
  *
@@ -40,7 +11,7 @@ export interface FullWaveformProps extends Node2DProps {
40
11
  *
41
12
  * ## Progress is authored, not assumed
42
13
  *
43
- * {@link follow} is off by default, and that default is the considered one. A
14
+ * `follow` is off by default, and that default is the considered one. A
44
15
  * scene has no idea where the recording it is drawing sits on the video's audio
45
16
  * lane — a clip is placed, trimmed and sped up out there, and none of that is
46
17
  * visible from in here. So the honest default is that the fill is *animation*:
@@ -52,53 +23,68 @@ export interface FullWaveformProps extends Node2DProps {
52
23
  *
53
24
  * ## Voices instead of progress
54
25
  *
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
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
58
28
  * floor, where the turns are, how long each one ran. It replaces the progress
59
29
  * colours rather than combining with them, because a bar cannot mean two things
60
30
  * at once and "played, and also Grace" is a legend nobody can hold in their
61
31
  * head.
62
32
  */
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
- }
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>>;
88
+ export type FullWaveform = NodeOf<typeof FullWaveform>;
89
+ export type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>;
104
90
  //# sourceMappingURL=full-waveform.d.ts.map
@@ -1 +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,mBAAmB,CAAA;AAG1B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/E,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,WAA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AQ;IAQhF;;;;OAIG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,sEAAsE;IACtE,OAAO,KAAK,MAAM,GAKjB;IAED,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;IAyChD;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ;CAQjB"}
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;;UAwBjC,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"}
@@ -1,13 +1,8 @@
1
- var __decorate = (this && this.__decorate) || 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/sdk";
8
- import { declarePaints } from "@motionscript/sdk/component";
1
+ import { Types, component2d, easeInOut, fillOps, } from "@motionscript/sdk";
9
2
  import { EMPTY_ENVELOPE, sampleEnvelope } from "./envelope.js";
10
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 });
11
6
  /**
12
7
  * A **waveform overview**: the whole recording's shape, drawn at once.
13
8
  *
@@ -19,7 +14,7 @@ import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./sha
19
14
  *
20
15
  * ## Progress is authored, not assumed
21
16
  *
22
- * {@link follow} is off by default, and that default is the considered one. A
17
+ * `follow` is off by default, and that default is the considered one. A
23
18
  * scene has no idea where the recording it is drawing sits on the video's audio
24
19
  * lane — a clip is placed, trimmed and sped up out there, and none of that is
25
20
  * visible from in here. So the honest default is that the fill is *animation*:
@@ -31,163 +26,121 @@ import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./sha
31
26
  *
32
27
  * ## Voices instead of progress
33
28
  *
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
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
37
31
  * floor, where the turns are, how long each one ran. It replaces the progress
38
32
  * colours rather than combining with them, because a bar cannot mean two things
39
33
  * at once and "played, and also Grace" is a legend nobody can hold in their
40
34
  * head.
41
35
  */
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,
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) }));
185
80
  },
186
- seed: {
187
- width: 900,
188
- height: 160,
189
- },
190
- })
191
- ], FullWaveform);
192
- export { FullWaveform };
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
+ }
193
146
  //# sourceMappingURL=full-waveform.js.map
@@ -1 +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,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,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;IAED;;;;OAIG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,UAA4B,CAAC,EAAE,CAAC,CAAA;IAC7E,CAAC;IAED,sEAAsE;IACtE,IAAY,MAAM;QAChB,IAAI,CAAC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,\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/sdk\"\n\nimport { declarePaints } from \"@motionscript/sdk/component\"\nimport type { Seekable } from \"@motionscript/sdk/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"]}
1
+ {"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,K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AAE,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 {\r\n Types,\r\n component2d,\r\n easeInOut,\r\n fillOps,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n type RenderContext,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\r\nimport {\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n type WaveformAlignment,\r\n} from \"./shared\"\r\n\r\n/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */\r\nconst paint = (initial: string) =>\r\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\r\n\r\n/**\r\n * A **waveform overview**: the whole recording's shape, drawn at once.\r\n *\r\n * The picture every audio editor opens with, and the one a podcast clip puts\r\n * under its caption — a static silhouette of the file, with a played portion\r\n * that advances. It answers \"how long is this and where are the loud parts\",\r\n * which is a question about the *file*, not about the moment; its sibling\r\n * {@link LiveWaveform} answers the other one.\r\n *\r\n * ## Progress is authored, not assumed\r\n *\r\n * `follow` is off by default, and that default is the considered one. A\r\n * scene has no idea where the recording it is drawing sits on the video's audio\r\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\r\n * visible from in here. So the honest default is that the fill is *animation*:\r\n * the author sweeps it with a command, the same as any other tween, and it lands\r\n * wherever they put it. `follow` is the shortcut for the common arrangement\r\n * where the node appears exactly as the track starts, and it says so by being a\r\n * switch someone has to turn on rather than a behaviour that quietly disagrees\r\n * with the mix.\r\n *\r\n * ## Voices instead of progress\r\n *\r\n * With `byVoice` on, the played/ahead split is replaced by one colour per\r\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\r\n * floor, where the turns are, how long each one ran. It replaces the progress\r\n * colours rather than combining with them, because a bar cannot mean two things\r\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\r\n * head.\r\n */\r\nexport const FullWaveform = component2d({\r\n key: \"fullWaveform\",\r\n state: {\r\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\r\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\r\n /** How many columns the whole file is drawn as. */\r\n bars: 120,\r\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\r\n gap: 0.3,\r\n /** Corner radius of a bar, capped at half its width. */\r\n radius: 2,\r\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\r\n progress: 0,\r\n /** Drive `progress` from the node's own clock instead of the prop. */\r\n follow: false,\r\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\r\n gain: 1,\r\n /** How much of the box a silent bar still occupies, `0`–`1`. */\r\n floor: 0.015,\r\n align: Types.custom<WaveformAlignment>(\"center\"),\r\n /** Colour each voice's turns rather than splitting on played / not played. */\r\n byVoice: false,\r\n /** A colour per voice index. Short or empty falls back to the palette. */\r\n voiceColors: Types.custom<string[]>([]),\r\n /** The bars ahead of the playhead. */\r\n fill: paint(\"#5b5b7a\"),\r\n /** …and the bars behind it. */\r\n playedFill: paint(\"#6366f1\"),\r\n },\r\n // Nothing declares a component's paints but itself: `fill` and `playedFill` both.\r\n load: (loader, state) => {\r\n loader.fill(state.fill)\r\n loader.fill(state.playedFill)\r\n },\r\n commands: {\r\n /**\r\n * Fill the waveform in, left to right — the node's one command, since\r\n * everything else about it is expressible as an ordinary `to`. Eased in-out\r\n * unless it is given an easing of its own.\r\n */\r\n sweep: (timeline, state) => {\r\n const ease = timeline.easing ? null : easeInOut()\r\n const from = state.progress\r\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\r\n },\r\n },\r\n render: (ctx, state) => {\r\n drawBars(ctx, state)\r\n ctx.children()\r\n },\r\n})\r\n\r\nexport type FullWaveform = NodeOf<typeof FullWaveform>\r\nexport type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>\r\n\r\ninterface FullState {\r\n readonly envelope: AudioEnvelope\r\n readonly bars: number\r\n readonly gap: number\r\n readonly radius: number\r\n readonly progress: number\r\n readonly follow: boolean\r\n readonly gain: number\r\n readonly floor: number\r\n readonly align: WaveformAlignment\r\n readonly byVoice: boolean\r\n readonly voiceColors: string[]\r\n readonly fill: FillResolved[]\r\n readonly playedFill: FillResolved[]\r\n}\r\n\r\nfunction drawBars(ctx: RenderContext, s: FullState): void {\r\n const { width, height } = ctx.size\r\n if (width <= 0 || height <= 0) return\r\n\r\n const count = Math.max(1, Math.round(s.bars))\r\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\r\n const boxes = layOutBars(sampled, {\r\n width,\r\n height,\r\n gap: s.gap,\r\n align: s.align,\r\n gain: s.gain,\r\n floor: s.floor,\r\n })\r\n if (boxes.length === 0) return\r\n\r\n // One draw per colour rather than per bar — see {@link paintBars}. The key\r\n // is a string because it has to be comparable; the paint it stands for is\r\n // resolved after the grouping.\r\n const edge = played(ctx, s) * boxes.length\r\n const groups = groupByPaint(boxes, (i) =>\r\n s.byVoice\r\n ? `voice:${sampled[i].speaker}`\r\n : i < edge\r\n ? \"played\"\r\n : \"ahead\"\r\n )\r\n\r\n for (const [key, run] of groups) {\r\n const graphics = paintBars(run, paintFor(s, key), s.radius)\r\n if (graphics) ctx.draw(graphics)\r\n }\r\n}\r\n\r\n/** Where the fill has reached, from whichever source is in charge. */\r\nfunction played(ctx: RenderContext, s: FullState): number {\r\n if (!s.follow) return clamp01(s.progress)\r\n const length = s.envelope.duration\r\n if (length <= 0) return 0\r\n return clamp01(ctx.time.elapsed / length)\r\n}\r\n\r\n/**\r\n * The paint a group takes.\r\n *\r\n * A voice's colour is a **colour string**, never one of the node's two fill\r\n * props, and that is deliberate: a voice is identified by hue, so a gradient\r\n * or an image there would defeat the only thing the colour is for. It also\r\n * means these paints declare no assets, which is why `load` only has to account\r\n * for the two real fill props.\r\n */\r\nfunction paintFor(s: FullState, key: string): Fill {\r\n if (key === \"played\") return s.playedFill\r\n if (key === \"ahead\") return s.fill\r\n\r\n const voice = Number(key.slice(\"voice:\".length))\r\n if (!Number.isFinite(voice) || voice < 0) return s.fill\r\n return s.voiceColors[voice] ?? voiceColor(voice)\r\n}\r\n"]}
@@ -1 +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"]}
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":["/**\r\n * The waveform family: one subject, two questions.\r\n *\r\n * - {@link FullWaveform} draws the **file** — the whole recording's silhouette,\r\n * with a played portion that advances. \"How long is this, and where are the\r\n * loud parts.\"\r\n * - {@link LiveWaveform} draws the **moment** — bars moving with playback, the\r\n * visualiser a podcast clip puts beside the artwork. \"Is anything happening\r\n * right now, and whose voice is it.\"\r\n *\r\n * Both read the same baked {@link AudioEnvelope}, which is why they cannot\r\n * disagree about a recording, and why neither listens to anything — see that\r\n * module for why a scene that has to export cannot use a live analyser.\r\n */\r\nexport { FullWaveform } from \"./full-waveform\"\r\nexport type { FullWaveformProps } from \"./full-waveform\"\r\nexport { LiveWaveform } from \"./live-waveform\"\r\nexport type { LiveWaveformProps } from \"./live-waveform\"\r\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./envelope\"\r\nexport type { AudioEnvelope, EnvelopeBar } from \"./envelope\"\r\nexport {\r\n VOICE_PALETTE,\r\n WAVEFORM_ALIGNMENTS,\r\n WAVEFORM_STYLES,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n} from \"./shared\"\r\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./shared\"\r\n"]}