pachet commited on
Commit
e0949bf
·
1 Parent(s): 964781b

Fallback to Python Verovio for generated scores

Browse files
Files changed (1) hide show
  1. apps/theme_lab/app.py +3 -3
apps/theme_lab/app.py CHANGED
@@ -379,7 +379,7 @@ def render_musicxml_with_python_verovio(musicxml_path: Path, svg_path: Path) ->
379
 
380
  toolkit = verovio.toolkit()
381
  toolkit.setOptions({"scale": 42})
382
- if not toolkit.loadFile(str(musicxml_path)):
383
  return None
384
  svg_path.write_text(toolkit.renderToSVG(1), encoding="utf-8")
385
  except Exception:
@@ -403,8 +403,8 @@ def render_musicxml_to_svg(musicxml_path: Path) -> Path | None:
403
  timeout=20,
404
  )
405
  except (subprocess.SubprocessError, OSError):
406
- return None
407
- return svg_path if svg_path.exists() else None
408
 
409
 
410
  def markov_cache_key(request: GenerateRequest) -> tuple[object, ...]:
 
379
 
380
  toolkit = verovio.toolkit()
381
  toolkit.setOptions({"scale": 42})
382
+ if not toolkit.loadFile(str(musicxml_path)) and not toolkit.loadData(musicxml_path.read_text(encoding="utf-8")):
383
  return None
384
  svg_path.write_text(toolkit.renderToSVG(1), encoding="utf-8")
385
  except Exception:
 
403
  timeout=20,
404
  )
405
  except (subprocess.SubprocessError, OSError):
406
+ return render_musicxml_with_python_verovio(musicxml_path, svg_path)
407
+ return svg_path if svg_path.exists() else render_musicxml_with_python_verovio(musicxml_path, svg_path)
408
 
409
 
410
  def markov_cache_key(request: GenerateRequest) -> tuple[object, ...]: