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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/dist/browser/chunks/chunk-U5OUQJHQ.js +2 -0
  4. package/dist/browser/chunks/chunk-U5OUQJHQ.js.map +7 -0
  5. package/dist/browser/index.js +2 -0
  6. package/dist/browser/index.js.map +7 -0
  7. package/dist/browser/kit.js +2 -0
  8. package/dist/browser/kit.js.map +7 -0
  9. package/dist/browser/manifest.json +12 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +3 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/kit.d.ts +13 -0
  15. package/dist/kit.d.ts.map +1 -0
  16. package/dist/kit.js +11 -0
  17. package/dist/kit.js.map +1 -0
  18. package/dist/nodes.d.ts +19 -0
  19. package/dist/nodes.d.ts.map +1 -0
  20. package/dist/nodes.js +19 -0
  21. package/dist/nodes.js.map +1 -0
  22. package/dist/waveform/envelope.d.ts +87 -0
  23. package/dist/waveform/envelope.d.ts.map +1 -0
  24. package/dist/waveform/envelope.js +96 -0
  25. package/dist/waveform/envelope.js.map +1 -0
  26. package/dist/waveform/full-waveform.d.ts +104 -0
  27. package/dist/waveform/full-waveform.d.ts.map +1 -0
  28. package/dist/waveform/full-waveform.js +193 -0
  29. package/dist/waveform/full-waveform.js.map +1 -0
  30. package/dist/waveform/index.d.ts +23 -0
  31. package/dist/waveform/index.d.ts.map +1 -0
  32. package/dist/waveform/index.js +19 -0
  33. package/dist/waveform/index.js.map +1 -0
  34. package/dist/waveform/live-waveform.d.ts +99 -0
  35. package/dist/waveform/live-waveform.d.ts.map +1 -0
  36. package/dist/waveform/live-waveform.js +191 -0
  37. package/dist/waveform/live-waveform.js.map +1 -0
  38. package/dist/waveform/shared.d.ts +96 -0
  39. package/dist/waveform/shared.d.ts.map +1 -0
  40. package/dist/waveform/shared.js +150 -0
  41. package/dist/waveform/shared.js.map +1 -0
  42. package/package.json +69 -3
  43. package/registry.json +28 -0
  44. package/src/index.ts +2 -0
  45. package/src/kit.ts +22 -0
  46. package/src/nodes.ts +19 -0
  47. package/src/waveform/envelope.ts +143 -0
  48. package/src/waveform/full-waveform.ts +218 -0
  49. package/src/waveform/index.ts +30 -0
  50. package/src/waveform/live-waveform.ts +221 -0
  51. package/src/waveform/shared.ts +194 -0
  52. package/README.md +0 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # @motionscript/audio
