@motionscript/audio 0.1.0 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/browser/chunks/chunk-WUH3G22N.js +2 -0
- package/dist/browser/chunks/chunk-WUH3G22N.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/kit.d.ts +1 -9
- package/dist/kit.d.ts.map +1 -1
- package/dist/kit.js +2 -9
- package/dist/kit.js.map +1 -1
- package/dist/nodes.d.ts +0 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -12
- package/dist/nodes.js.map +1 -1
- package/dist/waveform/envelope.d.ts +27 -98
- package/dist/waveform/envelope.d.ts.map +1 -1
- package/dist/waveform/envelope.js +17 -77
- package/dist/waveform/envelope.js.map +1 -1
- package/dist/waveform/full-waveform.d.ts +32 -61
- package/dist/waveform/full-waveform.d.ts.map +1 -1
- package/dist/waveform/full-waveform.js +25 -66
- package/dist/waveform/full-waveform.js.map +1 -1
- package/dist/waveform/index.d.ts +0 -16
- package/dist/waveform/index.d.ts.map +1 -1
- package/dist/waveform/index.js +0 -14
- package/dist/waveform/index.js.map +1 -1
- package/dist/waveform/live-waveform.d.ts +33 -70
- package/dist/waveform/live-waveform.d.ts.map +1 -1
- package/dist/waveform/live-waveform.js +24 -74
- package/dist/waveform/live-waveform.js.map +1 -1
- package/dist/waveform/shared.d.ts +21 -62
- package/dist/waveform/shared.d.ts.map +1 -1
- package/dist/waveform/shared.js +33 -71
- package/dist/waveform/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/kit.ts +1 -9
- package/src/nodes.ts +0 -12
- package/src/waveform/envelope.ts +28 -100
- package/src/waveform/full-waveform.ts +25 -67
- package/src/waveform/index.ts +0 -16
- package/src/waveform/live-waveform.ts +24 -74
- package/src/waveform/shared.ts +33 -78
- package/dist/browser/chunks/chunk-DD3KHRUL.js +0 -2
- package/dist/browser/chunks/chunk-DD3KHRUL.js.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/waveform/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAmBH,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;AASD;;;;;;GAMG;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,IAAI,OAAO,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,IAAI,CAAC;QAAE,OAAO,GAAG,CAAA;IAEtE,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAA;IAC7C,MAAM,IAAI,GAAG,CAAC,EAAE,GAAG,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B;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":["/**\n * The host decodes audio into an {@link AudioEnvelope} once per file, before the\n * build, and hands it to the node; nothing here decodes or listens. It is baked\n * because an export has no audio device or analyser, and the picture must be a\n * pure function of time.\n *\n * In a document an envelope is plain JSON, which `ArrayLike<number>` accepts.\n * A `Float32Array` is not JSON-serialisable (`JSON.stringify` writes an object\n * of indices), so convert with `Array.from` before storing it.\n */\n\n/**\n * A recording reduced to a uniform grid of loudness, plus who is talking in each\n * bucket when the host knows. The speaker track comes from a diarized transcript,\n * not the decoder; it lives here because every reader of it also reads the\n * magnitudes at the same index.\n */\nexport interface AudioEnvelope {\n /** Peak magnitude per bucket, 0 to 1; buckets span {@link duration} evenly. */\n magnitude: ArrayLike<number>\n /** Seconds. */\n duration: number\n /** Voice index per bucket (`-1` for nobody), parallel to {@link magnitude}, or `null` when never diarized. */\n speaker: ArrayLike<number> | null\n /** Zero when the diarizer did not run. */\n speakers: number\n}\n\n/** The envelope of a track that has not loaded or is not there. */\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\n magnitude: new Float32Array(0),\n duration: 0,\n speaker: null,\n speakers: 0,\n}\n\nexport interface EnvelopeBar {\n /** 0 to 1. */\n magnitude: number\n /** Voice index, or -1. */\n speaker: number\n}\n\n/**\n * Resamples `[from, to)` seconds down to `bars` columns, keeping peaks rather\n * than averaging: averaging flattens the transients that make a drawing read as\n * speech. A column's speaker is that of its loudest bucket. A window past either\n * end yields silent, unattributed columns rather than clamping onto the nearest\n * real one, which would smear the first bucket across a live window's run-up.\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 zoomed-in window draws the sample it stands on.\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 but `voice` silenced, not dropped, so a\n * filtered visualiser goes quiet while the other host talks instead of cutting\n * their turn out. `null` returns the bars untouched.\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,118 +1,89 @@
|
|
|
1
1
|
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps } from "@motionscript/sdk";
|
|
2
2
|
import { type AudioEnvelope } from "./envelope.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The whole recording's shape drawn at once, with a played portion that
|
|
5
|
+
* advances: a picture of the file where {@link LiveWaveform} is of the moment.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* ## Progress is authored, not assumed
|
|
13
|
-
*
|
|
14
|
-
* `follow` is off by default, and that default is the considered one. A
|
|
15
|
-
* scene has no idea where the recording it is drawing sits on the video's audio
|
|
16
|
-
* lane — a clip is placed, trimmed and sped up out there, and none of that is
|
|
17
|
-
* visible from in here. So the honest default is that the fill is *animation*:
|
|
18
|
-
* the author sweeps it with a command, the same as any other tween, and it lands
|
|
19
|
-
* wherever they put it. `follow` is the shortcut for the common arrangement
|
|
20
|
-
* where the node appears exactly as the track starts, and it says so by being a
|
|
21
|
-
* switch someone has to turn on rather than a behaviour that quietly disagrees
|
|
22
|
-
* with the mix.
|
|
23
|
-
*
|
|
24
|
-
* ## Voices instead of progress
|
|
25
|
-
*
|
|
26
|
-
* With `byVoice` on, the played/ahead split is replaced by one colour per
|
|
27
|
-
* speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
|
|
28
|
-
* floor, where the turns are, how long each one ran. It replaces the progress
|
|
29
|
-
* colours rather than combining with them, because a bar cannot mean two things
|
|
30
|
-
* at once and "played, and also Grace" is a legend nobody can hold in their
|
|
31
|
-
* head.
|
|
7
|
+
* `follow` is off by default because a scene cannot see where the recording sits
|
|
8
|
+
* on the video's audio lane (placed, trimmed, sped up); the author sweeps
|
|
9
|
+
* `progress` with a command, and `follow` is the opt-in for a node that appears
|
|
10
|
+
* exactly as the track starts. `byVoice` replaces the played/ahead split with
|
|
11
|
+
* one colour per voice rather than combining with it: a bar cannot mean two
|
|
12
|
+
* things at once.
|
|
32
13
|
*/
|
|
33
14
|
export declare const FullWaveform: import("@motionscript/sdk").Component<"fullWaveform", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
34
|
-
/** The baked recording
|
|
15
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
35
16
|
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
36
|
-
/** How many columns the whole file is drawn as. */
|
|
37
17
|
readonly bars: 120;
|
|
38
|
-
/** Space between bars
|
|
18
|
+
/** Space between bars as a fraction of the pitch; see {@link layOutBars}. */
|
|
39
19
|
readonly gap: 0.3;
|
|
40
|
-
/**
|
|
20
|
+
/** Capped at half the bar's width. */
|
|
41
21
|
readonly radius: 2;
|
|
42
|
-
/**
|
|
22
|
+
/** The share of the file that reads as played, `0`-`1`. */
|
|
43
23
|
readonly progress: 0;
|
|
44
|
-
/** Drive `progress` from the node's own clock instead
|
|
24
|
+
/** Drive `progress` from the node's own clock instead. */
|
|
45
25
|
readonly follow: false;
|
|
46
|
-
/** Multiplies every magnitude
|
|
26
|
+
/** Multiplies every magnitude, pulling a quiet track up to fill its box. */
|
|
47
27
|
readonly gain: 1;
|
|
48
|
-
/**
|
|
28
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
49
29
|
readonly floor: 0.015;
|
|
50
30
|
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
51
|
-
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
52
31
|
readonly byVoice: false;
|
|
53
|
-
/** A colour per voice index
|
|
32
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
54
33
|
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
55
34
|
/** The bars ahead of the playhead. */
|
|
56
35
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
57
|
-
/** …and the bars behind it. */
|
|
58
36
|
readonly playedFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
59
37
|
}>, {
|
|
60
38
|
readonly sweep: unknown;
|
|
61
39
|
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
62
|
-
/** The baked recording
|
|
40
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
63
41
|
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
64
|
-
/** How many columns the whole file is drawn as. */
|
|
65
42
|
readonly bars: 120;
|
|
66
|
-
/** Space between bars
|
|
43
|
+
/** Space between bars as a fraction of the pitch; see {@link layOutBars}. */
|
|
67
44
|
readonly gap: 0.3;
|
|
68
|
-
/**
|
|
45
|
+
/** Capped at half the bar's width. */
|
|
69
46
|
readonly radius: 2;
|
|
70
|
-
/**
|
|
47
|
+
/** The share of the file that reads as played, `0`-`1`. */
|
|
71
48
|
readonly progress: 0;
|
|
72
|
-
/** Drive `progress` from the node's own clock instead
|
|
49
|
+
/** Drive `progress` from the node's own clock instead. */
|
|
73
50
|
readonly follow: false;
|
|
74
|
-
/** Multiplies every magnitude
|
|
51
|
+
/** Multiplies every magnitude, pulling a quiet track up to fill its box. */
|
|
75
52
|
readonly gain: 1;
|
|
76
|
-
/**
|
|
53
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
77
54
|
readonly floor: 0.015;
|
|
78
55
|
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
79
|
-
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
80
56
|
readonly byVoice: false;
|
|
81
|
-
/** A colour per voice index
|
|
57
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
82
58
|
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
83
59
|
/** The bars ahead of the playhead. */
|
|
84
60
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
85
|
-
/** …and the bars behind it. */
|
|
86
61
|
readonly playedFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
87
62
|
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
88
|
-
/** The baked recording
|
|
63
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
89
64
|
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
90
|
-
/** How many columns the whole file is drawn as. */
|
|
91
65
|
readonly bars: 120;
|
|
92
|
-
/** Space between bars
|
|
66
|
+
/** Space between bars as a fraction of the pitch; see {@link layOutBars}. */
|
|
93
67
|
readonly gap: 0.3;
|
|
94
|
-
/**
|
|
68
|
+
/** Capped at half the bar's width. */
|
|
95
69
|
readonly radius: 2;
|
|
96
|
-
/**
|
|
70
|
+
/** The share of the file that reads as played, `0`-`1`. */
|
|
97
71
|
readonly progress: 0;
|
|
98
|
-
/** Drive `progress` from the node's own clock instead
|
|
72
|
+
/** Drive `progress` from the node's own clock instead. */
|
|
99
73
|
readonly follow: false;
|
|
100
|
-
/** Multiplies every magnitude
|
|
74
|
+
/** Multiplies every magnitude, pulling a quiet track up to fill its box. */
|
|
101
75
|
readonly gain: 1;
|
|
102
|
-
/**
|
|
76
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
103
77
|
readonly floor: 0.015;
|
|
104
78
|
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
105
|
-
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
106
79
|
readonly byVoice: false;
|
|
107
|
-
/** A colour per voice index
|
|
80
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
108
81
|
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
109
82
|
/** The bars ahead of the playhead. */
|
|
110
83
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
111
|
-
/** …and the bars behind it. */
|
|
112
84
|
readonly playedFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
113
85
|
}>, {
|
|
114
86
|
readonly sweep: unknown;
|
|
115
87
|
}, _Node2D<_Node2DProps>>>>;
|
|
116
88
|
export type FullWaveform = NodeOf<typeof FullWaveform>;
|
|
117
|
-
export type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>;
|
|
118
89
|
//# sourceMappingURL=full-waveform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"full-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"full-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAGX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EACjC,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAa/E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY;IAGrB,sDAAsD;;;IAGtD,6EAA6E;;IAE7E,sCAAsC;;IAEtC,2DAA2D;;IAE3D,0DAA0D;;IAE1D,4EAA4E;;IAE5E,iEAAiE;;;;IAIjE,0EAA0E;;IAE1E,sCAAsC;;;;;;IAnBtC,sDAAsD;;;IAGtD,6EAA6E;;IAE7E,sCAAsC;;IAEtC,2DAA2D;;IAE3D,0DAA0D;;IAE1D,4EAA4E;;IAE5E,iEAAiE;;;;IAIjE,0EAA0E;;IAE1E,sCAAsC;;;;IAnBtC,sDAAsD;;;IAGtD,6EAA6E;;IAE7E,sCAAsC;;IAEtC,2DAA2D;;IAE3D,0DAA0D;;IAE1D,4EAA4E;;IAE5E,iEAAiE;;;;IAIjE,0EAA0E;;IAE1E,sCAAsC;;;;;2BAqBxC,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA"}
|
|
@@ -1,78 +1,52 @@
|
|
|
1
|
-
import { Types, component2d, easeInOut, fillOps, } from "@motionscript/sdk";
|
|
1
|
+
import { Types, clamp, component2d, easeInOut, fillOps, } from "@motionscript/sdk";
|
|
2
2
|
import { EMPTY_ENVELOPE, sampleEnvelope } from "./envelope.js";
|
|
3
|
-
import {
|
|
4
|
-
/** A
|
|
3
|
+
import { groupByPaint, layOutBars, paintBars, voiceFill, } from "./shared.js";
|
|
4
|
+
/** A fill entry whose kind is read off the default. */
|
|
5
5
|
const paint = (initial) => Types.custom(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp });
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* The whole recording's shape drawn at once, with a played portion that
|
|
8
|
+
* advances: a picture of the file where {@link LiveWaveform} is of the moment.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* ## Progress is authored, not assumed
|
|
16
|
-
*
|
|
17
|
-
* `follow` is off by default, and that default is the considered one. A
|
|
18
|
-
* scene has no idea where the recording it is drawing sits on the video's audio
|
|
19
|
-
* lane — a clip is placed, trimmed and sped up out there, and none of that is
|
|
20
|
-
* visible from in here. So the honest default is that the fill is *animation*:
|
|
21
|
-
* the author sweeps it with a command, the same as any other tween, and it lands
|
|
22
|
-
* wherever they put it. `follow` is the shortcut for the common arrangement
|
|
23
|
-
* where the node appears exactly as the track starts, and it says so by being a
|
|
24
|
-
* switch someone has to turn on rather than a behaviour that quietly disagrees
|
|
25
|
-
* with the mix.
|
|
26
|
-
*
|
|
27
|
-
* ## Voices instead of progress
|
|
28
|
-
*
|
|
29
|
-
* With `byVoice` on, the played/ahead split is replaced by one colour per
|
|
30
|
-
* speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
|
|
31
|
-
* floor, where the turns are, how long each one ran. It replaces the progress
|
|
32
|
-
* colours rather than combining with them, because a bar cannot mean two things
|
|
33
|
-
* at once and "played, and also Grace" is a legend nobody can hold in their
|
|
34
|
-
* head.
|
|
10
|
+
* `follow` is off by default because a scene cannot see where the recording sits
|
|
11
|
+
* on the video's audio lane (placed, trimmed, sped up); the author sweeps
|
|
12
|
+
* `progress` with a command, and `follow` is the opt-in for a node that appears
|
|
13
|
+
* exactly as the track starts. `byVoice` replaces the played/ahead split with
|
|
14
|
+
* one colour per voice rather than combining with it: a bar cannot mean two
|
|
15
|
+
* things at once.
|
|
35
16
|
*/
|
|
36
17
|
export const FullWaveform = component2d({
|
|
37
18
|
key: "fullWaveform",
|
|
38
19
|
state: {
|
|
39
|
-
/** The baked recording
|
|
20
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
40
21
|
envelope: Types.custom(EMPTY_ENVELOPE),
|
|
41
|
-
/** How many columns the whole file is drawn as. */
|
|
42
22
|
bars: 120,
|
|
43
|
-
/** Space between bars
|
|
23
|
+
/** Space between bars as a fraction of the pitch; see {@link layOutBars}. */
|
|
44
24
|
gap: 0.3,
|
|
45
|
-
/**
|
|
25
|
+
/** Capped at half the bar's width. */
|
|
46
26
|
radius: 2,
|
|
47
|
-
/**
|
|
27
|
+
/** The share of the file that reads as played, `0`-`1`. */
|
|
48
28
|
progress: 0,
|
|
49
|
-
/** Drive `progress` from the node's own clock instead
|
|
29
|
+
/** Drive `progress` from the node's own clock instead. */
|
|
50
30
|
follow: false,
|
|
51
|
-
/** Multiplies every magnitude
|
|
31
|
+
/** Multiplies every magnitude, pulling a quiet track up to fill its box. */
|
|
52
32
|
gain: 1,
|
|
53
|
-
/**
|
|
33
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
54
34
|
floor: 0.015,
|
|
55
35
|
align: Types.custom("center"),
|
|
56
|
-
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
57
36
|
byVoice: false,
|
|
58
|
-
/** A colour per voice index
|
|
37
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
59
38
|
voiceColors: Types.custom([]),
|
|
60
39
|
/** The bars ahead of the playhead. */
|
|
61
40
|
fill: paint("#5b5b7a"),
|
|
62
|
-
/** …and the bars behind it. */
|
|
63
41
|
playedFill: paint("#6366f1"),
|
|
64
42
|
},
|
|
65
|
-
// Nothing declares a component's paints but itself
|
|
43
|
+
// Nothing declares a component's paints but itself.
|
|
66
44
|
load: (loader, state) => {
|
|
67
45
|
loader.fill(state.fill);
|
|
68
46
|
loader.fill(state.playedFill);
|
|
69
47
|
},
|
|
70
48
|
commands: {
|
|
71
|
-
/**
|
|
72
|
-
* Fill the waveform in, left to right — the node's one command, since
|
|
73
|
-
* everything else about it is expressible as an ordinary `to`. Eased in-out
|
|
74
|
-
* unless it is given an easing of its own.
|
|
75
|
-
*/
|
|
49
|
+
/** Fill the waveform in, left to right; eased in-out unless given an easing. */
|
|
76
50
|
sweep: (timeline, state) => {
|
|
77
51
|
const ease = timeline.easing ? null : easeInOut();
|
|
78
52
|
const from = state.progress;
|
|
@@ -100,9 +74,7 @@ function drawBars(ctx, s) {
|
|
|
100
74
|
});
|
|
101
75
|
if (boxes.length === 0)
|
|
102
76
|
return;
|
|
103
|
-
// One draw per colour
|
|
104
|
-
// is a string because it has to be comparable; the paint it stands for is
|
|
105
|
-
// resolved after the grouping.
|
|
77
|
+
// One draw per colour, not per bar (see {@link paintBars}); the key is a string so it is comparable.
|
|
106
78
|
const edge = played(ctx, s) * boxes.length;
|
|
107
79
|
const groups = groupByPaint(boxes, (i) => s.byVoice
|
|
108
80
|
? `voice:${sampled[i].speaker}`
|
|
@@ -115,32 +87,19 @@ function drawBars(ctx, s) {
|
|
|
115
87
|
ctx.draw(graphics);
|
|
116
88
|
}
|
|
117
89
|
}
|
|
118
|
-
/** Where the fill has reached, from whichever source is in charge. */
|
|
119
90
|
function played(ctx, s) {
|
|
120
91
|
if (!s.follow)
|
|
121
|
-
return
|
|
92
|
+
return clamp(s.progress, 0, 1);
|
|
122
93
|
const length = s.envelope.duration;
|
|
123
94
|
if (length <= 0)
|
|
124
95
|
return 0;
|
|
125
|
-
return
|
|
96
|
+
return clamp(ctx.time.elapsed / length, 0, 1);
|
|
126
97
|
}
|
|
127
|
-
/**
|
|
128
|
-
* The paint a group takes.
|
|
129
|
-
*
|
|
130
|
-
* A voice's colour is a **colour string**, never one of the node's two fill
|
|
131
|
-
* props, and that is deliberate: a voice is identified by hue, so a gradient
|
|
132
|
-
* or an image there would defeat the only thing the colour is for. It also
|
|
133
|
-
* means these paints declare no assets, which is why `load` only has to account
|
|
134
|
-
* for the two real fill props.
|
|
135
|
-
*/
|
|
136
98
|
function paintFor(s, key) {
|
|
137
99
|
if (key === "played")
|
|
138
100
|
return s.playedFill;
|
|
139
101
|
if (key === "ahead")
|
|
140
102
|
return s.fill;
|
|
141
|
-
|
|
142
|
-
if (!Number.isFinite(voice) || voice < 0)
|
|
143
|
-
return s.fill;
|
|
144
|
-
return s.voiceColors[voice] ?? voiceColor(voice);
|
|
103
|
+
return voiceFill(key, s.voiceColors, s.fill);
|
|
145
104
|
}
|
|
146
105
|
//# sourceMappingURL=full-waveform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,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;AAEjB,sHAAsH;AACtH,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE,CAChC,KAAK,CAAC,MAAM,CAAuB,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAE/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE;QACL,0EAA0E;QAC1E,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAgB,cAAc,CAAC;QACrD,mDAAmD;QACnD,IAAI,EAAE,GAAG;QACT,8EAA8E;QAC9E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n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\n/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */\nconst paint = (initial: string) =>\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * `follow` is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With `byVoice` on, the played/ahead split is replaced by one colour per\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\nexport const FullWaveform = component2d({\n key: \"fullWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many columns the whole file is drawn as. */\n bars: 120,\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: 0.3,\n /** Corner radius of a bar, capped at half its width. */\n radius: 2,\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: 0,\n /** Drive `progress` from the node's own clock instead of the prop. */\n follow: false,\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: 1,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.015,\n align: Types.custom<WaveformAlignment>(\"center\"),\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n /** The bars ahead of the playhead. */\n fill: paint(\"#5b5b7a\"),\n /** …and the bars behind it. */\n playedFill: paint(\"#6366f1\"),\n },\n // Nothing declares a component's paints but itself: `fill` and `playedFill` both.\n load: (loader, state) => {\n loader.fill(state.fill)\n loader.fill(state.playedFill)\n },\n commands: {\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`. Eased in-out\n * unless it is given an easing of its own.\n */\n sweep: (timeline, state) => {\n const ease = timeline.easing ? null : easeInOut()\n const from = state.progress\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\n },\n },\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type FullWaveform = NodeOf<typeof FullWaveform>\nexport type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>\n\ninterface FullState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly progress: number\n readonly follow: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n readonly playedFill: FillResolved[]\n}\n\nfunction drawBars(ctx: RenderContext, s: FullState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = played(ctx, s) * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n s.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\n/** Where the fill has reached, from whichever source is in charge. */\nfunction played(ctx: RenderContext, s: FullState): number {\n if (!s.follow) return clamp01(s.progress)\n const length = s.envelope.duration\n if (length <= 0) return 0\n return clamp01(ctx.time.elapsed / length)\n}\n\n/**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why `load` only has to account\n * for the two real fill props.\n */\nfunction paintFor(s: FullState, key: string): Fill {\n if (key === \"played\") return s.playedFill\n if (key === \"ahead\") return s.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return s.fill\n return s.voiceColors[voice] ?? voiceColor(voice)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAA;AAC/E,OAAO,EACL,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,GAEV,MAAM,UAAU,CAAA;AAEjB,uDAAuD;AACvD,MAAM,KAAK,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,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;AAC9C,CAAC","sourcesContent":["import {\n Types,\n clamp,\n component2d,\n easeInOut,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n groupByPaint,\n layOutBars,\n paintBars,\n voiceFill,\n type WaveformAlignment,\n} from \"./shared\"\n\n/** A fill entry whose kind is read off the default. */\nconst paint = (initial: string) =>\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\n\n/**\n * The whole recording's shape drawn at once, with a played portion that\n * advances: a picture of the file where {@link LiveWaveform} is of the moment.\n *\n * `follow` is off by default because a scene cannot see where the recording sits\n * on the video's audio lane (placed, trimmed, sped up); the author sweeps\n * `progress` with a command, and `follow` is the opt-in for a node that appears\n * exactly as the track starts. `byVoice` replaces the played/ahead split with\n * one colour per voice rather than combining with it: a bar cannot mean two\n * things at once.\n */\nexport const FullWaveform = component2d({\n key: \"fullWaveform\",\n state: {\n /** The baked recording; see {@link AudioEnvelope}. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n bars: 120,\n /** Space between bars as a fraction of the pitch; see {@link layOutBars}. */\n gap: 0.3,\n /** Capped at half the bar's width. */\n radius: 2,\n /** The share of the file that reads as played, `0`-`1`. */\n progress: 0,\n /** Drive `progress` from the node's own clock instead. */\n follow: false,\n /** Multiplies every magnitude, pulling a quiet track up to fill its box. */\n gain: 1,\n /** The share of the box a silent bar still occupies, `0`-`1`. */\n floor: 0.015,\n align: Types.custom<WaveformAlignment>(\"center\"),\n byVoice: false,\n /** A colour per voice index; short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n /** The bars ahead of the playhead. */\n fill: paint(\"#5b5b7a\"),\n playedFill: paint(\"#6366f1\"),\n },\n // Nothing declares a component's paints but itself.\n load: (loader, state) => {\n loader.fill(state.fill)\n loader.fill(state.playedFill)\n },\n commands: {\n /** Fill the waveform in, left to right; eased in-out unless given an easing. */\n sweep: (timeline, state) => {\n const ease = timeline.easing ? null : easeInOut()\n const from = state.progress\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\n },\n },\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type FullWaveform = NodeOf<typeof FullWaveform>\n\ninterface FullState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly progress: number\n readonly follow: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n readonly playedFill: FillResolved[]\n}\n\nfunction drawBars(ctx: RenderContext, s: FullState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour, not per bar (see {@link paintBars}); the key is a string so it is comparable.\n const edge = played(ctx, s) * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n s.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\nfunction played(ctx: RenderContext, s: FullState): number {\n if (!s.follow) return clamp(s.progress, 0, 1)\n const length = s.envelope.duration\n if (length <= 0) return 0\n return clamp(ctx.time.elapsed / length, 0, 1)\n}\n\nfunction paintFor(s: FullState, key: string): Fill {\n if (key === \"played\") return s.playedFill\n if (key === \"ahead\") return s.fill\n return voiceFill(key, s.voiceColors, s.fill)\n}\n"]}
|
package/dist/waveform/index.d.ts
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The waveform family: one subject, two questions.
|
|
3
|
-
*
|
|
4
|
-
* - {@link FullWaveform} draws the **file** — the whole recording's silhouette,
|
|
5
|
-
* with a played portion that advances. "How long is this, and where are the
|
|
6
|
-
* loud parts."
|
|
7
|
-
* - {@link LiveWaveform} draws the **moment** — bars moving with playback, the
|
|
8
|
-
* visualiser a podcast clip puts beside the artwork. "Is anything happening
|
|
9
|
-
* right now, and whose voice is it."
|
|
10
|
-
*
|
|
11
|
-
* Both read the same baked {@link AudioEnvelope}, which is why they cannot
|
|
12
|
-
* disagree about a recording, and why neither listens to anything — see that
|
|
13
|
-
* module for why a scene that has to export cannot use a live analyser.
|
|
14
|
-
*/
|
|
15
1
|
export { FullWaveform } from "./full-waveform.js";
|
|
16
|
-
export type { FullWaveformProps } from "./full-waveform.js";
|
|
17
2
|
export { LiveWaveform } from "./live-waveform.js";
|
|
18
|
-
export type { LiveWaveformProps } from "./live-waveform.js";
|
|
19
3
|
export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./envelope.js";
|
|
20
4
|
export type { AudioEnvelope, EnvelopeBar } from "./envelope.js";
|
|
21
5
|
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, groupByPaint, layOutBars, paintBars, voiceColor, } from "./shared.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACvE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/waveform/index.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The waveform family: one subject, two questions.
|
|
3
|
-
*
|
|
4
|
-
* - {@link FullWaveform} draws the **file** — the whole recording's silhouette,
|
|
5
|
-
* with a played portion that advances. "How long is this, and where are the
|
|
6
|
-
* loud parts."
|
|
7
|
-
* - {@link LiveWaveform} draws the **moment** — bars moving with playback, the
|
|
8
|
-
* visualiser a podcast clip puts beside the artwork. "Is anything happening
|
|
9
|
-
* right now, and whose voice is it."
|
|
10
|
-
*
|
|
11
|
-
* Both read the same baked {@link AudioEnvelope}, which is why they cannot
|
|
12
|
-
* disagree about a recording, and why neither listens to anything — see that
|
|
13
|
-
* module for why a scene that has to export cannot use a live analyser.
|
|
14
|
-
*/
|
|
15
1
|
export { FullWaveform } from "./full-waveform.js";
|
|
16
2
|
export { LiveWaveform } from "./live-waveform.js";
|
|
17
3
|
export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./envelope.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/waveform/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,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":["export { FullWaveform } from \"./full-waveform\"\nexport { LiveWaveform } 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"]}
|