-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdaptChordLabels.py
More file actions
120 lines (100 loc) · 3.26 KB
/
AdaptChordLabels.py
File metadata and controls
120 lines (100 loc) · 3.26 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#############################################################################
# AdaptChordLabels.py
# Tristan Carsault, Jérôme Nika, IRCAM STMS LAB
# copyleft 2018
#############################################################################
#############################################################################
# TODO: Doc
#############################################################################
"""
Adapt chord labels
===================
Tools to adapt chord labels to different alphabets of chord labels (using Mirex notation).
"""
from ChordLabels import *
def getDictChord(alpha):
'''
Fonction def
Parameters
----------
tf_mapping: keras.backend tensor float32
mapping of the costs for the loss function
Returns
-------
loss_function: function
'''
chordList = []
dictChord = {}
for v in gamme.values():
if v != 'N':
for u in alpha.values():
if u != 'N':
chordList.append(v+":"+u)
chordList.append('N')
#print(set(chordList))
listChord = list(set(chordList))
for i in range(len(listChord)):
dictChord[listChord[i]] = i
return dictChord, listChord
#dictA0 = getDictChord(a3)
def reduChord(initChord, alpha= 'a1', transp = 0, key = None):
'''
Fonction def
Parameters
----------
tf_mapping: keras.backend tensor float32
mapping of the costs for the loss function
Returns
-------
loss_function: function
'''
if initChord == "":
print("buuug")
initChord, bass = initChord.split("/") if "/" in initChord else (initChord, "")
root, qual = initChord.split(":") if ":" in initChord else (initChord, "")
root, noChord = root.split("(") if "(" in root else (root, "")
qual, additionalNotes = qual.split("(") if "(" in qual else (qual, "")
root = gamme[root]
for i in range(transp):
print("transpo")
root = tr[root]
if qual == "":
if root == "N" or noChord != "":
finalChord = "N"
else:
finalChord = root + ':maj'
elif root == "N":
finalChord = "N"
else:
if alpha == 'a1':
qual = a1[qual]
elif alpha == 'a0':
qual = a0[qual]
elif alpha == 'a2':
qual = a2[qual]
elif alpha == 'a3':
qual = a3[qual]
elif alpha == 'a5':
qual = a5[qual]
elif alpha == 'reduceWOmodif':
qual = qual
elif alpha == 'a2_1':
if not key is None :
root, qual = functional_tetrad(root, qual, key, base_alpha = a2)
else:
print("WARNING: THE KEY IS MISSING !!! -> CLASSIC ALPHABET A2")
qual = a2[qual]
elif alpha == 'a5_1':
if not key is None :
root, qual = functional_tetrad(root, qual, key, base_alpha = a5)
else:
print("WARNING: THE KEY IS MISSING !!! -> CLASSIC ALPHABET A2")
qual = a5[qual]
else:
print("wrong alphabet value")
qual = qual
if qual == "N":
finalChord = "N"
else:
finalChord = root + ':' + qual
return finalChord