8000 feat(triage): slice a chunk into fixed N-bar intervals by johannboehme · Pull Request #53 · 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
175 changes: 175 additions & 0 deletions frontend/src/components/triage/BarCountLcd.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/**
* Brass-bezel LCD with a click-to-edit integer field and a vertical
* stencil label — the deck-strip's reusable "bar count" instrument.
*
* Same edit pattern as the BpmReadout: click the display to type, Enter
* commits, Escape cancels. Mint-green when "off", phosphor-amber when
* engaged. Originally the MIN-bars filter; now shared by the inspector's
* SLICE control so the whole panel speaks one visual vocabulary.
*
* The LCD palette constants live here as the single source of truth and
* are re-exported for the sibling readouts (KEPT counter, snap LCD).
*/
import { useEffect, useRef, useState } from "react";

export const LCD_BG = `
repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 3px),
repeating-linear-gradient(90deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 3px),
radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,0.06), rgba(0,0,0,0) 60%),
linear-gradient(180deg, #0E1311 0%, #0A0E0C 100%)
`;
export const LCD_SHADOW = [
"inset 0 1px 0 rgba(255,255,255,0.05)",
"inset 0 -1px 0 rgba(0,0,0,0.5)",
"inset 0 0 18px rgba(0,0,0,0.55)",
"0 1px 0 rgba(255,255,255,0.5)",
].join(", ");
export const LCD_GREEN = "#9DEFD0";
export const LCD_AMBER = "#FFB347";
export const GLOW_GREEN =
"0 0 5px rgba(157,239,208,0.4), 0 0 1px rgba(157,239,208,0.8)";
export const GLOW_AMBER =
"0 0 6px rgba(255,179,71,0.55), 0 0 1px rgba(255,179,71,0.9)";

interface BarCountLcdProps {
value: number;
onChange: (n: number) => void;
/** Vertical stencil label, e.g. "MIN" or "BARS". */
label: string;
/** Display formatter. Default: `0 → "OFF"`, `n → "≥n"`. */
format?: (v: number) => string;
/** Whether a value reads as the mint-green "off" state (vs amber
* "engaged"). Default: off when `v === 0`. */
isOff?: (v: number) => boolean;
min?: number;
max?: number;
title?: string;
ariaLabel?: string;
}

export function BarCountLcd({
value,
onChange,
label,
format = (v) => (v === 0 ? "OFF" : `≥${v}`),
isOff = (v) => v === 0,
min = 0,
max = 999,
title,
ariaLabel,
}: BarCountLcdProps) {
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState("");
const inputRef = useRef<HTMLInputElement | null>(null);

useEffect(() => {
if (editing) {
inputRef.current?.focus();
inputRef.current?.select();
}
}, [editing]);

function startEdit() {
setDraft(value > 0 ? String(value) : "");
setEditing(true);
}
function commit() {
const trimmed = draft.trim();
if (trimmed === "") {
onChange(min);
} else {
const n = Math.floor(Number(trimmed));
if (Number.isFinite(n) && n >= min && n <= max) {
onChange(n);
}
}
setEditing(false);
}
function cancel() {
setEditing(false);
}

const off = isOff(value);
const lcdColor = off ? LCD_GREEN : LCD_AMBER;
const lcdGlow = off ? GLOW_GREEN : GLOW_AMBER;
const display = format(value);

const bezel: React.CSSProperties = {
background:
"linear-gradient(180deg, #FAF6EC 0%, #E8E1D0 50%, #C9BFA6 100%)",
boxShadow: [
"inset 0 1px 0 rgba(255,255,255,0.85)",
"inset 0 -1px 0 rgba(0,0,0,0.18)",
"0 1px 2px rgba(0,0,0,0.18)",
].join(", "),
borderRadius: 6,
padding: "5px 6px",
};

const lcdShared: React.CSSProperties = {
height: 28,
background: LCD_BG,
boxShadow: LCD_SHADOW,
color: lcdColor,
textShadow: lcdGlow,
};
const lcdClass = [
"font-mono tabular tracking-[0.05em]",
"text-base px-2 rounded-[3px] w-[68px]",
"border border-black/40",
"inline-flex items-center justify-center leading-none",
].join(" ");

return (
<div
className="inline-flex items-center gap-2 self-center shrink-0"
style={bezel}
>
<span
aria-hidden
className="font-display text-[8px] tracking-[0.18em] text-ink-2 leading-tight uppercase"
style={{
writingMode: "vertical-rl",
transform: "rotate(180deg)",
letterSpacing: "0.18em",
}}
>
{label}
</span>
{editing ? (
<input
ref={inputRef}
type="number"
min={min}
max={max}
step={1}
value={draft}
placeholder={String(min)}
=> setDraft(e.target.value)}
>
=> {
if (e.key === "Enter") commit();
else if (e.key === "Escape") cancel();
}}
className={`${lcdClass} text-right outline-none focus:border-hot`}
style={{
...lcdShared,
paddingTop: 0,
paddingBottom: 0,
}}
/>
) : (
<button
type="button"
>
aria-label={ariaLabel ?? `${label} ${display} — click to change`}
title={title}
className={`${lcdClass} cursor-pointer transition hover:brightness-110`}
style={lcdShared}
>
{display}
</button>
)}
</div>
);
}
61 changes: 61 additions & 0 deletions frontend/src/components/triage/ChunkInspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ import {
} from "../../local/triage/triage-store";
import {
joinFocusedGuarded,
sliceFocusedGuarded,
splitFocusedGuarded,
} from "../../local/triage/triage-guarded-actions";
import { BarCountLcd } from "./BarCountLcd";
import type { Chunk } from "../../storage/jobs-db";