2
+
3
+ ## 0.1.0-alpha.0
4
+
5
+ Initial release.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ var E={magnitude:new Float32Array(0),duration:0,speaker:null,speakers:0};function y(t,r,e,o){let n=Math.max(0,Math.floor(o)),a=new Array(n);for(let i=0;i<n;i++)a[i]={magnitude:0,speaker:-1};let l=t.magnitude.length;if(n===0||l===0||t.duration<=0)return a;let d=l/t.duration,u=(e-r)/n;for(let i=0;i<n;i++){let f=(r+u*i)*d,m=(r+u*(i+1))*d,p=Math.floor(f),s=Math.max(p,Math.ceil(m)-1),g=0,h=-1;for(let c=p;c<=s;c++){if(c<0||c>=l)continue;let k=t.magnitude[c];k<g||(g=k,h=t.speaker?t.speaker[c]:-1)}a[i]={magnitude:g,speaker:h}}return a}function A(t,r){return r===null?t:t.map(e=>e.speaker===r?e:{magnitude:0,speaker:e.speaker})}import{Graphics2D as w}from"@motionscript/core";var S=["center","bottom"],T=["bars","line","blocks"],x=["#6366f1","#14b8a6","#f59e0b","#ec4899","#22c55e","#3b82f6","#f97316","#a855f7"];function L(t){return x[(t%x.length+x.length)%x.length]}function _(t,r){let{width:e,height:o,gap:n,align:a,gain:l,floor:d}=r,u=t.length;if(u===0||e<=0||o<=0)return[];let i=e/u,f=Math.max(1,i*(1-M(n))),m=a==="center"?o/2:o,p=new Array(u);for(let s=0;s<u;s++){let g=M(t[s].magnitude*l),h=Math.max(m*M(d),m*g),c=-e/2+i*s+(i-f)/2;p[s]=a==="center"?{x:c,y:-h,width:f,height:Math.max(1,h*2)}:{x:c,y:o/2-h,width:f,height:Math.max(1,h)}}return p}function b(t,r,e){if(t.length===0||r.length===0)return null;let o=new w;for(let n of t)o.rect({x:n.x+n.width/2,y:n.y+n.height/2,width:n.width,height:n.height,cornerRadius:Math.min(e,n.width/2,n.height/2)});return o.fill(r)}function B(t,r){let e=new Map;for(let o=0;o<t.length;o++){let n=r(o),a=e.get(n);a?a.push(t[o]):e.set(n,[t[o]])}return e}function M(t){return t<0?0:t>1?1:t}function F(t,r,e){return e!==null?`voice:${e}`:r?`voice:${t}`:"all"}export{E as a,y as b,A as c,S as d,T as e,x as f,L as g,_ as h,b as i,B as j,M as k,F as l};
2
+ //# sourceMappingURL=chunk-U5OUQJHQ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/waveform/envelope.ts", "../../../src/waveform/shared.ts"],
4
+ "sourcesContent": ["/**\n * The shape of a recording, as the waveform nodes draw it.\n *\n * ## Why the data is baked rather than listened to\n *\n * A scene has to render identically in the preview and in a headless export,\n * and an export has no audio device, no `AudioContext` and no playback to\n * analyse. So a \"live\" visualiser cannot read a Web Audio analyser: what it\n * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is\n * then a pure function of time, which is what makes scrubbing backwards, jumping\n * to frame 900, and rendering out of order all produce the same frame.\n *\n * The decode happens in the app, once per file, and arrives here through the\n * build (see `SceneAsset.envelope`) — the same arrangement a chart's rows and a\n * protein's atoms already use, and for the same reason: the build is\n * synchronous and cannot await a fetch.\n *\n * ## Why magnitude rather than min/max\n *\n * An editor's waveform is drawn from per-bucket minima *and* maxima, because an\n * editor is a measuring instrument. These nodes are neither — they are a bar\n * chart of loudness that happens to be shaped like a recording — and audio is\n * near enough symmetric that a mirrored magnitude is indistinguishable at the\n * size a node draws. Half the numbers, and one array to reason about.\n */\n\n/**\n * A decoded recording, reduced to a uniform grid of loudness — plus, when the\n * app knows it, who is talking in each bucket.\n *\n * The speaker track is **not** something a decoder can produce; it comes from a\n * diarized transcript and is folded in by the app before the build. It lives\n * here rather than in a parallel structure because every reader of it is also a\n * reader of the magnitudes at the same index, and two arrays that must stay the\n * same length are better as one object than as two arguments.\n */\nexport interface AudioEnvelope {\n /** Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. */\n magnitude: Float32Array\n /** The decoded length in seconds. */\n duration: number\n /**\n * Which voice is speaking in each bucket, as an index into the recording's\n * own numbering, or `-1` for \"nobody identified\". Parallel to\n * {@link magnitude}, or `null` when the track was never diarized.\n */\n speaker: Int16Array | null\n /** How many distinct voices the diarizer found. Zero when it did not run. */\n speakers: number\n}\n\n/** The envelope of a track that hasn't loaded — or isn't there. */\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\n magnitude: new Float32Array(0),\n duration: 0,\n speaker: null,\n speakers: 0,\n}\n\n/** One drawn bar: how loud, and whose. */\nexport interface EnvelopeBar {\n /** 0…1. */\n magnitude: number\n /** The voice index, or -1. */\n speaker: number\n}\n\n/**\n * Resamples `[from, to)` seconds of an envelope down to `bars` columns.\n *\n * Peak-preserving rather than averaging, which is the whole difference between\n * a waveform and a blur: averaging a hundred buckets into one column flattens\n * every transient, and transients are what makes a drawn recording read as\n * speech rather than as noise. The speaker of a column is the speaker of its\n * *loudest* bucket, on the same reasoning — a column straddling a turn belongs\n * to whoever is actually audible in it.\n *\n * A window past either end of the recording yields silent, unattributed\n * columns rather than clamping onto the nearest real one. That matters for the\n * live visualiser, which is handed a window centred on the playhead and would\n * otherwise smear the first bucket across the whole run-up to a track's start.\n */\nexport function sampleEnvelope(\n envelope: AudioEnvelope,\n from: number,\n to: number,\n bars: number\n): EnvelopeBar[] {\n const count = Math.max(0, Math.floor(bars))\n const out: EnvelopeBar[] = new Array(count)\n for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }\n\n const buckets = envelope.magnitude.length\n if (count === 0 || buckets === 0 || envelope.duration <= 0) return out\n\n const perSecond = buckets / envelope.duration\n const span = (to - from) / count\n\n for (let i = 0; i < count; i++) {\n const start = (from + span * i) * perSecond\n const end = (from + span * (i + 1)) * perSecond\n\n // At least one bucket per column, so a window zoomed in past the grid draws\n // the sample it is standing on rather than an empty band.\n const first = Math.floor(start)\n const last = Math.max(first, Math.ceil(end) - 1)\n\n let loudest = 0\n let speaker = -1\n for (let b = first; b <= last; b++) {\n if (b < 0 || b >= buckets) continue\n const value = envelope.magnitude[b]\n if (value < loudest) continue\n loudest = value\n speaker = envelope.speaker ? envelope.speaker[b] : -1\n }\n\n out[i] = { magnitude: loudest, speaker }\n }\n\n return out\n}\n\n/**\n * The same window, with everything that isn't `voice` silenced.\n *\n * The point of the speaker filter, and the reason it silences rather than\n * *drops*: a podcast visualiser filtered to one host should go quiet while the\n * other one talks, not compress their turn out of existence. Keeping the bars\n * and zeroing them is what makes the picture read as \"this person is not\n * speaking right now\" instead of as a jump cut.\n *\n * `voice` of `null` returns the bars untouched, which is the unfiltered node.\n */\nexport function forSpeaker(\n bars: EnvelopeBar[],\n voice: number | null\n): EnvelopeBar[] {\n if (voice === null) return bars\n return bars.map((bar) =>\n bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }\n )\n}\n", "import { Graphics2D, type Fill, type FillResolved } from \"@motionscript/core\"\n\nimport type { EnvelopeBar } from \"./envelope\"\n\n/**\n * Geometry and paint shared by the two waveform nodes.\n *\n * They draw the same object — a row of bars whose heights are loudness — and\n * differ only in what decides the heights: the whole file for one, a window\n * around the playhead for the other. Everything about *how a row of bars is\n * laid out and painted* is therefore common, and lives here so the two cannot\n * drift into looking like different components.\n */\n\n/** How a bar is grown out of its baseline. */\nexport const WAVEFORM_ALIGNMENTS = [\"center\", \"bottom\"] as const\nexport type WaveformAlignment = (typeof WAVEFORM_ALIGNMENTS)[number]\n\n/** What the bars are shaped like. */\nexport const WAVEFORM_STYLES = [\"bars\", \"line\", \"blocks\"] as const\nexport type WaveformStyle = (typeof WAVEFORM_STYLES)[number]\n\n/**\n * The colours voices are drawn in when nobody has assigned any.\n *\n * The same eight the app's speaker library suggests, in the same order, so a\n * transcript whose voices are still unnamed already draws in the colours the\n * transcript panel is showing them in. Duplicated as literals rather than\n * imported because `scene-core` knows nothing about the app's speaker table —\n * and must not, since a scene has to build in a headless render with no\n * database in scope.\n */\nexport const VOICE_PALETTE = [\n \"#6366f1\",\n \"#14b8a6\",\n \"#f59e0b\",\n \"#ec4899\",\n \"#22c55e\",\n \"#3b82f6\",\n \"#f97316\",\n \"#a855f7\",\n] as const\n\n/** The colour a voice takes, wrapping past the end of the palette. */\nexport function voiceColor(index: number): string {\n return VOICE_PALETTE[\n ((index % VOICE_PALETTE.length) + VOICE_PALETTE.length) %\n VOICE_PALETTE.length\n ]\n}\n\n/** Where one bar sits and how tall it came out. */\nexport interface BarBox {\n x: number\n y: number\n width: number\n height: number\n}\n\n/**\n * Lays a row of bars out across a box.\n *\n * The gap is stated as a *fraction of the pitch* rather than in pixels, and\n * that is the one decision here worth stating out loud: the bar count is a\n * control, so a gap in pixels would silently become a solid block at 200 bars\n * and a picket fence at 20. As a fraction, the row keeps the same rhythm at\n * every density — which is what lets the count be a slider anyone can drag.\n *\n * A bar is never thinner than a hairline and never shorter than one either: a\n * silent passage has to read as \"audio, and nothing here\" rather than as a hole\n * in the drawing, exactly as it does on the timeline's clip bars.\n */\nexport function layOutBars(\n bars: readonly EnvelopeBar[],\n options: {\n width: number\n height: number\n gap: number\n align: WaveformAlignment\n /** Multiplies every magnitude before it is clamped back into 0…1. */\n gain: number\n /** Fraction of the box a silent bar still occupies. */\n floor: number\n }\n): BarBox[] {\n const { width, height, gap, align, gain, floor } = options\n const count = bars.length\n if (count === 0 || width <= 0 || height <= 0) return []\n\n const pitch = width / count\n const barWidth = Math.max(1, pitch * (1 - clamp01(gap)))\n // The tallest a bar may be. Centre-aligned bars grow both ways from the\n // middle, so the *half* is what a magnitude of 1 fills.\n const full = align === \"center\" ? height / 2 : height\n\n const out: BarBox[] = new Array(count)\n for (let i = 0; i < count; i++) {\n const magnitude = clamp01(bars[i].magnitude * gain)\n const reach = Math.max(full * clamp01(floor), full * magnitude)\n const x = -width / 2 + pitch * i + (pitch - barWidth) / 2\n\n out[i] =\n align === \"center\"\n ? { x, y: -reach, width: barWidth, height: Math.max(1, reach * 2) }\n : {\n x,\n y: height / 2 - reach,\n width: barWidth,\n height: Math.max(1, reach),\n }\n }\n return out\n}\n\n/**\n * Draws a run of bars in one paint.\n *\n * Batched by colour by the caller, and this is why: every `Graphics2D` handed to\n * `ctx.draw` is a surface the renderer composites, so a bar apiece would be a\n * thousand surfaces a frame. Chaining the rects of one colour into a single\n * `Graphics2D` before filling makes it one — and, as a bonus, a gradient fill\n * maps across the whole run rather than restarting inside every bar, which is\n * the behaviour anyone reaching for a gradient here actually wants.\n */\nexport function paintBars(\n boxes: readonly BarBox[],\n fill: Fill,\n radius: number\n): Graphics2D | null {\n if (boxes.length === 0) return null\n if ((fill as FillResolved[]).length === 0) return null\n\n const graphics = new Graphics2D()\n for (const box of boxes) {\n graphics.rect({\n x: box.x + box.width / 2,\n y: box.y + box.height / 2,\n width: box.width,\n height: box.height,\n // Never rounder than the bar is wide, or a thin bar becomes a lozenge\n // whose ends taper away to nothing.\n cornerRadius: Math.min(radius, box.width / 2, box.height / 2),\n })\n }\n return graphics.fill(fill)\n}\n\n/**\n * Groups bars by the paint they take, preserving order within each group.\n *\n * The seam that makes {@link paintBars} worth batching: a diarized waveform has\n * as many colours as it has voices, not as many as it has bars, so a\n * conversation of two people is two draws however long it runs.\n */\nexport function groupByPaint<K>(\n boxes: readonly BarBox[],\n keyOf: (index: number) => K\n): Map<K, BarBox[]> {\n const groups = new Map<K, BarBox[]>()\n for (let i = 0; i < boxes.length; i++) {\n const key = keyOf(i)\n const run = groups.get(key)\n if (run) run.push(boxes[i])\n else groups.set(key, [boxes[i]])\n }\n return groups\n}\n\nexport function clamp01(value: number): number {\n return value < 0 ? 0 : value > 1 ? 1 : value\n}\n\n/**\n * The {@link groupByPaint} key one bar of a live visualiser takes.\n *\n * Filtered to one voice, every bar is that voice regardless of `byVoice` or\n * whose turn the bucket originally belonged to. That second part is the one\n * worth spelling out: {@link forSpeaker} silences a bar by zeroing its\n * magnitude but leaves `speaker` exactly as it was, so a bar sitting in the\n * middle of a *different* voice's turn is still stamped with that voice's\n * index — grouping by `byVoice`'s usual per-bar key would paint those silent\n * stretches in whoever used to be talking there, in flickers too short to\n * read as anything but noise. Forcing every bar under the filtered voice's own\n * key is the true picture instead: the node is drawing exactly one person, on\n * or off, never anyone else's colour.\n */\nexport function livePaintKey(\n barSpeaker: number,\n byVoice: boolean,\n filteredVoice: number | null\n): string {\n if (filteredVoice !== null) return `voice:${filteredVoice}`\n return byVoice ? `voice:${barSpeaker}` : \"all\"\n}\n"],
5
+ "mappings": "AAoDO,IAAMA,EAAgC,CAC3C,UAAW,IAAI,aAAa,CAAC,EAC7B,SAAU,EACV,QAAS,KACT,SAAU,GA0BN,SAAUC,EACdC,EACAC,EACAC,EACAC,EAAY,CAEZ,IAAMC,EAAQ,KAAK,IAAI,EAAG,KAAK,MAAMD,CAAI,CAAC,EACpCE,EAAqB,IAAI,MAAMD,CAAK,EAC1C,QAAS,EAAI,EAAG,EAAIA,EAAO,IAAKC,EAAI,CAAC,EAAI,CAAE,UAAW,EAAG,QAAS,EAAE,EAEpE,IAAMC,EAAUN,EAAS,UAAU,OACnC,GAAII,IAAU,GAAKE,IAAY,GAAKN,EAAS,UAAY,EAAG,OAAOK,EAEnE,IAAME,EAAYD,EAAUN,EAAS,SAC/BQ,GAAQN,EAAKD,GAAQG,EAE3B,QAAS,EAAI,EAAG,EAAIA,EAAO,IAAK,CAC9B,IAAMK,GAASR,EAAOO,EAAO,GAAKD,EAC5BG,GAAO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,CAEM,SAAUf,EAAQkB,EAAa,CACnC,OAAOA,EAAQ,EAAI,EAAIA,EAAQ,EAAI,EAAIA,CACzC,CAgBM,SAAUC,EACdC,EACAC,EACAC,EAA4B,CAE5B,OAAIA,IAAkB,KAAa,SAASA,CAAa,GAClDD,EAAU,SAASD,CAAU,GAAK,KAC3C",
6
+ "names": ["EMPTY_ENVELOPE", "sampleEnvelope", "envelope", "from", "to", "bars", "count", "out", "buckets", "perSecond", "span", "start", "end", "first", "last", "loudest", "speaker", "b", "value", "forSpeaker", "voice", "bar", "Graphics2D", "WAVEFORM_ALIGNMENTS", "WAVEFORM_STYLES", "VOICE_PALETTE", "voiceColor", "index", "layOutBars", "bars", "options", "width", "height", "gap", "align", "gain", "floor", "count", "pitch", "barWidth", "clamp01", "full", "out", "i", "magnitude", "reach", "x", "paintBars", "boxes", "fill", "radius", "graphics", "box", "groupByPaint", "keyOf", "groups", "key", "run", "value", "livePaintKey", "barSpeaker", "byVoice", "filteredVoice"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as v,b as m,c as _,d as V,e as S,f as A,g as y,h as g,i as E,j as b,k as w,l as B}from"./chunks/chunk-U5OUQJHQ.js";import{Node2D as R,node as T,command as j,easeInOut as D,fillOps as F,property as h}from"@motionscript/core";import{declarePaints as k}from"@motionscript/core/component";var n=function(u,e,t,l){var a=arguments.length,o=a<3?e:l===null?l=Object.getOwnPropertyDescriptor(e,t):l,p;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(u,e,t,l);else for(var d=u.length-1;d>=0;d--)(p=u[d])&&(o=(a<3?p(o):a>3?p(e,t,o):p(e,t))||o);return a>3&&o&&Object.defineProperty(e,t,o),o},i=class extends R{sweep(e){return this.to({data:{progress:1},duration:e.duration,easing:e.easing??D()})}declareAssets(e){super.declareAssets(e),k(this,e,{fills:[this.playedFill]})}get played(){if(!this.follow)return w(this.progress);let e=this.envelope.duration;return e<=0?0:w(this.time.elapsed/e)}renderSelf(e){let t=this.layoutBounds,l=t?.width??0,a=t?.height??0;if(l<=0||a<=0)return;let o=Math.max(1,Math.round(this.bars)),p=m(this.envelope,0,this.envelope.duration,o),d=g(p,{width:l,height:a,gap:this.gap,align:this.align,gain:this.gain,floor:this.floor});if(d.length===0)return;let x=this.played*d.length,M=b(d,c=>this.byVoice?`voice:${p[c].speaker}`:c<x?"played":"ahead");for(let[c,O]of M){let P=E(O,this.paintFor(c),this.radius);P&&e.draw(P)}}paintFor(e){if(e==="played")return this.playedFill;if(e==="ahead")return this.fill;let t=Number(e.slice(6));return!Number.isFinite(t)||t<0?this.fill:this.voiceColors[t]??y(t)}};n([h({default:v})],i.prototype,"envelope",void 0);n([h({default:120})],i.prototype,"bars",void 0);n([h({default:.3})],i.prototype,"gap",void 0);n([h({default:2})],i.prototype,"radius",void 0);n([h({default:0})],i.prototype,"progress",void 0);n([h({default:!1})],i.prototype,"follow",void 0);n([h({default:1})],i.prototype,"gain",void 0);n([h({default:.015})],i.prototype,"floor",void 0);n([h({default:"center"})],i.prototype,"align",void 0);n([h({default:!1})],i.prototype,"byVoice",void 0);n([h({default:[]})],i.prototype,"voiceColors",void 0);n([h({default:"#5b5b7a",mapper:F.resolve,tween:F.lerp})],i.prototype,"fill",void 0);n([h({default:"#6366f1",mapper:F.resolve,tween:F.lerp})],i.prototype,"playedFill",void 0);n([j()],i.prototype,"sweep",null);i=n([T({key:"fullWaveform",parentKey:"node",forkable:!0,layout:{children:"freeform",defaultWidthMode:"fixed",defaultHeightMode:"fixed",acceptsChildren:!0},seed:{width:900,height:160}})],i);import{Node2D as Y,node as I,fillOps as C,property as f}from"@motionscript/core";import{declarePaints as K}from"@motionscript/core/component";var s=function(u,e,t,l){var a=arguments.length,o=a<3?e:l===null?l=Object.getOwnPropertyDescriptor(e,t):l,p;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(u,e,t,l);else for(var d=u.length-1;d>=0;d--)(p=u[d])&&(o=(a<3?p(o):a>3?p(e,t,o):p(e,t))||o);return a>3&&o&&Object.defineProperty(e,t,o),o},r=class extends Y{declareAssets(e){super.declareAssets(e),K(this,e)}get at(){return this.offset+(this.playing?Math.max(0,this.time.elapsed):0)}renderSelf(e){let t=this.layoutBounds,l=t?.width??0,a=t?.height??0;if(l<=0||a<=0)return;let o=Math.max(1,Math.round(this.bars)),p=Math.max(.05,this.window),d=this.at,x=this.speaker<0?null:Math.round(this.speaker),M=_(m(this.envelope,d-p/2,d+p/2,o),x),c=this.style==="line"?H(M):M,O=g(c,{width:l,height:a,gap:this.style==="blocks"?.12:this.gap,align:this.align,gain:this.gain,floor:this.floor});if(O.length===0)return;let P=b(O,W=>B(c[W].speaker,this.byVoice,x));for(let[W,L]of P){let N=E(L,this.paintFor(W),this.radius);N&&e.draw(N)}}paintFor(e){if(e==="all")return this.fill;let t=Number(e.slice(6));return!Number.isFinite(t)||t<0?this.fill:this.voiceColors[t]??y(t)}};s([f({default:v})],r.prototype,"envelope",void 0);s([f({default:48})],r.prototype,"bars",void 0);s([f({default:.35})],r.prototype,"gap",void 0);s([f({default:4})],r.prototype,"radius",void 0);s([f({default:3})],r.prototype,"window",void 0);s([f({default:0})],r.prototype,"offset",void 0);s([f({default:!0})],r.prototype,"playing",void 0);s([f({default:1.4})],r.prototype,"gain",void 0);s([f({default:.04})],r.prototype,"floor",void 0);s([f({default:"center"})],r.prototype,"align",void 0);s([f({default:"bars"})],r.prototype,"style",void 0);s([f({default:-1})],r.prototype,"speaker",void 0);s([f({default:!1})],r.prototype,"byVoice",void 0);s([f({default:[]})],r.prototype,"voiceColors",void 0);s([f({default:"#6366f1",mapper:C.resolve,tween:C.lerp})],r.prototype,"fill",void 0);r=s([I({key:"liveWaveform",parentKey:"node",forkable:!0,layout:{children:"freeform",defaultWidthMode:"fixed",defaultHeightMode:"fixed",acceptsChildren:!0},seed:{width:420,height:220}})],r);function H(u){let e=u.length;if(e<3)return[...u];let t=Math.max(1,Math.floor(e/5));return u.map((l,a)=>{let o=Math.min(a,e-1-a),p=w(o/t);return{magnitude:l.magnitude*p,speaker:l.speaker}})}var G=[i,r];export{v as EMPTY_ENVELOPE,i as FullWaveform,r as LiveWaveform,G as NODES,A as VOICE_PALETTE,V as WAVEFORM_ALIGNMENTS,S as WAVEFORM_STYLES,_ as forSpeaker,b as groupByPaint,g as layOutBars,E as paintBars,m as sampleEnvelope,y as voiceColor};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/waveform/full-waveform.ts", "../../src/waveform/live-waveform.ts", "../../src/nodes.ts"],
4
+ "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", "import {\n Node2D,\n node,\n fillOps,\n property,\n type AssetScope,\n type Fill,\n type Node2DProps,\n type RenderContext2D,\n} from \"@motionscript/core\"\n\nimport { declarePaints } from \"@motionscript/core/component\"\nimport {\n EMPTY_ENVELOPE,\n forSpeaker,\n sampleEnvelope,\n type AudioEnvelope,\n type EnvelopeBar,\n} from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n type WaveformStyle,\n} from \"./shared\"\n\nexport interface LiveWaveformProps extends Node2DProps {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: AudioEnvelope\n /** How many bars the visualiser is made of. */\n bars: number\n /** Space between bars, as a fraction of the pitch. */\n gap: number\n radius: number\n /** How many seconds of audio are on screen at once. */\n window: number\n /** Seconds into the file the node's first frame shows. */\n offset: number\n /** Advance with the scene clock. Off freezes the picture at {@link offset}. */\n playing: boolean\n /** Multiplies every magnitude before it is clamped. */\n gain: number\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: number\n align: WaveformAlignment\n style: WaveformStyle\n /**\n * Show only this voice's activity, by index into the recording's own\n * numbering. `-1` — the default — is every voice.\n */\n speaker: number\n /** Colour each bar by whoever is speaking in it. */\n byVoice: boolean\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: string[]\n fill: Fill\n}\n\n/**\n * A **live audio visualiser**: bars that move with the recording as it plays.\n *\n * The thing every podcast-to-video tool puts beside the artwork. It is not a\n * picture of the file — that is {@link FullWaveform} — it is a picture of *this\n * moment*, and what it is for is making a static frame of a talking head feel\n * like it is playing.\n *\n * ## \"Live\" without listening\n *\n * Nothing here reads an audio device. The bars are sampled out of a baked\n * envelope at the node's own elapsed time, which is what makes the visualiser\n * survive the thing it exists for: an **export**, where there is no playback to\n * analyse and frames may be rendered out of order or in parallel. A frame is a\n * pure function of its time, so scrubbing back and forth over the visualiser\n * redraws exactly what it drew the first time — which an analyser node, by\n * construction, cannot promise. See {@link AudioEnvelope}.\n *\n * ## The speaker filter\n *\n * {@link speaker} narrows the node to one voice of a diarized recording, and it\n * is the reason this node knows about transcripts at all. Two visualisers beside\n * two headshots, each filtered to its own host, is a podcast edit that would\n * otherwise be done by hand for every turn — and because the filter *silences*\n * rather than skips (see {@link forSpeaker}), the quiet host visibly stops\n * talking instead of vanishing. Nothing about that requires the words: only who\n * is talking when, which is what the diarizer produces.\n *\n * A filter naming a voice the recording doesn't have draws a resting row rather\n * than everything — a picture of \"this person never speaks here\", which is\n * true, where falling back to the unfiltered mix would be a silent lie about\n * whose voice you were watching.\n */\n@node({\n key: \"liveWaveform\",\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: 420,\n height: 220,\n },\n})\nexport class LiveWaveform extends Node2D<LiveWaveformProps> {\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\n @property({ default: 48 }) declare bars: number\n @property({ default: 0.35 }) declare gap: number\n @property({ default: 4 }) declare radius: number\n @property({ default: 3 }) declare window: number\n @property({ default: 0 }) declare offset: number\n @property({ default: true }) declare playing: boolean\n @property({ default: 1.4 }) declare gain: number\n @property({ default: 0.04 }) declare floor: number\n @property({ default: \"center\" }) declare align: WaveformAlignment\n @property({ default: \"bars\" }) declare style: WaveformStyle\n @property({ default: -1 }) declare speaker: number\n @property({ default: false }) declare byVoice: boolean\n @property({ default: [] }) declare voiceColors: string[]\n\n @property({\n default: \"#6366f1\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets)\n }\n\n /**\n * The second of the recording the visualiser is showing.\n *\n * Off the node's own clock rather than the scene's, which is what \"from the\n * moment this node appeared\" means — the same clock motion-script's own\n * `Video` times its picture from, and the same one that makes a node dropped\n * halfway through a scene start its recording at its entrance rather than\n * partway in.\n */\n private get at(): number {\n return this.offset + (this.playing ? Math.max(0, this.time.elapsed) : 0)\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 span = Math.max(0.05, this.window)\n const at = this.at\n const voice = this.speaker < 0 ? null : Math.round(this.speaker)\n\n // The window is centred on the playhead, so the bars run *toward* the\n // middle and away again — the arrangement every mixer's meter uses, and the\n // one that reads as sound arriving rather than as a strip scrolling past.\n const sampled = forSpeaker(\n sampleEnvelope(this.envelope, at - span / 2, at + span / 2, count),\n voice\n )\n\n const shaped = this.style === \"line\" ? taper(sampled) : sampled\n const boxes = layOutBars(shaped, {\n width,\n height,\n gap: this.style === \"blocks\" ? 0.12 : this.gap,\n align: this.align,\n gain: this.gain,\n floor: this.floor,\n })\n if (boxes.length === 0) return\n\n const groups = groupByPaint(boxes, (i) =>\n livePaintKey(shaped[i].speaker, this.byVoice, voice)\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 /** See {@link FullWaveform.paintFor} — a voice is a hue, never a gradient. */\n private paintFor(key: string): Fill {\n if (key === \"all\") return this.fill\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\n/**\n * Rolls the ends of a window off toward silence.\n *\n * What separates the `line` style from `bars`: a hard-edged window makes the\n * loud bar entering at the right edge appear from nothing, which reads as a\n * glitch rather than as sound arriving. Fading the outer fifth turns the same\n * data into a shape that grows out of the baseline — the profile a spectrum\n * display has, and the reason it looks like one object rather than a row of\n * separate meters.\n */\nfunction taper(bars: readonly EnvelopeBar[]): EnvelopeBar[] {\n const count = bars.length\n if (count < 3) return [...bars]\n const edge = Math.max(1, Math.floor(count / 5))\n\n return bars.map((bar, i) => {\n const fromEnd = Math.min(i, count - 1 - i)\n const weight = clamp01(fromEnd / edge)\n return { magnitude: bar.magnitude * weight, speaker: bar.speaker }\n })\n}\n", "import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n/**\n * Every node type this package publishes.\n *\n * A host registers these by handing the array to an engine —\n * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`\n * key. The decorator only *declares* that key: nothing is registered by the mere\n * act of importing a module, so a registry holds exactly what its owner asked\n * for and two engines in one process can differ about it.\n *\n * Listing class **values** is also what survives bundling. This package declares\n * `sideEffects: false`, which licenses a bundler to drop a module nothing\n * imports a value from, and a document names a node type by string — so\n * `import \"./waveform/full-waveform\"` for its side effect is exactly what gets shaken out, where an\n * array of bindings is a data dependency that cannot be.\n */\nexport const NODES = [FullWaveform, LiveWaveform];\n"],
5
+ "mappings": "4HAAA,OACE,UAAAA,EACA,QAAAC,EACA,WAAAC,EACA,aAAAC,EACA,WAAAC,EACA,YAAAC,MAOK,qBAEP,OAAS,iBAAAC,MAAqB,yWAsFjBC,EAAN,cAA2BC,CAAyB,CAgCzD,MAAMC,EAA+D,CACnE,OAAO,KAAK,GAAG,CACb,KAAM,CAAE,SAAU,CAAC,EACnB,SAAUA,EAAK,SACf,OAAQA,EAAK,QAAUC,EAAS,EACjC,CACH,CAOS,cAAcC,EAAkB,CACvC,MAAM,cAAcA,CAAM,EAC1BC,EAAc,KAAMD,E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AU,KAAK,IAAID,EAAGH,EAAQ,EAAIG,CAAC,EACnCE,EAASC,EAAQF,EAAUH,CAAI,EACrC,MAAO,CAAE,UAAWC,EAAI,UAAYG,EAAQ,QAASH,EAAI,OAAO,CAClE,CAAC,CACH,CC1MO,IAAMK,EAAQ,CAACC,EAAcC,CAAY",
6
+ "names": ["Node2D", "node", "command", "easeInOut", "fillOps", "property", "declarePaints", "FullWaveform", "Node2D", "args", "easeInOut", "assets", "declarePaints", "clamp01", "length", "ctx", "rect", "width", "height", "count", "sampled", "sampleEnvelope", "boxes", "layOutBars", "edge", "groups", "groupByPaint", "i", "key", "run", "graphics", "paintBars", "voice", "voiceColor", "__decorate", "property", "EMPTY_ENVELOPE", "fillOps", "command", "node", "Node2D", "node", "fillOps", "property", "declarePaints", "LiveWaveform", "Node2D", "assets", "declarePaints", "ctx", "rect", "width", "height", "count", "span", "at", "voice", "sampled", "forSpeaker", "sampleEnvelope", "shaped", "taper", "boxes", "layOutBars", "groups", "groupByPaint", "i", "livePaintKey", "key", "run", "graphics", "paintBars", "voiceColor", "__decorate", "property", "EMPTY_ENVELOPE", "fillOps", "node", "taper", "bars", "count", "edge", "bar", "i", "fromEnd", "weight", "clamp01", "NODES", "FullWaveform", "LiveWaveform"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as E,b as e,c as o,d as r,e as a,f as p,g as l,h as t,i,j as O,k as P,l as T}from"./chunks/chunk-U5OUQJHQ.js";export{E as EMPTY_ENVELOPE,p as VOICE_PALETTE,r as WAVEFORM_ALIGNMENTS,a as WAVEFORM_STYLES,P as clamp01,o as forSpeaker,O as groupByPaint,t as layOutBars,T as livePaintKey,i as paintBars,e as sampleEnvelope,l as voiceColor};
2
+ //# sourceMappingURL=kit.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@motionscript/audio",
3
+ "version": "0.1.0-alpha.0",
4
+ "exports": {
5
+ ".": "dist/browser/index.js",
6
+ "./kit": "dist/browser/kit.js"
7
+ },
8
+ "peers": [
9
+ "@motionscript/core"
10
+ ],
11
+ "assets": {}
12
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./waveform/index.js";
2
+ export { NODES } from "./nodes.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./waveform/index.js";
2
+ export { NODES } from "./nodes.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export * from \"./waveform\"\nexport { NODES } from \"./nodes\";\n"]}
package/dist/kit.d.ts ADDED
@@ -0,0 +1,13 @@
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.js";
10
+ export type { AudioEnvelope, EnvelopeBar } from "./waveform/envelope.js";
11
+ export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, clamp01, groupByPaint, layOutBars, livePaintKey, paintBars, voiceColor, } from "./waveform/shared.js";
12
+ export type { BarBox, WaveformAlignment, WaveformStyle } from "./waveform/shared.js";
13
+ //# sourceMappingURL=kit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAChF,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/kit.js ADDED
@@ -0,0 +1,11 @@
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.js";
10
+ export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, clamp01, groupByPaint, layOutBars, livePaintKey, paintBars, voiceColor, } from "./waveform/shared.js";
11
+ //# sourceMappingURL=kit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kit.js","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEhF,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAA","sourcesContent":["/**\n * What the two waveform nodes share, importable without copying it.\n *\n * A registry item copies `envelope.ts` and `shared.ts` beside its node: they\n * hold no class and no registered state, so a fork owning its own copy splits\n * no identity. This is the same surface for a host that samples envelopes or\n * lays bars out itself, and for a fork that keeps only its node file.\n */\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./waveform/envelope\"\nexport type { AudioEnvelope, EnvelopeBar } from \"./waveform/envelope\"\nexport {\n VOICE_PALETTE,\n WAVEFORM_ALIGNMENTS,\n WAVEFORM_STYLES,\n clamp01,\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceColor,\n} from \"./waveform/shared\"\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./waveform/shared\"\n"]}
@@ -0,0 +1,19 @@
1
+ import { FullWaveform } from "./waveform/full-waveform.js";
2
+ import { LiveWaveform } from "./waveform/live-waveform.js";
3
+ /**
4
+ * Every node type this package publishes.
5
+ *
6
+ * A host registers these by handing the array to an engine —
7
+ * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
8
+ * key. The decorator only *declares* that key: nothing is registered by the mere
9
+ * act of importing a module, so a registry holds exactly what its owner asked
10
+ * for and two engines in one process can differ about it.
11
+ *
12
+ * Listing class **values** is also what survives bundling. This package declares
13
+ * `sideEffects: false`, which licenses a bundler to drop a module nothing
14
+ * imports a value from, and a document names a node type by string — so
15
+ * `import "./waveform/full-waveform.js"` for its side effect is exactly what gets shaken out, where an
16
+ * array of bindings is a data dependency that cannot be.
17
+ */
18
+ export declare const NODES: (typeof FullWaveform | typeof LiveWaveform)[];
19
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,+CAA+B,CAAC"}
package/dist/nodes.js ADDED
@@ -0,0 +1,19 @@
1
+ import { FullWaveform } from "./waveform/full-waveform.js";
2
+ import { LiveWaveform } from "./waveform/live-waveform.js";
3
+ /**
4
+ * Every node type this package publishes.
5
+ *
6
+ * A host registers these by handing the array to an engine —
7
+ * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
8
+ * key. The decorator only *declares* that key: nothing is registered by the mere
9
+ * act of importing a module, so a registry holds exactly what its owner asked
10
+ * for and two engines in one process can differ about it.
11
+ *
12
+ * Listing class **values** is also what survives bundling. This package declares
13
+ * `sideEffects: false`, which licenses a bundler to drop a module nothing
14
+ * imports a value from, and a document names a node type by string — so
15
+ * `import "./waveform/full-waveform.js"` for its side effect is exactly what gets shaken out, where an
16
+ * array of bindings is a data dependency that cannot be.
17
+ */
18
+ export const NODES = [FullWaveform, LiveWaveform];
19
+ //# sourceMappingURL=nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC","sourcesContent":["import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n/**\n * Every node type this package publishes.\n *\n * A host registers these by handing the array to an engine —\n * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`\n * key. The decorator only *declares* that key: nothing is registered by the mere\n * act of importing a module, so a registry holds exactly what its owner asked\n * for and two engines in one process can differ about it.\n *\n * Listing class **values** is also what survives bundling. This package declares\n * `sideEffects: false`, which licenses a bundler to drop a module nothing\n * imports a value from, and a document names a node type by string — so\n * `import \"./waveform/full-waveform\"` for its side effect is exactly what gets shaken out, where an\n * array of bindings is a data dependency that cannot be.\n */\nexport const NODES = [FullWaveform, LiveWaveform];\n"]}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The shape of a recording, as the waveform nodes draw it.
3
+ *
4
+ * ## Why the data is baked rather than listened to
5
+ *
6
+ * A scene has to render identically in the preview and in a headless export,
7
+ * and an export has no audio device, no `AudioContext` and no playback to
8
+ * analyse. So a "live" visualiser cannot read a Web Audio analyser: what it
9
+ * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is
10
+ * then a pure function of time, which is what makes scrubbing backwards, jumping
11
+ * to frame 900, and rendering out of order all produce the same frame.
12
+ *
13
+ * The decode happens in the app, once per file, and arrives here through the
14
+ * build (see `SceneAsset.envelope`) — the same arrangement a chart's rows and a
15
+ * protein's atoms already use, and for the same reason: the build is
16
+ * synchronous and cannot await a fetch.
17
+ *
18
+ * ## Why magnitude rather than min/max
19
+ *
20
+ * An editor's waveform is drawn from per-bucket minima *and* maxima, because an
21
+ * editor is a measuring instrument. These nodes are neither — they are a bar
22
+ * chart of loudness that happens to be shaped like a recording — and audio is
23
+ * near enough symmetric that a mirrored magnitude is indistinguishable at the
24
+ * size a node draws. Half the numbers, and one array to reason about.
25
+ */
26
+ /**
27
+ * A decoded recording, reduced to a uniform grid of loudness — plus, when the
28
+ * app knows it, who is talking in each bucket.
29
+ *
30
+ * The speaker track is **not** something a decoder can produce; it comes from a
31
+ * diarized transcript and is folded in by the app before the build. It lives
32
+ * here rather than in a parallel structure because every reader of it is also a
33
+ * reader of the magnitudes at the same index, and two arrays that must stay the
34
+ * same length are better as one object than as two arguments.
35
+ */
36
+ export interface AudioEnvelope {
37
+ /** Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. */
38
+ magnitude: Float32Array;
39
+ /** The decoded length in seconds. */
40
+ duration: number;
41
+ /**
42
+ * Which voice is speaking in each bucket, as an index into the recording's
43
+ * own numbering, or `-1` for "nobody identified". Parallel to
44
+ * {@link magnitude}, or `null` when the track was never diarized.
45
+ */
46
+ speaker: Int16Array | null;
47
+ /** How many distinct voices the diarizer found. Zero when it did not run. */
48
+ speakers: number;
49
+ }
50
+ /** The envelope of a track that hasn't loaded — or isn't there. */
51
+ export declare const EMPTY_ENVELOPE: AudioEnvelope;
52
+ /** One drawn bar: how loud, and whose. */
53
+ export interface EnvelopeBar {
54
+ /** 0…1. */
55
+ magnitude: number;
56
+ /** The voice index, or -1. */
57
+ speaker: number;
58
+ }
59
+ /**
60
+ * Resamples `[from, to)` seconds of an envelope down to `bars` columns.
61
+ *
62
+ * Peak-preserving rather than averaging, which is the whole difference between
63
+ * a waveform and a blur: averaging a hundred buckets into one column flattens
64
+ * every transient, and transients are what makes a drawn recording read as
65
+ * speech rather than as noise. The speaker of a column is the speaker of its
66
+ * *loudest* bucket, on the same reasoning — a column straddling a turn belongs
67
+ * to whoever is actually audible in it.
68
+ *
69
+ * A window past either end of the recording yields silent, unattributed
70
+ * columns rather than clamping onto the nearest real one. That matters for the
71
+ * live visualiser, which is handed a window centred on the playhead and would
72
+ * otherwise smear the first bucket across the whole run-up to a track's start.
73
+ */
74
+ export declare function sampleEnvelope(envelope: AudioEnvelope, from: number, to: number, bars: number): EnvelopeBar[];
75
+ /**
76
+ * The same window, with everything that isn't `voice` silenced.
77
+ *
78
+ * The point of the speaker filter, and the reason it silences rather than
79
+ * *drops*: a podcast visualiser filtered to one host should go quiet while the
80
+ * other one talks, not compress their turn out of existence. Keeping the bars
81
+ * and zeroing them is what makes the picture read as "this person is not
82
+ * speaking right now" instead of as a jump cut.
83
+ *
84
+ * `voice` of `null` returns the bars untouched, which is the unfiltered node.
85
+ */
86
+ export declare function forSpeaker(bars: EnvelopeBar[], voice: number | null): EnvelopeBar[];
87
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,SAAS,EAAE,YAAY,CAAA;IACvB,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,OAAO,EAAE,UAAU,GAAG,IAAI,CAAA;IAC1B,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,aAK5B,CAAA;AAED,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,WAAW;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,WAAW,EAAE,CAkCf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EAAE,EACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,WAAW,EAAE,CAKf"}