-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.py
31 lines (28 loc) · 1.06 KB
/
process.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
import os
import subprocess
folder = 'rag'
midis = os.listdir(folder)
training = open('training', 'w')
# for midi in ['mapleaf2.mid']:
for midi in midis:
data = [x.split(', ') for x in subprocess.run(['midicsv', folder + '/' + midi], stdout=subprocess.PIPE).stdout.decode(errors='ignore').split('\n')]
# print(data[0])
out = ""
for entry in data:
if entry[2] == 'Header':
out += entry[5] + '\n'
elif entry[2] == 'Tempo':
out += entry[3] + '\n'
break
notes = ['' for x in range(int(data[-3][1]))]
for entry in data:
if entry[2] == 'End_of_file':
break
elif entry[2] == 'Note_on_c' and entry[5] != '0':
notes[int(entry[1])] += chr(33+int(entry[4]))
# current += chr(33+int(entry[4]))
# elif entry[2] == 'Note_off_c' or (len(entry) > 5 and entry[2] == 'Note_on_c' and entry[5] == '0'):
# current = current.replace(chr(33+int(entry[4])), '')
# out += current + " "
out += " ".join(notes)
training.write(out + '\n\n\n')