const CONFORM_STATUS_LABEL: Record<string, string> = {
Expand All @@ -63,6 +65,8 @@ export function ChunkInspector() {
const resetBpm = useTriageStore((s) => s.resetBpmToDetected);
const setBeatsPerBar = useTriageStore((s) => s.setBeatsPerBar);
const extendChunkBars = useTriageStore((s) => s.extendChunkBars);
const sliceIntervalBars = useTriageStore((s) => s.sliceIntervalBars);
const setSliceIntervalBars = useTriageStore((s) => s.setSliceIntervalBars);
const resetChunk = useTriageStore((s) => s.resetChunk);
const conformChunk = useTriageStore((s) => s.conformChunk);
const revertConform = useTriageStore((s) => s.revertConform);
Expand Down Expand Up @@ -129,6 +133,9 @@ export function ChunkInspector() {
jobBpmValue={jobBpm?.value ?? null}
beatsPerBar={beatsPerBar}
fwd) => extendChunkBars(focused.id, back, fwd)}
sliceIntervalBars={sliceIntervalBars}
>
=> void sliceFocusedGuarded(sliceIntervalBars)}
=> void splitFocusedGuarded(Math.round(currentTime * 1000))}
=> insertChunkAtPlayhead()}
=> void joinFocusedGuarded("prev")}
Expand Down Expand Up @@ -195,6 +202,9 @@ interface BodyProps {
jobBpmValue: number | null;
beatsPerBar: number;
onExtend: (barsBack: number, barsFwd: number) => void;
sliceIntervalBars: number;
onSliceIntervalChange: (n: number) => void;
onSlice: () => void;
onSplit: () => void;
onCreate: () => void;
onJoinPrev: () => void;
Expand All @@ -215,6 +225,9 @@ function ChunkBody({
jobBpmValue,
beatsPerBar,
onExtend,
sliceIntervalBars,
onSliceIntervalChange,
onSlice,
onSplit,
onCreate,
onJoinPrev,
Expand All @@ -234,6 +247,16 @@ function ChunkBody({
const effBpm = effectiveChunkBpm(chunk, jobBpmValue);
const bars = effBpm > 0 ? (lengthS * effBpm) / 60 / beatsPerBar : 0;
const canExtend = effBpm > 0;
// Slice preview — how many pieces `intervalBars` would carve this chunk
// into (incl. a shorter trailing remainder). Mirrors the count the
// store action produces so the hint never lies.
const msPerBar = effBpm > 0 ? (60_000 / effBpm) * beatsPerBar : 0;
const sliceStepMs = sliceIntervalBars * msPerBar;
const slicePieces =
sliceStepMs > 0 && lengthMs > sliceStepMs
? Math.ceil(lengthMs / sliceStepMs)
: 1;
const canSlice = effBpm > 0 && slicePieces > 1;
const phaseS = chunkBeatPhaseS(chunk);
const phaseDeltaMs = phaseS * 1000 - chunk.startMs;

Expand Down Expand Up @@ -420,6 +443,44 @@ function ChunkBody({
</div>
</Section>

{/* Slice into fixed N-bar intervals in one shot — for a long take
* that's really many repeated phrases. Cuts land on downbeats of
* the chunk's own grid; the remainder stays as a shorter final
* piece. */}
<Section
title="SLICE TO BARS"
right={
canExtend
? `→ ${slicePieces} ${slicePieces === 1 ? "piece" : "pieces"}`
: "needs BPM"
}
>
<div className="flex items-center gap-2">
<BarCountLcd
label="BARS"
value={sliceIntervalBars}
>
min={1}
max={999}
isOff={() => false}
format={(v) => String(v)}
title="Interval length in bars for the slice action"
ariaLabel={`Slice interval ${sliceIntervalBars} bars — click to change`}
/>
<ChunkyButton
variant="secondary"
size="xs"
disabled={!canSlice}
>
title={`Cut this chunk into ${sliceIntervalBars}-bar pieces`}
iconLeft={<ScissorsIcon className="w-3.5 h-3.5" />}
className="flex-1"
>
Cut into {sliceIntervalBars}b
</ChunkyButton>
</div>
</Section>

<Section
title="EDIT"
right={
Expand Down
Loading
Loading
0