@motionscript/audio 0.1.0 → 0.1.1-alpha.1
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 +21 -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,129 +1,92 @@
|
|
|
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
|
-
* A
|
|
4
|
+
* A visualiser whose bars move with the recording: a picture of this moment
|
|
5
|
+
* where {@link FullWaveform} is of the file. The bars are sampled from a baked
|
|
6
|
+
* envelope at the node's own elapsed time, so a frame is a pure function of time
|
|
7
|
+
* and an export, which has no playback to analyse and may render out of order,
|
|
8
|
+
* draws what the preview drew.
|
|
5
9
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* ## "Live" without listening
|
|
12
|
-
*
|
|
13
|
-
* Nothing here reads an audio device. The bars are sampled out of a baked
|
|
14
|
-
* envelope at the node's own elapsed time, which is what makes the visualiser
|
|
15
|
-
* survive the thing it exists for: an **export**, where there is no playback to
|
|
16
|
-
* analyse and frames may be rendered out of order or in parallel. A frame is a
|
|
17
|
-
* pure function of its time, so scrubbing back and forth over the visualiser
|
|
18
|
-
* redraws exactly what it drew the first time — which an analyser node, by
|
|
19
|
-
* construction, cannot promise. See {@link AudioEnvelope}.
|
|
20
|
-
*
|
|
21
|
-
* ## The speaker filter
|
|
22
|
-
*
|
|
23
|
-
* `speaker` narrows the node to one voice of a diarized recording, and it
|
|
24
|
-
* is the reason this node knows about transcripts at all. Two visualisers beside
|
|
25
|
-
* two headshots, each filtered to its own host, is a podcast edit that would
|
|
26
|
-
* otherwise be done by hand for every turn — and because the filter *silences*
|
|
27
|
-
* rather than skips (see {@link forSpeaker}), the quiet host visibly stops
|
|
28
|
-
* talking instead of vanishing. Nothing about that requires the words: only who
|
|
29
|
-
* is talking when, which is what the diarizer produces.
|
|
30
|
-
*
|
|
31
|
-
* A filter naming a voice the recording doesn't have draws a resting row rather
|
|
32
|
-
* than everything — a picture of "this person never speaks here", which is
|
|
33
|
-
* true, where falling back to the unfiltered mix would be a silent lie about
|
|
34
|
-
* whose voice you were watching.
|
|
10
|
+
* `speaker` narrows the node to one voice of a diarized recording; it silences
|
|
11
|
+
* the other voices (see {@link forSpeaker}) so the quiet host visibly stops. A
|
|
12
|
+
* voice the recording does not have draws a resting row, not the unfiltered mix,
|
|
13
|
+
* which would be a silent lie about whose voice you are watching.
|
|
35
14
|
*/
|
|
36
15
|
export declare const LiveWaveform: import("@motionscript/sdk").Component<"liveWaveform", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
37
|
-
/** The baked recording
|
|
16
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
38
17
|
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
39
|
-
/** How many bars the visualiser is made of. */
|
|
40
18
|
readonly bars: 48;
|
|
41
|
-
/** Space between bars
|
|
19
|
+
/** Space between bars as a fraction of the pitch. */
|
|
42
20
|
readonly gap: 0.35;
|
|
43
21
|
readonly radius: 4;
|
|
44
|
-
/**
|
|
22
|
+
/** Seconds of audio on screen at once. */
|
|
45
23
|
readonly window: 3;
|
|
46
|
-
/** Seconds into the file the
|
|
24
|
+
/** Seconds into the file the first frame shows. */
|
|
47
25
|
readonly offset: 0;
|
|
48
|
-
/** Advance with the scene clock
|
|
26
|
+
/** Advance with the scene clock; off freezes the picture at `offset`. */
|
|
49
27
|
readonly playing: true;
|
|
50
|
-
/** Multiplies every magnitude before it is clamped. */
|
|
51
28
|
readonly gain: 1.4;
|
|
52
|
-
/**
|
|
29
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
53
30
|
readonly floor: 0.04;
|
|
54
31
|
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
55
32
|
readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
|
|
56
|
-
/**
|
|
57
|
-
* Show only this voice's activity, by index into the recording's own
|
|
58
|
-
* numbering. `-1` — the default — is every voice.
|
|
59
|
-
*/
|
|
33
|
+
/** Show only this voice, by index into the recording's own numbering; `-1` is every voice. */
|
|
60
34
|
readonly speaker: -1;
|
|
61
35
|
/** Colour each bar by whoever is speaking in it. */
|
|
62
36
|
readonly byVoice: false;
|
|
63
|
-
/** A colour per voice index
|
|
37
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
64
38
|
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
65
39
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
66
40
|
}>, {}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
67
|
-
/** The baked recording
|
|
41
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
68
42
|
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
69
|
-
/** How many bars the visualiser is made of. */
|
|
70
43
|
readonly bars: 48;
|
|
71
|
-
/** Space between bars
|
|
44
|
+
/** Space between bars as a fraction of the pitch. */
|
|
72
45
|
readonly gap: 0.35;
|
|
73
46
|
readonly radius: 4;
|
|
74
|
-
/**
|
|
47
|
+
/** Seconds of audio on screen at once. */
|
|
75
48
|
readonly window: 3;
|
|
76
|
-
/** Seconds into the file the
|
|
49
|
+
/** Seconds into the file the first frame shows. */
|
|
77
50
|
readonly offset: 0;
|
|
78
|
-
/** Advance with the scene clock
|
|
51
|
+
/** Advance with the scene clock; off freezes the picture at `offset`. */
|
|
79
52
|
readonly playing: true;
|
|
80
|
-
/** Multiplies every magnitude before it is clamped. */
|
|
81
53
|
readonly gain: 1.4;
|
|
82
|
-
/**
|
|
54
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
83
55
|
readonly floor: 0.04;
|
|
84
56
|
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
85
57
|
readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
|
|
86
|
-
/**
|
|
87
|
-
* Show only this voice's activity, by index into the recording's own
|
|
88
|
-
* numbering. `-1` — the default — is every voice.
|
|
89
|
-
*/
|
|
58
|
+
/** Show only this voice, by index into the recording's own numbering; `-1` is every voice. */
|
|
90
59
|
readonly speaker: -1;
|
|
91
60
|
/** Colour each bar by whoever is speaking in it. */
|
|
92
61
|
readonly byVoice: false;
|
|
93
|
-
/** A colour per voice index
|
|
62
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
94
63
|
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
95
64
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
96
65
|
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
97
|
-
/** The baked recording
|
|
66
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
98
67
|
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
99
|
-
/** How many bars the visualiser is made of. */
|
|
100
68
|
readonly bars: 48;
|
|
101
|
-
/** Space between bars
|
|
69
|
+
/** Space between bars as a fraction of the pitch. */
|
|
102
70
|
readonly gap: 0.35;
|
|
103
71
|
readonly radius: 4;
|
|
104
|
-
/**
|
|
72
|
+
/** Seconds of audio on screen at once. */
|
|
105
73
|
readonly window: 3;
|
|
106
|
-
/** Seconds into the file the
|
|
74
|
+
/** Seconds into the file the first frame shows. */
|
|
107
75
|
readonly offset: 0;
|
|
108
|
-
/** Advance with the scene clock
|
|
76
|
+
/** Advance with the scene clock; off freezes the picture at `offset`. */
|
|
109
77
|
readonly playing: true;
|
|
110
|
-
/** Multiplies every magnitude before it is clamped. */
|
|
111
78
|
readonly gain: 1.4;
|
|
112
|
-
/**
|
|
79
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
113
80
|
readonly floor: 0.04;
|
|
114
81
|
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
115
82
|
readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
|
|
116
|
-
/**
|
|
117
|
-
* Show only this voice's activity, by index into the recording's own
|
|
118
|
-
* numbering. `-1` — the default — is every voice.
|
|
119
|
-
*/
|
|
83
|
+
/** Show only this voice, by index into the recording's own numbering; `-1` is every voice. */
|
|
120
84
|
readonly speaker: -1;
|
|
121
85
|
/** Colour each bar by whoever is speaking in it. */
|
|
122
86
|
readonly byVoice: false;
|
|
123
|
-
/** A colour per voice index
|
|
87
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
124
88
|
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
125
89
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
126
90
|
}>, {}, _Node2D<_Node2DProps>>>>;
|
|
127
91
|
export type LiveWaveform = NodeOf<typeof LiveWaveform>;
|
|
128
|
-
export type LiveWaveformProps = NonNullable<Parameters<typeof LiveWaveform>[0]>;
|
|
129
92
|
//# sourceMappingURL=live-waveform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"live-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAGX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EACjC,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAA;AAWnB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY;IAGrB,sDAAsD;;;IAGtD,qDAAqD;;;IAGrD,0CAA0C;;IAE1C,mDAAmD;;IAEnD,yEAAyE;;;IAGzE,iEAAiE;;;;IAIjE,8FAA8F;;IAE9F,oDAAoD;;IAEpD,0EAA0E;;;;IArB1E,sDAAsD;;;IAGtD,qDAAqD;;;IAGrD,0CAA0C;;IAE1C,mDAAmD;;IAEnD,yEAAyE;;;IAGzE,iEAAiE;;;;IAIjE,8FAA8F;;IAE9F,oDAAoD;;IAEpD,0EAA0E;;;;IArB1E,sDAAsD;;;IAGtD,qDAAqD;;;IAGrD,0CAA0C;;IAE1C,mDAAmD;;IAEnD,yEAAyE;;;IAGzE,iEAAiE;;;;IAIjE,8FAA8F;;IAE9F,oDAAoD;;IAEpD,0EAA0E;;;gCAS5E,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA"}
|
|
@@ -1,88 +1,53 @@
|
|
|
1
|
-
import { Types, component2d, fillOps, } from "@motionscript/sdk";
|
|
1
|
+
import { Types, clamp, component2d, fillOps, } from "@motionscript/sdk";
|
|
2
2
|
import { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope, } from "./envelope.js";
|
|
3
|
-
import {
|
|
3
|
+
import { groupByPaint, layOutBars, livePaintKey, paintBars, voiceFill, } from "./shared.js";
|
|
4
4
|
/**
|
|
5
|
-
* A
|
|
5
|
+
* A visualiser whose bars move with the recording: a picture of this moment
|
|
6
|
+
* where {@link FullWaveform} is of the file. The bars are sampled from a baked
|
|
7
|
+
* envelope at the node's own elapsed time, so a frame is a pure function of time
|
|
8
|
+
* and an export, which has no playback to analyse and may render out of order,
|
|
9
|
+
* draws what the preview drew.
|
|
6
10
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* ## "Live" without listening
|
|
13
|
-
*
|
|
14
|
-
* Nothing here reads an audio device. The bars are sampled out of a baked
|
|
15
|
-
* envelope at the node's own elapsed time, which is what makes the visualiser
|
|
16
|
-
* survive the thing it exists for: an **export**, where there is no playback to
|
|
17
|
-
* analyse and frames may be rendered out of order or in parallel. A frame is a
|
|
18
|
-
* pure function of its time, so scrubbing back and forth over the visualiser
|
|
19
|
-
* redraws exactly what it drew the first time — which an analyser node, by
|
|
20
|
-
* construction, cannot promise. See {@link AudioEnvelope}.
|
|
21
|
-
*
|
|
22
|
-
* ## The speaker filter
|
|
23
|
-
*
|
|
24
|
-
* `speaker` narrows the node to one voice of a diarized recording, and it
|
|
25
|
-
* is the reason this node knows about transcripts at all. Two visualisers beside
|
|
26
|
-
* two headshots, each filtered to its own host, is a podcast edit that would
|
|
27
|
-
* otherwise be done by hand for every turn — and because the filter *silences*
|
|
28
|
-
* rather than skips (see {@link forSpeaker}), the quiet host visibly stops
|
|
29
|
-
* talking instead of vanishing. Nothing about that requires the words: only who
|
|
30
|
-
* is talking when, which is what the diarizer produces.
|
|
31
|
-
*
|
|
32
|
-
* A filter naming a voice the recording doesn't have draws a resting row rather
|
|
33
|
-
* than everything — a picture of "this person never speaks here", which is
|
|
34
|
-
* true, where falling back to the unfiltered mix would be a silent lie about
|
|
35
|
-
* whose voice you were watching.
|
|
11
|
+
* `speaker` narrows the node to one voice of a diarized recording; it silences
|
|
12
|
+
* the other voices (see {@link forSpeaker}) so the quiet host visibly stops. A
|
|
13
|
+
* voice the recording does not have draws a resting row, not the unfiltered mix,
|
|
14
|
+
* which would be a silent lie about whose voice you are watching.
|
|
36
15
|
*/
|
|
37
16
|
export const LiveWaveform = component2d({
|
|
38
17
|
key: "liveWaveform",
|
|
39
18
|
state: {
|
|
40
|
-
/** The baked recording
|
|
19
|
+
/** The baked recording; see {@link AudioEnvelope}. */
|
|
41
20
|
envelope: Types.custom(EMPTY_ENVELOPE),
|
|
42
|
-
/** How many bars the visualiser is made of. */
|
|
43
21
|
bars: 48,
|
|
44
|
-
/** Space between bars
|
|
22
|
+
/** Space between bars as a fraction of the pitch. */
|
|
45
23
|
gap: 0.35,
|
|
46
24
|
radius: 4,
|
|
47
|
-
/**
|
|
25
|
+
/** Seconds of audio on screen at once. */
|
|
48
26
|
window: 3,
|
|
49
|
-
/** Seconds into the file the
|
|
27
|
+
/** Seconds into the file the first frame shows. */
|
|
50
28
|
offset: 0,
|
|
51
|
-
/** Advance with the scene clock
|
|
29
|
+
/** Advance with the scene clock; off freezes the picture at `offset`. */
|
|
52
30
|
playing: true,
|
|
53
|
-
/** Multiplies every magnitude before it is clamped. */
|
|
54
31
|
gain: 1.4,
|
|
55
|
-
/**
|
|
32
|
+
/** The share of the box a silent bar still occupies, `0`-`1`. */
|
|
56
33
|
floor: 0.04,
|
|
57
34
|
align: Types.custom("center"),
|
|
58
35
|
style: Types.custom("bars"),
|
|
59
|
-
/**
|
|
60
|
-
* Show only this voice's activity, by index into the recording's own
|
|
61
|
-
* numbering. `-1` — the default — is every voice.
|
|
62
|
-
*/
|
|
36
|
+
/** Show only this voice, by index into the recording's own numbering; `-1` is every voice. */
|
|
63
37
|
speaker: -1,
|
|
64
38
|
/** Colour each bar by whoever is speaking in it. */
|
|
65
39
|
byVoice: false,
|
|
66
|
-
/** A colour per voice index
|
|
40
|
+
/** A colour per voice index; short or empty falls back to the palette. */
|
|
67
41
|
voiceColors: Types.custom([]),
|
|
68
42
|
fill: Types.custom("#6366f1", { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
69
43
|
},
|
|
70
|
-
// Nothing declares a component's paints but itself.
|
|
71
44
|
load: (loader, state) => loader.fill(state.fill),
|
|
72
45
|
render: (ctx, state) => {
|
|
73
46
|
drawBars(ctx, state);
|
|
74
47
|
ctx.children();
|
|
75
48
|
},
|
|
76
49
|
});
|
|
77
|
-
/**
|
|
78
|
-
* The second of the recording the visualiser is showing.
|
|
79
|
-
*
|
|
80
|
-
* Off the node's own clock rather than the scene's, which is what "from the
|
|
81
|
-
* moment this node appeared" means — the same clock the engine's own
|
|
82
|
-
* `Video` times its picture from, and the same one that makes a node dropped
|
|
83
|
-
* halfway through a clip start its recording at its entrance rather than
|
|
84
|
-
* partway in.
|
|
85
|
-
*/
|
|
50
|
+
/** The second of the recording on show, off the node's own clock (as `Video`'s is), so a node entering halfway through a clip starts its recording at its entrance. */
|
|
86
51
|
function at(ctx, s) {
|
|
87
52
|
return s.offset + (s.playing ? Math.max(0, ctx.time.elapsed) : 0);
|
|
88
53
|
}
|
|
@@ -94,9 +59,7 @@ function drawBars(ctx, s) {
|
|
|
94
59
|
const span = Math.max(0.05, s.window);
|
|
95
60
|
const now = at(ctx, s);
|
|
96
61
|
const voice = s.speaker < 0 ? null : Math.round(s.speaker);
|
|
97
|
-
//
|
|
98
|
-
// middle and away again — the arrangement every mixer's meter uses, and the
|
|
99
|
-
// one that reads as sound arriving rather than as a strip scrolling past.
|
|
62
|
+
// Centred on the playhead, so sound reads as arriving rather than a strip scrolling past.
|
|
100
63
|
const sampled = forSpeaker(sampleEnvelope(s.envelope, now - span / 2, now + span / 2, count), voice);
|
|
101
64
|
const shaped = s.style === "line" ? taper(sampled) : sampled;
|
|
102
65
|
const boxes = layOutBars(shaped, {
|
|
@@ -116,25 +79,12 @@ function drawBars(ctx, s) {
|
|
|
116
79
|
ctx.draw(graphics);
|
|
117
80
|
}
|
|
118
81
|
}
|
|
119
|
-
/** See `FullWaveform`'s paints — a voice is a hue, never a gradient. */
|
|
120
82
|
function paintFor(s, key) {
|
|
121
83
|
if (key === "all")
|
|
122
84
|
return s.fill;
|
|
123
|
-
|
|
124
|
-
if (!Number.isFinite(voice) || voice < 0)
|
|
125
|
-
return s.fill;
|
|
126
|
-
return s.voiceColors[voice] ?? voiceColor(voice);
|
|
85
|
+
return voiceFill(key, s.voiceColors, s.fill);
|
|
127
86
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Rolls the ends of a window off toward silence.
|
|
130
|
-
*
|
|
131
|
-
* What separates the `line` style from `bars`: a hard-edged window makes the
|
|
132
|
-
* loud bar entering at the right edge appear from nothing, which reads as a
|
|
133
|
-
* glitch rather than as sound arriving. Fading the outer fifth turns the same
|
|
134
|
-
* data into a shape that grows out of the baseline — the profile a spectrum
|
|
135
|
-
* display has, and the reason it looks like one object rather than a row of
|
|
136
|
-
* separate meters.
|
|
137
|
-
*/
|
|
87
|
+
/** Fades the outer fifth of the window to silence, the `line` style: a hard edge makes a loud bar appear from nothing, which reads as a glitch. */
|
|
138
88
|
function taper(bars) {
|
|
139
89
|
const count = bars.length;
|
|
140
90
|
if (count < 3)
|
|
@@ -142,7 +92,7 @@ function taper(bars) {
|
|
|
142
92
|
const edge = Math.max(1, Math.floor(count / 5));
|
|
143
93
|
return bars.map((bar, i) => {
|
|
144
94
|
const fromEnd = Math.min(i, count - 1 - i);
|
|
145
|
-
const weight =
|
|
95
|
+
const weight = clamp(fromEnd / edge, 0, 1);
|
|
146
96
|
return { magnitude: bar.magnitude * weight, speaker: bar.speaker };
|
|
147
97
|
});
|
|
148
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-waveform.js","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,cAAc,EACd,UAAU,EACV,cAAc,GAGf,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GAGX,MAAM,UAAU,CAAA;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE;QACL,0EAA0E;QAC1E,QAAQ,EAAE,K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AAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAA;IAE/C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;QACtC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAA;IACpE,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n Types,\n component2d,\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 {\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\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 * `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 */\nexport const LiveWaveform = component2d({\n key: \"liveWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many bars the visualiser is made of. */\n bars: 48,\n /** Space between bars, as a fraction of the pitch. */\n gap: 0.35,\n radius: 4,\n /** How many seconds of audio are on screen at once. */\n window: 3,\n /** Seconds into the file the node's first frame shows. */\n offset: 0,\n /** Advance with the scene clock. Off freezes the picture at `offset`. */\n playing: true,\n /** Multiplies every magnitude before it is clamped. */\n gain: 1.4,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.04,\n align: Types.custom<WaveformAlignment>(\"center\"),\n style: Types.custom<WaveformStyle>(\"bars\"),\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: -1,\n /** Colour each bar by whoever is speaking in it. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n fill: Types.custom<Fill, FillResolved[]>(\"#6366f1\", { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n },\n // Nothing declares a component's paints but itself.\n load: (loader, state) => loader.fill(state.fill),\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type LiveWaveform = NodeOf<typeof LiveWaveform>\nexport type LiveWaveformProps = NonNullable<Parameters<typeof LiveWaveform>[0]>\n\ninterface LiveState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly window: number\n readonly offset: number\n readonly playing: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly style: WaveformStyle\n readonly speaker: number\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\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 the engine's own\n * `Video` times its picture from, and the same one that makes a node dropped\n * halfway through a clip start its recording at its entrance rather than\n * partway in.\n */\nfunction at(ctx: RenderContext, s: LiveState): number {\n return s.offset + (s.playing ? Math.max(0, ctx.time.elapsed) : 0)\n}\n\nfunction drawBars(ctx: RenderContext, s: LiveState): 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 span = Math.max(0.05, s.window)\n const now = at(ctx, s)\n const voice = s.speaker < 0 ? null : Math.round(s.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(s.envelope, now - span / 2, now + span / 2, count),\n voice\n )\n\n const shaped = s.style === \"line\" ? taper(sampled) : sampled\n const boxes = layOutBars(shaped, {\n width,\n height,\n gap: s.style === \"blocks\" ? 0.12 : s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n const groups = groupByPaint(boxes, (i) =>\n livePaintKey(shaped[i].speaker, s.byVoice, voice)\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/** See `FullWaveform`'s paints — a voice is a hue, never a gradient. */\nfunction paintFor(s: LiveState, key: string): Fill {\n if (key === \"all\") return s.fill\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\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"]}
|
|
1
|
+
{"version":3,"file":"live-waveform.js","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,WAAW,EACX,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,cAAc,EACd,UAAU,EACV,cAAc,GAGf,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,SAAS,GAGV,MAAM,UAAU,CAAA;AAEjB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE;QACL,sDAAsD;QACtD,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAgB,cAAc,CAAC;QACrD,IAAI,EAAE,EAAE;QACR,qDAAqD;QACrD,GAAG,EAAE,IAAI;QACT,MAAM,EAAE,CAAC;QACT,0CAA0C;QAC1C,MAAM,EAAE,CAAC;QACT,mDAAmD;QACnD,MAAM,EAAE,CAAC;QACT,yEAAyE;QACzE,OAAO,EAAE,IAAI;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n clamp,\n component2d,\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 {\n EMPTY_ENVELOPE,\n forSpeaker,\n sampleEnvelope,\n type AudioEnvelope,\n type EnvelopeBar,\n} from \"./envelope\"\nimport {\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceFill,\n type WaveformAlignment,\n type WaveformStyle,\n} from \"./shared\"\n\n/**\n * A visualiser whose bars move with the recording: a picture of this moment\n * where {@link FullWaveform} is of the file. The bars are sampled from a baked\n * envelope at the node's own elapsed time, so a frame is a pure function of time\n * and an export, which has no playback to analyse and may render out of order,\n * draws what the preview drew.\n *\n * `speaker` narrows the node to one voice of a diarized recording; it silences\n * the other voices (see {@link forSpeaker}) so the quiet host visibly stops. A\n * voice the recording does not have draws a resting row, not the unfiltered mix,\n * which would be a silent lie about whose voice you are watching.\n */\nexport const LiveWaveform = component2d({\n key: \"liveWaveform\",\n state: {\n /** The baked recording; see {@link AudioEnvelope}. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n bars: 48,\n /** Space between bars as a fraction of the pitch. */\n gap: 0.35,\n radius: 4,\n /** Seconds of audio on screen at once. */\n window: 3,\n /** Seconds into the file the first frame shows. */\n offset: 0,\n /** Advance with the scene clock; off freezes the picture at `offset`. */\n playing: true,\n gain: 1.4,\n /** The share of the box a silent bar still occupies, `0`-`1`. */\n floor: 0.04,\n align: Types.custom<WaveformAlignment>(\"center\"),\n style: Types.custom<WaveformStyle>(\"bars\"),\n /** Show only this voice, by index into the recording's own numbering; `-1` is every voice. */\n speaker: -1,\n /** Colour each bar by whoever is speaking in it. */\n byVoice: false,\n /** A colour per voice index; short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n fill: Types.custom<Fill, FillResolved[]>(\"#6366f1\", { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n },\n load: (loader, state) => loader.fill(state.fill),\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type LiveWaveform = NodeOf<typeof LiveWaveform>\n\ninterface LiveState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly window: number\n readonly offset: number\n readonly playing: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly style: WaveformStyle\n readonly speaker: number\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n}\n\n/** The second of the recording on show, off the node's own clock (as `Video`'s is), so a node entering halfway through a clip starts its recording at its entrance. */\nfunction at(ctx: RenderContext, s: LiveState): number {\n return s.offset + (s.playing ? Math.max(0, ctx.time.elapsed) : 0)\n}\n\nfunction drawBars(ctx: RenderContext, s: LiveState): 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 span = Math.max(0.05, s.window)\n const now = at(ctx, s)\n const voice = s.speaker < 0 ? null : Math.round(s.speaker)\n\n // Centred on the playhead, so sound reads as arriving rather than a strip scrolling past.\n const sampled = forSpeaker(\n sampleEnvelope(s.envelope, now - span / 2, now + span / 2, count),\n voice\n )\n\n const shaped = s.style === \"line\" ? taper(sampled) : sampled\n const boxes = layOutBars(shaped, {\n width,\n height,\n gap: s.style === \"blocks\" ? 0.12 : s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n const groups = groupByPaint(boxes, (i) =>\n livePaintKey(shaped[i].speaker, s.byVoice, voice)\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 paintFor(s: LiveState, key: string): Fill {\n if (key === \"all\") return s.fill\n return voiceFill(key, s.voiceColors, s.fill)\n}\n\n/** Fades the outer fifth of the window to silence, the `line` style: a hard edge makes a loud bar appear from nothing, which reads as a glitch. */\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 = clamp(fromEnd / edge, 0, 1)\n return { magnitude: bar.magnitude * weight, speaker: bar.speaker }\n })\n}\n"]}
|
|
@@ -1,36 +1,15 @@
|
|
|
1
1
|
import { Graphics2D, type Fill } from "@motionscript/sdk";
|
|
2
2
|
import type { EnvelopeBar } from "./envelope.js";
|
|
3
|
-
/**
|
|
4
|
-
* Geometry and paint shared by the two waveform nodes.
|
|
5
|
-
*
|
|
6
|
-
* They draw the same object — a row of bars whose heights are loudness — and
|
|
7
|
-
* differ only in what decides the heights: the whole file for one, a window
|
|
8
|
-
* around the playhead for the other. Everything about *how a row of bars is
|
|
9
|
-
* laid out and painted* is therefore common, and lives here so the two cannot
|
|
10
|
-
* drift into looking like different components.
|
|
11
|
-
*/
|
|
12
3
|
/** How a bar is grown out of its baseline. */
|
|
13
4
|
export declare const WAVEFORM_ALIGNMENTS: readonly ["center", "bottom"];
|
|
14
5
|
export type WaveformAlignment = (typeof WAVEFORM_ALIGNMENTS)[number];
|
|
15
|
-
/** What the bars are shaped like. */
|
|
16
6
|
export declare const WAVEFORM_STYLES: readonly ["bars", "line", "blocks"];
|
|
17
7
|
export type WaveformStyle = (typeof WAVEFORM_STYLES)[number];
|
|
18
|
-
/**
|
|
19
|
-
* The colours voices are drawn in when nobody has assigned any.
|
|
20
|
-
*
|
|
21
|
-
* Eight hues that can be told apart at a glance, handed out by voice index. They
|
|
22
|
-
* are literals rather than looked up, because a scene has to build in a
|
|
23
|
-
* headless render with no database in scope; a host that names its voices
|
|
24
|
-
* supplies its own colours instead.
|
|
25
|
-
*/
|
|
8
|
+
/** Eight distinct hues handed out by voice index. Literals, because a scene builds headless with no database in scope; a host that names its voices supplies its own. */
|
|
26
9
|
export declare const VOICE_PALETTE: readonly ["#6366f1", "#14b8a6", "#f59e0b", "#ec4899", "#22c55e", "#3b82f6", "#f97316", "#a855f7"];
|
|
27
10
|
/** The colour a voice takes, wrapping past the end of the palette. */
|
|
28
11
|
export declare function voiceColor(index: number): string;
|
|
29
|
-
/**
|
|
30
|
-
* Where one bar sits and how tall it came out: its top-left corner and size, in
|
|
31
|
-
* the node's own pixels with **y pointing down** from the middle of the box.
|
|
32
|
-
* {@link paintBars} turns that into the centred, y-up rect the renderer draws.
|
|
33
|
-
*/
|
|
12
|
+
/** A bar's top-left corner and size in the node's pixels, with y pointing down from the middle of the box; {@link paintBars} turns it into the centred y-up rect. */
|
|
34
13
|
export interface BarBox {
|
|
35
14
|
x: number;
|
|
36
15
|
y: number;
|
|
@@ -38,61 +17,41 @@ export interface BarBox {
|
|
|
38
17
|
height: number;
|
|
39
18
|
}
|
|
40
19
|
/**
|
|
41
|
-
* Lays a row of bars
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* control, so a gap in pixels would silently become a solid block at 200 bars
|
|
46
|
-
* and a picket fence at 20. As a fraction, the row keeps the same rhythm at
|
|
47
|
-
* every density — which is what lets the count be a slider anyone can drag.
|
|
48
|
-
*
|
|
49
|
-
* A bar is never thinner than a hairline and never shorter than one either: a
|
|
50
|
-
* silent passage has to read as "audio, and nothing here" rather than as a hole
|
|
51
|
-
* in the drawing.
|
|
20
|
+
* Lays a row of bars across a box. The gap is a fraction of the pitch, not px:
|
|
21
|
+
* the bar count is a control, and a px gap would become a solid block at 200
|
|
22
|
+
* bars and a picket fence at 20. A bar is never thinner or shorter than a
|
|
23
|
+
* hairline, so a silent passage reads as audio with nothing in it, not a hole.
|
|
52
24
|
*/
|
|
53
25
|
export declare function layOutBars(bars: readonly EnvelopeBar[], options: {
|
|
54
26
|
width: number;
|
|
55
27
|
height: number;
|
|
56
28
|
gap: number;
|
|
57
29
|
align: WaveformAlignment;
|
|
58
|
-
/** Multiplies every magnitude before it is clamped back into 0…1. */
|
|
59
30
|
gain: number;
|
|
60
31
|
/** Fraction of the box a silent bar still occupies. */
|
|
61
32
|
floor: number;
|
|
62
33
|
}): BarBox[];
|
|
63
34
|
/**
|
|
64
|
-
* Draws a run of bars in one paint.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* thousand surfaces a frame. Chaining the rects of one colour into a single
|
|
69
|
-
* `Graphics2D` before filling makes it one — and, as a bonus, a gradient fill
|
|
70
|
-
* maps across the whole run rather than restarting inside every bar, which is
|
|
71
|
-
* the behaviour anyone reaching for a gradient here actually wants.
|
|
35
|
+
* Draws a run of bars in one paint. Callers batch by colour: every `Graphics2D`
|
|
36
|
+
* handed to `ctx.draw` is a surface the renderer composites, so a bar apiece
|
|
37
|
+
* would be a thousand surfaces a frame. One `Graphics2D` per run also maps a
|
|
38
|
+
* gradient across the whole run instead of restarting inside every bar.
|
|
72
39
|
*/
|
|
73
40
|
export declare function paintBars(boxes: readonly BarBox[], fill: Fill, radius: number): Graphics2D | null;
|
|
41
|
+
/** Groups bars by the paint they take, in order within each group: a diarized waveform has as many colours as voices, so two people is two draws however long it runs. */
|
|
42
|
+
export declare function groupByPaint<K>(boxes: readonly BarBox[], keyOf: (index: number) => K): Map<K, BarBox[]>;
|
|
74
43
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* conversation of two people is two draws however long it runs.
|
|
44
|
+
* The colour of a `voice:N` group key, or `fallback` for a bad index. Always a
|
|
45
|
+
* colour string, never one of the node's fills: a voice is identified by hue, so
|
|
46
|
+
* a gradient or image would defeat the point, and it keeps these paints from
|
|
47
|
+
* declaring assets.
|
|
80
48
|
*/
|
|
81
|
-
export declare function
|
|
82
|
-
export declare function clamp01(value: number): number;
|
|
49
|
+
export declare function voiceFill(key: string, voiceColors: readonly string[], fallback: Fill): Fill;
|
|
83
50
|
/**
|
|
84
|
-
* The {@link groupByPaint} key one bar
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* worth spelling out: {@link forSpeaker} silences a bar by zeroing its
|
|
89
|
-
* magnitude but leaves `speaker` exactly as it was, so a bar sitting in the
|
|
90
|
-
* middle of a *different* voice's turn is still stamped with that voice's
|
|
91
|
-
* index — grouping by `byVoice`'s usual per-bar key would paint those silent
|
|
92
|
-
* stretches in whoever used to be talking there, in flickers too short to
|
|
93
|
-
* read as anything but noise. Forcing every bar under the filtered voice's own
|
|
94
|
-
* key is the true picture instead: the node is drawing exactly one person, on
|
|
95
|
-
* or off, never anyone else's colour.
|
|
51
|
+
* The {@link groupByPaint} key of one live bar. Filtered to a voice, every bar
|
|
52
|
+
* takes that voice's key: {@link forSpeaker} zeroes a bar's magnitude but leaves
|
|
53
|
+
* its `speaker`, so the usual per-bar key would paint the silenced stretches in
|
|
54
|
+
* whoever used to talk there, in flickers too short to read as anything but noise.
|
|
96
55
|
*/
|
|
97
56
|
export declare function livePaintKey(barSpeaker: number, byVoice: boolean, filteredVoice: number | null): string;
|
|
98
57
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/waveform/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/waveform/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAS,KAAK,IAAI,EAAqB,MAAM,mBAAmB,CAAA;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,8CAA8C;AAC9C,eAAO,MAAM,mBAAmB,+BAAgC,CAAA;AAChE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpE,eAAO,MAAM,eAAe,qCAAsC,CAAA;AAClE,MAAM,MAAM,aAAa,G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