-
Notifications
You must be signed in to change notification settings - Fork 1
/
unprocess.py
executable file
·28 lines (23 loc) · 1 KB
/
unprocess.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
#/usr/bin/python
import sys
with open(sys.argv[1]) as f:
msgss = [a.split('\n') for a in f.read().split('\n\n\n')]
for n, msgs in enumerate(msgss):
with open('test/' + str(n) + '.csv', 'w') as g:
g.write('0, 0, Header, 0, 1, ' + msgs[0] + '\n')
g.write('1, 0, Start_track' + '\n')
g.write('1, 0, Tempo, ' + msgs[1] + '\n')
last = []
current = []
for i, x in enumerate(msgs[2]):
if x == " ":
for note in last:
g.write('1, ' + str(i) + ', Note_off_c, 1, ' + str(note) + ', 96\n')
for note in current:
g.write('1, ' + str(i) + ', Note_on_c, 1, ' + str(note) + ', 96\n')
last = current
current = []
else:
current.append(ord(x) - 33)
g.write('1, ' + str(len(msgs[2])) + ', End_track\n')
g.write('0, 0, End_of_file')