Skip to content

Commit

Permalink
Merge pull request #191 from CPJKU/load_via_musescore-fix
Browse files Browse the repository at this point in the history
fix musescore loading and executable
  • Loading branch information
CarlosCancino-Chacon authored Feb 9, 2023
2 parents a71f607 + 13bbbf8 commit 92eb8ac
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions partitura/io/musescore.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,38 @@ def load_via_musescore(

raise MuseScoreNotFoundException()

with NamedTemporaryFile(suffix=".musicxml") as xml_fh:
xml_fh = os.path.splitext(os.path.basename(filename))[0] + ".musicxml"

cmd = [mscore_exec, "-o", xml_fh.name, filename]
cmd = [mscore_exec, "-o", xml_fh, filename]

try:

ps = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
try:

if ps.returncode != 0:
ps = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)

raise FileImportException(
(
"Command {} failed with code {}. MuseScore "
"error messages:\n {}"
).format(cmd, ps.returncode, ps.stderr.decode("UTF-8"))
)
except FileNotFoundError as f:
if ps.returncode != 0:

raise FileImportException(
'Executing "{}" returned {}.'.format(" ".join(cmd), f)
(
"Command {} failed with code {}. MuseScore "
"error messages:\n {}"
).format(cmd, ps.returncode, ps.stderr.decode("UTF-8"))
)
except FileNotFoundError as f:

return load_musicxml(
filename=xml_fh.name,
validate=validate,
force_note_ids=force_note_ids,
raise FileImportException(
'Executing "{}" returned {}.'.format(" ".join(cmd), f)
)

score = load_musicxml(
filename=xml_fh,
validate=validate,
force_note_ids=force_note_ids,
)

os.remove(xml_fh)

return score


@deprecated_alias(out_fn="out", part="score_data")
def render_musescore(
Expand Down

0 comments on commit 92eb8ac

Please sign in to comment.