Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat(timeline): show what an audio pill crops, and let it slip
EtienneLescot49d0ac569bbd
diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.cssindex 1ec4dd715..1b872e8e8 100644--- a/src/components/ai-edition/v4/EditorShellV4.module.css+++ b/src/components/ai-edition/v4/EditorShellV4.module.css@@ -1514,6 +1514,44 @@/* Imported audio tracks (issue #350). A distinct teal so a BGM/voiceover trackreads apart from the effect pills, and taller than a lane pill so the waveforminside it is legible. */+/* The rest of an audio pill's tape (audioGhostExtent): where its file's content still+ sits around the pill. Dimmed and unclickable, BELOW the pill, so the pill reads as a+ window onto it and an edge drag shows what is still available on each side.++ Height and row are set inline to match the pill exactly. They have to: a ghost that+ does not line up with the pill reads as a separate object sitting behind it rather+ than as the rest of the same strip. */+.lanePillGhost {+ position: absolute;+ min-width: 1px;+ overflow: hidden;+ border-radius: 6px;+ /* Faint enough to read as "not the pill". Louder than this and it draws the eye to+ the part you are NOT editing — and on a long file it spans the whole ruler. */+ border: 1px dashed color-mix(in oklch, var(--accent) 18%, transparent);+ pointer-events: none;+ z-index: 1;+}+.lanePillGhost .tlWave {+ opacity: 0.18;+}+/* Crop readout pinned to the pointer while an audio pill's edge is pulled, or while+ Alt slips the media under it — in -> out over the file's length. Rendered at the+ component root (see the JSX note about the canvas transform). */+.tlDragTip {+ position: fixed;+ z-index: 1200;+ transform: translate(-50%, calc(-100% - 18px));+ padding: 3px 8px;+ border-radius: 6px;+ border: 1px solid var(--border-hi);+ background: var(--bg);+ color: var(--fg);+ font-size: 11px;+ font-variant-numeric: tabular-nums;+ white-space: nowrap;+ pointer-events: none;+}.laneAudio {border-color: #14b8a6;background: rgba(20, 184, 166, 0.16);diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex 2133d7be2..b30154b51 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -33,7 +33,12 @@ import { ZOOM_DEPTH_SCALES } from "@/components/video-editor/types";import { useScopedT } from "@/contexts/I18nContext";import { useShortcuts } from "@/contexts/ShortcutsContext";import { useAudioPeaks } from "@/hooks/useAudioPeaks";-import { collapseTracksToPills, packAudioTrackRows } from "@/lib/ai-edition/document/audioTracks";+import {+ audioGhostExtent,+ collapseTracksToPills,+ packAudioTrackRows,+ slipAudioOffsetMs,+} from "@/lib/ai-edition/document/audioTracks";import { createId } from "@/lib/ai-edition/document/ids";import { setUiProbeScrubbing } from "@/lib/ai-edition/perf/uiFrameProbe";import type { AxcutAudioTrack, AxcutClip } from "@/lib/ai-edition/schema";@@ -376,6 +381,7 @@ const AudioLanePill = memo(function AudioLanePill({onSelect,label,outputGain,+ ghost,}: {track: AxcutAudioTrack;url: string | undefined;@@ -401,69 +407,106 @@ const AudioLanePill = memo(function AudioLanePill({/** Linear project output gain, applied on top of the track gain — the mixer* applies both, so the bars must too or they under-read the exported level. */outputGain: number;+ /** Where the rest of the file sits around the pill, as percentages of the canvas+ * and the source window it covers. Absent when there is nothing to show. */+ ghost?: {+ leftPct: number;+ widthPct: number;+ sourceStartSec: number;+ sourceEndSec: number;+ } | null;}) {const duration = assetDurationSec ?? track.durationSec;return (- <div- role="button"- tabIndex={0}- className={`${styles.lanePill} ${styles.laneAudio}${- selected ? ` ${styles.lanePillSel}` : ""- }`}- style={{- left: `${leftPct}%`,- width: `${widthPct}%`,- minWidth: 3,- top: AUDIO_LANE_PAD_PX + row * rowHeight,- height: AUDIO_ROW_HEIGHT_PX,- }}- // Body drag moves the track; it also selects and stops the .tlTracks scrub.- onPointerDown={(e) => onStartDrag(e, track, "move")}- onKeyDown={(e) => {- if (e.key === "Enter" || e.key === " ") {- e.preventDefault();- onSelect(track.id);- }- }}- title={label}- >- <span- className={styles.lanePillHandle}- style={{ left: 0 }}- onPointerDown={(e) => onStartDrag(e, track, "l")}- />- <ClipWaveform- videoUrl={url}- assetDurationSec={duration}- sourceStartSec={sourceStartSec}- sourceEndSec={sourceEndSec}- // Track gain AND the project output gain — `finish_audio` applies both and- // clamps, so scaling by the track gain alone under-read a boosted output.- gain={audioGainScalar(track.gainDb) * outputGain}- />- {/* Where the file starts over, so a looping bed reads as one deliberate+ <>+ {/* The rest of the tape, dimmed and unclickable, behind the pill — so the pill+ reads as a window onto it and an edge drag shows what is still available on+ each side before it hits the stop. Same height and row as the pill: a ghost+ that does not line up reads as a separate object sitting behind it. */}+ {ghost ? (+ <div+ aria-hidden+ className={styles.lanePillGhost}+ style={{+ left: `${ghost.leftPct}%`,+ width: `${ghost.widthPct}%`,+ top: AUDIO_LANE_PAD_PX + row * rowHeight,+ height: AUDIO_ROW_HEIGHT_PX,+ }}+ >+ <ClipWaveform+ videoUrl={url}+ assetDurationSec={duration}+ sourceStartSec={ghost.sourceStartSec}+ sourceEndSec={ghost.sourceEndSec}+ gain={audioGainScalar(track.gainDb) * outputGain}+ />+ </div>+ ) : null}+ <div+ role="button"+ tabIndex={0}+ className={`${styles.lanePill} ${styles.laneAudio}${+ selected ? ` ${styles.lanePillSel}` : ""+ }`}+ style={{+ left: `${leftPct}%`,+ width: `${widthPct}%`,+ minWidth: 3,+ top: AUDIO_LANE_PAD_PX + row * rowHeight,+ height: AUDIO_ROW_HEIGHT_PX,+ }}+ // Body drag moves the track; it also selects and stops the .tlTracks scrub.+ onPointerDown={(e) => onStartDrag(e, track, "move")}+ onKeyDown={(e) => {+ if (e.key === "Enter" || e.key === " ") {+ e.preventDefault();+ onSelect(track.id);+ }+ }}+ title={label}+ >+ <span+ className={styles.lanePillHandle}+ style={{ left: 0 }}+ onPointerDown={(e) => onStartDrag(e, track, "l")}+ />+ <ClipWaveform+ videoUrl={url}+ assetDurationSec={duration}+ sourceStartSec={sourceStartSec}+ sourceEndSec={sourceEndSec}+ // Track gain AND the project output gain — `finish_audio` applies both and+ // clamps, so scaling by the track gain alone under-read a boosted output.+ gain={audioGainScalar(track.gainDb) * outputGain}+ />+ {/* Where the file starts over, so a looping bed reads as one deliberaterepeat rather than a mystery. Only drawn when the pill actuallyoutruns its source — otherwise there is nothing to repeat. */}- {track.loop && loopWindowSec > 0- ? Array.from({ length: Math.min(200, Math.ceil(spanSec / loopWindowSec) - 1) }, (_, i) => (- <span- key={`loop-${i + 1}`}- data-testid="audio-loop-mark"- className={styles.laneLoopMark}- style={{ left: `${(((i + 1) * loopWindowSec) / spanSec) * 100}%` }}- />- ))- : null}- <span className={styles.laneAudioLabel}>- <Music size={11} />- {label}- </span>- <span- className={styles.lanePillHandle}- style={{ right: 0 }}- onPointerDown={(e) => onStartDrag(e, track, "r")}- />- </div>+ {track.loop && loopWindowSec > 0+ ? Array.from(+ { length: Math.min(200, Math.ceil(spanSec / loopWindowSec) - 1) },+ (_, i) => (+ <span+ key={`loop-${i + 1}`}+ data-testid="audio-loop-mark"+ className={styles.laneLoopMark}+ style={{ left: `${(((i + 1) * loopWindowSec) / spanSec) * 100}%` }}+ />+ ),+ )+ : null}+ <span className={styles.laneAudioLabel}>+ <Music size={11} />+ {label}+ </span>+ <span+ className={styles.lanePillHandle}+ style={{ right: 0 }}+ onPointerDown={(e) => onStartDrag(e, track, "r")}+ />+ </div>+ </>);});@@ -936,6 +979,16 @@ export function V4Timeline({trimEnd: number;} | null>(null);const audioDragRef = useRef<typeof audioDrag>(null);+ /** `in -> out / length` pinned to the pointer while an audio edge is pulled or the+ * media is slipped under the pill. Rendered at the component root: the lane sits+ * inside the zoomed canvas transform, which would scale a chip placed in it. */+ const [audioDragTip, setAudioDragTip] = useState<{+ x: number;+ y: number;+ inSec: number;+ outSec: number;+ durationSec: number;+ } | null>(null);// The user-visible tracks and their lane rows. Packed from the STORED spans,// not the live drag geometry: a pill that changed rows halfway through a drag// would jump out from under the pointer.@@ -969,6 +1022,17 @@ export function V4Timeline({const origStart = track.startMs / 1000;const origTrimStart = track.offsetMs / 1000;const origTrimEnd = origTrimStart + spanSec;+ // Alt inside the pill slips it: the span stays put and the media slides under+ // it. On the BODY only — the edges keep their crop semantics.+ //+ // An edge drag sets the in-point at TIMELINE scale, which is unusable once the+ // file is much longer than the pill: reaching 3:00 inside a four-minute bed on+ // a five-second view means dragging three minutes of ruler. So the slip rate is+ // derived from the FILE — one viewport width traverses all of it — floored at+ // the timeline's own scale so a slip is never slower than moving the pill,+ // which would be its own surprise on a file shorter than the view.+ const slipping = mode === "move" && e.altKey && sourceLen > 0;+ const slipSecPerPx = Math.max(total / r.width, sourceLen / Math.max(1, r.width * navSpan));// A looping track may be pulled out PAST the end of its file — that is// the whole point of looping, and capping at the source length is what// made the loop toggle do nothing: the span could never exceed the@@ -1002,6 +1066,33 @@ export function V4Timeline({return best;};const move = (ev: PointerEvent) => {+ if (slipping) {+ const nextOffsetMs = slipAudioOffsetMs(+ track.offsetMs,+ track.endMs - track.startMs,+ sourceLen,+ (ev.clientX - startX) * slipSecPerPx * 1000,+ );+ if (nextOffsetMs == null) return;+ const nextTrimStart = nextOffsetMs / 1000;+ setAudioDragTip({+ x: ev.clientX,+ y: ev.clientY,+ inSec: nextTrimStart,+ outSec: nextTrimStart + spanSec,+ durationSec: sourceLen,+ });+ // The span does not move; only the window onto the file does.+ const slipState = {+ id: track.id,+ start: origStart,+ trimStart: nextTrimStart,+ trimEnd: nextTrimStart + spanSec,+ };+ audioDragRef.current = slipState;+ setAudioDrag(slipState);+ return;+ }const dxSec = ((ev.clientX - startX) / r.width) * total;let ns = origStart;let nts = origTrimStart;@@ -1034,12 +1125,25 @@ export function V4Timeline({origTrimStart + Math.max(0, total - origStart),);}+ // The readout answers "where am I in the file", which is the one thing the+ // pill cannot show: its edges stop at the content, but nothing said where+ // that content was.+ if (mode !== "move") {+ setAudioDragTip({+ x: ev.clientX,+ y: ev.clientY,+ inSec: nts,+ outSec: nte,+ durationSec: sourceLen,+ });+ }const next = { id: track.id, start: ns, trimStart: nts, trimEnd: nte };audioDragRef.current = next;setAudioDrag(next);};const up = () => {setSnapPct(null);+ setAudioDragTip(null);window.removeEventListener("pointermove", move);window.removeEventListener("pointerup", up);const fin = audioDragRef.current;@@ -1067,7 +1171,10 @@ export function V4Timeline({window.addEventListener("pointermove", move);window.addEventListener("pointerup", up);},- [tl, total, clips, pxPerSec],+ // navSpan: the slip rate is derived from the VISIBLE width, so a zoom that+ // leaves `total` alone still changes it. Left out, the rate froze at whatever+ // the zoom was when the callback was last built.+ [tl, total, clips, pxPerSec, navSpan],);const startNavDrag = useCallback(@@ -1946,6 +2053,24 @@ export function V4Timeline({onSelect={tl.selectAudioTrack}label={track.label || asset?.label || ts("audioTrack.defaultLabel")}outputGain={audioGainScalar(settings.audioGainDb)}+ ghost={((g) =>+ g+ ? {+ leftPct: pctOf(g.startT),+ widthPct: pctOf(g.endT - g.startT),+ sourceStartSec: g.sourceStartSec,+ sourceEndSec: g.sourceEndSec,+ }+ : null)(+ audioGhostExtent(+ trimStart,+ widthSec,+ duration,+ start,+ start + widthSec,+ total,+ ),+ )}/>);})@@ -2119,6 +2244,16 @@ export function V4Timeline({</div></div>) : null}+ {/* The crop readout, at the component ROOT rather than in the lane: the lane+ sits inside the zoomed canvas transform, which would scale a chip placed+ there. `in -> out / length` — 0:00.0 and out = length are the boundary+ states, self-evident without copy, which is why this adds no locale key. */}+ {audioDragTip ? (+ <div className={styles.tlDragTip} style={{ left: audioDragTip.x, top: audioDragTip.y }}>+ {formatSec(audioDragTip.inSec)} → {formatSec(audioDragTip.outSec)}+ {audioDragTip.durationSec > 0 ? ` / ${formatSec(audioDragTip.durationSec)}` : ""}+ </div>+ ) : null}</div>);}diff --git a/src/lib/ai-edition/document/audioTracks.test.ts b/src/lib/ai-edition/document/audioTracks.test.tsindex 49b061d6e..67ae59a32 100644--- a/src/lib/ai-edition/document/audioTracks.test.ts+++ b/src/lib/ai-edition/document/audioTracks.test.ts@@ -2,11 +2,13 @@ import { describe, expect, it } from "vitest";import { type AxcutAsset, type AxcutClip, createAudioTrack, createEmptyDocument } from "../schema";import {anchorAudioTrackFragments,+ audioGhostExtent,collapseTracksToPills,packAudioTrackRows,patchAudioTrack,removeAudioTrack,resolveFadeSecs,+ slipAudioOffsetMs,trackGroupId,} from "./audioTracks";@@ -277,3 +279,69 @@ describe("packAudioTrackRows", () => {expect(packAudioTrackRows([]).rowCount).toBe(1);});});++describe("audioGhostExtent", () => {+ // A 4s pill starting at ruler 10, showing the file from 2s, on a 60s file.+ const base = () => audioGhostExtent(2, 4, 60, 10, 14, 100);++ it("reaches back by the in-point and forward by what is left of the file", () => {+ const g = base();+ expect(g).not.toBeNull();+ // 2s of head before the pill, 54s of tail after it.+ expect(g?.startT).toBeCloseTo(8, 6);+ expect(g?.endT).toBeCloseTo(68, 6);+ // And the window it draws is the file's own, not the pill's.+ expect(g?.sourceStartSec).toBeCloseTo(0, 6);+ expect(g?.sourceEndSec).toBeCloseTo(60, 6);+ });++ it("stays inside the programme however long the file is", () => {+ // A four-minute bed under a short programme would otherwise ask for an element+ // tens of screens wide. Clamped at both ends.+ const g = audioGhostExtent(2, 4, 600, 10, 14, 20);+ expect(g?.startT).toBeCloseTo(8, 6);+ expect(g?.endT).toBe(20);+ });++ it("refuses when there is nothing around the pill to show", () => {+ // The pill already shows the whole file.+ expect(audioGhostExtent(0, 60, 60, 0, 60, 100)).toBeNull();+ });++ it("refuses an unknown duration rather than drawing a bound it cannot measure", () => {+ // Same rule as the edge stops: a failed probe must never invent a limit.+ expect(audioGhostExtent(0, 4, null, 0, 4, 100)).toBeNull();+ expect(audioGhostExtent(0, 4, undefined, 0, 4, 100)).toBeNull();+ expect(audioGhostExtent(0, 4, 0, 0, 4, 100)).toBeNull();+ });+});++describe("slipAudioOffsetMs", () => {+ it("slides the in-point by the delta it is given", () => {+ expect(slipAudioOffsetMs(10_000, 4_000, 60, 5_000)).toBe(15_000);+ expect(slipAudioOffsetMs(10_000, 4_000, 60, -5_000)).toBe(5_000);+ });++ it("never windows past either end of the file", () => {+ // Past the head is negative source time; past the tail is silence nobody asked+ // for. The last legal in-point is duration - span.+ expect(slipAudioOffsetMs(2_000, 4_000, 60, -10_000)).toBe(0);+ expect(slipAudioOffsetMs(50_000, 4_000, 60, 999_000)).toBe(56_000);+ });++ it("refuses a file no longer than the window onto it", () => {+ expect(slipAudioOffsetMs(0, 60_000, 60, 5_000)).toBeNull();+ expect(slipAudioOffsetMs(0, 90_000, 60, 5_000)).toBeNull();+ });++ it("refuses an unknown duration", () => {+ expect(slipAudioOffsetMs(0, 4_000, null, 5_000)).toBeNull();+ expect(slipAudioOffsetMs(0, 4_000, 0, 5_000)).toBeNull();+ });++ it("returns whole milliseconds, which is what the schema stores", () => {+ // `offsetMs` is `z.number().int()`; a fractional slip would fail the parse on+ // the next save rather than at the gesture.+ expect(Number.isInteger(slipAudioOffsetMs(0, 4_000, 60, 1234.567) ?? 0)).toBe(true);+ });+});diff --git a/src/lib/ai-edition/document/audioTracks.ts b/src/lib/ai-edition/document/audioTracks.tsindex 73c23866c..ecf609d74 100644--- a/src/lib/ai-edition/document/audioTracks.ts+++ b/src/lib/ai-edition/document/audioTracks.ts@@ -216,6 +216,73 @@ export function resolveFadeSecs(** Returns the row index per track id, plus how many rows the lane needs.*/+/**+ * The rest of the tape a pill is a window onto: where the file's own content still+ * sits to the left and right of it, in timeline seconds.+ *+ * An audio pill is the only timeline object that edits media you cannot see. Every+ * other pill holds a value over a span, and a clip's crop produces a clip that is+ * right there on screen; resizing an audio pill crops an invisible file, and nothing+ * said where in that file the edges had landed. The edges already stop at the+ * content (see the `lowerLeft` / `maxEnd` clamps in the lane drag) — this is what+ * makes the stop legible before you hit it.+ *+ * Clamped to the programme, so the element stays bounded however long the file is:+ * a four-minute bed under a five-second view would otherwise ask for a box tens of+ * screens wide. Returns null when there is nothing to show — no known duration (a+ * failed probe must never draw a bound it cannot measure), or a file no longer than+ * the window onto it.+ */+export function audioGhostExtent(+ offsetSec: number,+ spanSec: number,+ durationSec: number | null | undefined,+ pillStartT: number,+ pillEndT: number,+ totalT: number,+): { startT: number; endT: number; sourceStartSec: number; sourceEndSec: number } | null {+ if (durationSec == null || !(durationSec > 0)) return null;+ const startT = Math.max(0, pillStartT - Math.max(0, offsetSec));+ const endT = Math.min(totalT, pillEndT + Math.max(0, durationSec - (offsetSec + spanSec)));+ if (endT - startT <= pillEndT - pillStartT + 1e-6) return null;+ return {+ startT,+ endT,+ sourceStartSec: offsetSec - (pillStartT - startT),+ sourceEndSec: offsetSec + (endT - pillStartT),+ };+}++/**+ * Slip: slide the media under a pill whose span does not move.+ *+ * The gesture the ghost makes necessary rather than optional. An edge drag sets the+ * in-point at TIMELINE scale, which is unusable the moment the file is much longer+ * than the region it fills — reaching 3:00 inside a four-minute bed on a five-second+ * view means dragging three minutes of ruler. Slip separates the two questions a+ * pill conflates: *where it plays* (the span) and *what plays* (`offsetMs`).+ *+ * The RATE is the caller's business, not this function's — it takes a delta already+ * in source ms, because the timeline's own scale is the wrong one here and that is+ * the whole point. What belongs here is the clamp: an offset outside+ * `[0, duration - span]` windows past one end of the file, which is silence nobody+ * asked for.+ *+ * Returns null when there is nothing to slip, on the same two conditions the ghost+ * refuses on.+ */+export function slipAudioOffsetMs(+ offsetMs: number,+ spanMs: number,+ durationSec: number | null | undefined,+ deltaMs: number,+): number | null {+ if (durationSec == null || !(durationSec > 0)) return null;+ const slackMs = durationSec * 1000 - spanMs;+ if (!(slackMs > 0)) return null;+ return Math.round(Math.min(slackMs, Math.max(0, offsetMs + deltaMs)));+}+export function packAudioTrackRows(tracks: Array<{ id: string; startMs: number; endMs: number }>): {rowOf: Map<string, number>;rowCount: number;