Improved progress status section layout

This commit is contained in:
patben8 committed 2026-10-01 10:55:09 +02:00
1 parent ecc0e4c8df
commit badf12b991
9 files changed
+154 -32

No files matched your search

+1 -1
View File
@@ -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
+18 -1
View File
@@ -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:
+3
View File
@@ -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
+28 -10
View File
@@ -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:
+18
View File
@@ -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())
+1 -1
View File
@@ -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")
+2
View File
@@ -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)
+5
View File
@@ -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<string, unknown> | null
error: string | null
started_at: number
+78 -19
View File
@@ -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 (
<div className="glass flex h-7 shrink-0 items-center gap-3 !rounded-full px-4 text-[11px] text-muted">
<span className="font-medium text-text">{sourceName}</span>
{/* The view's name gives way on a narrow window — the job section on the
right is a fixed width and does not. */}
<span className="min-w-0 truncate font-medium text-text" title={sourceName}>
{sourceName}
</span>
<span className="text-faint">·</span>
{loading ? (
<span>Loading…</span>
) : (
<span className="tabular-nums">
<span className="shrink-0 tabular-nums">
{showing === total ? (
<>{total.toLocaleString()} tracks</>
) : (
@@ -55,27 +65,76 @@ export function StatusBar({
{selected > 0 && (
<>
<span className="text-faint">·</span>
<span className="tabular-nums text-accent">{selected.toLocaleString()} selected</span>
<span className="shrink-0 tabular-nums text-accent">{selected.toLocaleString()} selected</span>
</>
)}
{job && (
<div className="ml-auto flex min-w-0 items-center gap-2">
<span className="shrink-0 tabular-nums text-text">
{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}`)}
</span>
<span className="well h-1.5 w-32 shrink-0 overflow-hidden rounded-full">
// 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.
<div className="ml-auto flex w-[560px] shrink-0 items-center gap-2">
<span className="shrink-0 text-text">{job.label}</span>
{job.total > 1 && job.unit !== 'bytes' && (
<span
className={`block h-full rounded-full bg-gradient-to-r from-[var(--amb-1)] to-accent shadow-[0_0_8px_var(--color-accent)] transition-[width] duration-300 ${
job.total > 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}
</span>
)}
{/* 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 (
<span className="well h-2 w-32 shrink-0 overflow-hidden rounded-full">
<span className="block h-full w-1/3 animate-pulse rounded-full bg-accent" />
</span>
)
}
const overall = (job.done + (job.unit === 'bytes' ? 0 : job.fraction ?? 0)) / job.total
if (job.unit === 'bytes' || !job.status) {
return (
<span className="well relative h-2 w-32 shrink-0 overflow-hidden rounded-full">
<span className={fill} style={{ width: pct(overall) }} />
</span>
)
}
return (
<span className="flex h-3.5 w-32 shrink-0 flex-col gap-[2px]" title="Top: this track · bottom: overall">
<span className="well relative flex-1 overflow-hidden rounded-full">
<span className={fill} style={{ width: pct(job.fraction ?? 0) }} />
</span>
<span className="well relative flex-1 overflow-hidden rounded-full">
<span className={fill} style={{ width: pct(overall) }} />
</span>
</span>
)
})()}
{/* 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)) && (
<>
<span className="shrink-0 tabular-nums text-muted">
{job.cancelling
? 'cancelling…'
: job.unit === 'bytes'
? `${Math.round(job.done / 1e6)} / ${Math.round(job.total / 1e6)} MB`
: job.status}
</span>
{job.detail && <span className="shrink-0 text-faint">·</span>}
</>
)}
<span className="min-w-0 flex-1 truncate text-faint" title={job.detail}>
{job.detail}
</span>
{job.detail && <span className="max-w-[240px] truncate text-faint">{job.detail}</span>}
<button
onClick={job.onCancel}
disabled={job.cancelling}