Audio Wave: skip overlapping segment labels (readable when splits are close)
Labels crowded when splits are near each other. Now labels are shortened to S{n} and
skipped if within ~26px (canvas) / 30px (image) of the previous drawn label; notes gated
wider. Lines still drawn for every split.
This commit is contained in:
+4
-4
@@ -145,13 +145,13 @@ function setupWave(node) {
|
||||
const { seg } = parseNotes(getW(node, "notes")?.value);
|
||||
ctx.font = "10px monospace";
|
||||
const nseg = nSegs();
|
||||
let lastLabelX = -999, lastNoteX = -999; // skip labels that would overlap
|
||||
pts.forEach((s, i) => { // split line; label seg i+1 (skip tail)
|
||||
const x = t2x(s);
|
||||
ctx.strokeStyle = "#7ec8a0"; ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, H); ctx.stroke();
|
||||
if (i < nseg) {
|
||||
ctx.fillStyle = "#fff"; ctx.fillText(`S${i + 1} ${s.toFixed(1)}s`, x + 3, 11);
|
||||
if (seg[i + 1]) { ctx.fillStyle = "#ffd27a"; ctx.fillText(seg[i + 1].slice(0, 22), x + 3, H - 4); }
|
||||
}
|
||||
if (i >= nseg) return;
|
||||
if (x - lastLabelX > 26) { ctx.fillStyle = "#fff"; ctx.fillText(`S${i + 1}`, x + 2, 11); lastLabelX = x; }
|
||||
if (seg[i + 1] && x - lastNoteX > 60) { ctx.fillStyle = "#ffd27a"; ctx.fillText(seg[i + 1].slice(0, 16), x + 2, H - 4); lastNoteX = x; }
|
||||
});
|
||||
ctx.strokeStyle = "#ff5a3c"; const px = t2x(st.audio.currentTime || 0); // playhead
|
||||
ctx.beginPath(); ctx.moveTo(px, 0); ctx.lineTo(px, H); ctx.stroke();
|
||||
|
||||
Reference in New Issue
Block a user