@motionscript/audio 0.1.0-alpha.0 → 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 (37) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/NOTICE +49 -0
  3. package/README.md +92 -0
  4. package/dist/browser/chunks/chunk-DD3KHRUL.js +2 -0
  5. package/dist/browser/chunks/chunk-DD3KHRUL.js.map +7 -0
  6. package/dist/browser/index.js +1 -1
  7. package/dist/browser/index.js.map +3 -3
  8. package/dist/browser/kit.js +1 -1
  9. package/dist/browser/manifest.json +4 -3
  10. package/dist/nodes.d.ts +6 -9
  11. package/dist/nodes.d.ts.map +1 -1
  12. package/dist/nodes.js +7 -9
  13. package/dist/nodes.js.map +1 -1
  14. package/dist/waveform/envelope.d.ts +42 -9
  15. package/dist/waveform/envelope.d.ts.map +1 -1
  16. package/dist/waveform/envelope.js +34 -4
  17. package/dist/waveform/envelope.js.map +1 -1
  18. package/dist/waveform/full-waveform.d.ts +89 -75
  19. package/dist/waveform/full-waveform.d.ts.map +1 -1
  20. package/dist/waveform/full-waveform.js +115 -162
  21. package/dist/waveform/full-waveform.js.map +1 -1
  22. package/dist/waveform/live-waveform.d.ts +93 -63
  23. package/dist/waveform/live-waveform.d.ts.map +1 -1
  24. package/dist/waveform/live-waveform.js +92 -134
  25. package/dist/waveform/live-waveform.js.map +1 -1
  26. package/dist/waveform/shared.d.ts +11 -9
  27. package/dist/waveform/shared.d.ts.map +1 -1
  28. package/dist/waveform/shared.js +15 -16
  29. package/dist/waveform/shared.js.map +1 -1
  30. package/package.json +8 -5
  31. package/src/nodes.ts +8 -10
  32. package/src/waveform/envelope.ts +42 -9
  33. package/src/waveform/full-waveform.ts +130 -160
  34. package/src/waveform/live-waveform.ts +114 -129
  35. package/src/waveform/shared.ts +20 -17
  36. package/dist/browser/chunks/chunk-U5OUQJHQ.js +0 -2
  37. package/dist/browser/chunks/chunk-U5OUQJHQ.js.map +0 -7
@@ -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/core";
8
- import { declarePaints } from "@motionscript/core/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,oBAAoB,CAAA;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAA;AAC/E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GAEX,MAAM,UAAU,CAAA;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAgBI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,MAAyB;IA2BzD;;;OAGG;IAEH,KAAK,CAAC,IAA+D;QACnE,OAAO,IAAI,CAAC,EAAE,CAAC;YACb,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAgC;YACnD,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS,EAAE;SACnC,CAAC,CAAA;IACJ,CAAC;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;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,CAoHxB","sourcesContent":["import {\n Node2D,\n node,\n command,\n easeInOut,\n fillOps,\n property,\n type AssetScope,\n type CommandArgs,\n type Fill,\n type FillResolved,\n type Node2DProps,\n type RenderContext2D,\n} from \"@motionscript/core\"\n\nimport { declarePaints } from \"@motionscript/core/component\"\nimport type { Seekable } from \"@motionscript/core/component\"\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\nexport interface FullWaveformProps extends Node2DProps {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: AudioEnvelope\n /** How many columns the whole file is drawn as. */\n bars: number\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: number\n /** Corner radius of a bar, capped at half its width. */\n radius: number\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: number\n /** Drive {@link progress} from the node's own clock instead of the prop. */\n follow: boolean\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: number\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: number\n align: WaveformAlignment\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: boolean\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: string[]\n /** The bars ahead of the playhead. */\n fill: Fill\n /** …and the bars behind it. */\n playedFill: Fill\n}\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * {@link follow} is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\n * speaking voice — the drawing the timeline's clip bars already make, at a size\n * you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\n@node({\n key: \"fullWaveform\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"freeform\",\n defaultWidthMode: \"fixed\",\n defaultHeightMode: \"fixed\",\n acceptsChildren: true,\n },\n seed: {\n width: 900,\n height: 160,\n },\n})\nexport class FullWaveform extends Node2D<FullWaveformProps> {\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\n @property({ default: 120 }) declare bars: number\n @property({ default: 0.3 }) declare gap: number\n @property({ default: 2 }) declare radius: number\n @property({ default: 0 }) declare progress: number\n @property({ default: false }) declare follow: boolean\n @property({ default: 1 }) declare gain: number\n @property({ default: 0.015 }) declare floor: number\n @property({ default: \"center\" }) declare align: WaveformAlignment\n @property({ default: false }) declare byVoice: boolean\n @property({ default: [] }) declare voiceColors: string[]\n\n @property({\n default: \"#5b5b7a\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n\n @property({\n default: \"#6366f1\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare playedFill: Fill\n\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`.\n */\n @command()\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\n return this.to({\n data: { progress: 1 } as Partial<FullWaveformProps>,\n duration: args.duration,\n easing: args.easing ?? easeInOut(),\n })\n }\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\n * past the conventional slots, so it is passed explicitly.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\n }\n\n /** Where the fill has reached, from whichever source is in charge. */\n private get played(): number {\n if (!this.follow) return clamp01(this.progress)\n const length = this.envelope.duration\n if (length <= 0) return 0\n return clamp01(this.time.elapsed / length)\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const rect = this.layoutBounds\n const width = rect?.width ?? 0\n const height = rect?.height ?? 0\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(this.bars))\n const sampled = sampleEnvelope(\n this.envelope,\n 0,\n this.envelope.duration,\n count\n )\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: this.gap,\n align: this.align,\n gain: this.gain,\n floor: this.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = this.played * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n this.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, this.paintFor(key), this.radius)\n if (graphics) ctx.draw(graphics)\n }\n }\n\n /**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why {@link declareAssets}\n * only has to account for the two real fill props.\n */\n private paintFor(key: string): Fill {\n if (key === \"played\") return this.playedFill\n if (key === \"ahead\") return this.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return this.fill\n return this.voiceColors[voice] ?? voiceColor(voice)\n }\n}\n"]}
1
+ {"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-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Q,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"]}
@@ -1,37 +1,5 @@
1
- import { Node2D, type AssetScope, type Fill, type Node2DProps, type RenderContext2D } from "@motionscript/core";
1
+ import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps } from "@motionscript/sdk";
2
2
  import { type AudioEnvelope } from "./envelope.js";
