pachet commited on
Commit
8e39f2b
·
1 Parent(s): c7a864a

Use Verovio renderData for score SVGs

Browse files
Files changed (1) hide show
  1. apps/theme_lab/app.py +9 -5
apps/theme_lab/app.py CHANGED
@@ -386,14 +386,18 @@ def render_musicxml_with_python_verovio(musicxml_path: Path, svg_path: Path) ->
386
  try:
387
  import verovio
388
 
 
389
  toolkit = verovio.toolkit()
390
  toolkit.setOptions({"scale": 42})
391
- loaded = toolkit.loadFile(str(musicxml_path))
392
- if not loaded and hasattr(toolkit, "loadData"):
393
- loaded = toolkit.loadData(musicxml_path.read_text(encoding="utf-8"))
394
- if not loaded:
 
 
 
395
  return None
396
- svg_path.write_text(toolkit.renderToSVG(1), encoding="utf-8")
397
  except Exception:
398
  return None
399
  return svg_path if svg_path.exists() else None
 
386
  try:
387
  import verovio
388
 
389
+ musicxml_data = musicxml_path.read_text(encoding="utf-8")
390
  toolkit = verovio.toolkit()
391
  toolkit.setOptions({"scale": 42})
392
+ svg = toolkit.renderData(musicxml_data, {}) if hasattr(toolkit, "renderData") else ""
393
+ if not svg:
394
+ loaded = toolkit.loadData(musicxml_data) if hasattr(toolkit, "loadData") else toolkit.loadFile(str(musicxml_path))
395
+ if not loaded:
396
+ return None
397
+ svg = toolkit.renderToSVG(1)
398
+ if "<svg" not in svg:
399
  return None
400
+ svg_path.write_text(svg, encoding="utf-8")
401
  except Exception:
402
  return None
403
  return svg_path if svg_path.exists() else None