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

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 (41) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +92 -0
  5. package/dist/browser/chunks/chunk-DAFIVUTT.js +2 -0
  6. package/dist/browser/chunks/chunk-DAFIVUTT.js.map +7 -0
  7. package/dist/browser/index.js +1 -1
  8. package/dist/browser/index.js.map +2 -2
  9. package/dist/browser/kit.js +1 -1
  10. package/dist/browser/manifest.json +3 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/kit.js.map +1 -1
  13. package/dist/nodes.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 +1 -2
  19. package/dist/waveform/full-waveform.d.ts.map +1 -1
  20. package/dist/waveform/full-waveform.js +1 -2
  21. package/dist/waveform/full-waveform.js.map +1 -1
  22. package/dist/waveform/index.js.map +1 -1
  23. package/dist/waveform/live-waveform.d.ts +2 -2
  24. package/dist/waveform/live-waveform.js +2 -2
  25. package/dist/waveform/live-waveform.js.map +1 -1
  26. package/dist/waveform/shared.d.ts +10 -8
  27. package/dist/waveform/shared.d.ts.map +1 -1
  28. package/dist/waveform/shared.js +14 -15
  29. package/dist/waveform/shared.js.map +1 -1
  30. package/package.json +7 -6
  31. package/registry.json +28 -28
  32. package/src/index.ts +2 -2
  33. package/src/kit.ts +22 -22
  34. package/src/nodes.ts +19 -19
  35. package/src/waveform/envelope.ts +176 -143
  36. package/src/waveform/full-waveform.ts +217 -218
  37. package/src/waveform/index.ts +30 -30
  38. package/src/waveform/live-waveform.ts +221 -221
  39. package/src/waveform/shared.ts +197 -194
  40. package/dist/browser/chunks/chunk-B3JXGNP6.js +0 -2
  41. package/dist/browser/chunks/chunk-B3JXGNP6.js.map +0 -7
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/waveform/envelope.ts", "../../../src/waveform/shared.ts"],
4
+ "sourcesContent": ["/**\r\n * The shape of a recording, as the waveform nodes draw it.\r\n *\r\n * ## How an envelope reaches a node: the host supplies it\r\n *\r\n * Nothing in the engine, and nothing in this kit, decodes audio. A waveform node\r\n * does not read a `sound` node's `src`, declares no audio asset and is not tied\r\n * to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`\r\n * prop. Decoding a file into an envelope is the host's job, done once per file\r\n * before the document is built. Where the recording sits on the audio lane is\r\n * the author's timing too, which is why `FullWaveform.follow` is opt-in.\r\n *\r\n * ### The JSON form\r\n *\r\n * A document holds the envelope as plain JSON, because a prop value in a\r\n * document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of\r\n * it; `ArrayLike<number>` also accepts the plain arrays a document stores:\r\n *\r\n * ```json\r\n * {\r\n * \"magnitude\": [0, 0.25, 0.5, 1, 0.5, 0],\r\n * \"duration\": 6,\r\n * \"speaker\": [0, 0, 0, 1, 1, -1],\r\n * \"speakers\": 2\r\n * }\r\n * ```\r\n *\r\n * `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`\r\n * seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice\r\n * index per bucket, `-1` for \"nobody\". `speakers` is the voice count, `0` when\r\n * `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable\r\n * (`JSON.stringify` writes an object of indices), so a host that holds the typed\r\n * form converts with `Array.from` before storing it in a document.\r\n *\r\n * ## Why the data is baked rather than listened to\r\n *\r\n * A scene has to render identically in the preview and in a headless export,\r\n * and an export has no audio device, no `AudioContext` and no playback to\r\n * analyse. So a \"live\" visualiser cannot read a Web Audio analyser: what it\r\n * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is\r\n * then a pure function of time, which is what makes scrubbing backwards, jumping\r\n * to frame 900, and rendering out of order all produce the same frame.\r\n *\r\n * The decode happens in the host, once per file, and arrives here through the\r\n * build — the same arrangement a chart's rows and a protein's atoms already use,\r\n * and for the same reason: the build is synchronous and cannot await a fetch.\r\n *\r\n * ## Why magnitude rather than min/max\r\n *\r\n * An editor's waveform is drawn from per-bucket minima *and* maxima, because an\r\n * editor is a measuring instrument. These nodes are neither — they are a bar\r\n * chart of loudness that happens to be shaped like a recording — and audio is\r\n * near enough symmetric that a mirrored magnitude is indistinguishable at the\r\n * size a node draws. Half the numbers, and one array to reason about.\r\n */\r\n\r\n/**\r\n * A decoded recording, reduced to a uniform grid of loudness — plus, when the\r\n * host knows it, who is talking in each bucket.\r\n *\r\n * The speaker track is **not** something a decoder can produce; it comes from a\r\n * diarized transcript and is folded in by the host before the build. It lives\r\n * here rather than in a parallel structure because every reader of it is also a\r\n * reader of the magnitudes at the same index, and two arrays that must stay the\r\n * same length are better as one object than as two arguments.\r\n */\r\nexport interface AudioEnvelope {\r\n /**\r\n * Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A\r\n * `Float32Array`, or the plain `number[]` a document stores.\r\n */\r\n magnitude: ArrayLike<number>\r\n /** The decoded length in seconds. */\r\n duration: number\r\n /**\r\n * Which voice is speaking in each bucket, as an index into the recording's\r\n * own numbering, or `-1` for \"nobody identified\". Parallel to\r\n * {@link magnitude}, or `null` when the track was never diarized.\r\n */\r\n speaker: ArrayLike<number> | null\r\n /** How many distinct voices the diarizer found. Zero when it did not run. */\r\n speakers: number\r\n}\r\n\r\n/** The envelope of a track that hasn't loaded — or isn't there. */\r\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\r\n magnitude: new Float32Array(0),\r\n duration: 0,\r\n speaker: null,\r\n speakers: 0,\r\n}\r\n\r\n/** One drawn bar: how loud, and whose. */\r\nexport interface EnvelopeBar {\r\n /** 0…1. */\r\n magnitude: number\r\n /** The voice index, or -1. */\r\n speaker: number\r\n}\r\n\r\n/**\r\n * Resamples `[from, to)` seconds of an envelope down to `bars` columns.\r\n *\r\n * Peak-preserving rather than averaging, which is the whole difference between\r\n * a waveform and a blur: averaging a hundred buckets into one column flattens\r\n * every transient, and transients are what makes a drawn recording read as\r\n * speech rather than as noise. The speaker of a column is the speaker of its\r\n * *loudest* bucket, on the same reasoning — a column straddling a turn belongs\r\n * to whoever is actually audible in it.\r\n *\r\n * A window past either end of the recording yields silent, unattributed\r\n * columns rather than clamping onto the nearest real one. That matters for the\r\n * live visualiser, which is handed a window centred on the playhead and would\r\n * otherwise smear the first bucket across the whole run-up to a track's start.\r\n */\r\nexport function sampleEnvelope(\r\n envelope: AudioEnvelope,\r\n from: number,\r\n to: number,\r\n bars: number\r\n): EnvelopeBar[] {\r\n const count = Math.max(0, Math.floor(bars))\r\n const out: EnvelopeBar[] = new Array(count)\r\n for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }\r\n\r\n const buckets = envelope.magnitude.length\r\n if (count === 0 || buckets === 0 || envelope.duration <= 0) return out\r\n\r\n const perSecond = buckets / envelope.duration\r\n const span = (to - from) / count\r\n\r\n for (let i = 0; i < count; i++) {\r\n const start = (from + span * i) * perSecond\r\n const end = (from + span * (i + 1)) * perSecond\r\n\r\n // At least one bucket per column, so a window zoomed in past the grid draws\r\n // the sample it is standing on rather than an empty band.\r\n const first = Math.floor(start)\r\n const last = Math.max(first, Math.ceil(end) - 1)\r\n\r\n let loudest = 0\r\n let speaker = -1\r\n for (let b = first; b <= last; b++) {\r\n if (b < 0 || b >= buckets) continue\r\n const value = envelope.magnitude[b]\r\n if (value < loudest) continue\r\n loudest = value\r\n speaker = envelope.speaker ? envelope.speaker[b] : -1\r\n }\r\n\r\n out[i] = { magnitude: loudest, speaker }\r\n }\r\n\r\n return out\r\n}\r\n\r\n/**\r\n * The same window, with everything that isn't `voice` silenced.\r\n *\r\n * The point of the speaker filter, and the reason it silences rather than\r\n * *drops*: a podcast visualiser filtered to one host should go quiet while the\r\n * other one talks, not compress their turn out of existence. Keeping the bars\r\n * and zeroing them is what makes the picture read as \"this person is not\r\n * speaking right now\" instead of as a jump cut.\r\n *\r\n * `voice` of `null` returns the bars untouched, which is the unfiltered node.\r\n */\r\nexport function forSpeaker(\r\n bars: EnvelopeBar[],\r\n voice: number | null\r\n): EnvelopeBar[] {\r\n if (voice === null) return bars\r\n return bars.map((bar) =>\r\n bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }\r\n )\r\n}\r\n", "import { Graphics2D, type Fill, type FillResolved } from \"@motionscript/sdk\"\r\n\r\nimport type { EnvelopeBar } from \"./envelope\"\r\n\r\n/**\r\n * Geometry and paint shared by the two waveform nodes.\r\n *\r\n * They draw the same object — a row of bars whose heights are loudness — and\r\n * differ only in what decides the heights: the whole file for one, a window\r\n * around the playhead for the other. Everything about *how a row of bars is\r\n * laid out and painted* is therefore common, and lives here so the two cannot\r\n * drift into looking like different components.\r\n */\r\n\r\n/** How a bar is grown out of its baseline. */\r\nexport const WAVEFORM_ALIGNMENTS = [\"center\", \"bottom\"] as const\r\nexport type WaveformAlignment = (typeof WAVEFORM_ALIGNMENTS)[number]\r\n\r\n/** What the bars are shaped like. */\r\nexport const WAVEFORM_STYLES = [\"bars\", \"line\", \"blocks\"] as const\r\nexport type WaveformStyle = (typeof WAVEFORM_STYLES)[number]\r\n\r\n/**\r\n * The colours voices are drawn in when nobody has assigned any.\r\n *\r\n * Eight hues that can be told apart at a glance, handed out by voice index. They\r\n * are literals rather than looked up, because a scene has to build in a\r\n * headless render with no database in scope; a host that names its voices\r\n * supplies its own colours instead.\r\n */\r\nexport const VOICE_PALETTE = [\r\n \"#6366f1\",\r\n \"#14b8a6\",\r\n \"#f59e0b\",\r\n \"#ec4899\",\r\n \"#22c55e\",\r\n \"#3b82f6\",\r\n \"#f97316\",\r\n \"#a855f7\",\r\n] as const\r\n\r\n/** The colour a voice takes, wrapping past the end of the palette. */\r\nexport function voiceColor(index: number): string {\r\n return VOICE_PALETTE[\r\n ((index % VOICE_PALETTE.length) + VOICE_PALETTE.length) %\r\n VOICE_PALETTE.length\r\n ]\r\n}\r\n\r\n/**\r\n * Where one bar sits and how tall it came out: its top-left corner and size, in\r\n * the node's own pixels with **y pointing down** from the middle of the box.\r\n * {@link paintBars} turns that into the centred, y-up rect the renderer draws.\r\n */\r\nexport interface BarBox {\r\n x: number\r\n y: number\r\n width: number\r\n height: number\r\n}\r\n\r\n/**\r\n * Lays a row of bars out across a box.\r\n *\r\n * The gap is stated as a *fraction of the pitch* rather than in pixels, and\r\n * that is the one decision here worth stating out loud: the bar count is a\r\n * control, so a gap in pixels would silently become a solid block at 200 bars\r\n * and a picket fence at 20. As a fraction, the row keeps the same rhythm at\r\n * every density — which is what lets the count be a slider anyone can drag.\r\n *\r\n * A bar is never thinner than a hairline and never shorter than one either: a\r\n * silent passage has to read as \"audio, and nothing here\" rather than as a hole\r\n * in the drawing.\r\n */\r\nexport function layOutBars(\r\n bars: readonly EnvelopeBar[],\r\n options: {\r\n width: number\r\n height: number\r\n gap: number\r\n align: WaveformAlignment\r\n /** Multiplies every magnitude before it is clamped back into 0…1. */\r\n gain: number\r\n /** Fraction of the box a silent bar still occupies. */\r\n floor: number\r\n }\r\n): BarBox[] {\r\n const { width, height, gap, align, gain, floor } = options\r\n const count = bars.length\r\n if (count === 0 || width <= 0 || height <= 0) return []\r\n\r\n const pitch = width / count\r\n const barWidth = Math.max(1, pitch * (1 - clamp01(gap)))\r\n // The tallest a bar may be. Centre-aligned bars grow both ways from the\r\n // middle, so the *half* is what a magnitude of 1 fills.\r\n const full = align === \"center\" ? height / 2 : height\r\n\r\n const out: BarBox[] = new Array(count)\r\n for (let i = 0; i < count; i++) {\r\n const magnitude = clamp01(bars[i].magnitude * gain)\r\n const reach = Math.max(full * clamp01(floor), full * magnitude)\r\n const x = -width / 2 + pitch * i + (pitch - barWidth) / 2\r\n\r\n // A hairline minimum, taken before the position so the bar stays inside the\r\n // box: a silent bar 1px tall that kept the position of a zero-height one\r\n // would hang half a pixel (centred) or a whole pixel (bottom) outside it.\r\n const h = Math.max(1, align === \"center\" ? reach * 2 : reach)\r\n out[i] =\r\n align === \"center\"\r\n ? { x, y: -h / 2, width: barWidth, height: h }\r\n : { x, y: height / 2 - h, width: barWidth, height: h }\r\n }\r\n return out\r\n}\r\n\r\n/**\r\n * Draws a run of bars in one paint.\r\n *\r\n * Batched by colour by the caller, and this is why: every `Graphics2D` handed to\r\n * `ctx.draw` is a surface the renderer composites, so a bar apiece would be a\r\n * thousand surfaces a frame. Chaining the rects of one colour into a single\r\n * `Graphics2D` before filling makes it one — and, as a bonus, a gradient fill\r\n * maps across the whole run rather than restarting inside every bar, which is\r\n * the behaviour anyone reaching for a gradient here actually wants.\r\n */\r\nexport function paintBars(\r\n boxes: readonly BarBox[],\r\n fill: Fill,\r\n radius: number\r\n): Graphics2D | null {\r\n if (boxes.length === 0) return null\r\n if ((fill as FillResolved[]).length === 0) return null\r\n\r\n const graphics = new Graphics2D()\r\n for (const box of boxes) {\r\n graphics.rect({\r\n x: box.x + box.width / 2,\r\n // The box is stated y-down and the rect is drawn y-up. A centred bar is\r\n // symmetric about the middle, so only a bottom-aligned one shows the flip.\r\n y: -(box.y + box.height / 2),\r\n width: box.width,\r\n height: box.height,\r\n // Never rounder than the bar is wide, or a thin bar becomes a lozenge\r\n // whose ends taper away to nothing.\r\n cornerRadius: Math.min(radius, box.width / 2, box.height / 2),\r\n })\r\n }\r\n return graphics.fill(fill)\r\n}\r\n\r\n/**\r\n * Groups bars by the paint they take, preserving order within each group.\r\n *\r\n * The seam that makes {@link paintBars} worth batching: a diarized waveform has\r\n * as many colours as it has voices, not as many as it has bars, so a\r\n * conversation of two people is two draws however long it runs.\r\n */\r\nexport function groupByPaint<K>(\r\n boxes: readonly BarBox[],\r\n keyOf: (index: number) => K\r\n): Map<K, BarBox[]> {\r\n const groups = new Map<K, BarBox[]>()\r\n for (let i = 0; i < boxes.length; i++) {\r\n const key = keyOf(i)\r\n const run = groups.get(key)\r\n if (run) run.push(boxes[i])\r\n else groups.set(key, [boxes[i]])\r\n }\r\n return groups\r\n}\r\n\r\nexport function clamp01(value: number): number {\r\n return value < 0 ? 0 : value > 1 ? 1 : value\r\n}\r\n\r\n/**\r\n * The {@link groupByPaint} key one bar of a live visualiser takes.\r\n *\r\n * Filtered to one voice, every bar is that voice regardless of `byVoice` or\r\n * whose turn the bucket originally belonged to. That second part is the one\r\n * worth spelling out: {@link forSpeaker} silences a bar by zeroing its\r\n * magnitude but leaves `speaker` exactly as it was, so a bar sitting in the\r\n * middle of a *different* voice's turn is still stamped with that voice's\r\n * index — grouping by `byVoice`'s usual per-bar key would paint those silent\r\n * stretches in whoever used to be talking there, in flickers too short to\r\n * read as anything but noise. Forcing every bar under the filtered voice's own\r\n * key is the true picture instead: the node is drawing exactly one person, on\r\n * or off, never anyone else's colour.\r\n */\r\nexport function livePaintKey(\r\n barSpeaker: number,\r\n byVoice: boolean,\r\n filteredVoice: number | null\r\n): string {\r\n if (filteredVoice !== null) return `voice:${filteredVoice}`\r\n return byVoice ? `voice:${barSpeaker}` : \"all\"\r\n}\r\n"],
5
+ "mappings": "AAqFO,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,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AAI,KAAKT,EAAML,CAAC,CAAC,EACrBY,EAAO,IAAIC,EAAK,CAACR,EAAML,CAAC,CAAC,CAAC,CACjC,CACA,OAAOY,CACT,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
+ }
@@ -1,2 +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-B3JXGNP6.js";import{Node2D as R,node as T,command as j,easeInOut as D,fillOps as F,property as h}from"@motionscript/sdk";import{declarePaints as k}from"@motionscript/sdk/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/sdk";import{declarePaints as K}from"@motionscript/sdk/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};
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-DAFIVUTT.js";import{Node2D as R,node as T,command as j,easeInOut as D,fillOps as F,property as h}from"@motionscript/sdk";import{declarePaints as k}from"@motionscript/sdk/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/sdk";import{declarePaints as K}from"@motionscript/sdk/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
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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/sdk\"\n\nimport { declarePaints } from \"@motionscript/sdk/component\"\nimport type { Seekable } from \"@motionscript/sdk/component\"\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\nexport interface FullWaveformProps extends Node2DProps {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: AudioEnvelope\n /** How many columns the whole file is drawn as. */\n bars: number\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: number\n /** Corner radius of a bar, capped at half its width. */\n radius: number\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: number\n /** Drive {@link progress} from the node's own clock instead of the prop. */\n follow: boolean\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: number\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: number\n align: WaveformAlignment\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: boolean\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: string[]\n /** The bars ahead of the playhead. */\n fill: Fill\n /** …and the bars behind it. */\n playedFill: Fill\n}\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * {@link follow} is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\n * speaking voice — the drawing the timeline's clip bars already make, at a size\n * you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\n@node({\n key: \"fullWaveform\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"freeform\",\n defaultWidthMode: \"fixed\",\n defaultHeightMode: \"fixed\",\n acceptsChildren: true,\n },\n seed: {\n width: 900,\n height: 160,\n },\n})\nexport class FullWaveform extends Node2D<FullWaveformProps> {\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\n @property({ default: 120 }) declare bars: number\n @property({ default: 0.3 }) declare gap: number\n @property({ default: 2 }) declare radius: number\n @property({ default: 0 }) declare progress: number\n @property({ default: false }) declare follow: boolean\n @property({ default: 1 }) declare gain: number\n @property({ default: 0.015 }) declare floor: number\n @property({ default: \"center\" }) declare align: WaveformAlignment\n @property({ default: false }) declare byVoice: boolean\n @property({ default: [] }) declare voiceColors: string[]\n\n @property({\n default: \"#5b5b7a\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n\n @property({\n default: \"#6366f1\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare playedFill: Fill\n\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`.\n */\n @command()\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\n return this.to({\n data: { progress: 1 } as Partial<FullWaveformProps>,\n duration: args.duration,\n easing: args.easing ?? easeInOut(),\n })\n }\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\n * past the conventional slots, so it is passed explicitly.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\n }\n\n /** Where the fill has reached, from whichever source is in charge. */\n private get played(): number {\n if (!this.follow) return clamp01(this.progress)\n const length = this.envelope.duration\n if (length <= 0) return 0\n return clamp01(this.time.elapsed / length)\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const rect = this.layoutBounds\n const width = rect?.width ?? 0\n const height = rect?.height ?? 0\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(this.bars))\n const sampled = sampleEnvelope(\n this.envelope,\n 0,\n this.envelope.duration,\n count\n )\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: this.gap,\n align: this.align,\n gain: this.gain,\n floor: this.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = this.played * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n this.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, this.paintFor(key), this.radius)\n if (graphics) ctx.draw(graphics)\n }\n }\n\n /**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why {@link declareAssets}\n * only has to account for the two real fill props.\n */\n private paintFor(key: string): Fill {\n if (key === \"played\") return this.playedFill\n if (key === \"ahead\") return this.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return this.fill\n return this.voiceColors[voice] ?? voiceColor(voice)\n }\n}\n", "import {\n Node2D,\n node,\n fillOps,\n property,\n type AssetScope,\n type Fill,\n type Node2DProps,\n type RenderContext2D,\n} from \"@motionscript/sdk\"\n\nimport { declarePaints } from \"@motionscript/sdk/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,oBAEP,OAAS,iBAAAC,MAAqB,wWAsFjBC,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,EAAQ,CAAE,MAAO,CAAC,KAAK,UAA4B,CAAC,CAAE,CAC5E,CAGA,IAAY,QAAM,CAChB,GAAI,CAAC,KAAK,OAAQ,OAAOE,EAAQ,KAAK,QAAQ,EAC9C,IAAMC,EAAS,KAAK,SAAS,SAC7B,OAAIA,GAAU,EAAU,EACjBD,EAAQ,KAAK,KAAK,QAAUC,CAAM,CAC3C,CAEU,WAAWC,EAAoB,CACvC,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,\r\n property,\r\n type AssetScope,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\nimport type { Seekable } from \"@motionscript/sdk/component\"\r\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\r\nimport {\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n type WaveformAlignment,\r\n} from \"./shared\"\r\n\r\nexport interface FullWaveformProps extends Node2DProps {\r\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\r\n envelope: AudioEnvelope\r\n /** How many columns the whole file is drawn as. */\r\n bars: number\r\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\r\n gap: number\r\n /** Corner radius of a bar, capped at half its width. */\r\n radius: number\r\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\r\n progress: number\r\n /** Drive {@link progress} from the node's own clock instead of the prop. */\r\n follow: boolean\r\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\r\n gain: number\r\n /** How much of the box a silent bar still occupies, `0`–`1`. */\r\n floor: number\r\n align: WaveformAlignment\r\n /** Colour each voice's turns rather than splitting on played / not played. */\r\n byVoice: boolean\r\n /** A colour per voice index. Short or empty falls back to the palette. */\r\n voiceColors: string[]\r\n /** The bars ahead of the playhead. */\r\n fill: Fill\r\n /** …and the bars behind it. */\r\n playedFill: Fill\r\n}\r\n\r\n/**\r\n * A **waveform overview**: the whole recording's shape, drawn at once.\r\n *\r\n * The picture every audio editor opens with, and the one a podcast clip puts\r\n * under its caption — a static silhouette of the file, with a played portion\r\n * that advances. It answers \"how long is this and where are the loud parts\",\r\n * which is a question about the *file*, not about the moment; its sibling\r\n * {@link LiveWaveform} answers the other one.\r\n *\r\n * ## Progress is authored, not assumed\r\n *\r\n * {@link follow} is off by default, and that default is the considered one. A\r\n * scene has no idea where the recording it is drawing sits on the video's audio\r\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\r\n * visible from in here. So the honest default is that the fill is *animation*:\r\n * the author sweeps it with a command, the same as any other tween, and it lands\r\n * wherever they put it. `follow` is the shortcut for the common arrangement\r\n * where the node appears exactly as the track starts, and it says so by being a\r\n * switch someone has to turn on rather than a behaviour that quietly disagrees\r\n * with the mix.\r\n *\r\n * ## Voices instead of progress\r\n *\r\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\r\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\r\n * floor, where the turns are, how long each one ran. It replaces the progress\r\n * colours rather than combining with them, because a bar cannot mean two things\r\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\r\n * head.\r\n */\r\n@node({\r\n key: \"fullWaveform\",\r\n parentKey: \"node\",\r\n forkable: true,\r\n layout: {\r\n children: \"freeform\",\r\n defaultWidthMode: \"fixed\",\r\n defaultHeightMode: \"fixed\",\r\n acceptsChildren: true,\r\n },\r\n seed: {\r\n width: 900,\r\n height: 160,\r\n },\r\n})\r\nexport class FullWaveform extends Node2D<FullWaveformProps> {\r\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\r\n @property({ default: 120 }) declare bars: number\r\n @property({ default: 0.3 }) declare gap: number\r\n @property({ default: 2 }) declare radius: number\r\n @property({ default: 0 }) declare progress: number\r\n @property({ default: false }) declare follow: boolean\r\n @property({ default: 1 }) declare gain: number\r\n @property({ default: 0.015 }) declare floor: number\r\n @property({ default: \"center\" }) declare align: WaveformAlignment\r\n @property({ default: false }) declare byVoice: boolean\r\n @property({ default: [] }) declare voiceColors: string[]\r\n\r\n @property({\r\n default: \"#5b5b7a\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare fill: Fill\r\n\r\n @property({\r\n default: \"#6366f1\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare playedFill: Fill\r\n\r\n /**\r\n * Fill the waveform in, left to right — the node's one command, since\r\n * everything else about it is expressible as an ordinary `to`.\r\n */\r\n @command()\r\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\r\n return this.to({\r\n data: { progress: 1 } as Partial<FullWaveformProps>,\r\n duration: args.duration,\r\n easing: args.easing ?? easeInOut(),\r\n })\r\n }\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\r\n * past the conventional slots, so it is passed explicitly.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\r\n }\r\n\r\n /** Where the fill has reached, from whichever source is in charge. */\r\n private get played(): number {\r\n if (!this.follow) return clamp01(this.progress)\r\n const length = this.envelope.duration\r\n if (length <= 0) return 0\r\n return clamp01(this.time.elapsed / length)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const rect = this.layoutBounds\r\n const width = rect?.width ?? 0\r\n const height = rect?.height ?? 0\r\n if (width <= 0 || height <= 0) return\r\n\r\n const count = Math.max(1, Math.round(this.bars))\r\n const sampled = sampleEnvelope(\r\n this.envelope,\r\n 0,\r\n this.envelope.duration,\r\n count\r\n )\r\n const boxes = layOutBars(sampled, {\r\n width,\r\n height,\r\n gap: this.gap,\r\n align: this.align,\r\n gain: this.gain,\r\n floor: this.floor,\r\n })\r\n if (boxes.length === 0) return\r\n\r\n // One draw per colour rather than per bar — see {@link paintBars}. The key\r\n // is a string because it has to be comparable; the paint it stands for is\r\n // resolved after the grouping.\r\n const edge = this.played * boxes.length\r\n const groups = groupByPaint(boxes, (i) =>\r\n this.byVoice\r\n ? `voice:${sampled[i].speaker}`\r\n : i < edge\r\n ? \"played\"\r\n : \"ahead\"\r\n )\r\n\r\n for (const [key, run] of groups) {\r\n const graphics = paintBars(run, this.paintFor(key), this.radius)\r\n if (graphics) ctx.draw(graphics)\r\n }\r\n }\r\n\r\n /**\r\n * The paint a group takes.\r\n *\r\n * A voice's colour is a **colour string**, never one of the node's two fill\r\n * props, and that is deliberate: a voice is identified by hue, so a gradient\r\n * or an image there would defeat the only thing the colour is for. It also\r\n * means these paints declare no assets, which is why {@link declareAssets}\r\n * only has to account for the two real fill props.\r\n */\r\n private paintFor(key: string): Fill {\r\n if (key === \"played\") return this.playedFill\r\n if (key === \"ahead\") return this.fill\r\n\r\n const voice = Number(key.slice(\"voice:\".length))\r\n if (!Number.isFinite(voice) || voice < 0) return this.fill\r\n return this.voiceColors[voice] ?? voiceColor(voice)\r\n }\r\n}\r\n", "import {\r\n Node2D,\r\n node,\r\n fillOps,\r\n property,\r\n type AssetScope,\r\n type Fill,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\nimport {\r\n EMPTY_ENVELOPE,\r\n forSpeaker,\r\n sampleEnvelope,\r\n type AudioEnvelope,\r\n type EnvelopeBar,\r\n} from \"./envelope\"\r\nimport {\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n livePaintKey,\r\n paintBars,\r\n voiceColor,\r\n type WaveformAlignment,\r\n type WaveformStyle,\r\n} from \"./shared\"\r\n\r\nexport interface LiveWaveformProps extends Node2DProps {\r\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\r\n envelope: AudioEnvelope\r\n /** How many bars the visualiser is made of. */\r\n bars: number\r\n /** Space between bars, as a fraction of the pitch. */\r\n gap: number\r\n radius: number\r\n /** How many seconds of audio are on screen at once. */\r\n window: number\r\n /** Seconds into the file the node's first frame shows. */\r\n offset: number\r\n /** Advance with the scene clock. Off freezes the picture at {@link offset}. */\r\n playing: boolean\r\n /** Multiplies every magnitude before it is clamped. */\r\n gain: number\r\n /** How much of the box a silent bar still occupies, `0`–`1`. */\r\n floor: number\r\n align: WaveformAlignment\r\n style: WaveformStyle\r\n /**\r\n * Show only this voice's activity, by index into the recording's own\r\n * numbering. `-1` — the default — is every voice.\r\n */\r\n speaker: number\r\n /** Colour each bar by whoever is speaking in it. */\r\n byVoice: boolean\r\n /** A colour per voice index. Short or empty falls back to the palette. */\r\n voiceColors: string[]\r\n fill: Fill\r\n}\r\n\r\n/**\r\n * A **live audio visualiser**: bars that move with the recording as it plays.\r\n *\r\n * The thing every podcast-to-video tool puts beside the artwork. It is not a\r\n * picture of the file — that is {@link FullWaveform} — it is a picture of *this\r\n * moment*, and what it is for is making a static frame of a talking head feel\r\n * like it is playing.\r\n *\r\n * ## \"Live\" without listening\r\n *\r\n * Nothing here reads an audio device. The bars are sampled out of a baked\r\n * envelope at the node's own elapsed time, which is what makes the visualiser\r\n * survive the thing it exists for: an **export**, where there is no playback to\r\n * analyse and frames may be rendered out of order or in parallel. A frame is a\r\n * pure function of its time, so scrubbing back and forth over the visualiser\r\n * redraws exactly what it drew the first time — which an analyser node, by\r\n * construction, cannot promise. See {@link AudioEnvelope}.\r\n *\r\n * ## The speaker filter\r\n *\r\n * {@link speaker} narrows the node to one voice of a diarized recording, and it\r\n * is the reason this node knows about transcripts at all. Two visualisers beside\r\n * two headshots, each filtered to its own host, is a podcast edit that would\r\n * otherwise be done by hand for every turn — and because the filter *silences*\r\n * rather than skips (see {@link forSpeaker}), the quiet host visibly stops\r\n * talking instead of vanishing. Nothing about that requires the words: only who\r\n * is talking when, which is what the diarizer produces.\r\n *\r\n * A filter naming a voice the recording doesn't have draws a resting row rather\r\n * than everything — a picture of \"this person never speaks here\", which is\r\n * true, where falling back to the unfiltered mix would be a silent lie about\r\n * whose voice you were watching.\r\n */\r\n@node({\r\n key: \"liveWaveform\",\r\n parentKey: \"node\",\r\n forkable: true,\r\n layout: {\r\n children: \"freeform\",\r\n defaultWidthMode: \"fixed\",\r\n defaultHeightMode: \"fixed\",\r\n acceptsChildren: true,\r\n },\r\n seed: {\r\n width: 420,\r\n height: 220,\r\n },\r\n})\r\nexport class LiveWaveform extends Node2D<LiveWaveformProps> {\r\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\r\n @property({ default: 48 }) declare bars: number\r\n @property({ default: 0.35 }) declare gap: number\r\n @property({ default: 4 }) declare radius: number\r\n @property({ default: 3 }) declare window: number\r\n @property({ default: 0 }) declare offset: number\r\n @property({ default: true }) declare playing: boolean\r\n @property({ default: 1.4 }) declare gain: number\r\n @property({ default: 0.04 }) declare floor: number\r\n @property({ default: \"center\" }) declare align: WaveformAlignment\r\n @property({ default: \"bars\" }) declare style: WaveformStyle\r\n @property({ default: -1 }) declare speaker: number\r\n @property({ default: false }) declare byVoice: boolean\r\n @property({ default: [] }) declare voiceColors: string[]\r\n\r\n @property({\r\n default: \"#6366f1\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare fill: Fill\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets)\r\n }\r\n\r\n /**\r\n * The second of the recording the visualiser is showing.\r\n *\r\n * Off the node's own clock rather than the scene's, which is what \"from the\r\n * moment this node appeared\" means — the same clock the engine's own\r\n * `Video` times its picture from, and the same one that makes a node dropped\r\n * halfway through a clip start its recording at its entrance rather than\r\n * partway in.\r\n */\r\n private get at(): number {\r\n return this.offset + (this.playing ? Math.max(0, this.time.elapsed) : 0)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const rect = this.layoutBounds\r\n const width = rect?.width ?? 0\r\n const height = rect?.height ?? 0\r\n if (width <= 0 || height <= 0) return\r\n\r\n const count = Math.max(1, Math.round(this.bars))\r\n const span = Math.max(0.05, this.window)\r\n const at = this.at\r\n const voice = this.speaker < 0 ? null : Math.round(this.speaker)\r\n\r\n // The window is centred on the playhead, so the bars run *toward* the\r\n // middle and away again — the arrangement every mixer's meter uses, and the\r\n // one that reads as sound arriving rather than as a strip scrolling past.\r\n const sampled = forSpeaker(\r\n sampleEnvelope(this.envelope, at - span / 2, at + span / 2, count),\r\n voice\r\n )\r\n\r\n const shaped = this.style === \"line\" ? taper(sampled) : sampled\r\n const boxes = layOutBars(shaped, {\r\n width,\r\n height,\r\n gap: this.style === \"blocks\" ? 0.12 : this.gap,\r\n align: this.align,\r\n gain: this.gain,\r\n floor: this.floor,\r\n })\r\n if (boxes.length === 0) return\r\n\r\n const groups = groupByPaint(boxes, (i) =>\r\n livePaintKey(shaped[i].speaker, this.byVoice, voice)\r\n )\r\n\r\n for (const [key, run] of groups) {\r\n const graphics = paintBars(run, this.paintFor(key), this.radius)\r\n if (graphics) ctx.draw(graphics)\r\n }\r\n }\r\n\r\n /** See {@link FullWaveform.paintFor} — a voice is a hue, never a gradient. */\r\n private paintFor(key: string): Fill {\r\n if (key === \"all\") return this.fill\r\n const voice = Number(key.slice(\"voice:\".length))\r\n if (!Number.isFinite(voice) || voice < 0) return this.fill\r\n return this.voiceColors[voice] ?? voiceColor(voice)\r\n }\r\n}\r\n\r\n/**\r\n * Rolls the ends of a window off toward silence.\r\n *\r\n * What separates the `line` style from `bars`: a hard-edged window makes the\r\n * loud bar entering at the right edge appear from nothing, which reads as a\r\n * glitch rather than as sound arriving. Fading the outer fifth turns the same\r\n * data into a shape that grows out of the baseline — the profile a spectrum\r\n * display has, and the reason it looks like one object rather than a row of\r\n * separate meters.\r\n */\r\nfunction taper(bars: readonly EnvelopeBar[]): EnvelopeBar[] {\r\n const count = bars.length\r\n if (count < 3) return [...bars]\r\n const edge = Math.max(1, Math.floor(count / 5))\r\n\r\n return bars.map((bar, i) => {\r\n const fromEnd = Math.min(i, count - 1 - i)\r\n const weight = clamp01(fromEnd / edge)\r\n return { magnitude: bar.magnitude * weight, speaker: bar.speaker }\r\n })\r\n}\r\n", "import { FullWaveform } from \"./waveform/full-waveform\";\r\nimport { LiveWaveform } from \"./waveform/live-waveform\";\r\n\r\n/**\r\n * Every node type this package publishes.\r\n *\r\n * A host registers these by handing the array to an engine —\r\n * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`\r\n * key. The decorator only *declares* that key: nothing is registered by the mere\r\n * act of importing a module, so a registry holds exactly what its owner asked\r\n * for and two engines in one process can differ about it.\r\n *\r\n * Listing class **values** is also what survives bundling. This package declares\r\n * `sideEffects: false`, which licenses a bundler to drop a module nothing\r\n * imports a value from, and a document names a node type by string — so\r\n * `import \"./waveform/full-waveform\"` for its side effect is exactly what gets shaken out, where an\r\n * array of bindings is a data dependency that cannot be.\r\n */\r\nexport const NODES = [FullWaveform, LiveWaveform];\r\n"],
5
+ "mappings": "4HAAA,OACE,UAAAA,EACA,QAAAC,EACA,WAAAC,EACA,aAAAC,EACA,WAAAC,EACA,YAAAC,MAOK,oBAEP,OAAS,iBAAAC,MAAqB,wWAqFjBC,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,EAAQ,CAAE,MAAO,CAAC,KAAK,UAA4B,CAAC,CAAE,CAC5E,CAGA,IAAY,QAAM,CAChB,GAAI,CAAC,KAAK,OAAQ,OAAOE,EAAQ,KAAK,QAAQ,EAC9C,IAAMC,EAAS,KAAK,SAAS,SAC7B,OAAIA,GAAU,EAAU,EACjBD,EAAQ,KAAK,KAAK,QAAUC,CAAM,CAC3C,CAEU,WAAWC,EAAoB,CACvC,IAAMC,EAAO,KAAK,aACZC,EAAQD,GAAM,OAAS,EACvBE,EAASF,GAAM,QAAU,EAC/B,GAAIC,GAAS,GAAKC,GAAU,EAAG,OAE/B,IAAMC,EAAQ,KAAK,IAAI,EAAG,KAAK,MAAM,KAAK,IAAI,CAAC,EACzCC,EAAUC,EACd,KAAK,SACL,EACA,KAAK,SAAS,SACdF,CAAK,EAEDG,EAAQC,EAAWH,EAAS,CAChC,MAAAH,EACA,OAAAC,EACA,IAAK,KAAK,IACV,MAAO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AAE,QAAS,EAAE,CAAE,iCACaD,EAAA,CAArCC,EAAS,CAAE,QAAS,EAAK,CAAE,iCACOD,EAAA,CAAlCC,EAAS,CAAE,QAAS,CAAA,CAAE,CAAE,qCAOjBD,EAAA,CALPC,EAAS,CACR,QAAS,UACT,OAAQE,EAAQ,QAChB,MAAOA,EAAQ,KAChB,8BApBU/B,EAAY4B,EAAA,CAfxBI,EAAK,CACJ,IAAK,eACL,UAAW,OACX,SAAU,GACV,OAAQ,CACN,SAAU,WACV,iBAAkB,QAClB,kBAAmB,QACnB,gBAAiB,IAEnB,KAAM,CACJ,MAAO,IACP,OAAQ,KAEX,GACYhC,CAAY,EAoGzB,SAASiC,EAAMC,EAA4B,CACzC,IAAMC,EAAQD,EAAK,OACnB,GAAIC,EAAQ,EAAG,MAAO,CAAC,GAAGD,CAAI,EAC9B,IAAME,EAAO,KAAK,IAAI,EAAG,KAAK,MAAMD,EAAQ,CAAC,CAAC,EAE9C,OAAOD,EAAK,IAAI,CAACG,EAAKC,IAAK,CACzB,IAAMC,EAAU,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
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
7
  }
