-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathConvert_MidiABC.py
39 lines (37 loc) · 1.03 KB
/
Convert_MidiABC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import subprocess
import sys
import os
def midi2abc(filename):
version = sys.platform
if (version == "win32"):
string = "midi2abc.exe " + filename + " -o tt.txt"
os.system(string)
file = open("tt.txt","r")
result = file.read()
file.close()
os.remove("tt.txt")
else:
result = subprocess.check_output(["midi2abc",filename])
return result
def abc2midi(filename):
version = sys.platform
if (os.path.isfile("count.txt")== False):
file = open("count.txt","w")
file.write("output0.mid")
file.close()
file = open("count.txt","r")
cnt = file.read()
cnt = cnt[6:-4]
cnt = int(cnt)
cnt = cnt+1
cnt = str(cnt)
file.close()
file = open("count.txt","w")
string = "output"+cnt+".mid"
file.write(string)
file.close()
if (version == "win32"):
string = "abc2midi.exe " + filename + " -o output" + cnt + ".mid"
else:
string = "abc2midi " + filename + " -o output"+cnt+".mid"
os.system(string)