8000 perf: cut 60 Hz rework from timeline/triage/scope, fix pill auto-persist, dedup helpers by johannboehme · Pull Request #63 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions frontend/src/components/arrange/PlayerCockpit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "../../local/arrange/chunk-mel";
import { PHOSPHOR_LUT } from "../../local/arrange/chunk-mel-render";
import { CamPreviewArrange } from "./CamPreviewArrange";
import { formatTime } from "../../lib/time-format";

// ─── Props (presentational layer) ──────────────────────────────────────

Expand Down Expand Up @@ -640,12 +641,6 @@ function BezelDivider() {

// ─── Helpers ────────────────────────────────────────────────────────────

function formatTime(s: number): string {
if (!Number.isFinite(s) || s < 0) return "0:00";
const m = Math.floor(s / 60);
const sec = Math.floor(s % 60);
return `${m}:${sec.toString().padStart(2, "0")}`;
}

function pad(n: number, width: number): string {
return n.toString().padStart(width, "0");
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/arrange/Polaroid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { Chunk, VideoAsset } from "../../storage/jobs-db";
import { useChunkThumbnail } from "./useChunkThumbnail";
import { useArrangeStore } from "../../local/arrange/arrange-store";
import { renderMelOverlay } from "../../local/arrange/chunk-mel-render";
import { formatTime } from "../../lib/time-format";

/** Image-well column count for the screen-blended mel overlay. The
* well is ~108 px wide on the deployed card; 96 internal columns
Expand Down Expand Up @@ -338,9 +339,3 @@ function UsageDots({ count }: { count: number }) {
);
}

function formatTime(s: number): string {
if (!Number.isFinite(s) || s < 0) return "0:00";
const m = Math.floor(s / 60);
const sec = Math.floor(s % 60);
return `${m}:${sec.toString().padStart(2, "0")}`;
}
6 changes: 1 addition & 5 deletions frontend/src/components/arrange/useArrangeAudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { useArrangeStore } from "../../local/arrange/arrange-store";
import { resolveJobAssetUrl } from "../../local/jobs";

import { clampSeek } from "../../lib/clamp";
const LEAD_TIME_S = 0.05;
const CROSSFADE_S = 0.008;

Expand Down Expand Up @@ -307,11 +308,6 @@ function Driver({
return null;
}

function clampSeek(target: number, duration: number): number {
if (!Number.isFinite(target)) return 0;
if (!Number.isFinite(duration) || duration <= 0) return Math.max(0, target);
return Math.max(0, Math.min(duration, target));
}

function scheduleCrossfade(g: AudioGraph, fromSide: "A" | "B", fireCtxT: number) {
const fromGain = fromSide === "A" ? g.gainA : g.gainB;
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/triage/ChunkInspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from "../../local/triage/triage-guarded-actions";
import { BarCountLcd } from "./BarCountLcd";
import type { Chunk } from "../../storage/jobs-db";
import { formatTime } from "../../lib/time-format";

const CONFORM_STATUS_LABEL: Record<string, string> = {
ok: "✓ conformed",
Expand Down Expand Up @@ -830,9 +831,3 @@ function Sep() {
return <span className="text-ink-3">·</span>;
}

function formatTime(s: number): string {
if (!Number.isFinite(s) || s < 0) return "0:00";
const m = Math.floor(s / 60);
const sec = Math.floor(s % 60);
return `${m}:${sec.toString().padStart(2, "0")}`;
}
7 changes: 1 addition & 6 deletions frontend/src/components/triage/ChunksList.tsx
Original file line number Diff line number Diff line change
E870 Expand Up @@ -19,6 +19,7 @@ import {
} from "../../local/triage/triage-store";
import { buildSequence } from "../../local/triage/triage-sequence";
import type { Chunk } from "../../storage/jobs-db";
import { formatTime } from "../../lib/time-format";

const HOT_COLOR = "#FF5722";
const BRASS_COLOR = "#C9A95A";
Expand Down Expand Up @@ -336,9 +337,3 @@ function SeamStepButton({
);
}

function formatTime(s: number): string {
if (!Number.isFinite(s) || s < 0) return "0:00";
const m = Math.floor(s / 60);
const sec = Math.floor(s % 60);
return `${m}:${sec.toString().padStart(2, "0")}`;
}
4 changes: 1 addition & 3 deletions frontend/src/components/triage/SeamStrip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { buildPeakPyramidAsync } from "../../local/waveform/build-pyramid-async";
import { drawWaveform, TRIAGE_STYLE } from "../../local/waveform/draw-waveform";
import { getCachedPyramid } from "../../local/waveform/pyramid-cache";
import { clamp } from "../../lib/clamp";

const HOT = "#FF5722";
const BRASS = "#C9A95A";
Expand Down Expand Up @@ -534,9 +535,6 @@ function SeamLane({

// ─── Helpers ──────────────────────────────────────────────────────────────

function clamp(v: number, lo: number, hi: number): number {
return Math.max(lo, Math.min(hi, v));
}

interface LaneView {
startS: number;
Expand Down
28 changes: 15 additions & 13 deletions frontend/src/components/triage/TriageTimeline.tsx
O 10BC8 riginal file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* Plus a playhead overlay and zoom/pan affordances.
*/
import { useEffect, useMemo, useRef, useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
import {
chunkBeatPhaseS,
Expand All @@ -35,6 +35,7 @@ import {
getCachedPyramid,
savePyramid,
} from "../../local/waveform/pyramid-cache";
import { formatTime } from "../../lib/time-format";

// Visual hierarchy (top to bottom):
// Time ruler — secondary, MM:SS for absolute reference, faint
Expand Down Expand Up @@ -189,12 +190,19 @@ export function TriageTimeline() {
// eslint-disable-next-line react-hooks/exhaustive-deps -- intentionally only re-pan on focus-id changes
}, [focusedChunkId]);

function timeToX(tS: number): number {
return (tS - viewStartS) * pxPerSec;
}
function xToTime(xPx: number): number {
return viewStartS + xPx / pxPerSec;
}
// Stable identities — both sit in effect dependency arrays (waveform
// redraw, window drag listeners). As plain functions they'd get a fresh
// identity on every render, and this component re-renders on every
// playhead tick (`playback.currentTime` above) — the waveform would
// redraw its full hi-res body 60×/s during playback for nothing.
const timeToX = useCallback(
(tS: number): number => (tS - viewStartS) * pxPerSec,
[viewStartS, pxPerSec],
);
const xToTime = useCallback(
(xPx: number): number => viewStartS + xPx / pxPerSec,
[viewStartS, pxPerSec],
);

function onWheel(e: React.WheelEvent) {
e.preventDefault();
Expand Down Expand Up @@ -1307,9 +1315,3 @@ function niceStep(raw: number): number {
return Math.ceil(raw / 3600) * 3600;
}

function formatTime(s: number): string {
if (!Number.isFinite(s) || s < 0) return "0:00";
const m = Math.floor(s / 60);
const sec = Math.floor(s % 60);
return `${m}:${sec.toString().padStart(2, "0")}`;
}
6 changes: 1 addition & 5 deletions frontend/src/components/triage/useTriageAudio.tsx
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "../../local/triage/triage-sequence";
import { resolveJobAssetUrl } from "../../local/jobs";

import { clampSeek } from "../../lib/clamp";
/** Seconds before the loop wrap point at which the crossfade is
* armed. The idle element is `play()`'d at this point so it's
* running by the time the gain ramp hits. 50 ms is conservative —
Expand Down Expand Up @@ -470,11 +471,6 @@ function Driver({

// ─── Helpers ────────────────────────────────────────────────────────────

function clampSeek(target: number, duration: number): number {
if (!Number.isFinite(target)) return 0;
if (!Number.isFinite(duration) || duration <= 0) return Math.max(0, target);
return Math.max(0, Math.min(duration, target));
}

function scheduleCrossfade(g: AudioGraph, fromSide: "A" | "B", fireCtxT: number) {
const fromGain = fromSide === "A" ? g.gainA : g.gainB;
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/editor/components/FxHardwarePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SidechainScope } from "./SidechainScope";
import { SegmentedControl } from "./SegmentedControl";
import { useIsNarrowViewport } from "../use-is-narrow";

import { clamp } from "../../lib/clamp";
interface PadDef {
slotKey: string;
kind: FxKind;
Expand Down Expand Up @@ -2594,9 +2595,6 @@ function snapDetent(v: number): number {
return v;
}

function clamp(v: number, lo: number, hi: number): number {
return v < lo ? lo : v > hi ? hi : v;
}

// — Constants & styles ————————————————————————————————————

Expand Down
87 changes: 54 additions & 33 deletions frontend/src/editor/components/SidechainScope.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
totalArrDuration,
} from "../arrangement-time";

import { clamp01 } from "../../lib/clamp";
const LCD_GREEN = "#9FE08E";
const RENDER_W = 280; // logical px (SVG viewBox); scales to container
const RENDER_H = 80;
Expand All @@ -41,9 +42,6 @@ const PAD_Y = 5;
/** Fallback window (no arrangement) — ~8 beats so a kick is a clear peak. */
const FALLBACK_BEATS = 8;

function clamp01(v: number): number {
return v < 0 ? 0 : v > 1 ? 1 : v;
}

/**
* Filled area path, PEAK-bucketed per column: each column takes the max
Expand Down Expand Up @@ -155,8 +153,6 @@ export function SidechainScope({ kind }: { kind: FxKind }) {
winStart = timelineT - spanS / 2;
}
const innerW = RENDER_W - 2 * PAD_X;
const toMaster = (arrT: number) =>
arrTotal > 0 ? arrToMaster(arrT, segments) : arrT;
// Sub-samples per column: enough to catch the tallest env sample a column
// spans (so peak HEIGHT isn't under-shown when zoomed out), capped for perf.
const envFps = audioEnv?.fps ?? 120;
Expand All @@ -165,43 +161,68 @@ export function SidechainScope({ kind }: { kind: FxKind }) {
Math.max(4, Math.ceil((spanS / Math.max(1, innerW)) * envFps)),
);

let masterPath = "";
let followerPath = "";
const beatLines: { x: number; down: boolean }[] = [];
if (hasAudio && audioEnv) {
masterPath = peakAreaPath(
(m) => sampleEnv(audioEnv, m),
toMaster,
winStart,
spanS,
RENDER_W,
RENDER_H,
peakSub,
);
if (follower) {
followerPath = peakAreaPath(
(m) => sampleEnv(follower, m),
// The paths + grid depend only on the window and the curves — NOT on the
// playhead. This component re-renders on every timelineT tick (60 Hz
// during playback); without the memo it would re-trace both SVG area
// paths (~columns × sub-samples envelope lookups each, plus arr→master
// projections) per tick just to move the playhead line. In the
// no-arrangement fallback the window is playhead-centred, so `winStart`
// changes per tick and the memo recomputes — same behaviour as before.
const { masterPath, followerPath, beatLines } = useMemo(() => {
const toMaster = (arrT: number) =>
arrTotal > 0 ? arrToMaster(arrT, segments) : arrT;
let masterPath = "";
let followerPath = "";
const beatLines: { x: number; down: boolean }[] = [];
if (hasAudio && audioEnv) {
masterPath = peakAreaPath(
(m) => sampleEnv(audioEnv, m),
toMaster,
winStart,
spanS,
RENDER_W,
RENDER_H,
peakSub,
);
}
if (bpm && bpm > 0 && spanS > 0) {
const period = 60 / bpm;
const firstK = Math.ceil((winStart - beatPhaseS) / period);
for (let k = firstK; ; k++) {
const t = beatPhaseS + k * period;
if (t > winStart + spanS) break;
if (t < winStart) continue;
const x = PAD_X + ((t - winStart) / spanS) * innerW;
const down = ((k % beatsPerBar) + beatsPerBar) % beatsPerBar === 0;
beatLines.push({ x, down });
if (follower) {
followerPath = peakAreaPath(
(m) => sampleEnv(follower, m),
toMaster,
winStart,
spanS,
RENDER_W,
RENDER_H,
peakSub,
);
}
if (bpm && bpm > 0 && spanS > 0) {
const period = 60 / bpm;
const firstK = Math.ceil((winStart - beatPhaseS) / period);
for (let k = firstK; ; k++) {
const t = beatPhaseS + k * period;
if (t > winStart + spanS) break;
if (t < winStart) continue;
const x = PAD_X + ((t - winStart) / spanS) * innerW;
const down = ((k % beatsPerBar) + beatsPerBar) % beatsPerBar === 0;
beatLines.push({ x, down });
}
}
}
}
return { masterPath, followerPath, beatLines };
}, [
hasAudio,
audioEnv,
follower,
arrTotal,
segments,
winStart,
spanS,
peakSub,
bpm,
beatPhaseS,
beatsPerBar,
innerW,
]);

// Playhead at its TRUE position in the window (matches the timeline).
const playheadFrac = spanS > 0 ? (timelineT - winStart) / spanS : -1;
Expand Down
Loading
Oops, something went wrong.
Loading
0