Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(timeline): a softer clip card with a smooth waveform

EtienneLescot6a2ff67e224b
diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.css
index d13c870cf..fcdbadd13 100644
--- a/src/components/ai-edition/v4/EditorShellV4.module.css
+++ b/src/components/ai-edition/v4/EditorShellV4.module.css
@@ -1317,7 +1317,8 @@
align-items: center;
gap: 8px;
padding: 0 16px;
- height: 40px;
+ /* Room above AND below the 34px play button: at 40px it sat on the bottom rule. */
+ height: 48px;
flex-shrink: 0;
border-bottom: 1px solid var(--border-soft);
}
@@ -1780,13 +1781,14 @@
/* px, like .lanePill's: the gutter is subtracted from the clip's width, so a
clip narrower than 6px would otherwise compute to nothing. */
min-width: 1px;
- border-radius: 11px;
- border: 1.5px solid var(--border);
- background: var(--surface-1);
+ /* A soft mint card rather than a dark slab: the recording is the one thing on the
+ timeline everything else hangs off, and it should look like it, gently. */
+ border-radius: 12px;
+ border: 1px solid var(--accent-border);
+ background: color-mix(in oklab, var(--accent) 8%, var(--surface-1));
overflow: hidden;
cursor: grab;
box-sizing: border-box;
- box-shadow: inset 0 1px 8px rgba(255, 255, 255, 0.06);
/* pointer-driven reorder: suppress native touch scroll + text selection */
touch-action: none;
user-select: none;
@@ -1795,6 +1797,7 @@
}
.tlClipSel {
border-color: var(--accent);
+ box-shadow: 0 0 0 1px var(--accent);
}
/* A generated clip: the media behind an inserted word, which nobody shot. Amber on the box
itself rather than a badge inside it, so it stays legible at the zoom levels where a clip
@@ -1818,16 +1821,11 @@
top: 50%;
transform: translateY(-50%);
max-width: none;
- padding: 3px 6px;
- cursor: pointer;
}
-.tlClipSel.tlClipNarrow .tlClipName {
- display: none;
-}
-/* Clear of the pencil chip beside it. */
+/* Clear of the edit button beside it. */
.tlClipDelete[data-narrow] {
right: auto;
- left: calc(100% + 43px);
+ left: calc(100% + 42px);
top: 50%;
transform: translateY(-50%);
}
@@ -1843,65 +1841,68 @@
opacity: 0.9;
z-index: 5;
border-color: var(--accent);
- box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5), inset 0 1px 8px rgba(255, 255, 255, 0.06);
+ box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
transition: box-shadow var(--motion-fast) var(--ease), opacity var(--motion-fast) var(--ease);
}
+/* Stands on the bottom edge and takes a little over half the height: the top of the card
+ is the controls' row. Stretched to the box (`preserveAspectRatio="none"`), while the line
+ keeps its width however wide the clip is. */
.tlWave {
position: absolute;
- inset: 0;
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 1px;
- padding: 0 2px;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ width: 100%;
+ height: 58%;
pointer-events: none;
}
-.tlWave span {
- flex: 1 1 0;
- align-self: center;
- min-height: 2px;
- max-width: 2px;
- border-radius: 2px;
- background: var(--accent);
+.tlWaveArea {
+ fill: color-mix(in oklab, var(--accent) 24%, transparent);
+}
+.tlWaveLine {
+ fill: none;
+ stroke: color-mix(in oklab, var(--accent) 70%, transparent);
+ stroke-width: 1.5px;
+ stroke-linejoin: round;
+ vector-effect: non-scaling-stroke;
}
.tlClipLabel {
position: absolute;
- left: 10px;
+ left: 8px;
top: 8px;
z-index: 2;
display: inline-flex;
align-items: center;
gap: 8px;
max-width: calc(100% - 50px);
- padding: 3px 9px 3px 6px;
- border-radius: 8px;
- background: color-mix(in srgb, #080a0d 55%, transparent);
- border: 1px solid rgba(255, 255, 255, 0.08);
- backdrop-filter: blur(8px);
- -webkit-backdrop-filter: blur(8px);
}
-.tlClipIcon {
- width: 20px;
- height: 20px;
+/* Round, raised and a size a pointer finds without aiming: the clip's main action. */
+.tlClipEdit,
+.tlClipDelete {
+ width: 30px;
+ height: 30px;
+ flex-shrink: 0;
display: grid;
place-items: center;
- border-radius: 6px;
- background: var(--surface);
+ padding: 0;
+ border-radius: 999px;
+ border: 1px solid var(--border);
+ background: var(--surface-hi);
color: var(--fg);
- flex-shrink: 0;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
+ cursor: pointer;
+ transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease),
+ border-color var(--motion-fast) var(--ease);
}
-.tlClipName {
- font-size: 12px;
- font-weight: 500;
- color: #fff;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
+.tlClipEdit:hover {
+ border-color: var(--accent-border);
+ background: var(--accent-soft);
+ color: var(--accent);
}
.tlClipDuration {
- font: 500 11px/1.2 var(--font-body);
+ font: 500 12px/1.2 var(--font-body);
font-variant-numeric: tabular-nums;
- color: rgba(255, 255, 255, 0.75);
+ color: var(--fg-2);
white-space: nowrap;
flex-shrink: 0;
}
@@ -1910,25 +1911,9 @@
right: 8px;
top: 8px;
z-index: 2;
- width: 26px;
- height: 26px;
- display: grid;
- place-items: center;
- border-radius: 8px;
- /* The chip itself is a fixed dark frosted-glass overlay regardless of
- theme (it sits on top of an arbitrary video thumbnail), so its icon
- needs the "light text on a dark overlay" token, not --muted — which
- is tuned for the app's own light/dark surfaces and reads as
- near-invisible against this chip in light theme. */
- color: var(--overlay-text);
- background: color-mix(in srgb, #080a0d 55%, transparent);
- border: 1px solid rgba(255, 255, 255, 0.08);
- backdrop-filter: blur(8px);
- -webkit-backdrop-filter: blur(8px);
- cursor: pointer;
- transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.tlClipDelete:hover {
+ border-color: var(--danger-soft);
background: var(--danger-soft);
color: var(--danger);
}
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
index 01269a5c5..80f0a7de0 100644
--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
@@ -487,7 +487,7 @@ describe("V4Timeline clip row", () => {
it("withholds the duration from a card too small to hold it", () => {
// 250s at this zoom is a 125px card: past the narrow gate, so it still shows
- // its name and pencil, but not wide enough for the timecode — which would
+ // its edit button, but not wide enough for the timecode — which would
// otherwise escape the label pill and sit on the delete button. Measured in
// the running window, not derived here.
renderTimeline([clip(0, 250), clip(250, TOTAL_SEC)]);
@@ -498,26 +498,27 @@ describe("V4Timeline clip row", () => {
});
it("asks for the room this card's own timecode needs, not the shortest one", () => {
- // 600s of 3965s is a ~130px card. `0:12.0` would fit there; `10:00.0` is a
- // character wider and does not, and `formatSec` has no hour field to stop
- // the string growing — a clip past a hundred minutes reads `100:00.0`. A
- // single fixed width would have let those through onto the delete button.
- renderTimeline([clip(0, 600), clip(600, 3965)]);
+ // 600s of 4000s is a 129px card. `0:12.0` would fit there (50 + 38 + 6×6 =
+ // 124); `10:00.0` is a character wider and does not (130), and `formatSec`
+ // has no hour field to stop the string growing — a clip past a hundred
+ // minutes reads `100:00.0`. A single fixed width would have let those
+ // through onto the delete button.
+ renderTimeline([clip(0, 600), clip(600, 4000)]);
expect(screen.queryByText("10:00.0")).not.toBeInTheDocument();
- expect(screen.getByText("56:05.0")).toBeInTheDocument();
+ expect(screen.getByText("56:40.0")).toBeInTheDocument();
});
it("measures the timecode where a canvas exists, rather than averaging its length", () => {
- // The stubbed face costs 9px a character against the 6px the jsdom fallback
- // assumes. A 700s clip of this 3965s span is a ~159px card — roomy enough
- // by the count (50 + 47 + 7×6 = 139) and too tight once the face is read
- // (50 + 47 + 7×9 = 160) — so only a measured gate withholds it.
+ // The stubbed face costs 9px a character against the 6px the default stub
+ // charges. A 700s clip of this 4315s span is a 140px card — roomy enough by
+ // the count (50 + 38 + 7×6 = 130) and too tight once the face is read
+ // (50 + 38 + 7×9 = 151) — so only a measured gate withholds it.
measureText.mockImplementation((text: string) => ({ width: text.length * 9 }));
- renderTimeline([clip(0, 700), clip(700, 3965)]);
+ renderTimeline([clip(0, 700), clip(700, 4315)]);
expect(screen.queryByText("11:40.0")).not.toBeInTheDocument();
- expect(screen.getByText("54:25.0")).toBeInTheDocument();
+ expect(screen.getByText("60:15.0")).toBeInTheDocument();
});
it("takes the card gutter out of each clip's own width", () => {
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index 663f6c171..1f296abb8 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -18,6 +18,7 @@ import {
import {
Fragment,
memo,
+ type KeyboardEvent as ReactKeyboardEvent,
type PointerEvent as ReactPointerEvent,
useCallback,
useEffect,
@@ -151,20 +152,19 @@ const PILL_SNAP_PX = 8;
* clips that follow — which is what a flex `gap` did, once per junction. */
/** Below this a clip cannot show a label and a delete button inside itself. */
const NARROW_CLIP_PX = 120;
-// Whether a card can also carry its edited duration. The label pill is capped at
-// `calc(100% - 50px)` so it clears the delete button, and everything inside it
-// but the name is incompressible: 15px of pill padding (`3px 9px 3px 6px`), the
-// pencil and two 8px gaps — 47px. The timecode is the part that varies —
-// `formatSec` never prints an hour field, so a clip past ten minutes reads
-// `16:40.0` and one past a hundred `100:00.0` — so its width is measured with
-// canvas `measureText` in the face `.tlClipDuration` actually renders, rather
-// than guessed from a per-character average. Only where canvas is unavailable
-// (jsdom) does the gate fall back to the first cut's estimate: 6px per
-// character at 10px in the mono face.
+// Whether a card can also carry its edited duration. The label row is capped at
+// `calc(100% - 50px)` so it clears the delete button, and everything in it but
+// the duration is incompressible: the 30px edit button and the 8px gap after it.
+// The timecode is the part that varies — `formatSec` never prints an hour field,
+// so a clip past ten minutes reads `16:40.0` and one past a hundred `100:00.0` —
+// so its width is measured with canvas `measureText` in the face
+// `.tlClipDuration` actually renders, rather than guessed from a per-character
+// average. Only where canvas is unavailable (jsdom) does the gate fall back to an
+// estimate: 7px per character at 12px.
const CLIP_LABEL_RESERVE_PX = 50;
-const CLIP_LABEL_FIXED_PX = 47;
-const CLIP_LABEL_FALLBACK_CHAR_PX = 6;
-// `.tlClipDuration` renders `500 10px/1.2 var(--font-mono)`; canvas wants the
+const CLIP_LABEL_FIXED_PX = 38;
+const CLIP_LABEL_FALLBACK_CHAR_PX = 7;
+// `.tlClipDuration` renders `500 12px/1.2 var(--font-body)`; canvas wants the
// same face without the line height, so the family comes from the token itself.
let durationMeasureCtx: CanvasRenderingContext2D | null | undefined;
function durationTextPx(text: string): number | undefined {
@@ -173,8 +173,8 @@ function durationTextPx(text: string): number | undefined {
}
const ctx = durationMeasureCtx;
if (ctx === null) return undefined;
- const family = getComputedStyle(document.documentElement).getPropertyValue("--font-mono").trim();
- ctx.font = `500 10px ${family || "monospace"}`;
+ const family = getComputedStyle(document.documentElement).getPropertyValue("--font-body").trim();
+ ctx.font = `500 12px ${family || "sans-serif"}`;
return ctx.measureText(text).width;
}
function cardFitsDuration(cardPx: number, text: string): boolean {
@@ -183,6 +183,13 @@ function cardFitsDuration(cardPx: number, text: string): boolean {
}
const CLIP_GUTTER_PX = 6;
+
+/** Enter and Space belong to the focused button. The shell's play/pause shortcut is Space on
+ * WINDOW and `preventDefault()`s it, which cancels the button's own activation, so the
+ * keystroke stops here, natively, and is not prevented. */
+function keepActivationKey(e: ReactKeyboardEvent) {
+ if (e.key === "Enter" || e.key === " ") e.nativeEvent.stopPropagation();
+}
/**
* Shortest region a resize may leave behind — the storage grid itself (regions
* are `Math.round`ed to whole ms, and coalesceRegionsForRuler's epsilon is 1 ms),
@@ -297,9 +304,37 @@ const PlayheadOverlay = memo(function PlayheadOverlay({
);
});
-// Waveform preview bars inside a timeline clip. Derived from peaks data;
-// asset only decode once. Renders nothing while decoding or if the source has
-// no audio track, so the clip pill just shows its label until peaks arrive.
+/**
+ * A clip's loudness as one smooth shape standing on its bottom edge, the way Screen Studio
+ * draws it: a filled area under a line, not a row of 2px bars, which read as a barcode.
+ *
+ * `heights` are percentages of the wave box, one per sample, spread evenly across it. The
+ * curve is a Catmull-Rom spline through the samples, so each sample is a point ON the line:
+ * the shape is smoothed between them, never moved at them. Control points are held inside
+ * the box, and a Bézier stays within its control points, so no stretch of it can poke above
+ * full scale or below the baseline.
+ */
+function waveformPaths(heights: readonly number[]): { area: string; line: string } {
+ const n = heights.length;
+ const y = (i: number) => 100 - (heights[Math.min(n - 1, Math.max(0, i))] ?? 0);
+ const r = (v: number) => Math.round(v * 100) / 100;
+ const inBox = (v: number) => r(Math.min(100, Math.max(0, v)));
+ let curve = "";
+ for (let i = 0; i < n - 1; i++) {
+ const c1 = inBox(y(i) + (y(i + 1) - y(i - 1)) / 6);
+ const c2 = inBox(y(i + 1) - (y(i + 2) - y(i)) / 6);
+ curve += ` C${r(i + 1 / 6)},${c1} ${r(i + 1 - 1 / 6)},${c2} ${i + 1},${r(y(i + 1))}`;
+ }
+ const start = `0,${r(y(0))}`;
+ return {
+ area: `M0,100 L${start}${curve} L${n - 1},100 Z`,
+ line: `M${start}${curve}`,
+ };
+}
+
+// The waveform inside a timeline clip. Derived from peaks data; each asset only
+// decodes once. Renders nothing while decoding or if the source has no audio
+// track, so the clip pill just shows its label until peaks arrive.
const ClipWaveform = memo(function ClipWaveform({
videoUrl,
assetDurationSec,
@@ -321,7 +356,7 @@ const ClipWaveform = memo(function ClipWaveform({
// The duration is what tells `useAudioPeaks` whether this recording is small
// enough to decode whole — the file's byte size does not, on compressed video.
const peaks = useAudioPeaks(videoUrl, assetDurationSec);
- const bars = useMemo(() => {
+ const levels = useMemo(() => {
if (!peaks || peaks.length === 0 || !assetDurationSec) return null;
const totalBlocks = Math.floor(peaks.length / 2);
if (totalBlocks === 0) return null;
@@ -329,17 +364,19 @@ const ClipWaveform = memo(function ClipWaveform({
const startBlock = Math.max(0, Math.floor(sourceStartSec * blocksPerSec));
const endBlock = Math.min(totalBlocks, Math.ceil(sourceEndSec * blocksPerSec));
const rangeBlocks = Math.max(1, endBlock - startBlock);
- // One bar per ~120ms of clip duration — dense enough to read as a
- // continuous waveform — but capped so a long recording doesn't spawn
- // thousands of DOM nodes in a single clip (a clip is at most ~the timeline
- // width on screen, so beyond a few hundred bars they're sub-pixel anyway).
- const barCount = Math.min(400, Math.max(20, Math.round((sourceEndSec - sourceStartSec) * 8)));
+ // One sample per ~120ms of clip duration — dense enough to follow speech —
+ // but capped so a long recording doesn't build a path of thousands of
+ // points for a clip that is at most ~the timeline width on screen.
+ const sampleCount = Math.min(
+ 400,
+ Math.max(20, Math.round((sourceEndSec - sourceStartSec) * 8)),
+ );
const result: number[] = [];
- for (let i = 0; i < barCount; i++) {
- const blockStart = startBlock + Math.floor((i / barCount) * rangeBlocks);
+ for (let i = 0; i < sampleCount; i++) {
+ const blockStart = startBlock + Math.floor((i / sampleCount) * rangeBlocks);
const blockEnd = Math.max(
blockStart + 1,
- startBlock + Math.floor(((i + 1) / barCount) * rangeBlocks),
+ startBlock + Math.floor(((i + 1) / sampleCount) * rangeBlocks),
);
let amp = 0;
for (let b = blockStart; b < blockEnd && b < totalBlocks; b++) {
@@ -352,42 +389,38 @@ const ClipWaveform = memo(function ClipWaveform({
return result;
}, [peaks, assetDurationSec, sourceStartSec, sourceEndSec]);
- if (!bars) return null;
+ if (!levels) return null;
+ // Gain is applied HERE and not inside the memo above, which scans the whole
+ // asset's blocks: a slider drag fires one setLive per pointer move, so this
+ // keeps a tick at one multiply per sample instead of re-folding the peaks.
+ //
+ // Clamped because `finish_audio` clamps: it does `(sample * trim).clamp(-1, 1)`
+ // per sample, and a sample here is `max|sample|` over its bucket. Gain is positive
+ // and clamping is monotonic, so `clamp(max(|s|) * g)` IS the peak of the gained,
+ // clipped signal — the shape is exact at every sample, not an impression.
+ //
+ // The 8% floor is deliberately NOT scaled: it exists so an empty clip still
+ // reads as a clip, and it is not amplitude.
+ const { area, line } = waveformPaths(
+ levels.map((h) => Math.max(8, Math.round(Math.min(1, h * gain) * 100))),
+ );
return (
- <div aria-hidden className={styles.tlWave}>
- {bars.map((h, bi) => {
- // Gain is applied HERE and not inside the memo above, which scans the whole
- // asset's blocks: a slider drag fires one setLive per pointer move, so this
- // keeps a tick at `barCount` multiplies instead of re-folding the peaks.
- //
- // Clamped because `finish_audio` clamps: it does `(sample * trim).clamp(-1, 1)`
- // per sample, and this bar is `max|sample|` over its bucket. Gain is positive
- // and clamping is monotonic, so `clamp(max(|s|) * g)` IS the peak of the gained,
- // clipped signal — the bar is exact, not an impression. Without the clamp a
- // 0.5 peak at +12 dB computes `height: 199%` and is merely hidden by the clip's
- // `overflow`, which draws a signal the export will never write.
- //
- // The 8% floor is deliberately NOT scaled: it exists so an empty clip still
- // reads as a clip, and it is not amplitude.
- const amplitude = Math.min(1, h * gain);
- return (
- <span
- key={bi}
- style={{
- height: `${Math.max(8, Math.round(amplitude * 100))}%`,
- opacity: (0.5 + amplitude * 0.5).toFixed(2),
- }}
- />
- );
- })}
- </div>
+ <svg
+ aria-hidden
+ className={styles.tlWave}
+ viewBox={`0 0 ${levels.length - 1} 100`}
+ preserveAspectRatio="none"
+ >
+ <path className={styles.tlWaveArea} d={area} />
+ <path className={styles.tlWaveLine} d={line} />
+ </svg>
);
});
// One imported audio track on its lane (issue #350). Grab the body to move it,
// the edge handles to trim (left = in-point, which moves the head too; right =
-// out-point). The waveform reuses ClipWaveform (its `.tlWave` is inset:0, so it
-// paints behind the label here just as it does inside a clip), windowed to the
+// out-point). The waveform reuses ClipWaveform (its `.tlWave` stands on the pill's
+// bottom edge, behind the label, just as it does inside a clip), windowed to the
// track's trim and scaled by the track's own gain. `leftPct`/`widthPct` are
// precomputed by the parent — during a drag they carry the live preview geometry
// — so this stays memoisable: a doc edit that doesn't touch this track, and a
@@ -2241,7 +2274,9 @@ export function V4Timeline({
e.stopPropagation();
onEditClip(c);
}}
- title={t("toolbar.dragToReorderHint")}
+ // The file name is here rather than on the card: which file a clip
+ // comes from matters less than what can be done with it.
+ title={`${asset?.label ?? c.assetId}\n${t("toolbar.dragToReorderHint")}`}
>
<ClipWaveform
videoUrl={clipVideoUrl}
@@ -2251,20 +2286,20 @@ export function V4Timeline({
gain={audioGainScalar(settings.audioGainDb)}
/>
<div className={styles.tlClipLabel}>
- <span
- className={styles.tlClipIcon}
+ <button
+ type="button"
+ className={styles.tlClipEdit}
data-no-clip-drag
title={t("toolbar.editInOutPoints")}
+ aria-label={t("toolbar.editInOutPoints")}
onClick={(e) => {
e.stopPropagation();
onEditClip(c);
}}
+ onKeyDown={keepActivationKey}
>
- <Pencil size={12} />
- </span>
- <span className={styles.tlClipName}>
- {tl.assets.find((a) => a.id === c.assetId)?.label ?? c.assetId}
- </span>
+ <Pencil size={15} />
+ </button>
{cardFitsDuration(boxLen * pxPerSec - CLIP_GUTTER_PX, durText) ? (
<span className={styles.tlClipDuration}>{durText}</span>
) : null}
@@ -2281,8 +2316,9 @@ export function V4Timeline({
e.stopPropagation();
void tl.removeClip(c.id);
}}
+ onKeyDown={keepActivationKey}
>
- <Trash2 size={14} />
+ <Trash2 size={15} />
</button>
) : null}
</div>
diff --git a/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx b/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx
index b62a303e7..a4348a911 100644
--- a/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.waveform.test.tsx
@@ -15,7 +15,7 @@ import { beforeAll, describe, expect, it, vi } from "vitest";
const VIEWPORT_PX = 900;
const CLIP_SEC = 10;
-/** ClipWaveform's own rule: one bar per ~125ms, floored at 20 and capped at 400. */
+/** ClipWaveform's own rule: one sample per ~125ms, floored at 20 and capped at 400. */
const BAR_COUNT = Math.min(400, Math.max(20, Math.round(CLIP_SEC * 8)));
const LOUD = 0.5;
@@ -93,7 +93,14 @@ beforeAll(() => {
});
});
-/** Bar heights as the DOM carries them, in document order. */
+/** Every coordinate pair of the wave's line, as the DOM carries it. */
+let lastWavePoints: Array<[number, number]> = [];
+
+/**
+ * The wave's height at each sample, left to right, as a percentage of the wave box. The line
+ * is a spline THROUGH the samples, so each one is the end point of a curve segment: the pair
+ * after the segment's two control points.
+ */
function renderBars(atGainDb: number): string[] {
gainDb = atGainDb;
const tl = {
@@ -142,12 +149,14 @@ function renderBars(atGainDb: number): string[] {
/>
</ShortcutsProvider>,
);
- const bars = Array.from(
- document.querySelectorAll<HTMLElement>('[class*="tlWave"] span'),
- (span) => span.style.height,
- );
+ const d = document.querySelector('[class*="tlWaveLine"]')?.getAttribute("d") ?? "";
view.unmount();
- return bars;
+ lastWavePoints = [...d.matchAll(/(-?[\d.]+),(-?[\d.]+)/g)].map((m) => [
+ Number(m[1]),
+ Number(m[2]),
+ ]);
+ const onCurve = [lastWavePoints[0], ...lastWavePoints.slice(1).filter((_, i) => i % 3 === 2)];
+ return onCurve.map((point) => `${Math.round(100 - (point?.[1] ?? 100))}%`);
}
describe("ClipWaveform output gain", () => {
@@ -167,6 +176,12 @@ describe("ClipWaveform output gain", () => {
const bars = renderBars(12);
expect(bars[0]).toBe("100%");
expect(bars[BAR_COUNT - 1]).toBe("40%");
+ // Smoothed, but never past full scale or under the baseline: the curve stays inside
+ // its control points, and those are held inside the box.
+ for (const [, y] of lastWavePoints) {
+ expect(y).toBeGreaterThanOrEqual(0);
+ expect(y).toBeLessThanOrEqual(100);
+ }
});
it("shrinks the bars when the gain is cut, down to the empty-clip floor", () => {