3
- import { type WaveformAlignment, type WaveformStyle } from "./shared.js";
4
- export interface LiveWaveformProps extends Node2DProps {
5
- /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
6
- envelope: AudioEnvelope;
7
- /** How many bars the visualiser is made of. */
8
- bars: number;
9
- /** Space between bars, as a fraction of the pitch. */
10
- gap: number;
11
- radius: number;
12
- /** How many seconds of audio are on screen at once. */
13
- window: number;
14
- /** Seconds into the file the node's first frame shows. */
15
- offset: number;
16
- /** Advance with the scene clock. Off freezes the picture at {@link offset}. */
17
- playing: boolean;
18
- /** Multiplies every magnitude before it is clamped. */
19
- gain: number;
20
- /** How much of the box a silent bar still occupies, `0`–`1`. */
21
- floor: number;
22
- align: WaveformAlignment;
23
- style: WaveformStyle;
24
- /**
25
- * Show only this voice's activity, by index into the recording's own
26
- * numbering. `-1` — the default — is every voice.
27
- */
28
- speaker: number;
29
- /** Colour each bar by whoever is speaking in it. */
30
- byVoice: boolean;
31
- /** A colour per voice index. Short or empty falls back to the palette. */
32
- voiceColors: string[];
33
- fill: Fill;
34
- }
35
3
  /**
36
4
  * A **live audio visualiser**: bars that move with the recording as it plays.
37
5
  *
@@ -52,7 +20,7 @@ export interface LiveWaveformProps extends Node2DProps {
52
20
  *
53
21
  * ## The speaker filter
54
22
  *
55
- * {@link speaker} narrows the node to one voice of a diarized recording, and it
23
+ * `speaker` narrows the node to one voice of a diarized recording, and it
56
24
  * is the reason this node knows about transcripts at all. Two visualisers beside
57
25
  * two headshots, each filtered to its own host, is a podcast edit that would
58
26
  * otherwise be done by hand for every turn — and because the filter *silences*
@@ -65,35 +33,97 @@ export interface LiveWaveformProps extends Node2DProps {
65
33
  * true, where falling back to the unfiltered mix would be a silent lie about
66
34
  * whose voice you were watching.
67
35
  */