@@ -1,2 +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-B3JXGNP6.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};
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-DAFIVUTT.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
2
  //# sourceMappingURL=kit.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motionscript/audio",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.5",
4
4
  "exports": {
5
5
  ".": "dist/browser/index.js",
6
6
  "./kit": "dist/browser/kit.js"
@@ -8,5 +8,6 @@
8
8
  "peers": [
9
9
  "@motionscript/sdk"
10
10
  ],
11
- "assets": {}
11
+ "assets": {},
12
+ "thirdParty": []
12
13
  }
package/dist/index.js.map CHANGED
@@ -1 +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"]}
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\"\r\nexport { NODES } from \"./nodes\";\r\n"]}
package/dist/kit.js.map CHANGED
@@ -1 +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"]}
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":["/**\r\n * What the two waveform nodes share, importable without copying it.\r\n *\r\n * A registry item copies `envelope.ts` and `shared.ts` beside its node: they\r\n * hold no class and no registered state, so a fork owning its own copy splits\r\n * no identity. This is the same surface for a host that samples envelopes or\r\n * lays bars out itself, and for a fork that keeps only its node file.\r\n */\r\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./waveform/envelope\"\r\nexport type { AudioEnvelope, EnvelopeBar } from \"./waveform/envelope\"\r\nexport {\r\n VOICE_PALETTE,\r\n WAVEFORM_ALIGNMENTS,\r\n WAVEFORM_STYLES,\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n livePaintKey,\r\n paintBars,\r\n voiceColor,\r\n} from \"./waveform/shared\"\r\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./waveform/shared\"\r\n"]}
package/dist/nodes.js.map CHANGED
@@ -1 +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"]}
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\";\r\nimport { LiveWaveform } from \"./waveform/live-waveform\";\r\n\r\n/**\r\n * Every node type this package publishes.\r\n *\r\n * A host registers these by handing the array to an engine —\r\n * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`\r\n * key. The decorator only *declares* that key: nothing is registered by the mere\r\n * act of importing a module, so a registry holds exactly what its owner asked\r\n * for and two engines in one process can differ about it.\r\n *\r\n * Listing class **values** is also what survives bundling. This package declares\r\n * `sideEffects: false`, which licenses a bundler to drop a module nothing\r\n * imports a value from, and a document names a node type by string — so\r\n * `import \"./waveform/full-waveform\"` for its side effect is exactly what gets shaken out, where an\r\n * array of bindings is a data dependency that cannot be.\r\n */\r\nexport const NODES = [FullWaveform, LiveWaveform];\r\n"]}
@@ -1,6 +1,37 @@
1
1
  /**
2
2
  * The shape of a recording, as the waveform nodes draw it.
3
3
  *
4
+ * ## How an envelope reaches a node: the host supplies it
5
+ *
6
+ * Nothing in the engine, and nothing in this kit, decodes audio. A waveform node
7
+ * does not read a `sound` node's `src`, declares no audio asset and is not tied
8
+ * to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`
9
+ * prop. Decoding a file into an envelope is the host's job, done once per file
10
+ * before the document is built. Where the recording sits on the audio lane is
11
+ * the author's timing too, which is why `FullWaveform.follow` is opt-in.
12
+ *
13
+ * ### The JSON form
14
+ *
15
+ * A document holds the envelope as plain JSON, because a prop value in a
16
+ * document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of
17
+ * it; `ArrayLike<number>` also accepts the plain arrays a document stores:
18
+ *
19
+ * ```json
20
+ * {
21
+ * "magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
22
+ * "duration": 6,
23
+ * "speaker": [0, 0, 0, 1, 1, -1],
24
+ * "speakers": 2
25
+ * }
26
+ * ```
27
+ *
28
+ * `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`
29
+ * seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice
30
+ * index per bucket, `-1` for "nobody". `speakers` is the voice count, `0` when
31
+ * `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable
32
+ * (`JSON.stringify` writes an object of indices), so a host that holds the typed
33
+ * form converts with `Array.from` before storing it in a document.
34
+ *
4
35
  * ## Why the data is baked rather than listened to
5
36
  *
6
37
  * A scene has to render identically in the preview and in a headless export,
@@ -10,10 +41,9 @@
10
41
  * then a pure function of time, which is what makes scrubbing backwards, jumping
11
42
  * to frame 900, and rendering out of order all produce the same frame.
12
43
  *
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.
44
+ * The decode happens in the host, once per file, and arrives here through the
45
+ * build — the same arrangement a chart's rows and a protein's atoms already use,
46
+ * and for the same reason: the build is synchronous and cannot await a fetch.
17
47
  *
18
48
  * ## Why magnitude rather than min/max
19
49
  *
@@ -25,17 +55,20 @@
25
55
  */
