From badf12b9912bce03257d6eb1db3935b64676b7f0 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Thu, 1 Oct 2026 10:19:10 +0200 Subject: [PATCH] Improved progress status section layout --- CLAUDE.md | 2 +- backend/konduktor/jobs.py | 19 +++++- backend/konduktor/schemas.py | 3 + backend/konduktor/stems/convert.py | 38 ++++++++--- backend/test_grid_batch.py | 18 +++++ backend/test_stems_batch.py | 2 +- frontend/src/App.tsx | 2 + frontend/src/api.ts | 5 ++ frontend/src/components/StatusBar.tsx | 97 +++++++++++++++++++++------ 9 files changed, 154 insertions(+), 32 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index d7f69e6..891e9db 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -628,7 +628,7 @@ Two independent apps that talk over HTTP: platform cannot play stem files as stems. SaveBar adds "Saving deletes N original files" while conversions are pending (decided: the consequence is shown where Save is pressed). `Toast` takes an optional `action`; - `StatusJob.unit: 'bytes'` shows a download in MB. + `StatusJob.unit: 'bytes'` shows a download in MB. Every background job's status-bar entry reads label + count · a bar SPLIT horizontally when the job reports per-item progress (top = the current item's `fraction`, 0-100 %; bottom = the whole job, (done + fraction) / total, so 99 % into the first of two tracks reads ~50 %) — a single bar otherwise; two colours in one bar was tried and read as confusing · its `status` ("separating 41 %") at its natural width · the item's name LAST (the only part that truncates; full name on hover). The section is a FIXED width (560 px; the view name on the left gives way instead) and everything BEFORE the bar is fixed (count sized for its largest value, "cancelling…" as a status, not a label), so neither a long name nor a phase change moves the bar. The status deliberately has no fixed slot: it is after the bar, and a slot left a gap before the name. `Job.fraction`/`status` come from `JobHandle.progress(fraction=, status=)` and reset whenever `done` advances; a stem conversion maps decode / separate / encode onto a track's 0-1 by measured shares. `AutoCueDialog` (the Auto Hotcues slot template: event + beat offset per slot, a per-slot Replace tick for occupied slots — never remembered, since overwriting is a decision about THIS track — and the template itself diff --git a/backend/konduktor/jobs.py b/backend/konduktor/jobs.py index 94937e6..5dca800 100644 --- a/backend/konduktor/jobs.py +++ b/backend/konduktor/jobs.py @@ -53,6 +53,13 @@ class Job: #: library is written — so the UI can word them. Empty = unspecified. unit: str = "" message: str = "" + #: How far the CURRENT unit of work has got, 0..1 — so the overall bar can + #: move within a long item: at 99 % of the first of two tracks it reads + #: ~50 %, not 0. Reset whenever `done` advances. + fraction: float = 0.0 + #: What the current item is doing ("separating 41 %"), shown beside its name + #: and never truncated in its place. Reset whenever `done` advances. + status: str = "" result: Any = None error: str | None = None started_at: float = field(default_factory=time.time) @@ -75,6 +82,8 @@ class Job: "done": self.done, "unit": self.unit, "message": self.message, + "fraction": self.fraction, + "status": self.status, "result": self.result, "error": self.error, "started_at": self.started_at, @@ -94,11 +103,19 @@ class JobHandle: self._job = job def progress(self, done: int | None = None, total: int | None = None, - message: str | None = None, unit: str | None = None) -> None: + message: str | None = None, unit: str | None = None, + fraction: float | None = None, status: str | None = None) -> None: if unit is not None: self._job.unit = unit if done is not None: + if done != self._job.done: # a new item: its progress starts over + self._job.fraction = 0.0 + self._job.status = "" self._job.done = done + if fraction is not None: + self._job.fraction = max(0.0, min(1.0, fraction)) + if status is not None: + self._job.status = status if total is not None: self._job.total = total if message is not None: diff --git a/backend/konduktor/schemas.py b/backend/konduktor/schemas.py index f08fec5..a3151fb 100644 --- a/backend/konduktor/schemas.py +++ b/backend/konduktor/schemas.py @@ -489,6 +489,9 @@ class JobStatus(BaseModel): # needs to tell a byte count from a track count. unit: str = "" message: str + # The current item's own progress (0..1) and what it is doing — see jobs.Job. + fraction: float = 0.0 + status: str = "" result: dict | None = None error: str | None = None started_at: float diff --git a/backend/konduktor/stems/convert.py b/backend/konduktor/stems/convert.py index 040545a..b08d4ae 100644 --- a/backend/konduktor/stems/convert.py +++ b/backend/konduktor/stems/convert.py @@ -39,6 +39,13 @@ _BYTES_PER_SECOND = {256_000: 5 * 256_000 / 8 * 1.03, 320_000: 5 * 320_000 / 8 * _WORK_BYTES_PER_SECOND = 5 * 2 * 4 * sf.SR +#: Shares of ONE track's conversion time, for the status bar's within-track +#: progress (measured on the M3 Pro: decode ~1 s, separate ~50 s, encode + +#: verify ~4 s for a 4-minute track). +_DECODE_SHARE = 0.03 +_SEPARATE_SHARE = 0.90 + + class ConvertError(Exception): """User-facing; refuses the whole batch.""" @@ -87,10 +94,13 @@ class Plan: def _title(track) -> str: + """How a track is named in progress, skip lists and reports: the track's + name FIRST — it is what tells one track from another when the end is cut + off in the status bar.""" if track is None: return "?" if track.artist and track.title: - return f"{track.artist} - {track.title}" + return f"{track.title} - {track.artist}" return track.title or Path(track.filepath or "").name or track.id @@ -229,7 +239,7 @@ def run(handle, adapter, planned: Plan, opts: Options, pending: Pending, *, try: for i, item in enumerate(items): checkpoint() - handle.progress(done=i, message=item.title) + handle.progress(done=i, message=item.title, fraction=0.0, status="") partial = partial_name(item.target) if item.reuse is not None: written = sf.Written(path=partial, **{k: item.reuse["written"][k] for k in ("bit_rate", "duration", "size")}, @@ -241,21 +251,29 @@ def run(handle, adapter, planned: Plan, opts: Options, pending: Pending, *, finished.append((item, pitem, written)) continue if engine is None: - handle.progress(message="Starting the stem engine…") + handle.progress(status="starting…") engine = stack.enter_context(EngineProcess(mgr.executable(), mgr.weights_dir(), device=opts.device)) stack.enter_context(keep_awake(engine.proc.pid)) pitem = pending.add({"track_id": item.track_id, "mode": opts.collection, "source": str(item.source), "stem": str(item.target), "state": "converting", "facts": source_facts(item.source)}) item.target.parent.mkdir(parents=True, exist_ok=True) - def on_progress(f: float, i=i, item=item) -> None: - handle.progress(message=f"{item.title} — separating {f * 100:.0f} %") + # Of a TRACK's time, separation is nearly all (~90 % on MPS); + # decoding before it and encoding + verifying after share the rest. + def on_progress(f: float) -> None: + frac = _DECODE_SHARE + f * (_SEPARATE_SHARE) + handle.progress(fraction=frac, status=f"separating {frac * 100:.0f} %") + def separate(pcm): + handle.progress(fraction=_DECODE_SHARE, status=f"separating {_DECODE_SHARE * 100:.0f} %") + stems = engine.separate(pcm, work, on_progress=on_progress, cancelled=lambda: handle.cancelled) + done_at = _DECODE_SHARE + _SEPARATE_SHARE + handle.progress(fraction=done_at, status=f"encoding {done_at * 100:.0f} %") + return stems + + handle.progress(status="decoding 0 %") try: - written = sf.build(item.source, partial, - lambda pcm: engine.separate(pcm, work, on_progress=on_progress, - cancelled=lambda: handle.cancelled), - checkpoint=checkpoint) + written = sf.build(item.source, partial, separate, checkpoint=checkpoint) except (_Cancel, EngineCancelled): partial.unlink(missing_ok=True) pending.drop([pitem]) @@ -281,7 +299,7 @@ def run(handle, adapter, planned: Plan, opts: Options, pending: Pending, *, finally: shutil.rmtree(work, ignore_errors=True) - handle.progress(done=len(items), message="Swapping the converted tracks into the collection…") + handle.progress(done=len(items), message="Swapping the converted tracks into the collection…", status="") with mutation: if not still_current(): for _item, pitem, written in finished: diff --git a/backend/test_grid_batch.py b/backend/test_grid_batch.py index 0362ad5..f7ccee5 100644 --- a/backend/test_grid_batch.py +++ b/backend/test_grid_batch.py @@ -213,6 +213,24 @@ with tempfile.TemporaryDirectory() as d: gate.set() check("…and returns once it has finished", main.JOBS.wait(first.id, timeout=5) is True) + # Within-item progress: what lets the overall bar move inside a long + # track (99 % of the first of two = ~50 %), and it starts over per item. + from konduktor.jobs import Job, JobHandle + j = Job(id="x", kind="t") + h = JobHandle(j) + h.progress(done=0, total=2, fraction=0.99, status="separating 99 %") + d = j.as_dict() + check("a job reports its current item's fraction and status", + d["fraction"] == 0.99 and d["status"] == "separating 99 %", str(d)) + h.progress(done=1) + check("…both reset when the next item starts", j.fraction == 0.0 and j.status == "") + h.progress(fraction=1.7) + check("…and the fraction is clamped to 0..1", j.fraction == 1.0) + from konduktor.schemas import JobStatus + r = JobStatus(**j.as_dict()).model_dump() + check("the job's response model carries fraction and status (not silently dropped)", + r["fraction"] == 1.0 and "status" in r, str(r)[:200]) + check("nothing was written to disk (edits stay in memory until Save)", work.read_bytes() == REAL.read_bytes()) diff --git a/backend/test_stems_batch.py b/backend/test_stems_batch.py index 1d8c5bc..4e477e9 100644 --- a/backend/test_stems_batch.py +++ b/backend/test_stems_batch.py @@ -202,7 +202,7 @@ with TestClient(main.app) as c: os.environ["FAKE_DELAY"] = "0.15" jid = c.post("/api/tracks/stems/convert", json={"track_ids": ids, "mode": "replace"}).json()["id"] end = time.time() + 30 - while time.time() < end and "separating" not in c.get(f"/api/jobs/{jid}").json()["message"]: + while time.time() < end and "separating" not in c.get(f"/api/jobs/{jid}").json()["status"]: time.sleep(0.05) time.sleep(1.8) # into the second track c.post(f"/api/jobs/{jid}/cancel") diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ffc07ea..4e60c24 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1461,6 +1461,8 @@ export default function App() { done: batchJobStatus.data?.done ?? 0, total: batchJobStatus.data?.total ?? 0, detail: batchJobStatus.data?.message, + fraction: batchJobStatus.data?.fraction, + status: batchJobStatus.data?.status, cancelling: batchCancelling, onCancel: () => { setBatchCancelling(true) diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 0f595fd..1882f3d 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -411,6 +411,11 @@ export interface JobStatus { * is written; '' when unspecified. */ unit: string message: string + /** The CURRENT item's own progress, 0..1 — so the overall bar moves within + * a long item. Resets as each item starts. */ + fraction: number + /** What the current item is doing, e.g. "separating 41 %". */ + status: string result: Record | null error: string | null started_at: number diff --git a/frontend/src/components/StatusBar.tsx b/frontend/src/components/StatusBar.tsx index 307bcd4..262b55c 100644 --- a/frontend/src/components/StatusBar.tsx +++ b/frontend/src/components/StatusBar.tsx @@ -5,8 +5,14 @@ export interface StatusJob { done: number /** 0 until the job knows its size → indeterminate bar. */ total: number - /** What it is working on right now, e.g. the current track's title. */ + /** What it is working on right now, e.g. the current track's title. This is + * the one part that shortens when space runs out. */ detail?: string + /** How far the current item has got, 0..1: the TOP half of a split bar (the + * bottom half is the whole job, which moves within an item too). */ + fraction?: number + /** What the current item is doing ("separating 41 %") — never truncated. */ + status?: string cancelling?: boolean onCancel: () => void /** `bytes`: done/total are byte counts (a download), shown in MB. */ @@ -37,12 +43,16 @@ export function StatusBar({ }: Props) { return (
- {sourceName} + {/* The view's name gives way on a narrow window — the job section on the + right is a fixed width and does not. */} + + {sourceName} + · {loading ? ( Loading… ) : ( - + {showing === total ? ( <>{total.toLocaleString()} tracks ) : ( @@ -55,27 +65,76 @@ export function StatusBar({ {selected > 0 && ( <> · - {selected.toLocaleString()} selected + {selected.toLocaleString()} selected )} {job && ( -
- - {job.cancelling ? 'Cancelling…' : job.label} - {job.total > 0 && - (job.unit === 'bytes' - ? ` ${Math.round(job.done / 1e6)}/${Math.round(job.total / 1e6)} MB` - : ` ${Math.min(job.done + 1, job.total)}/${job.total}`)} - - + // FIXED positions: the section is a fixed width, and everything before + // the name has a fixed width too (the count sized for its largest value, + // the status a fixed slot), so neither a long track name nor + // "decoding" → "separating" can move the bar. The name fills what is + // left and is the only thing that shortens. +
+ {job.label} + {job.total > 1 && job.unit !== 'bytes' && ( 0 ? '' : 'w-1/3 animate-pulse' - }`} - style={job.total > 0 ? { width: `${(job.done / job.total) * 100}%` } : undefined} - /> + className="-ml-1 shrink-0 text-left tabular-nums text-text" + style={{ minWidth: `${2 * String(job.total).length + 1}ch` }} + > + {Math.min(job.done + 1, job.total)}/{job.total} + + )} + {/* One bar, split horizontally when the job reports per-item progress + (a stem conversion): TOP = the current item, 0-100 % across the + full width; BOTTOM = the whole job, (done + fraction) / total, so + it moves within a long item too. Other jobs: one full-height bar. */} + {(() => { + const fill = + 'absolute inset-y-0 left-0 rounded-full bg-gradient-to-r from-[var(--amb-1)] to-accent shadow-[0_0_6px_var(--color-accent)] transition-[width] duration-300' + const pct = (v: number) => `${Math.max(0, Math.min(1, v)) * 100}%` + if (job.total <= 0) { + return ( + + + + ) + } + const overall = (job.done + (job.unit === 'bytes' ? 0 : job.fraction ?? 0)) / job.total + if (job.unit === 'bytes' || !job.status) { + return ( + + + + ) + } + return ( + + + + + + + + + ) + })()} + {/* Status at its natural width: it sits AFTER the bar, so it cannot + move it — and a fixed slot left a gap before the name. */} + {(job.cancelling || job.status || (job.unit === 'bytes' && job.total > 0)) && ( + <> + + {job.cancelling + ? 'cancelling…' + : job.unit === 'bytes' + ? `${Math.round(job.done / 1e6)} / ${Math.round(job.total / 1e6)} MB` + : job.status} + + {job.detail && ·} + + )} + + {job.detail} - {job.detail && {job.detail}}