BoxOfColors commited on
Commit
b94a4ba
Β·
1 Parent(s): 41cd582

fix: correct crossfade indicator position on waveform

Browse files

Overlap zone is [seg[i+1].start, seg[i].end] β€” both halves occupy the
same time range, so the hatch must be drawn there (end of seg i), not
at the start of seg i+1. Previously appeared only 'after c' because
overlapStart was used instead of the correct seg[i].end boundary.

Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -1750,11 +1750,16 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1750
  }});
1751
 
1752
  // ── Crossfade overlap indicators ──
 
 
 
 
 
1753
  if (crossfadeSec > 0 && segments.length > 1) {{
1754
  for (let i = 0; i < segments.length - 1; i++) {{
1755
- // Overlap zone: where segment i ends and segment i+1 starts
1756
- const overlapStart = segments[i+1][0];
1757
- const overlapEnd = Math.min(segments[i][1], overlapStart + crossfadeSec);
1758
  const xL = (overlapStart / duration) * W;
1759
  const xR = (overlapEnd / duration) * W;
1760
  // Diagonal hatch pattern over the overlap zone
@@ -1772,12 +1777,14 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1772
  ctx.stroke();
1773
  }}
1774
  ctx.restore();
1775
- // Label
1776
- ctx.fillStyle = 'rgba(255,255,255,0.5)';
1777
- ctx.font = '9px sans-serif';
1778
  const cfW = xR - xL;
1779
- if (cfW > 20) {{
1780
- ctx.fillText('CF', xL + (cfW - ctx.measureText('CF').width) / 2, H - 3);
 
 
1781
  }}
1782
  }}
1783
  }}
 
1750
  }});
1751
 
1752
  // ── Crossfade overlap indicators ──
1753
+ // The overlap region spans [segments[i+1][0], segments[i][1]]:
1754
+ // - last crossfadeSec of seg i fades OUT
1755
+ // - first crossfadeSec of seg i+1 fades IN
1756
+ // Both halves are the same duration (crossfadeSec) and occupy the same
1757
+ // time range, so we draw the hatch centred on the join boundary.
1758
  if (crossfadeSec > 0 && segments.length > 1) {{
1759
  for (let i = 0; i < segments.length - 1; i++) {{
1760
+ // The actual overlap window in time
1761
+ const overlapStart = segments[i+1][0]; // = seg_i.end - crossfadeSec
1762
+ const overlapEnd = segments[i][1]; // = seg_i.end
1763
  const xL = (overlapStart / duration) * W;
1764
  const xR = (overlapEnd / duration) * W;
1765
  // Diagonal hatch pattern over the overlap zone
 
1777
  ctx.stroke();
1778
  }}
1779
  ctx.restore();
1780
+ // Label β€” centred on the join boundary line, straddling both segments
1781
+ ctx.fillStyle = 'rgba(255,255,255,0.6)';
1782
+ ctx.font = 'bold 9px sans-serif';
1783
  const cfW = xR - xL;
1784
+ const label = '\u21C4 CF'; // ⇄ CF
1785
+ const lw = ctx.measureText(label).width;
1786
+ if (cfW > lw + 4) {{
1787
+ ctx.fillText(label, xL + (cfW - lw) / 2, H - 3);
1788
  }}
1789
  }}
1790
  }}