dottes/render_and_play.py

31 lines
899 B
Python

import os
import pathlib
import subprocess
import sys
win_root = pathlib.Path(r"C:\Users\louis\GitKraken\dottes")
lin_root = pathlib.Path("~/dottes")
try:
win_abc_file_path = pathlib.Path(sys.argv[1])
except IndexError:
win_abc_file_path = pathlib.Path(input())
if not str(win_abc_file_path).lower().endswith(".abc"):
input("Doesn't look like an abc file.")
exit(1)
lin_abc_file_path = lin_root / win_abc_file_path.relative_to(win_root)
out_file_name = lin_abc_file_path.name.rsplit(".", 1)[0] + ".mid"
lin_output_path = lin_abc_file_path.parent / out_file_name
win_output_path = win_abc_file_path.parent / out_file_name
if win_output_path.exists():
win_output_path.unlink()
command = f"abc2midi {lin_abc_file_path.as_posix()} -o {lin_output_path.as_posix()}"
print("Command:", command)
r = subprocess.run([r"wsl"], input=command.encode())
os.system(str(win_output_path))