26
56
  /**
27
57
  * A decoded recording, reduced to a uniform grid of loudness — plus, when the
28
- * app knows it, who is talking in each bucket.
58
+ * host knows it, who is talking in each bucket.
29
59
  *
30
60
  * 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
61
+ * diarized transcript and is folded in by the host before the build. It lives
32
62
  * here rather than in a parallel structure because every reader of it is also a
33
63
  * reader of the magnitudes at the same index, and two arrays that must stay the
34
64
  * same length are better as one object than as two arguments.
35
65
  */
36
66
  export interface AudioEnvelope {
37
- /** Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. */
38
- magnitude: Float32Array;
67
+ /**
68
+ * Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A
69
+ * `Float32Array`, or the plain `number[]` a document stores.
70
+ */
71
+ magnitude: ArrayLike<number>;
39
72
  /** The decoded length in seconds. */
40
73
  duration: number;
41
74
  /**
@@ -43,7 +76,7 @@ export interface AudioEnvelope {
43
76
  * own numbering, or `-1` for "nobody identified". Parallel to
44
77
  * {@link magnitude}, or `null` when the track was never diarized.
45
78
  */
46
- speaker: Int16Array | null;
79
+ speaker: ArrayLike<number> | null;
47
80
  /** How many distinct voices the diarizer found. Zero when it did not run. */
48
81
  speakers: number;
49
82
  }
