JacobLinCool commited on
Commit
54a8453
·
verified ·
1 Parent(s): e5e54f5

Preview: full-song plan strip

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -201,15 +201,17 @@ def write_tja(gen, bpm, title, course, level, downbeats=None, grid_fit=None):
201
  "", "#START", *lines, "#END"]) + "\n"
202
 
203
 
204
- def render(mel, gen, title, course):
205
  import matplotlib
206
  matplotlib.use("Agg")
207
  import matplotlib.pyplot as plt
208
 
209
  dur = mel.shape[1] / FPS
210
  t0, t1 = dur * 0.33, min(dur * 0.33 + 26, dur)
211
- fig = plt.figure(figsize=(13, 4))
212
- gs = fig.add_gridspec(2, 1, height_ratios=[2.3, 1], hspace=0.1)
 
 
213
  ax0 = fig.add_subplot(gs[0])
214
  ax0.imshow(mel[:, int(t0 * FPS):int(t1 * FPS)], aspect="auto", origin="lower",
215
  cmap="magma", extent=[t0, t1, 0, N_MELS])
@@ -229,8 +231,22 @@ def render(mel, gen, title, course):
229
  ax1.set_xlim(t0, t1)
230
  ax1.set_ylim(-1, 1)
231
  ax1.set_yticks([])
232
- ax1.set_xlabel("time (s)")
233
  ax1.grid(axis="x", alpha=0.25)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  out = tempfile.mktemp(suffix=".png")
235
  fig.savefig(out, dpi=130, bbox_inches="tight")
236
  plt.close(fig)
@@ -303,7 +319,7 @@ def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_pla
303
  tja_path = tempfile.mktemp(suffix=f"_{course}.tja")
304
  with open(tja_path, "w") as f:
305
  f.write(tja)
306
- img = render(mel, g, title, course)
307
  if grid is not None:
308
  grid_info = (f" · grid: rms {grid['rms_ms']:.1f}ms ({grid['inlier_frac']:.0%} inlier)"
309
  + (f" · {grid['n_segments']} tempo segs" if grid.get("piecewise") else "")
 
201
  "", "#START", *lines, "#END"]) + "\n"
202
 
203
 
204
+ def render(mel, gen, title, course, plan=None):
205
  import matplotlib
206
  matplotlib.use("Agg")
207
  import matplotlib.pyplot as plt
208
 
209
  dur = mel.shape[1] / FPS
210
  t0, t1 = dur * 0.33, min(dur * 0.33 + 26, dur)
211
+ fig = plt.figure(figsize=(13, 5.2 if plan else 4))
212
+ gs = fig.add_gridspec(3 if plan else 2, 1,
213
+ height_ratios=[2.3, 1, 0.8] if plan else [2.3, 1],
214
+ hspace=0.16 if plan else 0.1)
215
  ax0 = fig.add_subplot(gs[0])
216
  ax0.imshow(mel[:, int(t0 * FPS):int(t1 * FPS)], aspect="auto", origin="lower",
217
  cmap="magma", extent=[t0, t1, 0, N_MELS])
 
231
  ax1.set_xlim(t0, t1)
232
  ax1.set_ylim(-1, 1)
233
  ax1.set_yticks([])
234
+ ax1.set_xlabel("" if plan else "time (s)")
235
  ax1.grid(axis="x", alpha=0.25)
236
+ if plan:
237
+ # full-song plan strip: what the planner asked for (density envelope,
238
+ # gaps, climax), with the zoomed preview window marked
239
+ ax2 = fig.add_subplot(gs[2])
240
+ for a, b, d, f in plan:
241
+ c = "#d64545" if f == 2 else ("#4a90d9" if f == 1 else "#999999")
242
+ ax2.bar((a + b) / 2, max(d, 0.15), width=(b - a) * 0.92, color=c, alpha=0.85)
243
+ ax2.axvspan(t0, t1, color="#e8b23a", alpha=0.18, lw=0)
244
+ ax2.set_xlim(0, dur)
245
+ ax2.set_ylim(0, 8)
246
+ ax2.set_yticks([0, 4, 8])
247
+ ax2.set_ylabel("plan", fontsize=8)
248
+ ax2.set_xlabel("time (s) — plan: grey=density blue=gap red=climax, "
249
+ "yellow band = preview window above")
250
  out = tempfile.mktemp(suffix=".png")
251
  fig.savefig(out, dpi=130, bbox_inches="tight")
252
  plt.close(fig)
 
319
  tja_path = tempfile.mktemp(suffix=f"_{course}.tja")
320
  with open(tja_path, "w") as f:
321
  f.write(tja)
322
+ img = render(mel, g, title, course, plan=plan)
323
  if grid is not None:
324
  grid_info = (f" · grid: rms {grid['rms_ms']:.1f}ms ({grid['inlier_frac']:.0%} inlier)"
325
  + (f" · {grid['n_segments']} tempo segs" if grid.get("piecewise") else "")