Upload 2 files
Browse files
TMIDIX.py
CHANGED
|
@@ -8830,6 +8830,36 @@ ALL_CHORDS_FULL = [[0], [0, 3], [0, 3, 5], [0, 3, 5, 8], [0, 3, 5, 9], [0, 3, 5,
|
|
| 8830 |
[5, 10], [5, 11], [6], [6, 9], [6, 10], [6, 11], [7], [7, 10], [7, 11], [8],
|
| 8831 |
[8, 11], [9], [10], [11]]
|
| 8832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8833 |
###################################################################################
|
| 8834 |
#
|
| 8835 |
# This is the end of the TMIDI X Python module
|
|
|
|
| 8830 |
[5, 10], [5, 11], [6], [6, 9], [6, 10], [6, 11], [7], [7, 10], [7, 11], [8],
|
| 8831 |
[8, 11], [9], [10], [11]]
|
| 8832 |
|
| 8833 |
+
###################################################################################
|
| 8834 |
+
|
| 8835 |
+
def escore_notes_to_parsons_code(escore_notes,
|
| 8836 |
+
times_index=1,
|
| 8837 |
+
pitches_index=4
|
| 8838 |
+
):
|
| 8839 |
+
|
| 8840 |
+
parsons = ""
|
| 8841 |
+
|
| 8842 |
+
prev = ['note', -1, -1, -1, -1, -1, -1]
|
| 8843 |
+
|
| 8844 |
+
for e in escore_notes:
|
| 8845 |
+
if e[times_index] != prev[times_index]:
|
| 8846 |
+
|
| 8847 |
+
if parsons == "":
|
| 8848 |
+
parsons += "*"
|
| 8849 |
+
|
| 8850 |
+
elif e[pitches_index] > prev[pitches_index]:
|
| 8851 |
+
parsons += "U"
|
| 8852 |
+
|
| 8853 |
+
elif e[pitches_index] < prev[pitches_index]:
|
| 8854 |
+
parsons += "D"
|
| 8855 |
+
|
| 8856 |
+
elif e[pitches_index] == prev[pitches_index]:
|
| 8857 |
+
parsons += "R"
|
| 8858 |
+
|
| 8859 |
+
prev = e
|
| 8860 |
+
|
| 8861 |
+
return parsons
|
| 8862 |
+
|
| 8863 |
###################################################################################
|
| 8864 |
#
|
| 8865 |
# This is the end of the TMIDI X Python module
|
TPLOTS.py
CHANGED
|
@@ -1131,6 +1131,129 @@ def downsample_square_matrix(square_matrix, downsampling_factor=4):
|
|
| 1131 |
|
| 1132 |
return dmatrix.tolist()
|
| 1133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1134 |
################################################################################
|
| 1135 |
# [WIP] Future dev functions
|
| 1136 |
################################################################################
|
|
|
|
| 1131 |
|
| 1132 |
return dmatrix.tolist()
|
| 1133 |
|
| 1134 |
+
################################################################################
|
| 1135 |
+
|
| 1136 |
+
def plot_parsons_code(parsons_code,
|
| 1137 |
+
start_pitch=60,
|
| 1138 |
+
return_plot_dict=False,
|
| 1139 |
+
return_plot_string=False,
|
| 1140 |
+
plot_size=(10, 10),
|
| 1141 |
+
labels_size=16,
|
| 1142 |
+
save_plot=''
|
| 1143 |
+
):
|
| 1144 |
+
|
| 1145 |
+
'''
|
| 1146 |
+
Plot parsons code string
|
| 1147 |
+
'''
|
| 1148 |
+
|
| 1149 |
+
if parsons_code[0] != "*":
|
| 1150 |
+
return None
|
| 1151 |
+
|
| 1152 |
+
contour_dict = {}
|
| 1153 |
+
pitch = 0
|
| 1154 |
+
index = 0
|
| 1155 |
+
|
| 1156 |
+
maxp = 0
|
| 1157 |
+
minp = 0
|
| 1158 |
+
|
| 1159 |
+
contour_dict[(pitch, index)] = "*"
|
| 1160 |
+
|
| 1161 |
+
for point in parsons_code:
|
| 1162 |
+
if point == "R":
|
| 1163 |
+
index += 1
|
| 1164 |
+
contour_dict[(pitch, index)] = "-"
|
| 1165 |
+
|
| 1166 |
+
index += 1
|
| 1167 |
+
contour_dict[(pitch, index)] = "*"
|
| 1168 |
+
|
| 1169 |
+
elif point == "U":
|
| 1170 |
+
index += 1
|
| 1171 |
+
pitch -= 1
|
| 1172 |
+
contour_dict[(pitch, index)] = "/"
|
| 1173 |
+
|
| 1174 |
+
index += 1
|
| 1175 |
+
pitch -= 1
|
| 1176 |
+
contour_dict[(pitch, index)] = "*"
|
| 1177 |
+
|
| 1178 |
+
if pitch < maxp:
|
| 1179 |
+
maxp = pitch
|
| 1180 |
+
|
| 1181 |
+
elif point == "D":
|
| 1182 |
+
index += 1
|
| 1183 |
+
pitch += 1
|
| 1184 |
+
contour_dict[(pitch, index)] = "\\"
|
| 1185 |
+
|
| 1186 |
+
index += 1
|
| 1187 |
+
pitch += 1
|
| 1188 |
+
contour_dict[(pitch, index)] = "*"
|
| 1189 |
+
|
| 1190 |
+
if pitch > minp:
|
| 1191 |
+
minp = pitch
|
| 1192 |
+
|
| 1193 |
+
if return_plot_dict:
|
| 1194 |
+
return contour_dict
|
| 1195 |
+
|
| 1196 |
+
if return_plot_string:
|
| 1197 |
+
|
| 1198 |
+
plot_string = ''
|
| 1199 |
+
|
| 1200 |
+
for pitch in range(maxp, minp+1):
|
| 1201 |
+
line = [" " for _ in range(index + 1)]
|
| 1202 |
+
for pos in range(index + 1):
|
| 1203 |
+
if (pitch, pos) in contour_dict:
|
| 1204 |
+
line[pos] = contour_dict[(pitch, pos)]
|
| 1205 |
+
|
| 1206 |
+
plot_string = "".join(line)
|
| 1207 |
+
|
| 1208 |
+
return plot_string
|
| 1209 |
+
|
| 1210 |
+
labels = []
|
| 1211 |
+
pitches = []
|
| 1212 |
+
positions = []
|
| 1213 |
+
cur_pitch = start_pitch
|
| 1214 |
+
pitch_idx = 0
|
| 1215 |
+
|
| 1216 |
+
for k, v in contour_dict.items():
|
| 1217 |
+
|
| 1218 |
+
if v != '*':
|
| 1219 |
+
|
| 1220 |
+
pitches.append(cur_pitch)
|
| 1221 |
+
positions.append(pitch_idx)
|
| 1222 |
+
|
| 1223 |
+
if v == '/':
|
| 1224 |
+
cur_pitch += 1
|
| 1225 |
+
labels.append('U')
|
| 1226 |
+
|
| 1227 |
+
elif v == '\\':
|
| 1228 |
+
cur_pitch -= 1
|
| 1229 |
+
labels.append('D')
|
| 1230 |
+
|
| 1231 |
+
elif v == '-':
|
| 1232 |
+
labels.append('R')
|
| 1233 |
+
|
| 1234 |
+
pitch_idx += 1
|
| 1235 |
+
|
| 1236 |
+
plt.figure(figsize=plot_size)
|
| 1237 |
+
|
| 1238 |
+
|
| 1239 |
+
plt.plot(pitches)
|
| 1240 |
+
|
| 1241 |
+
for i, point in enumerate(zip(positions, pitches)):
|
| 1242 |
+
plt.annotate(labels[i], point, fontsize=labels_size)
|
| 1243 |
+
|
| 1244 |
+
|
| 1245 |
+
plt.title('Parsons Code with Labels', fontsize=labels_size)
|
| 1246 |
+
plt.xlabel('Position', fontsize=labels_size)
|
| 1247 |
+
plt.ylabel('Pitch', fontsize=labels_size)
|
| 1248 |
+
|
| 1249 |
+
if save_plot != '':
|
| 1250 |
+
plt.savefig(save_plot, bbox_inches="tight")
|
| 1251 |
+
plt.close()
|
| 1252 |
+
|
| 1253 |
+
plt.show()
|
| 1254 |
+
|
| 1255 |
+
plt.close()
|
| 1256 |
+
|
| 1257 |
################################################################################
|
| 1258 |
# [WIP] Future dev functions
|
| 1259 |
################################################################################
|