Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 7066f8eddf4eef9db787264108bc8d65745916af
parent 09d24d6fb305ee40a38c2f53d668555e70c81a03
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri,  6 Nov 2026 23:17:18 -0500

Merge lane/bench-modes: the clip bench is a two-mode editor -- Cut (the default) where the handles are what plays and dragging past the clip grows it, Clip for the reviewed range; one set of handles, Undo save, plain status lines (operator, 6 Nov: "this split between the clip and the cut is hard to reason around. Can it be a switchable mode instead and we start in cut mode?")

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/components/projects/ClipBench.tsx | 460+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Mumtool/components/projects/bench/CutEdges.tsx | 8+++++---
Mumtool/components/projects/bench/RenderGhosts.tsx | 4+++-
Mumtool/components/projects/bench/TightenTools.tsx | 24++++++++++++++++++++++--
Mumtool/docs/clip-bench.md | 31++++++++++++++++++++++---------
Mumtool/e2e/clip-bench.spec.ts | 23+++++++++++++++++++----
Mumtool/e2e/gaps-zoom.spec.ts | 133++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
7 files changed, 472 insertions(+), 211 deletions(-)

diff --git a/umtool/components/projects/ClipBench.tsx b/umtool/components/projects/ClipBench.tsx @@ -465,6 +465,64 @@ const PEEK_STEP = 60; */ const NEAR_SIBLING = 15; +// --------------------------------------------------------------------------- +// THE TWO MODES (lane/bench-modes; operator, 6 Nov: "this split between the +// clip and the cut is hard to reason around. Can it be a switchable mode +// instead and we start in cut mode?"). The data keeps both -- the EXTENT +// (`start`/`end`, the seconds reviewed) and the CUT (`cutStart`/`cutEnd`, +// what plays) -- and the bench edits one at a time with the same handles: +// +// Cut (every time the bench opens) the handles ARE what plays: the cut, or +// the extent when there is no cut (then the two are one). Gaps live +// here. Dragging past the extent grows it with the cut -- the seconds +// were just reviewed -- in the same write. +// Clip the handles are the extent; the cut is a band inside it, and an +// extent pulled in past the cut takes the cut in with it (cleared +// when less than half a second would be left). +// --------------------------------------------------------------------------- + +export type BenchMode = "cut" | "clip"; +type Edges = { start: number; end: number; cutStart: number | null; cutEnd: number | null }; + +/** The span the handles edit in a mode, as saved. */ +const spanIn = (c: Edges, m: BenchMode) => + m === "cut" && c.cutStart != null && c.cutEnd != null ? { from: c.cutStart, to: c.cutEnd } : { from: c.start, to: c.end }; + +/** + * The clip's edges once the handles' span is written in a mode: `cut` says + * what became of the cut, `grew` whether a cut drag grew the extent. + */ +function edgesAfter(c: Edges, span: { from: number; to: number }, m: BenchMode) { + const a = round2(span.from); + const b = round2(span.to); + if (c.cutStart == null || c.cutEnd == null) { + return { start: a, end: b, cutStart: null, cutEnd: null, cut: "none" as const, grew: false }; + } + if (m === "cut") { + const start = Math.min(c.start, a); + const end = Math.max(c.end, b); + return { start, end, cutStart: a, cutEnd: b, cut: "moved" as const, grew: start < c.start - 0.005 || end > c.end + 0.005 }; + } + const cs = Math.max(c.cutStart, a); + const ce = Math.min(c.cutEnd, b); + if (Math.abs(cs - c.cutStart) < 0.005 && Math.abs(ce - c.cutEnd) < 0.005) { + return { start: a, end: b, cutStart: c.cutStart, cutEnd: c.cutEnd, cut: "kept" as const, grew: false }; + } + return ce - cs >= 0.5 + ? { start: a, end: b, cutStart: round2(cs), cutEnd: round2(ce), cut: "shrunk" as const, grew: false } + : { start: a, end: b, cutStart: null, cutEnd: null, cut: "cleared" as const, grew: false }; +} + +/** What a written span did beyond itself, in words ("" when nothing). */ +const edgesSaid = (e: ReturnType<typeof edgesAfter>, hms: (t: number) => string) => + e.grew + ? `the reviewed range grew with it to ${hms(e.start)}–${hms(e.end)}` + : e.cut === "shrunk" + ? `the cut shrank with it to ${hms(e.cutStart!)}–${hms(e.cutEnd!)}` + : e.cut === "cleared" + ? "the cut no longer fitted and was cleared — the whole clip plays" + : ""; + /** m:ss, for a list of positions rather than a pair of edges. */ const clock = (t: number) => { const s = Math.max(0, Math.floor(t)); @@ -474,10 +532,11 @@ const clock = (t: number) => { /** What `save window` (and a confirmation that moved something) writes. */ type WindowPatch = { - start: number; - end: number; - cutStart?: string; - cutEnd?: string; + start?: number; + end?: number; + /** A number to set the cut's edge, "" to clear the cut; absent leaves it alone. */ + cutStart?: number | string; + cutEnd?: number | string; /** A number to set the mark, "" to clear it; absent leaves it alone. */ muteFrom?: number | string; }; @@ -511,10 +570,55 @@ export default function ClipBench({ const [cues, setCues] = useState<Cue[]>(data.cues); const [proposed, setProposed] = useState(data.proposed); const [view, setView] = useState(data.view); - const [sel, setSel] = useState({ from: data.clip.start, to: data.clip.end }); + // Cut mode every time the bench opens (see "THE TWO MODES" above). + const [mode, setModeState] = useState<BenchMode>("cut"); + const modeRef = useRef<BenchMode>("cut"); + modeRef.current = mode; + const hasCut = clip.cutStart != null && clip.cutEnd != null; + /** The handles edit the cut (not the extent): cut mode, on a clip with a cut. */ + const editsCut = mode === "cut" && hasCut; + const [sel, setSel] = useState(() => spanIn(data.clip, "cut")); + /** The clip's edges as the handles would write them. */ + const after = edgesAfter(clip, sel, mode); // Where the render will actually cut the drafted selection (bench/RenderGhosts.tsx): the // desk's waveform and the phone's edge strip both draw it. - const renderEdges = useRenderEdges(data.project, clip, sel, takeId); + const renderEdges = useRenderEdges(data.project, clip, { from: after.start, to: after.end }, takeId, { cutStart: after.cutStart, cutEnd: after.cutEnd }); + /** The patch that writes a span as the handles' (no mute mark): edgesAfter, as keys. */ + const edgePatch = useCallback( + (span: { from: number; to: number }): WindowPatch => { + const e = edgesAfter(clip, span, mode); + const out: WindowPatch = {}; + if (mode === "cut" && clip.cutStart != null && clip.cutEnd != null) { + out.cutStart = e.cutStart!; + out.cutEnd = e.cutEnd!; + if (e.start !== clip.start) out.start = e.start; + if (e.end !== clip.end) out.end = e.end; + } else { + out.start = e.start; + out.end = e.end; + if (e.cut === "shrunk") { + out.cutStart = e.cutStart!; + out.cutEnd = e.cutEnd!; + } else if (e.cut === "cleared") { + out.cutStart = ""; + out.cutEnd = ""; + } + } + return out; + }, + [clip, mode], + ); + /** The edges as they are now, as a patch: what puts a written span back. */ + const edgesBack = useCallback( + (): WindowPatch => ({ + start: clip.start, + end: clip.end, + cutStart: clip.cutStart ?? "", + cutEnd: clip.cutEnd ?? "", + }), + [clip.start, clip.end, clip.cutStart, clip.cutEnd], + ); + // The mute mark as drafted. Like the edges it is unsaved until `save window` // or `y`, and it is what the bench's own playback mutes at -- so a mark is // heard before it is written. @@ -543,7 +647,8 @@ export default function ClipBench({ // The window an Extend (the verdict bar's) saved over, so Reset can put it // back: Extend saves at once -- its button names its result -- and Reset is // its undo. Null once undone, or after any other window save. - const [extendedFrom, setExtendedFrom] = useState<{ start: number; end: number } | null>(null); + // A saved Extend: the span it replaced (in the mode's terms) and the patch that puts it back. + const [extendedFrom, setExtendedFrom] = useState<{ start: number; end: number; back: Record<string, unknown> } | null>(null); const resetRef = useRef<() => void>(() => {}); // Defaults on the server and on the first paint, then whatever this browser // remembers. Reading localStorage during render would be a hydration @@ -952,8 +1057,8 @@ export default function ClipBench({ setClip(next); // Only a window save moves the selection. An attribution field saving on // blur must not throw away edges somebody has nudged but not saved. - if (patch.start !== undefined || patch.end !== undefined) { - setSel({ from: next.start, to: next.end }); + if (patch.start !== undefined || patch.end !== undefined || patch.cutStart !== undefined || patch.cutEnd !== undefined) { + setSel(spanIn(next, modeRef.current)); setDirty(false); } // The mark goes back to what was STORED -- rounded, or cleared because @@ -1024,7 +1129,17 @@ export default function ClipBench({ const seen = new Set<number>(); return [...cues, ...peek].filter((c) => (seen.has(c.start) ? false : (seen.add(c.start), true))).sort((a, b) => a.start - b.start); }, [cues, peek]); + // In cut mode the tools settle the CUT (the extent grown past it); in clip mode the extent, the cut kept inside. + const edgeWrites = useMemo( + () => ({ + patchFor: (sp: { from: number; to: number }) => ({ patch: { ...edgePatch(sp) }, also: edgesSaid(edgesAfter(clip, sp, mode), hms) }), + back: () => ({ ...edgesBack() }), + anchorCut: !editsCut, + }), + [edgePatch, edgesBack, clip, mode, editsCut], + ); const edgeTools = useEdgeTools({ + writes: edgeWrites, project: data.project, clip, video: clip.video, @@ -1076,8 +1191,9 @@ export default function ClipBench({ // `save window` writes it on demand; a confirmation carries it when the edges // have actually moved. Both need the same rule about a cut the new extent no // longer contains, so the rule lives here rather than in each of them. + const savedSpan = spanIn(clip, mode); const windowMoved = - Math.abs(round2(sel.from) - clip.start) > 0.02 || Math.abs(round2(sel.to) - clip.end) > 0.02; + Math.abs(round2(sel.from) - savedSpan.from) > 0.02 || Math.abs(round2(sel.to) - savedSpan.to) > 0.02; // The mark moved, set or cleared since the last save. const muteMoved = (mute == null) !== (clip.muteFrom == null) || @@ -1085,25 +1201,18 @@ export default function ClipBench({ const unsaved = dirty || muteMoved; const windowPatch = useCallback((): WindowPatch => { - const start = round2(sel.from); - const end = round2(sel.to); - const cutOutside = - clip.cutStart != null && - clip.cutEnd != null && - (clip.cutStart < start - 0.02 || clip.cutEnd > end + 0.02); - // The extent is the judgement being made right now; the cut was derived - // from a wider one and is no longer inside it. Clearing it in the SAME - // patch is what keeps the writer's rule and the screen agreeing. - const out: WindowPatch = cutOutside - ? { start, end, cutStart: "", cutEnd: "" } - : { start, end }; + // The handles' span, in the mode's terms (edgesAfter): a cut drag writes + // the cut and grows the extent past it; an extent drag keeps the cut + // inside it, shrunk or -- under half a second -- cleared. + const e = edgesAfter(clip, sel, mode); + const out: WindowPatch = edgePatch(sel); // The mute mark rides the same patch, by the same rule: a mark the new // extent does not hold is cleared rather than refused. - const markOutside = mute != null && (mute < start - 0.02 || mute > end + 0.02); + const markOutside = mute != null && (mute < e.start - 0.02 || mute > e.end + 0.02); if (markOutside) out.muteFrom = ""; else if (muteMoved) out.muteFrom = mute == null ? "" : round2(mute); return out; - }, [sel.from, sel.to, clip.cutStart, clip.cutEnd, mute, muteMoved]); + }, [clip, sel, mode, mute, muteMoved, edgePatch]); // ---- the walk's verdict --------------------------------------------------- // @@ -1121,12 +1230,10 @@ export default function ClipBench({ // A note survives a confirmation. It stops being a complaint and becomes // what it now says it is: why this clip is here in the shape it is in. const ok = await save({ verdict: "confirmed", ...(win ?? {}) }); - if (ok && win) - setNote( - win.cutStart !== undefined - ? "saved — the window moved with it, and the cut no longer fitted and was cleared" - : "saved — the window you moved was saved with it", - ); + if (ok && win) { + const also = edgesSaid(after, hms); + setNote(`saved — the ${editsCut ? "cut" : "window"} you moved was saved with it${also ? `, and ${also}` : ""}`); + } if (!ok) return; // Undo for ten seconds: the phone's toast, on whichever page shows next. // A verdict is a state change, and a thumb lands where it did not mean to. @@ -1142,7 +1249,8 @@ export default function ClipBench({ } const nextHref = hrefOf("next"); if (nextHref) router.push(nextHref); - }, [save, router, data.project, data.next, clip.id, windowMoved, muteMoved, windowPatch, hrefOf]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [save, router, data.project, data.next, clip.id, windowMoved, muteMoved, windowPatch, hrefOf, after, editsCut]); /** * Undo a Confirm: the verdict as it was, and the edges too when the Confirm @@ -1184,7 +1292,7 @@ export default function ClipBench({ if (u.clip === clip.id) { const next = fromEntry(clip, j.entry as Record<string, unknown>); setClip(next); - setSel({ from: next.start, to: next.end }); + setSel(spanIn(next, modeRef.current)); setDirty(false); setMute(next.muteFrom); muteRef.current = next.muteFrom; @@ -1300,25 +1408,24 @@ export default function ClipBench({ // list back as it was. The rule is checked here first, with the same // sentences, so a refusal is said before anything is sent. // - // WHERE A GAP MAY GO (lane/clip-fixes): the cut when the clip has one, else - // the extent AS DRAFTED -- an edge dragged out over a wider fetch is where - // the operator is cutting, and the window patch rides along with the gap's - // write (as it does with a Confirm), so the writer checks the gap against - // the extent it will have. Before, the saved extent was a wall the drag - // stopped at with nothing on screen to say so. + // WHERE A GAP MAY GO: what plays -- the cut, else the extent -- AS DRAFTED + // (edgesAfter): in cut mode the handles' span itself. The window patch rides + // along with the gap's write (as it does with a Confirm), so the writer + // checks the gap against the edges it will have, and the note says what + // else the patch did (a cut cleared or shrunk, the extent grown). const draftEntry = useMemo( () => ({ type: "clip" as const, id: clip.id, - start: windowMoved ? round2(sel.from) : clip.start, - end: windowMoved ? round2(sel.to) : clip.end, - cutStart: clip.cutStart, - cutEnd: clip.cutEnd, + start: after.start, + end: after.end, + cutStart: after.cutStart, + cutEnd: after.cutEnd, muteFrom: windowMoved || muteMoved ? mute : clip.muteFrom, // The marks too: the writer refuses a gap over one, so the check here does. claims: (clip.marks ?? []).map((m) => (m.id ? { id: m.id, at: m.at } : { at: m.at })), }), - [clip.id, clip.start, clip.end, clip.cutStart, clip.cutEnd, clip.muteFrom, clip.marks, windowMoved, muteMoved, sel.from, sel.to, mute], + [clip.id, clip.muteFrom, clip.marks, after.start, after.end, after.cutStart, after.cutEnd, windowMoved, muteMoved, mute], ); const gapsSpan = gapSpan(draftEntry); // Every wall a gap stops at, drawn (bench/GapsZoom.tsx GapWallsLayer). @@ -1331,9 +1438,8 @@ export default function ClipBench({ [draftEntry], ); const gapRefusal = useCallback((gaps: Span[]) => gapRefusalFor(gaps), [gapRefusalFor]); - /** A cut narrower than the extent: the wall a gap (and the video) stops at. */ - const hasCut = clip.cutStart != null && clip.cutEnd != null; - const cutNarrower = hasCut && (clip.cutStart! > sel.from + 0.05 || clip.cutEnd! < sel.to - 0.05); + /** A cut narrower than the extent (as drafted): Use the whole clip offers the rest back. */ + const cutNarrower = after.cutStart != null && after.cutEnd != null && (after.cutStart > after.start + 0.05 || after.cutEnd < after.end - 0.05); // bench/useGapEditor.ts, writing through the window writer: `gapAdd` / `gapRemove`, Undo the whole list. const gap = useGapEditor({ key: clip.id, @@ -1341,7 +1447,7 @@ export default function ClipBench({ span: gapsSpan, refusal: gapRefusal, write: async (op, _next) => { - // A moved edge rides along: the gap was checked against the extent as drafted. + // A moved edge rides along: the gap was checked against the edges as drafted. const win = windowMoved || muteMoved ? windowPatch() : null; const ok = await save({ ...(win ?? {}), @@ -1349,28 +1455,31 @@ export default function ClipBench({ }); return ok; }, - said: (next) => - `the cut plays ${gappedLength(gapsSpan.from, gapsSpan.to, next).toFixed(2)} s, one segment${windowMoved ? " (the window you moved was saved with it)" : ""}`, + // Said in full: a moved edge saved with the gap, and what that did to the cut. + said: (next) => { + const also = windowMoved ? edgesSaid(after, hms) : ""; + return ( + `the cut plays ${gappedLength(gapsSpan.from, gapsSpan.to, next).toFixed(2)} s, one segment` + + (windowMoved ? ` (the ${editsCut ? "cut" : "window"} you moved was saved with it${also ? `, and ${also}` : ""})` : "") + ); + }, setNote, fmt: hms, wall: (side, at) => - hasCut - ? `stopped at the cut's ${side} (${hms(at)}) — gaps go inside the cut: drag its edge on the waveform, or Use the whole clip` + mode === "clip" + ? "gaps are cut in Cut mode" : side === "end" - ? `stopped at the clip's end (${hms(at)}) — drag the clip's end out first${atEndEdge ? ", past the cache: Fetch more" : ""}` - : `stopped at the clip's start (${hms(at)}) — drag the clip's start out first${atStartEdge ? ", past the cache: Fetch more" : ""}`, + ? `stopped at the end of what plays (${hms(at)}) — drag the end handle out first${atEndEdge ? ", past the cache: Fetch more" : ""}` + : `stopped at the start of what plays (${hms(at)}) — drag the start handle out first${atStartEdge ? ", past the cache: Fetch more" : ""}`, }); - // ---- the cut's edges, on the waveform ---------------------------------------- + // ---- the cut, cleared and put back ------------------------------------------- // - // Drawn and dragged there (bench/CutEdges.tsx), written on release through - // the window writer with an Undo -- as are Use the whole clip and Clear cut. - // A gap left outside the new cut is refused here first, with the writer's - // sentence; a moved extent rides along, as with a gap. - const [cutDraft, setCutDraft] = useState<Span | null>(null); + // Use the whole clip (and Clear cut) clears the cut -- what plays becomes the + // extent -- through the window writer, with an Undo cut. A moved span rides + // along, as with a gap. const [cutUndo, setCutUndo] = useState<{ cutStart: number | null; cutEnd: number | null; lockCut: boolean; what: string } | null>(null); useEffect(() => { - setCutDraft(null); setCutUndo(null); }, [clip.id]); const writeCut = useCallback( @@ -1379,20 +1488,19 @@ export default function ClipBench({ const cutPatch = next ? { cutStart: round2(next.from), cutEnd: round2(next.to) } : { cutStart: "", cutEnd: "", lockCut: false }; const why = gapRefusalFor(clip.gaps ?? [], next ? { cutStart: round2(next.from), cutEnd: round2(next.to) } : { cutStart: null, cutEnd: null }); if (why) { - setCutDraft(null); - setNote(`the cut was not moved: ${why}`); + setNote(`the cut was not changed: ${why}`); return false; } - const win = windowMoved || muteMoved ? windowPatch() : null; + // A moved span rides along -- as the extent it makes, since the cut is being replaced. + const win = windowMoved || muteMoved ? { ...windowPatch(), start: after.start, end: after.end } : null; const ok = await save({ ...(win ?? {}), ...cutPatch }); - setCutDraft(null); if (ok) { setCutUndo({ ...before, what }); - setNote(`${what}${win ? " — the window you moved was saved with it" : ""}`); + setNote(`${what}${win ? " — the edges you moved were saved with it" : ""}`); } return ok; }, - [clip.cutStart, clip.cutEnd, clip.lockCut, clip.gaps, gapRefusalFor, windowMoved, muteMoved, windowPatch, save], + [clip.cutStart, clip.cutEnd, clip.lockCut, clip.gaps, gapRefusalFor, windowMoved, muteMoved, windowPatch, save, after.start, after.end], ); const takeWholeClip = useCallback( () => void writeCut(null, "the cut cleared — the whole clip plays, and gaps can go anywhere in it"), @@ -1411,26 +1519,27 @@ export default function ClipBench({ setNote(`undone — ${u.what.split(" — ")[0]} is reversed`); } }, [cutUndo, save]); - const onCutDrag = useCallback( - (side: "start" | "end", t: number, done: boolean) => { - if (clip.cutStart == null || clip.cutEnd == null) return; - const cur = cutDraft ?? { from: clip.cutStart, to: clip.cutEnd }; - // Inside the extent as drafted, and at least half a second (the writer's rule). - const next = - side === "start" - ? { from: Math.max(sel.from, Math.min(t, cur.to - 0.5)), to: cur.to } - : { from: cur.from, to: Math.min(sel.to, Math.max(t, cur.from + 0.5)) }; - if (!done) { - setCutDraft(next); - return; - } - if (Math.abs(next.from - clip.cutStart) < 0.005 && Math.abs(next.to - clip.cutEnd) < 0.005) { - setCutDraft(null); + + /** + * Switch what the handles edit. Never over unsaved edges: they were drafted + * as one span or the other, and carrying them across would write the wrong one. + */ + const setMode = useCallback( + (m: BenchMode) => { + if (m === mode) return; + if (dirty) { + setNote(`save or reset the ${editsCut ? "cut" : "window"} you moved first`); return; } - void writeCut(next, `the cut moved to ${hms(next.from)}–${hms(next.to)}`); + setModeState(m); + modeRef.current = m; + setSel(spanIn(clip, m)); + gap.setSel(null); + gap.setPick(false); }, - [clip.cutStart, clip.cutEnd, cutDraft, sel.from, sel.to, writeCut], + // `gap`'s setters are stable. + // eslint-disable-next-line react-hooks/exhaustive-deps + [mode, dirty, editsCut, clip], ); // ---- the zoom ---------------------------------------------------------------- @@ -1577,11 +1686,13 @@ export default function ClipBench({ break; // Gaps: g cuts the selected span (or starts selecting one), G puts back the gap at the playhead. case "g": - if (gap.sel) void gap.cut(); + if (modeRef.current === "clip") setNote("gaps are cut in Cut mode — switch the handles to Cut first"); + else if (gap.sel) void gap.cut(); else gap.setPick((v) => !v); break; case "G": - gap.removeAt(playheadRef.current); + if (modeRef.current === "clip") setNote("gaps are cut in Cut mode — switch the handles to Cut first"); + else gap.removeAt(playheadRef.current); break; case "Escape": // Reject ▾'s reasons are up: the Escape closes them (RejectClip), nothing else. @@ -1856,27 +1967,48 @@ export default function ClipBench({ ); return; } - setClip((prev) => fromEntry(prev, j.entry ?? {})); + const cutNext = fromEntry(clip, j.entry ?? {}); + setClip(cutNext); + // In cut mode the handles are the cut: they go to the new one (nothing drafted is lost -- the + // button writes only the cut, and an unsaved edge drag keeps its handles). + if (!dirty) setSel(spanIn(cutNext, modeRef.current)); token.current = String(j.token ?? ""); if (wroteNotes(j)) void notes.reload(); setCutScore(j.score ?? null); setNote(`cut to the quote (match ${(j.score ?? 0).toFixed(2)})`); - }, [data.project, clip.id]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [data.project, clip, dirty]); /** Save the window, and drop a cut the new extent no longer contains. */ const saveWindow = useCallback(() => { const patch = windowPatch(); + const did = edgesSaid(after, hms); + // ONE undo point for the one write: the edges (and the mark) as they were. + const back: Record<string, unknown> = { ...edgesBack(), ...(patch.muteFrom !== undefined ? { muteFrom: clip.muteFrom ?? "" } : {}) }; + const is = `${editsCut ? "the cut" : "the window"} is ${hms(round2(sel.from))}–${hms(round2(sel.to))}`; + const what = `saving ${editsCut ? "the cut" : "the window"} as ${hms(round2(sel.from))}–${hms(round2(sel.to))}`; void save(patch).then((ok) => { if (!ok) return; // A window saved by hand is the one Reset keeps from now on. setExtendedFrom(null); - const cleared = [ - patch.cutStart !== undefined ? "the cut" : null, - patch.muteFrom === "" && mute != null ? "the mute mark" : null, + setWindowUndo({ patch: back, what }); + const said = [ + did || null, + patch.muteFrom === "" && mute != null ? "the mute mark no longer fitted and was cleared" : null, ].filter(Boolean); - if (cleared.length) setNote(`saved — ${cleared.join(" and ")} no longer fitted this window and ${cleared.length > 1 ? "were" : "was"} cleared`); + setNote(`saved — ${[is, ...said].join("; ")}`); }); - }, [windowPatch, save, mute]); + }, [windowPatch, save, mute, after, edgesBack, clip.muteFrom, editsCut, sel.from, sel.to]); + const [windowUndo, setWindowUndo] = useState<{ patch: Record<string, unknown>; what: string } | null>(null); + useEffect(() => setWindowUndo(null), [clip.id]); + const undoWindow = useCallback(async () => { + const u = windowUndo; + if (!u) return; + const ok = await save(u.patch); + if (!ok) return; + setWindowUndo(null); + setNote(`undone — ${u.what} is reversed`); + }, [windowUndo, save]); // ---- the warnings -------------------------------------------------------- const endCue = cues.find((c) => sel.to >= c.start - 0.02 && sel.to <= c.end + 0.02) ?? null; @@ -1887,11 +2019,12 @@ export default function ClipBench({ // `resolve-windows --write` reverts it. Offering the matching lock is what // stops that being a silent loss -- and is why five of six real manifests are // 100% locked. + // About the EXTENT (widen() proposes one), as the handles would write it. const wouldRevert = !clip.lock && proposed != null && - (Math.abs(proposed.start - round2(sel.from)) > 0.05 || - Math.abs(proposed.end - round2(sel.to)) > 0.05); + (Math.abs(proposed.start - after.start) > 0.05 || + Math.abs(proposed.end - after.end) > 0.05); const span = Math.max(1e-6, view.to - view.from); const pct = (t: number) => `${((t - view.from) / span) * 100}%`; @@ -2034,7 +2167,7 @@ export default function ClipBench({ // stale check still guards them. const returnState = useRef({ busy: false, clean: true }); returnState.current = { - busy: !!busy || !!gap.sel || gap.pick || cutDraft != null, + busy: !!busy || !!gap.sel || gap.pick, clean: !dirty && !muteMoved && !osChanged && ATTRIB.every(([k]) => draft[k] === attribValue(clip, k)), }; const windowsRef = useRef(windows); @@ -2064,7 +2197,7 @@ export default function ClipBench({ token.current = j.token; const next = fromEntry(clipRef.current, j.clip); setClip(next); - setSel({ from: next.start, to: next.end }); + setSel(spanIn(next, modeRef.current)); setDirty(false); setMute(next.muteFrom); muteRef.current = next.muteFrom; @@ -2124,8 +2257,9 @@ export default function ClipBench({ const pastCache = sentenceEnd != null && sentenceEnd > clampTo + 0.02; const extendTo = (t: number) => { const to = round2(t); - const was = { start: clip.start, end: clip.end }; - void save({ start: round2(sel.from), end: to }).then((ok) => { + // In the mode's terms: in cut mode the cut ends there (the extent grows with it). + const was = { start: savedSpan.from, end: savedSpan.to, back: { ...edgesBack() } }; + void save({ ...edgePatch({ from: sel.from, to }) }).then((ok) => { if (!ok) return; setExtendedFrom(was); setNote(`saved — ${clip.id} now ends at ${hms(to)}, the end of the sentence; R undoes it`); @@ -2135,14 +2269,14 @@ export default function ClipBench({ // Extend goes back to the window it replaced. resetRef.current = () => { if (unsaved || !extendedFrom) { - setSel({ from: clip.start, to: clip.end }); + setSel(spanIn(clip, mode)); setDirty(false); setMute(clip.muteFrom); muteRef.current = clip.muteFrom; return; } const back = extendedFrom; - void save({ start: back.start, end: back.end }).then((ok) => { + void save(back.back).then((ok) => { if (!ok) return; setExtendedFrom(null); setNote(`the extension is undone — ${clip.id} ends at ${hms(back.end)} again`); @@ -2956,7 +3090,7 @@ export default function ClipBench({ </span> {dirty && ( <span className="num text-[var(--color-dirty)]"> - unsaved — was {hms(clip.start)} – {hms(clip.end)} + unsaved — was {hms(savedSpan.from)} – {hms(savedSpan.to)} </span> )} {muteMoved && ( @@ -2974,6 +3108,18 @@ export default function ClipBench({ > Save window </button> + {windowUndo && !unsaved && ( + <button + type="button" + data-window-undo="" + className={buttonVariants({ variant: "outline", size: "sm" })} + disabled={!!busy} + title={`undo: ${windowUndo.what}`} + onClick={() => void undoWindow()} + > + Undo save + </button> + )} <button type="button" data-play-selection="" @@ -3086,7 +3232,7 @@ export default function ClipBench({ <span className="text-[var(--color-dim)]"> ({(clip.cutEnd - clip.cutStart).toFixed(2)}s {cutScore != null ? `, quote match ${cutScore.toFixed(2)}` : ""} - {clip.lockCut ? ", pinned" : ""}) + ) </span> </span> ) : ( @@ -3200,40 +3346,74 @@ export default function ClipBench({ On a phone the edge strip is the instrument; this one is still there, folded under Window, for the mute mark. */} <div data-bench-sel={`${sel.from.toFixed(2)}-${sel.to.toFixed(2)}`} className={cn("flex flex-col gap-1", secBody("window", "max-md:order-[52]"))}> - {/* A cut narrower than the clip: the wall a gap -- and the video -- stops - at, said above the waveform it is drawn on, with the way out. */} - {cutNarrower && ( - <div data-cut-limits={`${clip.cutStart}-${clip.cutEnd}`} className="flex flex-wrap items-center gap-2 rounded border border-[var(--color-good)] px-2 py-1 text-[12px]"> - <span className="text-[var(--color-text)]"> - The video plays only the cut{" "} - <span className="num"> - {hms(clip.cutStart!)}–{hms(clip.cutEnd!)} - </span> - , and gaps go inside it{" "} - <span className="text-[var(--color-dim)]"> - (the clip is {hms(sel.from)}–{hms(sel.to)} - {clip.lockCut ? "; the cut is pinned" : ""}) - </span> - </span> + {/* ---- the MODE: what the handles edit ---- + Cut (what plays; gaps live here) or Clip (the seconds reviewed), + and the line that reads the two in the mode's terms. */} + <div data-bench-mode={mode} className="flex flex-wrap items-center gap-2 text-[12px]"> + <span role="group" aria-label="what the handles edit" className="inline-flex overflow-hidden rounded border border-[var(--color-line)]"> + {(["cut", "clip"] as const).map((m) => ( + <button + key={m} + type="button" + data-bench-mode-set={m} + aria-pressed={mode === m} + disabled={!!busy || (dirty && mode !== m)} + title={ + dirty && mode !== m + ? `save or reset the ${editsCut ? "cut" : "window"} you moved first` + : m === "cut" + ? "the handles are what plays; gaps are cut here" + : "the handles are the seconds reviewed; what plays is the band inside" + } + onClick={() => setMode(m)} + className={ + mode === m + ? "bg-[var(--color-panel-2)] px-2.5 py-0.5 font-semibold text-[var(--color-text)] disabled:opacity-60" + : "px-2.5 py-0.5 text-[var(--color-dim)] hover:text-[var(--color-text)] disabled:opacity-50" + } + > + {m === "cut" ? "Cut" : "Clip"} + </button> + ))} + </span> + <span data-bench-plays={`${(after.cutStart ?? after.start).toFixed(2)}-${(after.cutEnd ?? after.end).toFixed(2)}`} className="num text-[var(--color-text)]"> + {mode === "cut" ? ( + <> + Plays {hms(after.cutStart ?? after.start)}–{hms(after.cutEnd ?? after.end)} + <span className="text-[var(--color-dim)]"> + {" "}· reviewed {hms(after.start)}–{hms(after.end)} + </span> + </> + ) : ( + <> + Reviewed {hms(after.start)}–{hms(after.end)} + <span className="text-[var(--color-dim)]"> + {" "}· plays {hms(after.cutStart ?? after.start)}–{hms(after.cutEnd ?? after.end)} + {after.cutStart != null ? " (edit it in Cut)" : ""} + </span> + </> + )} + </span> + {/* A cut narrower than what was reviewed: the rest back in one press. */} + {cutNarrower && !dirty && ( <button type="button" data-cut-use-whole="" - className={buttonVariants({ size: "sm" })} + className={buttonVariants({ variant: "outline", size: "sm" })} disabled={!!busy} - title="clear the cut: the whole clip plays, and gaps can go anywhere in it (Undo puts the cut back)" + title="play everything reviewed: the cut is cleared, and gaps can go anywhere in the clip (Undo cut puts it back)" onClick={takeWholeClip} > Use the whole clip </button> - <span className="text-[var(--color-dim)]">or drag the cut&apos;s edges (the green tabs) on the waveform</span> - </div> - )} + )} + </div> {/* Zoomed: round ticks over what is shown. */} {zoom.zoomed && <ZoomRuler vis={zoom.vis} />} <BenchWaveBox zoom={zoom} sel={sel} - cand={{ from: clip.start, to: clip.end }} + cand={savedSpan} cues={cues} peaks={peaks} playhead={playhead} @@ -3243,8 +3423,8 @@ export default function ClipBench({ silences={renderEdges?.silences ?? null} words={nearWords?.words ?? null} busy={!!busy} - held={mutePick} - walls={walls} + held={mutePick || mode === "clip"} + walls={mode === "cut" ? walls : null} > {/* The mute mark over the waveform: a line where the sound stops and a hatch over what is silent to the end of the selection. @@ -3271,16 +3451,9 @@ export default function ClipBench({ </div> </> )} - {/* The cut, when the clip has one: its edges, dragged here (bench/CutEdges.tsx). */} - {hasCut && ( - <CutEdges - vis={zoom.vis} - cut={cutDraft ?? { from: clip.cutStart!, to: clip.cutEnd! }} - extent={sel} - busy={!!busy} - fmt={hms} - onDrag={onCutDrag} - /> + {/* Clip mode: the cut as a band inside the extent (bench/CutEdges.tsx), passive. */} + {mode === "clip" && after.cutStart != null && after.cutEnd != null && ( + <CutEdges vis={zoom.vis} cut={{ from: after.cutStart, to: after.cutEnd }} extent={sel} busy={!!busy} fmt={hms} /> )} {/* Where the render will actually cut: each edge snapped to its silence, faint. */} <RenderGhosts edges={renderEdges} view={zoom.vis} /> @@ -3302,7 +3475,13 @@ export default function ClipBench({ {/* Under the waveform: its zoom, and the clip's gaps (the waveform keeps its place on the page). */} <div data-wave-tools="" className="flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px]"> {/* ---- GAPS inside the clip (bench/BenchWave.tsx GapTools) ---- */} - <GapTools gap={gap} gaps={clip.gaps ?? []} span={gapsSpan} sel={sel} busy={!!busy} fmt={hms} play={play} /> + {mode === "cut" ? ( + <GapTools gap={gap} gaps={clip.gaps ?? []} span={gapsSpan} sel={sel} busy={!!busy} fmt={hms} play={play} /> + ) : ( + <span data-gaps-clip-mode="" className="text-[var(--color-dim)]"> + {(clip.gaps ?? []).length ? `${(clip.gaps ?? []).length} gap${(clip.gaps ?? []).length === 1 ? "" : "s"} — ` : ""}gaps are cut in Cut mode + </span> + )} <TightenButtons tools={edgeTools} busy={!!busy} /> <span className="micro max-md:hidden"> <kbd>z</kbd> <kbd>Z</kbd> zoom (or Ctrl/⌘ + wheel), <kbd>f</kbd> fit, <kbd>F</kbd> to the selection ·{" "} @@ -3559,10 +3738,11 @@ export default function ClipBench({ className={buttonVariants({ variant: "outline", size: "sm" })} onClick={() => void save({ - start: round2(sel.from), - end: round2(sel.to), - lockStart: Math.abs(proposed!.start - round2(sel.from)) > 0.05, - lockEnd: Math.abs(proposed!.end - round2(sel.to)) > 0.05, + ...edgePatch(sel), + start: after.start, + end: after.end, + lockStart: Math.abs(proposed!.start - after.start) > 0.05, + lockEnd: Math.abs(proposed!.end - after.end) > 0.05, }) } > diff --git a/umtool/components/projects/bench/CutEdges.tsx b/umtool/components/projects/bench/CutEdges.tsx @@ -31,8 +31,8 @@ export function CutEdges({ extent: Span; busy: boolean; fmt: (t: number) => string; - /** An edge dragged to `t`; `done` on release. */ - onDrag: (side: "start" | "end", t: number, done: boolean) => void; + /** An edge dragged to `t`; `done` on release. Absent: drawn only (the bench's clip mode), no tabs. */ + onDrag?: (side: "start" | "end", t: number, done: boolean) => void; }) { const span = Math.max(1e-6, vis.to - vis.from); const pct = (t: number) => `${((Math.min(vis.to, Math.max(vis.from, t)) - vis.from) / span) * 100}%`; @@ -53,7 +53,7 @@ export function CutEdges({ <div key={`out-${o.side}`} data-wave-outside-cut={o.side} - title={`${fmt(o.from)}–${fmt(o.to)} is in the clip but not in its cut: the video does not play it, and no gap can go here`} + title={`${fmt(o.from)}–${fmt(o.to)} was reviewed but is not in the cut: the video does not play it`} className="pointer-events-none absolute top-0 h-full [background:repeating-linear-gradient(-45deg,color-mix(in_srgb,var(--color-good)_16%,transparent)_0_2px,transparent_2px_8px)]" style={{ left: pct(o.from), width: width(o.from, o.to) }} /> @@ -69,6 +69,7 @@ export function CutEdges({ className="pointer-events-none absolute top-0 z-[4] h-full border-l-2 border-[var(--color-good)]" style={{ left: pct(t) }} > + {onDrag && ( <button type="button" data-wave-cut-grip={side} @@ -105,6 +106,7 @@ export function CutEdges({ > {side === "start" ? "cut ▸" : "◂ cut"} </button> + )} </div> ); })} diff --git a/umtool/components/projects/bench/RenderGhosts.tsx b/umtool/components/projects/bench/RenderGhosts.tsx @@ -57,6 +57,8 @@ export function useRenderEdges( sel: { from: number; to: number }, /** Walking a take: the clip is the take's (the cut-points route reads its manifest). */ take: string | null = null, + /** The cut as drafted (the bench's cut mode drags it), in place of the saved one; `sel` is then the extent as drafted. */ + cutDraft: { cutStart: number | null; cutEnd: number | null } | null = null, ): RenderEdges { const [got, setGot] = useState<{ key: string; row: Row | null; knobs: Got["knobs"]; leadIn: number } | null>(null); // Measured again when what was SAVED moves (the extent picks the file and the span). @@ -76,7 +78,7 @@ export function useRenderEdges( }, [key, project, clip.id, take]); const row = got?.row; if (!got || !row || !row.silences || row.fetchStart == null || row.montage) return null; - const pw = playWindowOf(sel, clip, got.leadIn); + const pw = playWindowOf(sel, cutDraft ?? clip, got.leadIn); const render = { snapWindow: got.knobs.snapWindow ?? undefined, snapLead: got.knobs.snapLead ?? undefined, diff --git a/umtool/components/projects/bench/TightenTools.tsx b/umtool/components/projects/bench/TightenTools.tsx @@ -64,6 +64,7 @@ export function useEdgeTools({ lastSaved, play, setNote, + writes = null, }: { project: string; clip: ClipEdges; @@ -78,6 +79,13 @@ export function useEdgeTools({ lastSaved: React.MutableRefObject<Record<string, unknown> | null>; play: (from: number, to: number) => unknown; setNote: (s: string | null) => void; + /** + * What a span the tools settle on is written AS (the clip bench's cut mode, + * lane/bench-modes: the cut, the extent grown past it): the patch, what else + * it did in words, and the patch that puts the edges back. Absent: the + * extent, the cut and the mute mark cleared when they no longer fit. + */ + writes?: { patchFor: (s: Span) => { patch: Record<string, unknown>; also: string }; back: () => Record<string, unknown>; anchorCut: boolean } | null; }) { const [undo, setUndo] = useState<{ patch: Record<string, unknown>; what: string } | null>(null); const [working, setWorking] = useState<string | null>(null); @@ -89,6 +97,17 @@ export function useEdgeTools({ async (next: Span, what: string, moved: "start" | "end" | "both") => { const start = r2(next.from); const end = r2(next.to); + if (writes) { + const { patch, also } = writes.patchFor({ from: start, to: end }); + const backPatch = writes.back(); + const ok = await save(patch); + if (!ok) return false; + setUndo({ patch: backPatch, what }); + setNote(`${what}${also ? ` — ${also}` : ""} · Undo puts it back`); + if (moved === "end") play(Math.max(start, end - 4), end); + else play(start, Math.min(end, start + 4)); + return true; + } const patch: Record<string, unknown> = { start, end }; const cleared: string[] = []; if (clip.cutStart != null && clip.cutEnd != null && (clip.cutStart < start - 0.02 || clip.cutEnd > end + 0.02)) { @@ -123,7 +142,7 @@ export function useEdgeTools({ else play(start, Math.min(end, start + 4)); return true; }, - [clip, save, lastSaved, play, setNote], + [clip, save, lastSaved, play, setNote, writes], ); const tighten = useCallback(async () => { @@ -133,7 +152,8 @@ export function useEdgeTools({ const at = playhead; const words = await benchWords(project, clip.id, video, sel.from - 12, sel.to + 12); const r = tightWindow({ - clip: { start: sel.from, end: sel.to, cutStart: clip.cutStart, cutEnd: clip.cutEnd }, + // The handles' span is the cut itself in the bench's cut mode: nothing inside it anchors it. + clip: { start: sel.from, end: sel.to, cutStart: writes && !writes.anchorCut ? null : clip.cutStart, cutEnd: writes && !writes.anchorCut ? null : clip.cutEnd }, cues, words: toWords(words), silences, diff --git a/umtool/docs/clip-bench.md b/umtool/docs/clip-bench.md @@ -126,15 +126,28 @@ drag stopped dead there); the only cap is the window's, end to end: window is at most 15 min end to end — Fetch whole source for more" — and the route refuses a wider ask with the same next step. -**A cut narrower than the clip is drawn on the waveform** — its edges in the -cut's green with a `cut ▸` / `◂ cut` tab each, the clip's seconds outside it -hatched — and said above it: *The video plays only the cut …, and gaps go -inside it*. A gap dragged past it stops at it and says so while it is dragged. -The tabs drag the cut's edges (written on release, inside the extent as -drafted, a moved extent saved with it); **Use the whole clip** (and Clear cut) -clears it; **Undo cut** puts back what either did. A gap's span is the cut, -else the extent as DRAFTED: an edge dragged out over a wider fetch can be cut -into at once, and the moved window is saved with the gap. +**Two modes, one set of handles** (lane/bench-modes; operator, 6 Nov: "this +split between the clip and the cut is hard to reason around. Can it be a +switchable mode instead and we start in cut mode?"). The data keeps both +numbers — the extent (`start`/`end`, what was reviewed) and the cut +(`cutStart`/`cutEnd`, what plays; see report-video.md, "Extent vs cut") — and +the bench edits one at a time, chosen by the **Cut | Clip** switch above the +waveform: + +- **Cut** (every time the bench opens): the handles are what plays — the cut, + or the extent when there is no cut (then the two are one). Gaps are cut + here. A handle dragged past the extent grows it with the cut (the seconds + were just reviewed): Save window writes both in one write, and **Undo save** + puts both back. The line beside the switch reads *Plays 0:12–0:31 · reviewed + 0:05–0:44*; **Use the whole clip** (shown when the cut is narrower than what + was reviewed) clears the cut, with **Undo cut**. +- **Clip**: the handles are the extent, the cut a band inside it. An extent + pulled in past the cut takes the cut in with it ("the cut shrank with it + to …"), and clears it — said — when under half a second would be left. + +The switch does not move under unsaved edges (save or Reset first). Tighten, +snap and Extend to the sentence write in the mode's terms; a gap written with +a moved edge says what that did to the cut. **One edge at a time.** Extending a window is nearly always one-sided — you want the sentence that follows, not another twenty seconds of the lead-in you diff --git a/umtool/e2e/clip-bench.spec.ts b/umtool/e2e/clip-bench.spec.ts @@ -1540,17 +1540,32 @@ test("a cut that is not inside its window is refused by the writer", async ({ re expect(readClip("c01").cutStart).toBe(3); }); -test("pulling the window in past the cut clears it, and says so", async ({ page }) => { +test("in Clip mode, pulling the window in past the cut takes the cut in with it; under half a second it is cleared, and both say so", async ({ page, request }) => { await page.goto(bench("c01")); await keyboardLive(page); - // c01 is 0.00-12.00 with a cut at 3.00-9.00. Bring the end in to 8.5, inside - // the cut: the extent is the judgement being made right now, and the cut was - // derived from a wider one. + // The bench opens in Cut mode -- the handles are the cut, 3.00-9.00 -- and + // the window (the seconds reviewed) is edited in Clip mode (lane/bench-modes). + await expect(page.locator("[data-bench-mode]")).toHaveAttribute("data-bench-mode", "cut"); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "3.00-9.00"); + await page.locator("[data-bench-mode-set=clip]").click(); + await expect(page.locator("[data-bench-mode]")).toHaveAttribute("data-bench-mode", "clip"); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "0.00-12.00"); + // c01 is 0.00-12.00 with a cut at 3.00-9.00. Bring the end in to 8.5, inside the cut: the cut comes in with it. for (let i = 0; i < 7; i += 1) await page.locator("body").press("Shift+Comma"); await page.getByRole("button", { name: "save window" }).click(); + await expect(page.locator("[data-bench-note]")).toContainText("the cut shrank with it to 0:03.00–0:08.50"); + await expect.poll(() => readClip("c01").cutEnd).toBe(8.5); + expect(readClip("c01").cutStart).toBe(3); + // The end in to 2.5, before the cut's start: nothing of the cut would be left -- it is cleared, and said. + for (let i = 0; i < 12; i += 1) await page.locator("body").press("Shift+Comma"); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "0.00-2.50"); + await page.getByRole("button", { name: "save window" }).click(); await expect(page.locator("[data-bench-note]")).toContainText("cut no longer fitted"); await expect.poll(() => readClip("c01").cutStart).toBeUndefined(); await expect(page.locator("[data-cut]")).toContainText("no cut"); + // Back to the window the rest of this file expects (0.00-8.50, no cut). + const { token: t } = await token(request, "c01"); + expect((await request.put("/api/report/window", { data: { project: PROJECT, clip: "c01", start: 0, end: 8.5, token: t } })).ok()).toBeTruthy(); }); test("the CLI pass reports every cut it can find, and writes none on a dry run", () => { diff --git a/umtool/e2e/gaps-zoom.spec.ts b/umtool/e2e/gaps-zoom.spec.ts @@ -319,75 +319,104 @@ test("Play the cut on a take plays a gapped clip's kept pieces only", async ({ p }); // --------------------------------------------------------------------------- -// A cut narrower than the clip (lane/clip-fixes; operator, 6 Nov: "I can't add -// gaps beyond like 9:21"): an extent widened over a cut kept from an earlier -// pass. Gaps lie inside the cut, so every gap stopped at the cut's end with -// nothing on the waveform to say why. Now the cut is drawn there, said above -// it, its edges drag, and Use the whole clip clears it -- each with an Undo. +// The bench's two modes (lane/bench-modes; operator, 6 Nov: "this split +// between the clip and the cut is hard to reason around. Can it be a +// switchable mode instead and we start in cut mode?"). Cut mode -- every time +// the bench opens -- the handles are what plays; dragged past the extent they +// grow it, in one write with one undo. Clip mode: the handles are the extent, +// the cut a band inside it that comes in with an extent pulled past it. // --------------------------------------------------------------------------- const cutOf = () => { - const e = (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: { id: string; cutStart?: number; cutEnd?: number }[] }).timeline.find((x) => x.id === "g01")!; - return { cutStart: e.cutStart ?? null, cutEnd: e.cutEnd ?? null }; + const e = (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: { id: string; start: number; end: number; cutStart?: number; cutEnd?: number }[] }).timeline.find((x) => x.id === "g01")!; + return { start: e.start, end: e.end, cutStart: e.cutStart ?? null, cutEnd: e.cutEnd ?? null }; }; const SHOTS = process.env.E2E_CLIP_FIXES_SHOTS ?? null; -const shot = async (page: Page, name: string) => { +const shot = async (page: Page, name: string, whole = false) => { if (!SHOTS) return; mkdirSync(SHOTS, { recursive: true }); - await page.locator("[data-wave-box]").screenshot({ path: path.join(SHOTS, `${name}.png`) }); + const box = page.locator("[data-wave-box]"); + if (!whole) { + await box.screenshot({ path: path.join(SHOTS, `${name}.png`) }); + return; + } + // The mode row, the waveform and its tools: the instrument's whole column. + await page.locator("[data-bench-sel]").screenshot({ path: path.join(SHOTS, `${name}.png`) }); +}; +/** Drag a waveform handle (the one nearer `a`) from source second a to b. */ +const dragHandle = async (page: Page, a: number, b: number) => { + await page.locator("[data-wave-box]").scrollIntoViewIfNeeded(); + const y = await midY(page); + await page.mouse.move(await xAt(page, a), y); + await page.mouse.down(); + await page.mouse.move(await xAt(page, b), y, { steps: 5 }); + await page.mouse.up(); }; -test("a cut narrower than the clip: drawn on the waveform, said, a gap stops at it with the reason, its edge drags, Use the whole clip", async ({ page, request }) => { +test("a clip with a cut opens in Cut mode: the handles are what plays, dragged past the extent they grow it in one write with one undo; Clip mode edits the extent with the cut a band inside", async ({ page, request }) => { expect((await putWindow(request, { cutStart: 1, cutEnd: 4 })).ok()).toBeTruthy(); try { await openBench(page); - await expect(page.locator("[data-cut-limits]")).toContainText("The video plays only the cut"); - await expect(page.locator("[data-cut-limits]")).toContainText("gaps go inside it"); - await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(2); - await expect(page.locator("[data-wave-outside-cut]")).toHaveCount(2); - await shot(page, "cut-narrower"); - - // Alt + drag from inside the cut out past its end: the span stops at the cut's - // end, and -- BEFORE release -- turns red and says why, the clamp included. - await page.keyboard.down("Alt"); - const y = await midY(page); - await page.mouse.move(await xAt(page, 2.5), y); - await page.mouse.down(); - await page.mouse.move(await xAt(page, 6), y, { steps: 4 }); - const live = page.locator("[data-gap-selection-why]"); - await expect(live).toContainText("stopped at the cut's end"); - await expect(live).toContainText("keep at least 0.5 s"); - await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "refused"); - expect(spanOf(await page.locator("[data-gap-selection]").getAttribute("data-gap-selection"))[1]).toBeCloseTo(4, 2); - await shot(page, "gap-at-cut-wall"); - await page.mouse.up(); - await page.keyboard.up("Alt"); - await expect(page.locator("[data-bench-note]")).toContainText("stopped at the cut's end"); - await page.locator("body").press("Escape"); - - // The cut's end tab drags the edge out; written on release, with an Undo. - const grip = page.locator("[data-wave-cut-grip=end]"); - const gb = (await grip.boundingBox())!; - await page.mouse.move(gb.x + gb.width / 2, gb.y + gb.height / 2); - await page.mouse.down(); - await page.mouse.move(await xAt(page, 7), gb.y + gb.height / 2, { steps: 5 }); - await page.mouse.up(); - await expect.poll(() => cutOf().cutEnd ?? 0).toBeGreaterThan(6.5); - expect(cutOf().cutStart).toBe(1); - await expect(page.locator("[data-bench-note]")).toContainText("the cut moved to"); - await page.locator("[data-cut-undo]").click(); - await expect.poll(() => cutOf().cutEnd).toBe(4); + const mode = page.locator("[data-bench-mode]"); + await expect(mode).toHaveAttribute("data-bench-mode", "cut"); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "1.00-4.00"); + await expect(page.locator("[data-bench-plays]")).toContainText("Plays 0:01.00–0:04.00 · reviewed 0:00.50–0:08.50"); + // One set of handles: no second pair for the cut, nothing called "pinned". + await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(0); + await expect(page.locator("[data-cut-use-whole]")).toBeVisible(); + await expect(page.locator("[data-bench-mode]")).not.toContainText("pinned"); + await shot(page, "mode-cut", true); - // Use the whole clip: the cut cleared, the wall gone; Undo puts it back. + // The end handle past the extent's 8.50 to 8.9 (the cache runs to 9): no wall. + const puts: string[] = []; + page.on("request", (r) => { + if (r.method() === "PUT" && r.url().endsWith("/api/report/window")) puts.push(r.url()); + }); + await dragHandle(page, 4, 8.9); + const [, to] = spanOf(await page.locator("[data-bench-sel]").getAttribute("data-bench-sel")); + expect(to).toBeGreaterThan(8.6); + await expect(page.locator("[data-bench-plays]")).toContainText(`reviewed 0:00.50–`); + // Unsaved: the mode cannot switch under it. + await expect(page.locator("[data-bench-mode-set=clip]")).toBeDisabled(); + await page.locator("[data-save-window]").click(); + await expect(page.locator("[data-bench-note]")).toContainText("the reviewed range grew with it"); + await expect.poll(() => cutOf().cutEnd).toBeCloseTo(to, 2); + expect(cutOf()).toMatchObject({ start: 0.5, cutStart: 1 }); + expect(cutOf().end).toBeCloseTo(to, 2); + expect(puts.length, "one write").toBe(1); + // One undo puts both back. + await page.locator("[data-window-undo]").click(); + await expect.poll(() => cutOf()).toEqual({ start: 0.5, end: 8.5, cutStart: 1, cutEnd: 4 }); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "1.00-4.00"); + + // Clip mode: the handles are the extent, the cut a band inside it (no tabs to drag). + await page.locator("[data-bench-mode-set=clip]").click(); + await expect(mode).toHaveAttribute("data-bench-mode", "clip"); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", "0.50-8.50"); + await expect(page.locator("[data-bench-plays]")).toContainText("Reviewed 0:00.50–0:08.50 · plays 0:01.00–0:04.00"); + await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(2); + await expect(page.locator("[data-wave-cut-grip]")).toHaveCount(0); + await expect(page.locator("[data-gaps-clip-mode]")).toContainText("gaps are cut in Cut mode"); + await shot(page, "mode-clip", true); + // The extent's start pulled in past the cut's: the cut comes in with it. + await dragHandle(page, 0.5, 2); + await page.locator("[data-save-window]").click(); + await expect(page.locator("[data-bench-note]")).toContainText("the cut shrank with it"); + await expect.poll(() => cutOf().cutStart ?? 0).toBeGreaterThan(1.8); + expect(cutOf().cutStart).toBe(cutOf().start); + expect(cutOf().cutEnd).toBe(4); + + // And back to Cut: the handles are the (smaller) cut; Use the whole clip clears it, Undo cut puts it back. + await page.locator("[data-bench-mode-set=cut]").click(); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", `${cutOf().cutStart!.toFixed(2)}-4.00`); await page.locator("[data-cut-use-whole]").click(); await expect.poll(() => cutOf().cutStart).toBeNull(); - await expect(page.locator("[data-cut-limits]")).toHaveCount(0); - await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(0); + await expect(page.locator("[data-bench-sel]")).toHaveAttribute("data-bench-sel", `${cutOf().start.toFixed(2)}-8.50`); + await expect(page.locator("[data-cut-use-whole]")).toHaveCount(0); await page.locator("[data-cut-undo]").click(); - await expect.poll(() => cutOf()).toEqual({ cutStart: 1, cutEnd: 4 }); - await expect(page.locator("[data-wave-cut-edge]")).toHaveCount(2); + await expect.poll(() => cutOf().cutEnd).toBe(4); } finally { - expect((await putWindow(request, { cutStart: "", cutEnd: "", lockCut: false })).ok()).toBeTruthy(); + expect((await putWindow(request, { start: 0.5, end: 8.5, cutStart: "", cutEnd: "", lockCut: false })).ok()).toBeTruthy(); } });