@@ -1 +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"}
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAC5B,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;IACjC,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,aAK5B,CAAA;AAED,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,WAAW;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,WAAW,EAAE,CAkCf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,WAAW,EAAE,EACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,WAAW,EAAE,CAKf"}
@@ -1,6 +1,37 @@
1
1
  /**
2
2
  * The shape of a recording, as the waveform nodes draw it.
3
3
  *
4
+ * ## How an envelope reaches a node: the host supplies it
5
+ *
6
+ * Nothing in the engine, and nothing in this kit, decodes audio. A waveform node
7
+ * does not read a `sound` node's `src`, declares no audio asset and is not tied
8
+ * to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`
9
+ * prop. Decoding a file into an envelope is the host's job, done once per file
10
+ * before the document is built. Where the recording sits on the audio lane is
11
+ * the author's timing too, which is why `FullWaveform.follow` is opt-in.
12
+ *
13
+ * ### The JSON form
14
+ *
15
+ * A document holds the envelope as plain JSON, because a prop value in a
16
+ * document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of
17
+ * it; `ArrayLike<number>` also accepts the plain arrays a document stores:
18
+ *
19
+ * ```json
20
+ * {
21
+ * "magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
22
+ * "duration": 6,
23
+ * "speaker": [0, 0, 0, 1, 1, -1],
24
+ * "speakers": 2
25
+ * }
26
+ * ```
27
+ *
28
+ * `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`
29
+ * seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice
30
+ * index per bucket, `-1` for "nobody". `speakers` is the voice count, `0` when
31
+ * `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable
32
+ * (`JSON.stringify` writes an object of indices), so a host that holds the typed
33
+ * form converts with `Array.from` before storing it in a document.
34
+ *
4
35
  * ## Why the data is baked rather than listened to
5
36
  *
6
37
  * A scene has to render identically in the preview and in a headless export,
@@ -10,10 +41,9 @@
10
41
  * then a pure function of time, which is what makes scrubbing backwards, jumping
11
42
  * to frame 900, and rendering out of order all produce the same frame.
12
43
  *
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.
44
+ * The decode happens in the host, once per file, and arrives here through the
45
+ * build — the same arrangement a chart's rows and a protein's atoms already use,
46
+ * and for the same reason: the build is synchronous and cannot await a fetch.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E,EAAE,CACtB,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CACrE,CAAA;AACH,CAAC","sourcesContent":["/**\n * The shape of a recording, as the waveform nodes draw it.\n *\n * ## 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"]}
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AA8BH,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,SAAS,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,CAAC;CACZ,CAAA;AAUD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAuB,EACvB,IAAY,EACZ,EAAU,EACV,IAAY;IAEZ,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAC3C,MAAM,GAAG,GAAkB,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAA;IAEtE,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAA;IACzC,IAAI,KAAK,KAAK,CAAC,I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AAA;QACvD,CAAC;QAED,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IAC1C,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,IAAmB,EACnB,KAAoB;IAEpB,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACtB,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CACrE,CAAA;AACH,CAAC","sourcesContent":["/**\r\n * The shape of a recording, as the waveform nodes draw it.\r\n *\r\n * ## How an envelope reaches a node: the host supplies it\r\n *\r\n * Nothing in the engine, and nothing in this kit, decodes audio. A waveform node\r\n * does not read a `sound` node's `src`, declares no audio asset and is not tied\r\n * to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`\r\n * prop. Decoding a file into an envelope is the host's job, done once per file\r\n * before the document is built. Where the recording sits on the audio lane is\r\n * the author's timing too, which is why `FullWaveform.follow` is opt-in.\r\n *\r\n * ### The JSON form\r\n *\r\n * A document holds the envelope as plain JSON, because a prop value in a\r\n * document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of\r\n * it; `ArrayLike<number>` also accepts the plain arrays a document stores:\r\n *\r\n * ```json\r\n * {\r\n * \"magnitude\": [0, 0.25, 0.5, 1, 0.5, 0],\r\n * \"duration\": 6,\r\n * \"speaker\": [0, 0, 0, 1, 1, -1],\r\n * \"speakers\": 2\r\n * }\r\n * ```\r\n *\r\n * `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`\r\n * seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice\r\n * index per bucket, `-1` for \"nobody\". `speakers` is the voice count, `0` when\r\n * `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable\r\n * (`JSON.stringify` writes an object of indices), so a host that holds the typed\r\n * form converts with `Array.from` before storing it in a document.\r\n *\r\n * ## Why the data is baked rather than listened to\r\n *\r\n * A scene has to render identically in the preview and in a headless export,\r\n * and an export has no audio device, no `AudioContext` and no playback to\r\n * analyse. So a \"live\" visualiser cannot read a Web Audio analyser: what it\r\n * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is\r\n * then a pure function of time, which is what makes scrubbing backwards, jumping\r\n * to frame 900, and rendering out of order all produce the same frame.\r\n *\r\n * The decode happens in the host, once per file, and arrives here through the\r\n * build — the same arrangement a chart's rows and a protein's atoms already use,\r\n * and for the same reason: the build is synchronous and cannot await a fetch.\r\n *\r\n * ## Why magnitude rather than min/max\r\n *\r\n * An editor's waveform is drawn from per-bucket minima *and* maxima, because an\r\n * editor is a measuring instrument. These nodes are neither — they are a bar\r\n * chart of loudness that happens to be shaped like a recording — and audio is\r\n * near enough symmetric that a mirrored magnitude is indistinguishable at the\r\n * size a node draws. Half the numbers, and one array to reason about.\r\n */\r\n\r\n/**\r\n * A decoded recording, reduced to a uniform grid of loudness — plus, when the\r\n * host knows it, who is talking in each bucket.\r\n *\r\n * The speaker track is **not** something a decoder can produce; it comes from a\r\n * diarized transcript and is folded in by the host before the build. It lives\r\n * here rather than in a parallel structure because every reader of it is also a\r\n * reader of the magnitudes at the same index, and two arrays that must stay the\r\n * same length are better as one object than as two arguments.\r\n */\r\nexport interface AudioEnvelope {\r\n /**\r\n * Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A\r\n * `Float32Array`, or the plain `number[]` a document stores.\r\n */\r\n magnitude: ArrayLike<number>\r\n /** The decoded length in seconds. */\r\n duration: number\r\n /**\r\n * Which voice is speaking in each bucket, as an index into the recording's\r\n * own numbering, or `-1` for \"nobody identified\". Parallel to\r\n * {@link magnitude}, or `null` when the track was never diarized.\r\n */\r\n speaker: ArrayLike<number> | null\r\n /** How many distinct voices the diarizer found. Zero when it did not run. */\r\n speakers: number\r\n}\r\n\r\n/** The envelope of a track that hasn't loaded — or isn't there. */\r\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\r\n magnitude: new Float32Array(0),\r\n duration: 0,\r\n speaker: null,\r\n speakers: 0,\r\n}\r\n\r\n/** One drawn bar: how loud, and whose. */\r\nexport interface EnvelopeBar {\r\n /** 0…1. */\r\n magnitude: number\r\n /** The voice index, or -1. */\r\n speaker: number\r\n}\r\n\r\n/**\r\n * Resamples `[from, to)` seconds of an envelope down to `bars` columns.\r\n *\r\n * Peak-preserving rather than averaging, which is the whole difference between\r\n * a waveform and a blur: averaging a hundred buckets into one column flattens\r\n * every transient, and transients are what makes a drawn recording read as\r\n * speech rather than as noise. The speaker of a column is the speaker of its\r\n * *loudest* bucket, on the same reasoning — a column straddling a turn belongs\r\n * to whoever is actually audible in it.\r\n *\r\n * A window past either end of the recording yields silent, unattributed\r\n * columns rather than clamping onto the nearest real one. That matters for the\r\n * live visualiser, which is handed a window centred on the playhead and would\r\n * otherwise smear the first bucket across the whole run-up to a track's start.\r\n */\r\nexport function sampleEnvelope(\r\n envelope: AudioEnvelope,\r\n from: number,\r\n to: number,\r\n bars: number\r\n): EnvelopeBar[] {\r\n const count = Math.max(0, Math.floor(bars))\r\n const out: EnvelopeBar[] = new Array(count)\r\n for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }\r\n\r\n const buckets = envelope.magnitude.length\r\n if (count === 0 || buckets === 0 || envelope.duration <= 0) return out\r\n\r\n const perSecond = buckets / envelope.duration\r\n const span = (to - from) / count\r\n\r\n for (let i = 0; i < count; i++) {\r\n const start = (from + span * i) * perSecond\r\n const end = (from + span * (i + 1)) * perSecond\r\n\r\n // At least one bucket per column, so a window zoomed in past the grid draws\r\n // the sample it is standing on rather than an empty band.\r\n const first = Math.floor(start)\r\n const last = Math.max(first, Math.ceil(end) - 1)\r\n\r\n let loudest = 0\r\n let speaker = -1\r\n for (let b = first; b <= last; b++) {\r\n if (b < 0 || b >= buckets) continue\r\n const value = envelope.magnitude[b]\r\n if (value < loudest) continue\r\n loudest = value\r\n speaker = envelope.speaker ? envelope.speaker[b] : -1\r\n }\r\n\r\n out[i] = { magnitude: loudest, speaker }\r\n }\r\n\r\n return out\r\n}\r\n\r\n/**\r\n * The same window, with everything that isn't `voice` silenced.\r\n *\r\n * The point of the speaker filter, and the reason it silences rather than\r\n * *drops*: a podcast visualiser filtered to one host should go quiet while the\r\n * other one talks, not compress their turn out of existence. Keeping the bars\r\n * and zeroing them is what makes the picture read as \"this person is not\r\n * speaking right now\" instead of as a jump cut.\r\n *\r\n * `voice` of `null` returns the bars untouched, which is the unfiltered node.\r\n */\r\nexport function forSpeaker(\r\n bars: EnvelopeBar[],\r\n voice: number | null\r\n): EnvelopeBar[] {\r\n if (voice === null) return bars\r\n return bars.map((bar) =>\r\n bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }\r\n )\r\n}\r\n"]}
@@ -53,8 +53,7 @@ export interface FullWaveformProps extends Node2DProps {
53
53
  * ## Voices instead of progress
54
54
  *
55
55
  * With {@link byVoice} on, the played/ahead split is replaced by one colour per
56
- * speaking voice — the drawing the timeline's clip bars already make, at a size
57
- * you can read. For a two-hander it is a map of the conversation: who has the
56
+ * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
58
57
  * floor, where the turns are, how long each one ran. It replaces the progress
59
58
  * colours rather than combining with them, because a bar cannot mean two things
60
59
  * at once and "played, and also Grace" is a legend nobody can hold in their
@@ -1 +1 @@
1
- {"version":3,"file":"full-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAMN,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,IAAI,EAET,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,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E,iBAAiB,CAAA;IACxB,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAA;IAChB,0EAA0E;IAC1E,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,sCAAsC;IACtC,IAAI,EAAE,IAAI,CAAA;IACV,+BAA+B;IAC/B,UAAU,EAAE,IAAI,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAea,YAAa,SAAQ,MAAM,CAAC,iBAAiB,CAAC;IACV,QAAQ,EAAE,aAAa,CAAA;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACR,KAAK,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,iBAAiB,CAAA;IAC3B,OAAO,EAAE,OAAO,CAAA;IACnB,WAAW,EAAE,MAAM,EAAE,CAAA;IAOhD,IAAI,EAAE,IAAI,CAAA;IAOV,UAAU,EAAE,IAAI,CAAA;IAExB;;;OAGG;IAEH,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAQhF;;;;OAIG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,sEAAsE;IACtE,OAAO,KAAK,MAAM,GAKjB;IAED,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;IAyChD;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ;CAQjB"}
@@ -32,8 +32,7 @@ import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./sha
32
32
  * ## Voices instead of progress
33
33
  *
34
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
35
+ * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
37
36
  * floor, where the turns are, how long each one ran. It replaces the progress
38
37
  * colours rather than combining with them, because a bar cannot mean two things
39
38
  * at once and "played, and also Grace" is a legend nobody can hold in their
@@ -1 +1 @@
1
- {"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,GAOT,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAA;AAC/E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GAEX,MAAM,UAAU,CAAA;AA8BjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAgBI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,MAAyB;IA2BzD;;;OAGG;IAEH,KAAK,CAAC,IAA+D;QACnE,OAAO,IAAI,CAAC,EAAE,CAAC;YACb,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAgC;YACnD,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS,EAAE;SACnC,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,UAA4B,CAAC,EAAE,CAAC,CAAA;IAC7E,CAAC;IAED,sEAAsE;IACtE,IAAY,MAAM;QAChB,IAAI,CAAC,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\n fillOps,\n property,\n type AssetScope,\n type CommandArgs,\n type Fill,\n type FillResolved,\n type Node2DProps,\n type RenderContext2D,\n} from \"@motionscript/sdk\"\n\nimport { declarePaints } from \"@motionscript/sdk/component\"\nimport type { Seekable } from \"@motionscript/sdk/component\"\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\nexport interface FullWaveformProps extends Node2DProps {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: AudioEnvelope\n /** How many columns the whole file is drawn as. */\n bars: number\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: number\n /** Corner radius of a bar, capped at half its width. */\n radius: number\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: number\n /** Drive {@link progress} from the node's own clock instead of the prop. */\n follow: boolean\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: number\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: number\n align: WaveformAlignment\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: boolean\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: string[]\n /** The bars ahead of the playhead. */\n fill: Fill\n /** …and the bars behind it. */\n playedFill: Fill\n}\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * {@link follow} is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\n * speaking voice — the drawing the timeline's clip bars already make, at a size\n * you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\n@node({\n key: \"fullWaveform\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"freeform\",\n defaultWidthMode: \"fixed\",\n defaultHeightMode: \"fixed\",\n acceptsChildren: true,\n },\n seed: {\n width: 900,\n height: 160,\n },\n})\nexport class FullWaveform extends Node2D<FullWaveformProps> {\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\n @property({ default: 120 }) declare bars: number\n @property({ default: 0.3 }) declare gap: number\n @property({ default: 2 }) declare radius: number\n @property({ default: 0 }) declare progress: number\n @property({ default: false }) declare follow: boolean\n @property({ default: 1 }) declare gain: number\n @property({ default: 0.015 }) declare floor: number\n @property({ default: \"center\" }) declare align: WaveformAlignment\n @property({ default: false }) declare byVoice: boolean\n @property({ default: [] }) declare voiceColors: string[]\n\n @property({\n default: \"#5b5b7a\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n\n @property({\n default: \"#6366f1\",\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare playedFill: Fill\n\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`.\n */\n @command()\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\n return this.to({\n data: { progress: 1 } as Partial<FullWaveformProps>,\n duration: args.duration,\n easing: args.easing ?? easeInOut(),\n })\n }\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\n * past the conventional slots, so it is passed explicitly.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\n }\n\n /** Where the fill has reached, from whichever source is in charge. */\n private get played(): number {\n if (!this.follow) return clamp01(this.progress)\n const length = this.envelope.duration\n if (length <= 0) return 0\n return clamp01(this.time.elapsed / length)\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const rect = this.layoutBounds\n const width = rect?.width ?? 0\n const height = rect?.height ?? 0\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(this.bars))\n const sampled = sampleEnvelope(\n this.envelope,\n 0,\n this.envelope.duration,\n count\n )\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: this.gap,\n align: this.align,\n gain: this.gain,\n floor: this.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = this.played * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n this.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, this.paintFor(key), this.radius)\n if (graphics) ctx.draw(graphics)\n }\n }\n\n /**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why {@link declareAssets}\n * only has to account for the two real fill props.\n */\n private paintFor(key: string): Fill {\n if (key === \"played\") return this.playedFill\n if (key === \"ahead\") return this.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return this.fill\n return this.voiceColors[voice] ?? voiceColor(voice)\n }\n}\n"]}
1
+ {"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,E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AAE,CAAC;2CAAsB;AACV;IAAxC,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;2CAAiC;AAC3B;IAArC,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;6CAAyB;AACnB;IAAlC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;iDAA8B;AAOhD;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;0CACgB;AAOV;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;gDACsB;AAOxB;IADC,OAAO,EAAE;yCAOT;AAtCU,YAAY;IAfxB,IAAI,CAAC;QACJ,GAAG,EAAE,cAAc;QACnB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,QAAQ,EAAE,UAAU;YACpB,gBAAgB,EAAE,OAAO;YACzB,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,IAAI;SACtB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;SACZ;KACF,CAAC;GACW,YAAY,CAoHxB","sourcesContent":["import {\r\n Node2D,\r\n node,\r\n command,\r\n easeInOut,\r\n fillOps,\r\n property,\r\n type AssetScope,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\nimport type { Seekable } from \"@motionscript/sdk/component\"\r\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\r\nimport {\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n type WaveformAlignment,\r\n} from \"./shared\"\r\n\r\nexport interface FullWaveformProps extends Node2DProps {\r\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\r\n envelope: AudioEnvelope\r\n /** How many columns the whole file is drawn as. */\r\n bars: number\r\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\r\n gap: number\r\n /** Corner radius of a bar, capped at half its width. */\r\n radius: number\r\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\r\n progress: number\r\n /** Drive {@link progress} from the node's own clock instead of the prop. */\r\n follow: boolean\r\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\r\n gain: number\r\n /** How much of the box a silent bar still occupies, `0`–`1`. */\r\n floor: number\r\n align: WaveformAlignment\r\n /** Colour each voice's turns rather than splitting on played / not played. */\r\n byVoice: boolean\r\n /** A colour per voice index. Short or empty falls back to the palette. */\r\n voiceColors: string[]\r\n /** The bars ahead of the playhead. */\r\n fill: Fill\r\n /** …and the bars behind it. */\r\n playedFill: Fill\r\n}\r\n\r\n/**\r\n * A **waveform overview**: the whole recording's shape, drawn at once.\r\n *\r\n * The picture every audio editor opens with, and the one a podcast clip puts\r\n * under its caption — a static silhouette of the file, with a played portion\r\n * that advances. It answers \"how long is this and where are the loud parts\",\r\n * which is a question about the *file*, not about the moment; its sibling\r\n * {@link LiveWaveform} answers the other one.\r\n *\r\n * ## Progress is authored, not assumed\r\n *\r\n * {@link follow} is off by default, and that default is the considered one. A\r\n * scene has no idea where the recording it is drawing sits on the video's audio\r\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\r\n * visible from in here. So the honest default is that the fill is *animation*:\r\n * the author sweeps it with a command, the same as any other tween, and it lands\r\n * wherever they put it. `follow` is the shortcut for the common arrangement\r\n * where the node appears exactly as the track starts, and it says so by being a\r\n * switch someone has to turn on rather than a behaviour that quietly disagrees\r\n * with the mix.\r\n *\r\n * ## Voices instead of progress\r\n *\r\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\r\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\r\n * floor, where the turns are, how long each one ran. It replaces the progress\r\n * colours rather than combining with them, because a bar cannot mean two things\r\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\r\n * head.\r\n */\r\n@node({\r\n key: \"fullWaveform\",\r\n parentKey: \"node\",\r\n forkable: true,\r\n layout: {\r\n children: \"freeform\",\r\n defaultWidthMode: \"fixed\",\r\n defaultHeightMode: \"fixed\",\r\n acceptsChildren: true,\r\n },\r\n seed: {\r\n width: 900,\r\n height: 160,\r\n },\r\n})\r\nexport class FullWaveform extends Node2D<FullWaveformProps> {\r\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\r\n @property({ default: 120 }) declare bars: number\r\n @property({ default: 0.3 }) declare gap: number\r\n @property({ default: 2 }) declare radius: number\r\n @property({ default: 0 }) declare progress: number\r\n @property({ default: false }) declare follow: boolean\r\n @property({ default: 1 }) declare gain: number\r\n @property({ default: 0.015 }) declare floor: number\r\n @property({ default: \"center\" }) declare align: WaveformAlignment\r\n @property({ default: false }) declare byVoice: boolean\r\n @property({ default: [] }) declare voiceColors: string[]\r\n\r\n @property({\r\n default: \"#5b5b7a\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare fill: Fill\r\n\r\n @property({\r\n default: \"#6366f1\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare playedFill: Fill\r\n\r\n /**\r\n * Fill the waveform in, left to right — the node's one command, since\r\n * everything else about it is expressible as an ordinary `to`.\r\n */\r\n @command()\r\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\r\n return this.to({\r\n data: { progress: 1 } as Partial<FullWaveformProps>,\r\n duration: args.duration,\r\n easing: args.easing ?? easeInOut(),\r\n })\r\n }\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\r\n * past the conventional slots, so it is passed explicitly.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\r\n }\r\n\r\n /** Where the fill has reached, from whichever source is in charge. */\r\n private get played(): number {\r\n if (!this.follow) return clamp01(this.progress)\r\n const length = this.envelope.duration\r\n if (length <= 0) return 0\r\n return clamp01(this.time.elapsed / length)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const rect = this.layoutBounds\r\n const width = rect?.width ?? 0\r\n const height = rect?.height ?? 0\r\n if (width <= 0 || height <= 0) return\r\n\r\n const count = Math.max(1, Math.round(this.bars))\r\n const sampled = sampleEnvelope(\r\n this.envelope,\r\n 0,\r\n this.envelope.duration,\r\n count\r\n )\r\n const boxes = layOutBars(sampled, {\r\n width,\r\n height,\r\n gap: this.gap,\r\n align: this.align,\r\n gain: this.gain,\r\n floor: this.floor,\r\n })\r\n if (boxes.length === 0) return\r\n\r\n // One draw per colour rather than per bar — see {@link paintBars}. The key\r\n // is a string because it has to be comparable; the paint it stands for is\r\n // resolved after the grouping.\r\n const edge = this.played * boxes.length\r\n const groups = groupByPaint(boxes, (i) =>\r\n this.byVoice\r\n ? `voice:${sampled[i].speaker}`\r\n : i < edge\r\n ? \"played\"\r\n : \"ahead\"\r\n )\r\n\r\n for (const [key, run] of groups) {\r\n const graphics = paintBars(run, this.paintFor(key), this.radius)\r\n if (graphics) ctx.draw(graphics)\r\n }\r\n }\r\n\r\n /**\r\n * The paint a group takes.\r\n *\r\n * A voice's colour is a **colour string**, never one of the node's two fill\r\n * props, and that is deliberate: a voice is identified by hue, so a gradient\r\n * or an image there would defeat the only thing the colour is for. It also\r\n * means these paints declare no assets, which is why {@link declareAssets}\r\n * only has to account for the two real fill props.\r\n */\r\n private paintFor(key: string): Fill {\r\n if (key === \"played\") return this.playedFill\r\n if (key === \"ahead\") return this.fill\r\n\r\n const voice = Number(key.slice(\"voice:\".length))\r\n if (!Number.isFinite(voice) || voice < 0) return this.fill\r\n return this.voiceColors[voice] ?? voiceColor(voice)\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEvE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAA","sourcesContent":["/**\n * The waveform family: one subject, two questions.\n *\n * - {@link FullWaveform} draws the **file** — the whole recording's silhouette,\n * with a played portion that advances. \"How long is this, and where are the\n * loud parts.\"\n * - {@link LiveWaveform} draws the **moment** — bars moving with playback, the\n * visualiser a podcast clip puts beside the artwork. \"Is anything happening\n * right now, and whose voice is it.\"\n *\n * Both read the same baked {@link AudioEnvelope}, which is why they cannot\n * disagree about a recording, and why neither listens to anything — see that\n * module for why a scene that has to export cannot use a live analyser.\n */\nexport { FullWaveform } from \"./full-waveform\"\nexport type { FullWaveformProps } from \"./full-waveform\"\nexport { LiveWaveform } from \"./live-waveform\"\nexport type { LiveWaveformProps } from \"./live-waveform\"\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./envelope\"\nexport type { AudioEnvelope, EnvelopeBar } from \"./envelope\"\nexport {\n VOICE_PALETTE,\n WAVEFORM_ALIGNMENTS,\n WAVEFORM_STYLES,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n} from \"./shared\"\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./shared\"\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEvE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAA","sourcesContent":["/**\r\n * The waveform family: one subject, two questions.\r\n *\r\n * - {@link FullWaveform} draws the **file** — the whole recording's silhouette,\r\n * with a played portion that advances. \"How long is this, and where are the\r\n * loud parts.\"\r\n * - {@link LiveWaveform} draws the **moment** — bars moving with playback, the\r\n * visualiser a podcast clip puts beside the artwork. \"Is anything happening\r\n * right now, and whose voice is it.\"\r\n *\r\n * Both read the same baked {@link AudioEnvelope}, which is why they cannot\r\n * disagree about a recording, and why neither listens to anything — see that\r\n * module for why a scene that has to export cannot use a live analyser.\r\n */\r\nexport { FullWaveform } from \"./full-waveform\"\r\nexport type { FullWaveformProps } from \"./full-waveform\"\r\nexport { LiveWaveform } from \"./live-waveform\"\r\nexport type { LiveWaveformProps } from \"./live-waveform\"\r\nexport { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from \"./envelope\"\r\nexport type { AudioEnvelope, EnvelopeBar } from \"./envelope\"\r\nexport {\r\n VOICE_PALETTE,\r\n WAVEFORM_ALIGNMENTS,\r\n WAVEFORM_STYLES,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n} from \"./shared\"\r\nexport type { BarBox, WaveformAlignment, WaveformStyle } from \"./shared\"\r\n"]}
@@ -86,9 +86,9 @@ export declare class LiveWaveform extends Node2D<LiveWaveformProps> {
86
86
  * The second of the recording the visualiser is showing.
87
87
  *
88
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
89
+ * moment this node appeared" means — the same clock the engine's own
90
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
91
+ * halfway through a clip start its recording at its entrance rather than
92
92
  * partway in.
93
93
  */
94
94
  private get at();
@@ -50,9 +50,9 @@ let LiveWaveform = class LiveWaveform extends Node2D {
50
50
  * The second of the recording the visualiser is showing.
51
51
  *
52
52
  * Off the node's own clock rather than the scene's, which is what "from the
53
- * moment this node appeared" means — the same clock motion-script's own
53
+ * moment this node appeared" means — the same clock the engine's own
54
54
  * `Video` times its picture from, and the same one that makes a node dropped
55
- * halfway through a scene start its recording at its entrance rather than
55
+ * halfway through a clip start its recording at its entrance rather than
56
56
  * partway in.
57
57
  */
58
58
  get at() {