commit 877943cfd384009de059f20845ce5eded4852c20
parent 2a9b597b4ef7810b149321dafebd101e8269f879
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 22 Oct 2026 10:08:25 -0400
clip editor: Count & stamp and Audio boxes (Set at playhead, Shift+S; listen replays 3 s)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 280 insertions(+), 1 deletion(-)
diff --git a/umtool/components/projects/review/ClipEditor.tsx b/umtool/components/projects/review/ClipEditor.tsx
@@ -14,6 +14,7 @@ import { cn } from "@/lib/utils";
import { ROOM, roomShade } from "umtool-report-to-video/room";
import { startTakeJob } from "../NewTakePanel";
import AssistBox from "../report/AssistBox";
+import { AudioBox, CountStampBox } from "./ClipKnobs";
// Release 36 lane D: the assistant's labels, Suggest, Ask and Apply (all optional).
import type { ReplyProposal } from "@/lib/annotations/types";
import { proposalWords, ReplyProposalRow, SuggestLabel, SuggestPanel, SuggestWhy, useClipSuggest, type ClipSuggest } from "./ClipSuggest";
@@ -37,6 +38,9 @@ import { proposalWords, ReplyProposalRow, SuggestLabel, SuggestPanel, SuggestWhy
// the short (release 36) a 9:16 box dragged on the player (the clip's
// `vertical.crop`), Make a short (a job: shorts/<clip>.mp4);
// a speaker's name for the captions in the Speakers list
+// the knobs (video knobs) Count & stamp on a claimed clip -- the stamp's
+// second (Set at playhead, Shift+S), hold, on/off, count,
+// label -- and Audio: sync nudge, gain, fades (./ClipKnobs.tsx)
//
// Every write is one POST to /api/report/clip-editor; the answer is the whole
// view again, so the page never guesses what the server did. Edge edits are
@@ -351,6 +355,18 @@ export default function ClipEditor({
setPlayhead(t);
player.current?.seek(t);
};
+ // The video knobs: the claim's stamp at the playhead (Shift+S), and the 3 s around it, heard.
+ const stampAtPlayhead = () => {
+ if (playhead === null) {
+ setError("put the playhead where the stamp should land first");
+ return;
+ }
+ void flush().then(() => write({ op: "claim", clip: clip.id, knobs: { at: r2(playhead) } }, `The stamp lands at ${edgeClock(playhead)}`));
+ };
+ const listen = () => {
+ if (playhead === null) return;
+ player.current?.listen(playhead);
+ };
// ---- keys -----------------------------------------------------------------
const keyRef = useRef<(e: KeyboardEvent) => void>(() => {});
@@ -358,6 +374,13 @@ export default function ClipEditor({
if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey) return;
const t = e.target as HTMLElement | null;
if (t?.closest?.(TYPING) || t?.closest?.("dialog[open]")) return;
+ // Shift+S: the claim's stamp lands at the playhead (S alone splits).
+ if (e.shiftKey && e.key.toLowerCase() === "s") {
+ if (!clip.claim) return;
+ e.preventDefault();
+ stampAtPlayhead();
+ return;
+ }
const k = e.key.length === 1 ? e.key.toLowerCase() : e.key;
const act: Record<string, () => void> = {
" ": () => player.current?.toggle(),
@@ -572,6 +595,22 @@ export default function ClipEditor({
</div>
)}
+ {/* ---- the knobs (video knobs) -------------------------------------- */}
+ {clip.claim && (
+ <CountStampBox
+ clipId={clip.id}
+ claim={clip.claim}
+ stampsOn={clip.stampsOn ?? null}
+ defaults={view.knobs}
+ playhead={playhead}
+ span={{ start: clip.start, end: clip.end, cutStart: cut.cutStart, cutEnd: cut.cutEnd }}
+ busy={busy}
+ write={write}
+ onGo={choose}
+ />
+ )}
+ <AudioBox clipId={clip.id} audio={clip.audio ?? null} busy={busy} write={write} canListen={playhead !== null} onListen={listen} />
+
{/* ---- the decisions ----------------------------------------------- */}
<div className="flex flex-wrap items-center gap-2" data-editor-actions="">
<button type="button" data-rule="keep" aria-pressed={clip.ruling === "keep"} disabled={busy} onClick={() => rule(clip.ruling === "keep" ? null : "keep")} className={buttonVariants({ variant: clip.ruling === "keep" ? "pressed" : "outline", size: "md" })}>
@@ -747,7 +786,7 @@ export default function ClipEditor({
// clip's extent, else its cut; loops the cut.
// ---------------------------------------------------------------------------
-type PlayerHandle = { toggle: () => void; seek: (t: number) => void };
+type PlayerHandle = { toggle: () => void; seek: (t: number) => void; listen: (t: number) => void };
/** The short's framing on the player: the clip's crop (null = the centre) and its writer. */
type Frame = { crop: number[] | null; onChange: (crop: number[] | null, aspect?: number) => void; busy: boolean };
type Target = { channel: string; video: string; from: number; to: number; project: string; clip: string };
@@ -760,6 +799,7 @@ const Player = forwardRef<PlayerHandle, { clipId: string; targets: Target[]; cut
// The seek to the cut on load is the player's own, not a person's: it must
// not move the playhead somebody just set by clicking a word.
const ownSeek = useRef(false);
+ const listenTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const cutRef = useRef(cut);
cutRef.current = cut;
const key = targets.map((t) => `${t.clip}|${t.from}|${t.to}`).join(",");
@@ -818,6 +858,20 @@ const Player = forwardRef<PlayerHandle, { clipId: string; targets: Target[]; cut
ownSeek.current = true;
m.currentTime = fileT(t);
},
+ // The 3 s around a second, then stop where it started (the Audio box's "listen").
+ listen: (t: number) => {
+ const m = media.current;
+ if (!m) return;
+ if (listenTimer.current) clearTimeout(listenTimer.current);
+ ownSeek.current = true;
+ m.currentTime = fileT(Math.max(0, t - 1.5));
+ void m.play().catch(() => {});
+ listenTimer.current = setTimeout(() => {
+ m.pause();
+ ownSeek.current = true;
+ m.currentTime = fileT(t);
+ }, 3000);
+ },
}));
if (found === undefined) return <div data-editor-player="looking" className="flex aspect-video w-full max-w-[720px] items-center justify-center rounded-[3px] bg-panel-2 text-[12px] text-muted">looking for the clip…</div>;
diff --git a/umtool/components/projects/review/ClipKnobs.tsx b/umtool/components/projects/review/ClipKnobs.tsx
@@ -0,0 +1,225 @@
+"use client";
+
+import { useEffect, useState } from "react";
+import { buttonVariants } from "@/components/ui/button";
+import { edgeClock } from "@/lib/report/clipEditorModel.mjs";
+import type { ClaimKnobs, ClipAudio, KnobDefaults } from "@/lib/report/clipEditorTypes";
+
+// THE CLIP'S KNOBS (video knobs, plans/video-knobs-ui.md), in the clip editor:
+//
+// Count & stamp on a clip that carries a claim: the source second its stamp
+// lands and the tally steps (`claim.at`, Set at playhead,
+// Shift+S), how long it stays (`hold`), whether it is drawn
+// (`stamp`), how much it counts (`count`), what it says
+// (`label`)
+// Audio the clip's sound at the encode: a sync nudge in ms (+ =
+// later), gain in dB, fades in s; "listen" replays the 3 s
+// around the playhead
+//
+// Every field shows the default it gets when its key is absent; Clear removes
+// the key (the default again). Each change is one write through the clip
+// editor's route (op claim / op audio), the same writer `umtool set` uses.
+
+const input = "num w-[6em] rounded border border-seam-2 bg-ground px-1.5 py-0.5 font-mono text-[12px] text-text outline-none focus:border-signal";
+const box = "space-y-1.5 rounded-[3px] border border-seam bg-panel p-2 text-[12px] text-text-2";
+
+type Write = (body: Record<string, unknown>, done?: string) => Promise<unknown>;
+
+/** A field that writes on Enter or blur; empty clears it. */
+function KnobField({
+ name,
+ label,
+ value,
+ placeholder,
+ unit,
+ kind = "number",
+ step,
+ maxLength,
+ busy,
+ onSave,
+}: {
+ name: string;
+ label: string;
+ value: number | string | undefined;
+ placeholder: string;
+ unit?: string;
+ kind?: "number" | "text";
+ step?: number;
+ maxLength?: number;
+ busy: boolean;
+ onSave: (v: string) => void;
+}) {
+ const shown = value === undefined ? "" : String(value);
+ const [text, setText] = useState(shown);
+ useEffect(() => setText(shown), [shown]);
+ const commit = () => {
+ if (text.trim() === shown) return;
+ onSave(text.trim());
+ };
+ return (
+ <label className="inline-flex items-center gap-1.5">
+ <span className="micro">{label}</span>
+ <input
+ data-knob={name}
+ type={kind}
+ step={step}
+ maxLength={maxLength}
+ value={text}
+ placeholder={placeholder}
+ disabled={busy}
+ onChange={(e) => setText(e.target.value)}
+ onBlur={commit}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ commit();
+ (e.target as HTMLInputElement).blur();
+ }
+ if (e.key === "Escape") {
+ setText(shown);
+ (e.target as HTMLInputElement).blur();
+ }
+ }}
+ className={kind === "text" ? input.replace("w-[6em]", "w-[11em]") : input}
+ />
+ {unit && <span className="text-muted">{unit}</span>}
+ {value !== undefined && (
+ <button type="button" data-knob-clear={name} disabled={busy} onMouseDown={(e) => e.preventDefault()} onClick={() => onSave("")} className={buttonVariants({ variant: "quiet", size: "sm" })} title="back to the default">
+ Clear
+ </button>
+ )}
+ </label>
+ );
+}
+
+const numOrNull = (s: string) => (s === "" ? null : Number(s));
+
+export function CountStampBox({
+ clipId,
+ claim,
+ stampsOn,
+ defaults,
+ playhead,
+ span,
+ busy,
+ write,
+ onGo,
+}: {
+ clipId: string;
+ claim: ClaimKnobs;
+ stampsOn: string | null;
+ defaults: KnobDefaults | undefined;
+ playhead: number | null;
+ span: { start: number; end: number; cutStart: number; cutEnd: number };
+ busy: boolean;
+ write: Write;
+ onGo: (id: string) => void;
+}) {
+ const set = (knobs: Record<string, unknown>, done: string) => void write({ op: "claim", clip: clipId, knobs }, done);
+ const hold = defaults?.hold ?? 3;
+ const word = defaults?.labels?.[claim.verdict] ?? claim.verdict;
+ const stampOn = claim.stamp !== false;
+ const outsideCut = typeof claim.at === "number" && (claim.at < span.cutStart || claim.at > span.cutEnd);
+ return (
+ <section id="clip-stamp" data-count-stamp={clipId} data-claim-id={claim.id} className={box}>
+ <div className="flex flex-wrap items-baseline gap-2">
+ <h2 className="micro m-0">Count & stamp</h2>
+ <span className="font-mono text-[11.5px]">
+ {claim.id} · {claim.verdict}
+ </span>
+ {stampsOn && stampsOn !== clipId && (
+ <span data-stamps-on={stampsOn} className="text-muted">
+ this claim stamps on{" "}
+ <button type="button" onClick={() => onGo(stampsOn)} className="underline">
+ {stampsOn}
+ </button>{" "}
+ (the last clip carrying it) — its knobs are read there
+ </span>
+ )}
+ </div>
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1.5">
+ <span className="inline-flex items-center gap-1.5" data-knob-at={claim.at ?? ""}>
+ <span className="micro">lands at</span>
+ <span className="num font-mono">{typeof claim.at === "number" ? edgeClock(claim.at) : "default (before the clip leaves)"}</span>
+ <button
+ type="button"
+ data-claim-at-playhead=""
+ disabled={busy || playhead === null}
+ onMouseDown={(e) => e.preventDefault()}
+ onClick={() => playhead !== null && set({ at: Math.round(playhead * 100) / 100 }, `The stamp lands at ${edgeClock(playhead)}`)}
+ className={buttonVariants({ size: "sm" })}
+ title="the stamp lands and the count steps at the playhead (a source second inside the clip)"
+ >
+ Set at playhead <kbd>⇧S</kbd>
+ </button>
+ {typeof claim.at === "number" && (
+ <button type="button" data-knob-clear="at" disabled={busy} onClick={() => set({ at: null }, "The stamp lands at its default")} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ Clear
+ </button>
+ )}
+ </span>
+ <KnobField name="hold" label="hold" unit="s" step={0.5} value={claim.hold} placeholder={String(hold)} busy={busy} onSave={(v) => set({ hold: numOrNull(v) }, v ? `The stamp stays ${v} s` : "The stamp stays the cut's default")} />
+ <label className="inline-flex items-center gap-1.5 text-text">
+ <input type="checkbox" data-knob="stamp" checked={stampOn} disabled={busy} onChange={(e) => set({ stamp: e.target.checked ? null : false }, e.target.checked ? "Stamp drawn" : "Counts, no stamp")} />
+ draw the stamp
+ </label>
+ <KnobField name="count" label="count" step={1} value={claim.count} placeholder={String(defaults?.count ?? 1)} busy={busy} onSave={(v) => set({ count: numOrNull(v) }, v ? `Counts ${v}` : "Counts 1")} />
+ <KnobField name="label" label="label" kind="text" maxLength={20} value={claim.label} placeholder={word} busy={busy} onSave={(v) => set({ label: v || null }, v ? `The stamp says “${v}”` : "The stamp says the verdict's word")} />
+ </div>
+ {defaults && !defaults.stampShown && <p className="m-0 text-muted">The cut draws no stamps (the fact-check's stamp effect is off): the count still steps here.</p>}
+ {outsideCut && (
+ <p data-knob-warning="" className="m-0 text-reject-text">
+ {edgeClock(claim.at as number)} is outside the cut ({edgeClock(span.cutStart)}–{edgeClock(span.cutEnd)}): the stamp would land on footage the cut does not play.
+ </p>
+ )}
+ </section>
+ );
+}
+
+const AUDIO_NUDGES = [-40, -10, 10, 40] as const;
+
+export function AudioBox({
+ clipId,
+ audio,
+ busy,
+ write,
+ canListen,
+ onListen,
+}: {
+ clipId: string;
+ audio: ClipAudio | null;
+ busy: boolean;
+ write: Write;
+ canListen: boolean;
+ onListen: () => void;
+}) {
+ const a = audio ?? {};
+ const set = (patch: Record<string, unknown> | null, done: string) => void write({ op: "audio", clip: clipId, audio: patch }, done);
+ const offset = a.offset ?? 0;
+ return (
+ <section id="clip-audio" data-audio-box={clipId} data-audio={JSON.stringify(a)} className={box}>
+ <div className="flex flex-wrap items-baseline gap-2">
+ <h2 className="micro m-0">Audio</h2>
+ <span className="text-muted">applied when the clip is encoded; the player plays the source as it is</span>
+ {audio && (
+ <button type="button" data-audio-clear-all="" disabled={busy} onClick={() => set(null, "The clip's sound is as recorded")} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ Clear all
+ </button>
+ )}
+ </div>
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1.5">
+ <KnobField name="offset" label="sync" unit="ms (+ later)" step={1} value={a.offset} placeholder="0" busy={busy} onSave={(v) => set({ offset: numOrNull(v) }, v ? `Sound moved ${v} ms` : "Sound in sync as recorded")} />
+ {AUDIO_NUDGES.map((d) => (
+ <button key={d} type="button" data-audio-nudge={d} disabled={busy} onMouseDown={(e) => e.preventDefault()} onClick={() => set({ offset: Math.max(-2000, Math.min(2000, offset + d)) }, `Sound moved ${offset + d} ms`)} className={buttonVariants({ variant: "quiet", size: "sm" })}>
+ {d > 0 ? `+${d}` : `−${Math.abs(d)}`}
+ </button>
+ ))}
+ <button type="button" data-audio-listen="" disabled={!canListen} onMouseDown={(e) => e.preventDefault()} onClick={onListen} className={buttonVariants({ size: "sm" })} title="play the 3 s around the playhead">
+ listen
+ </button>
+ <KnobField name="gain" label="gain" unit="dB" step={0.5} value={a.gain} placeholder="0" busy={busy} onSave={(v) => set({ gain: numOrNull(v) }, v ? `Gain ${v} dB` : "Gain as recorded")} />
+ <KnobField name="fadeIn" label="fade in" unit="s" step={0.05} value={a.fadeIn} placeholder="0" busy={busy} onSave={(v) => set({ fadeIn: numOrNull(v) }, v ? `Fades in over ${v} s` : "No fade in")} />
+ <KnobField name="fadeOut" label="fade out" unit="s" step={0.05} value={a.fadeOut} placeholder="0" busy={busy} onSave={(v) => set({ fadeOut: numOrNull(v) }, v ? `Fades out over ${v} s` : "No fade out")} />
+ </div>
+ </section>
+ );
+}