-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-output-expand.py
88 lines (64 loc) · 2.17 KB
/
custom-output-expand.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from chorale import Chorale
from copy import deepcopy
import sys
choraleManager = Chorale()
file = sys.argv[1]
[headers, lines] = choraleManager.readchorale('custom/music/' + file)
lines.append(Chorale.AFTER)
if 'dur' in headers[2]:
hiddensymbols = open("model-chords-moll/SYMBOLS_HIDDEN").readlines()
else:
hiddensymbols = open("model-chords-dur/SYMBOLS_HIDDEN").readlines()
linesC = []
ofile = open("custom/viterbi/" + file)
output = []
for line in ofile.readlines():
if line != "\n":
output.append(line.split(" ")[0])
ofile.close()
if (len(output) - 1) != int((len(lines) / 4)):
if (len(output) - 1) - int((len(lines) / 4)):
print("Ignoring last: " + str(int(len(output) - (len(lines) / 4))) + " rows")
else:
print("Line count doesn't match")
exit(1)
lines.pop()
cont = 0
for i in range(0, len(lines)):
row = deepcopy(lines[i][0:3])
row.append('')
row.append('')
row.append('')
row.append('')
row.append('')
row.append('')
if row[2][0] != '-' and row[2] != '':
if i % 4 == 0:
row[6] = hiddensymbols[int(output[cont])].split("/")[0]
intervals = row[6].split(":")
soprano = choraleManager.notepitch(row[2])
intervals[0] = intervals[0].lstrip("-")
for j in range(3, 6):
if not intervals[j - 2].lstrip("-").isdigit():
row[j] = intervals[j - 2]
else:
prefix = ""
if "-" in intervals[j - 2]:
prefix = "-"
intervals[j - 2] = intervals[j - 2].replace("-", "")
row[j] = prefix + choraleManager.notesymbol(soprano - (int(intervals[0]) - int(intervals[j - 2])))
else:
row[0] = ''
row[1] = ''
cont += 1
else:
row[0] = ''
row[1] = ''
row[2] = ''
lines[i] = deepcopy(row)
f = open('custom/viterbi-results/' + file, 'w+')
choraleManager.writeheaders(f, headers[0], headers[1], headers[2], headers[3], headers[4], headers[5])
f.write("\n")
for line in lines:
f.write("\t".join(line).replace("_", " ") + "\n")
f.close()