68
- export declare class LiveWaveform extends Node2D<LiveWaveformProps> {
69
- envelope: AudioEnvelope;
70
- bars: number;
71
- gap: number;
72
- radius: number;
73
- window: number;
74
- offset: number;
75
- playing: boolean;
76
- gain: number;
77
- floor: number;
78
- align: WaveformAlignment;
79
- style: WaveformStyle;
80
- speaker: number;
81
- byVoice: boolean;
82
- voiceColors: string[];
83
- fill: Fill;
84
- declareAssets(assets: AssetScope): void;
36
+ export declare const LiveWaveform: import("@motionscript/sdk").Component<"liveWaveform", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
37
+ /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
38
+ readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
39
+ /** How many bars the visualiser is made of. */
40
+ readonly bars: 48;
41
+ /** Space between bars, as a fraction of the pitch. */
42
+ readonly gap: 0.35;
43
+ readonly radius: 4;
44
+ /** How many seconds of audio are on screen at once. */
45
+ readonly window: 3;
46
+ /** Seconds into the file the node's first frame shows. */
47
+ readonly offset: 0;
48
+ /** Advance with the scene clock. Off freezes the picture at `offset`. */
49
+ readonly playing: true;
50
+ /** Multiplies every magnitude before it is clamped. */
51
+ readonly gain: 1.4;
52
+ /** How much of the box a silent bar still occupies, `0`–`1`. */
53
+ readonly floor: 0.04;
54
+ readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
55
+ readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
56
+ /**
57
+ * Show only this voice's activity, by index into the recording's own
58
+ * numbering. `-1` — the default — is every voice.
59
+ */
60
+ readonly speaker: -1;
61
+ /** Colour each bar by whoever is speaking in it. */
62
+ readonly byVoice: false;
63
+ /** A colour per voice index. Short or empty falls back to the palette. */
64
+ readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
65
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
66
+ }>, {}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
67
+ /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
68
+ readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
69
+ /** How many bars the visualiser is made of. */
70
+ readonly bars: 48;
71
+ /** Space between bars, as a fraction of the pitch. */
72
+ readonly gap: 0.35;
73
+ readonly radius: 4;
74
+ /** How many seconds of audio are on screen at once. */
75
+ readonly window: 3;
76
+ /** Seconds into the file the node's first frame shows. */
77
+ readonly offset: 0;
78
+ /** Advance with the scene clock. Off freezes the picture at `offset`. */
79
+ readonly playing: true;
80
+ /** Multiplies every magnitude before it is clamped. */
81
+ readonly gain: 1.4;
82
+ /** How much of the box a silent bar still occupies, `0`–`1`. */
83
+ readonly floor: 0.04;
84
+ readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
85
+ readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
85
86
  /**
86
- * The second of the recording the visualiser is showing.
87
- *
88
- * Off the node's own clock rather than the scene's, which is what "from the
89
- * moment this node appeared" means — the same clock motion-script's own
90
- * `Video` times its picture from, and the same one that makes a node dropped
91
- * halfway through a scene start its recording at its entrance rather than
92
- * partway in.
87
+ * Show only this voice's activity, by index into the recording's own
88
+ * numbering. `-1` — the default — is every voice.
93
89
  */
94
- private get at();
95
- protected renderSelf(ctx: RenderContext2D): void;
96
- /** See {@link FullWaveform.paintFor} — a voice is a hue, never a gradient. */
97
- private paintFor;
98
- }
90
+ readonly speaker: -1;
91
+ /** Colour each bar by whoever is speaking in it. */
92
+ readonly byVoice: false;
93
+ /** A colour per voice index. Short or empty falls back to the palette. */
94
+ readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
95
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
96
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
97
+ /** The baked recording. See {@link AudioEnvelope} for why it is baked. */
98
+ readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
99
+ /** How many bars the visualiser is made of. */
100
+ readonly bars: 48;
101
+ /** Space between bars, as a fraction of the pitch. */
102
+ readonly gap: 0.35;
103
+ readonly radius: 4;
104
+ /** How many seconds of audio are on screen at once. */
105
+ readonly window: 3;
106
+ /** Seconds into the file the node's first frame shows. */
107
+ readonly offset: 0;
108
+ /** Advance with the scene clock. Off freezes the picture at `offset`. */
109
+ readonly playing: true;
110
+ /** Multiplies every magnitude before it is clamped. */
111
+ readonly gain: 1.4;
112
+ /** How much of the box a silent bar still occupies, `0`–`1`. */
113
+ readonly floor: 0.04;
114
+ readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
115
+ readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
116
+ /**
117
+ * Show only this voice's activity, by index into the recording's own
118
+ * numbering. `-1` — the default — is every voice.
119
+ */
120
+ readonly speaker: -1;
121
+ /** Colour each bar by whoever is speaking in it. */
122
+ readonly byVoice: false;
123
+ /** A colour per voice index. Short or empty falls back to the palette. */
124
+ readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
125
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
126
+ }>, {}, _Node2D<_Node2DProps>>>>;
127
+ export type LiveWaveform = NodeOf<typeof LiveWaveform>;
128
+ export type LiveWaveformProps = NonNullable<Parameters<typeof LiveWaveform>[0]>;
99
129
  //# sourceMappingURL=live-waveform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIN,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAOL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,0EAA0E;IAC1E,QAAQ,EAAE,aAAa,CAAA;IACvB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAA;IACd,+EAA+E;IAC/E,OAAO,EAAE,OAAO,CAAA;IAChB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAA;IACZ,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,iBAAiB,CAAA;IACxB,KAAK,EAAE,aAAa,CAAA;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;IACf,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAA;IAChB,0EAA0E;IAC1E,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,IAAI,EAAE,IAAI,CAAA;CACX;AAED;;;;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