projectlosangeles
commited on
Commit
•
3e3cb7a
1
Parent(s):
0c995cd
Upload 9 files
Browse files
Los_Angeles_MIDI_Dataset_Maker.ipynb
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
-
"# Los Angeles MIDI Dataset Maker (ver.
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
@@ -76,7 +76,7 @@
|
|
76 |
"source": [
|
77 |
"#@title Import all needed modules\n",
|
78 |
"\n",
|
79 |
-
"print('Loading
|
80 |
"import os\n",
|
81 |
"\n",
|
82 |
"import math\n",
|
@@ -84,15 +84,23 @@
|
|
84 |
"import random\n",
|
85 |
"from collections import Counter\n",
|
86 |
"import shutil\n",
|
87 |
-
"import
|
88 |
"from tqdm import tqdm\n",
|
89 |
"\n",
|
|
|
|
|
90 |
"if not os.path.exists('/content/Dataset'):\n",
|
91 |
" os.makedirs('/content/Dataset')\n",
|
92 |
"\n",
|
93 |
"if not os.path.exists('/content/Output'):\n",
|
94 |
" os.makedirs('/content/Output')\n",
|
95 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
"print('Loading TMIDIX module...')\n",
|
97 |
"os.chdir('/content/tegridy-tools/tegridy-tools')\n",
|
98 |
"\n",
|
@@ -204,12 +212,6 @@
|
|
204 |
},
|
205 |
{
|
206 |
"cell_type": "code",
|
207 |
-
"execution_count": null,
|
208 |
-
"metadata": {
|
209 |
-
"id": "CeGo7CruaCJQ",
|
210 |
-
"cellView": "form"
|
211 |
-
},
|
212 |
-
"outputs": [],
|
213 |
"source": [
|
214 |
"#@title Process MIDIs with TMIDIX MIDI processor\n",
|
215 |
"\n",
|
@@ -229,12 +231,10 @@
|
|
229 |
"\n",
|
230 |
"melody_chords_f = []\n",
|
231 |
"\n",
|
232 |
-
"
|
233 |
-
"
|
234 |
-
"\n",
|
235 |
-
"
|
236 |
-
"\n",
|
237 |
-
"stats = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
|
238 |
"\n",
|
239 |
"print('Processing MIDI files. Please wait...')\n",
|
240 |
"print('=' * 70)\n",
|
@@ -244,85 +244,86 @@
|
|
244 |
" input_files_count += 1\n",
|
245 |
"\n",
|
246 |
" fn = os.path.basename(f)\n",
|
247 |
-
"
|
|
|
|
|
248 |
"\n",
|
249 |
-
"
|
250 |
-
"
|
|
|
251 |
"\n",
|
252 |
-
"
|
253 |
-
" score = TMIDIX.midi2ms_score(open(f, 'rb').read())\n",
|
254 |
"\n",
|
255 |
-
"
|
256 |
-
"
|
257 |
-
"
|
258 |
-
"
|
259 |
-
"
|
260 |
-
"
|
261 |
-
"
|
262 |
-
"
|
263 |
-
"
|
264 |
-
"
|
265 |
-
"
|
266 |
-
"
|
267 |
-
"
|
268 |
-
"
|
269 |
-
"
|
270 |
"\n",
|
271 |
" events_matrix.sort(key=lambda x: x[1])\n",
|
272 |
"\n",
|
273 |
-
"
|
274 |
-
"
|
275 |
-
"
|
276 |
-
"
|
277 |
-
"
|
278 |
-
"
|
279 |
-
" pitches = [e[4] for e in events_matrix]\n",
|
280 |
-
" pitches_sum = sum(pitches)\n",
|
281 |
-
" pitches_number = len(pitches)\n",
|
282 |
-
"\n",
|
283 |
-
" if pitches_sum not in pitches_sums:\n",
|
284 |
-
" pitches_count = sorted([[key, val] for key,val in Counter(pitches).most_common()], reverse=True)\n",
|
285 |
-
" #=======================================================\n",
|
286 |
-
" \n",
|
287 |
-
" if [y[1] for y in pitches_count] not in pitches_counts:\n",
|
288 |
-
"\n",
|
289 |
-
" # Saving every 5000 processed files\n",
|
290 |
-
" if files_count % 50000 == 0:\n",
|
291 |
-
" dir_count = ((files_count // 50000)+1) * 50000\n",
|
292 |
-
" dir_count_str = str(dir_count).zfill(7)\n",
|
293 |
-
" copy_path = '/content/Output/'+dir_count_str\n",
|
294 |
-
" if not os.path.exists(copy_path):\n",
|
295 |
-
" os.mkdir(copy_path)\n",
|
296 |
-
" print('SAVING !!!')\n",
|
297 |
-
" print('=' * 70)\n",
|
298 |
-
" print('Saving processed files...')\n",
|
299 |
-
" print('=' * 70)\n",
|
300 |
-
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
301 |
-
" print('=' * 70)\n",
|
302 |
-
"\n",
|
303 |
-
" if files_count % 5000 == 0:\n",
|
304 |
-
" print('=' * 70)\n",
|
305 |
-
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
306 |
-
" print('=' * 70)\n",
|
307 |
-
" TMIDIX.Tegridy_Any_Pickle_File_Writer(pitches_data, '/content/Output/pitches_data')\n",
|
308 |
-
"\n",
|
309 |
-
" shutil.copy2(f, copy_path+'/'+fn)\n",
|
310 |
-
"\n",
|
311 |
-
" # Processed files counter\n",
|
312 |
-
" files_count += 1\n",
|
313 |
-
" \n",
|
314 |
-
" data = []\n",
|
315 |
-
" \n",
|
316 |
-
" data = [fn.split('.mid')[0], times[-1], len(set(times))]\n",
|
317 |
-
" for p in pitches_count:\n",
|
318 |
-
" data.extend(p)\n",
|
319 |
-
" \n",
|
320 |
-
" pitches_data.append(data)\n",
|
321 |
-
" \n",
|
322 |
-
" pitches_sums.append(pitches_sum)\n",
|
323 |
-
" pitches_counts.append([y[1] for y in pitches_count])\n",
|
324 |
"\n",
|
|
|
|
|
325 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
" except KeyboardInterrupt:\n",
|
327 |
" print('Saving current progress and quitting...')\n",
|
328 |
" break \n",
|
@@ -335,15 +336,13 @@
|
|
335 |
" print('=' * 70)\n",
|
336 |
" continue\n",
|
337 |
"\n",
|
338 |
-
"# Saving last processed
|
339 |
"print('=' * 70)\n",
|
340 |
-
"print('Saving processed
|
341 |
"print('=' * 70)\n",
|
342 |
-
"
|
343 |
"print('=' * 70)\n",
|
344 |
-
"
|
345 |
-
"\n",
|
346 |
-
"# Displaying resulting processing stats...\n",
|
347 |
"print('=' * 70)\n",
|
348 |
"print('Done!') \n",
|
349 |
"print('=' * 70)\n",
|
@@ -352,7 +351,13 @@
|
|
352 |
"print('=' * 70)\n",
|
353 |
"print('Total good processed MIDI files:', files_count)\n",
|
354 |
"print('=' * 70)"
|
355 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
},
|
357 |
{
|
358 |
"cell_type": "markdown",
|
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
+
"# Los Angeles MIDI Dataset Maker (ver. 3.0)\n",
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
|
|
76 |
"source": [
|
77 |
"#@title Import all needed modules\n",
|
78 |
"\n",
|
79 |
+
"print('Loading core modules... Please wait...')\n",
|
80 |
"import os\n",
|
81 |
"\n",
|
82 |
"import math\n",
|
|
|
84 |
"import random\n",
|
85 |
"from collections import Counter\n",
|
86 |
"import shutil\n",
|
87 |
+
"import hashlib\n",
|
88 |
"from tqdm import tqdm\n",
|
89 |
"\n",
|
90 |
+
"print('Creating IO dirs...')\n",
|
91 |
+
"\n",
|
92 |
"if not os.path.exists('/content/Dataset'):\n",
|
93 |
" os.makedirs('/content/Dataset')\n",
|
94 |
"\n",
|
95 |
"if not os.path.exists('/content/Output'):\n",
|
96 |
" os.makedirs('/content/Output')\n",
|
97 |
"\n",
|
98 |
+
"output_dirs_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']\n",
|
99 |
+
"\n",
|
100 |
+
"for o in output_dirs_list:\n",
|
101 |
+
" if not os.path.exists('/content/Output/'+str(o)+'/'):\n",
|
102 |
+
" os.makedirs('/content/Output/'+str(o)+'/')\n",
|
103 |
+
"\n",
|
104 |
"print('Loading TMIDIX module...')\n",
|
105 |
"os.chdir('/content/tegridy-tools/tegridy-tools')\n",
|
106 |
"\n",
|
|
|
212 |
},
|
213 |
{
|
214 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
"source": [
|
216 |
"#@title Process MIDIs with TMIDIX MIDI processor\n",
|
217 |
"\n",
|
|
|
231 |
"\n",
|
232 |
"melody_chords_f = []\n",
|
233 |
"\n",
|
234 |
+
"all_md5_names = []\n",
|
235 |
+
"all_pitches_sums = []\n",
|
236 |
+
"all_pitches_counts = []\n",
|
237 |
+
"all_pitches_and_counts = []\n",
|
|
|
|
|
238 |
"\n",
|
239 |
"print('Processing MIDI files. Please wait...')\n",
|
240 |
"print('=' * 70)\n",
|
|
|
244 |
" input_files_count += 1\n",
|
245 |
"\n",
|
246 |
" fn = os.path.basename(f)\n",
|
247 |
+
" \n",
|
248 |
+
" # Filtering out giant MIDIs\n",
|
249 |
+
" file_size = os.path.getsize(f)\n",
|
250 |
"\n",
|
251 |
+
" if file_size <= 1000000:\n",
|
252 |
+
" \n",
|
253 |
+
" fdata = open(f, 'rb').read()\n",
|
254 |
"\n",
|
255 |
+
" md5sum = hashlib.md5(fdata).hexdigest()\n",
|
|
|
256 |
"\n",
|
257 |
+
" md5name = str(md5sum) + '.mid'\n",
|
258 |
+
"\n",
|
259 |
+
" #=======================================================\n",
|
260 |
+
" # START PROCESSING\n",
|
261 |
+
"\n",
|
262 |
+
" # Convering MIDI to ms score with MIDI.py module\n",
|
263 |
+
" score = TMIDIX.midi2score(fdata)\n",
|
264 |
+
"\n",
|
265 |
+
" events_matrix = []\n",
|
266 |
+
" itrack = 1\n",
|
267 |
+
"\n",
|
268 |
+
" while itrack < len(score):\n",
|
269 |
+
" for event in score[itrack]: \n",
|
270 |
+
" events_matrix.append(event)\n",
|
271 |
+
" itrack += 1\n",
|
272 |
"\n",
|
273 |
" events_matrix.sort(key=lambda x: x[1])\n",
|
274 |
"\n",
|
275 |
+
" notes = [y for y in events_matrix if y[0] == 'note']\n",
|
276 |
+
"\n",
|
277 |
+
" if len(notes) >= 256:\n",
|
278 |
+
"\n",
|
279 |
+
" times = [n[1] for n in notes]\n",
|
280 |
+
" durs = [n[2] for n in notes]\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
"\n",
|
282 |
+
" if min(times) >= 0 and min(durs) >= 0:\n",
|
283 |
+
" if len(times) > len(set(times)):\n",
|
284 |
"\n",
|
285 |
+
" if str(md5sum) not in all_md5_names:\n",
|
286 |
+
"\n",
|
287 |
+
" pitches = [n[4] for n in notes]\n",
|
288 |
+
" pitches_sum = sum(pitches)\n",
|
289 |
+
"\n",
|
290 |
+
" if pitches_sum not in all_pitches_sums:\n",
|
291 |
+
" pitches_and_counts = sorted([[key, val] for key,val in Counter(pitches).most_common()], reverse=True, key = lambda x: x[1])\n",
|
292 |
+
" pitches_counts = [p[1] for p in pitches_and_counts]\n",
|
293 |
+
" \n",
|
294 |
+
" #=======================================================\n",
|
295 |
+
"\n",
|
296 |
+
" if pitches_counts not in all_pitches_counts:\n",
|
297 |
+
"\n",
|
298 |
+
" # Saving data every 50000 processed files\n",
|
299 |
+
" if files_count % 50000 == 0:\n",
|
300 |
+
" print('SAVING !!!')\n",
|
301 |
+
" print('=' * 70)\n",
|
302 |
+
" print('Saving processed data...')\n",
|
303 |
+
" print('=' * 70)\n",
|
304 |
+
" TMIDIX.Tegridy_Any_Pickle_File_Writer([all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')\n",
|
305 |
+
" print('=' * 70)\n",
|
306 |
+
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
307 |
+
" print('=' * 70)\n",
|
308 |
+
" \n",
|
309 |
+
"\n",
|
310 |
+
" shutil.copy2(f, '/content/Output/'+str(md5name[0])+'/'+md5name)\n",
|
311 |
+
"\n",
|
312 |
+
" all_md5_names.append(str(md5sum))\n",
|
313 |
+
" all_pitches_sums.append(pitches_sum)\n",
|
314 |
+
" all_pitches_counts.append(pitches_counts)\n",
|
315 |
+
" all_pitches_and_counts.append(pitches_and_counts)\n",
|
316 |
+
" \n",
|
317 |
+
" if files_count % 1000 == 0:\n",
|
318 |
+
" print('=' * 70)\n",
|
319 |
+
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
320 |
+
" print('=' * 70)\n",
|
321 |
+
"\n",
|
322 |
+
" # Processed files counter\n",
|
323 |
+
" files_count += 1\n",
|
324 |
+
"\n",
|
325 |
+
" #=======================================================\n",
|
326 |
+
" \n",
|
327 |
" except KeyboardInterrupt:\n",
|
328 |
" print('Saving current progress and quitting...')\n",
|
329 |
" break \n",
|
|
|
336 |
" print('=' * 70)\n",
|
337 |
" continue\n",
|
338 |
"\n",
|
339 |
+
"# Saving last processed data...\n",
|
340 |
"print('=' * 70)\n",
|
341 |
+
"print('Saving processed data...')\n",
|
342 |
"print('=' * 70)\n",
|
343 |
+
"TMIDIX.Tegridy_Any_Pickle_File_Writer([all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')\n",
|
344 |
"print('=' * 70)\n",
|
345 |
+
"print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
|
|
|
|
346 |
"print('=' * 70)\n",
|
347 |
"print('Done!') \n",
|
348 |
"print('=' * 70)\n",
|
|
|
351 |
"print('=' * 70)\n",
|
352 |
"print('Total good processed MIDI files:', files_count)\n",
|
353 |
"print('=' * 70)"
|
354 |
+
],
|
355 |
+
"metadata": {
|
356 |
+
"cellView": "form",
|
357 |
+
"id": "OtmMHNozWPSV"
|
358 |
+
},
|
359 |
+
"execution_count": null,
|
360 |
+
"outputs": []
|
361 |
},
|
362 |
{
|
363 |
"cell_type": "markdown",
|
Los_Angeles_MIDI_Dataset_Metadata_Maker.ipynb
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
-
"# Los Angeles MIDI Dataset Metadata Maker (ver.
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
@@ -286,6 +286,8 @@
|
|
286 |
" # Convering MIDI to score with MIDI.py module\n",
|
287 |
" score = TMIDIX.opus2score(opus)\n",
|
288 |
"\n",
|
|
|
|
|
289 |
" events_matrix = []\n",
|
290 |
" full_events_matrix = []\n",
|
291 |
" \n",
|
@@ -312,7 +314,7 @@
|
|
312 |
" event.extend([patches[event[3]]])\n",
|
313 |
" events_matrix1.append(event)\n",
|
314 |
"\n",
|
315 |
-
" if len(events_matrix1) >
|
316 |
" \n",
|
317 |
" events_matrix1.sort(key=lambda x: x[1])\n",
|
318 |
"\n",
|
@@ -325,16 +327,14 @@
|
|
325 |
"\n",
|
326 |
" pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]\n",
|
327 |
" pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
|
328 |
-
"\n",
|
329 |
-
" patches_counts = [[y[0],y[1]] for y in Counter([y[6] for y in events_matrix1]).most_common()]\n",
|
330 |
-
" patches_counts.sort(key=lambda x: x[1], reverse=True)\n",
|
331 |
" \n",
|
332 |
-
"
|
333 |
-
"
|
|
|
334 |
" \n",
|
335 |
" midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
|
336 |
" if len(midi_patches) == 0:\n",
|
337 |
-
" midi_patches = [
|
338 |
" \n",
|
339 |
" times = []\n",
|
340 |
" pt = ms_events_matrix[0][1]\n",
|
@@ -345,7 +345,7 @@
|
|
345 |
" start = False\n",
|
346 |
" pt = e[1]\n",
|
347 |
" \n",
|
348 |
-
" times_sum = sum(times)\n",
|
349 |
" \n",
|
350 |
" durs = [e[2] for e in ms_events_matrix]\n",
|
351 |
" vels = [e[5] for e in ms_events_matrix]\n",
|
@@ -363,14 +363,14 @@
|
|
363 |
" median_vel = int(statistics.median(vels))\n",
|
364 |
" \n",
|
365 |
" text_events_list = ['text_event', \n",
|
366 |
-
"
|
367 |
-
"
|
368 |
-
"
|
369 |
-
"
|
370 |
-
"
|
371 |
-
"
|
372 |
-
"
|
373 |
-
"
|
374 |
" \n",
|
375 |
" text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])\n",
|
376 |
" lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])\n",
|
@@ -397,11 +397,15 @@
|
|
397 |
" chords.append(sorted(cho))\n",
|
398 |
"\n",
|
399 |
" ms_chords_counts = sorted([[list(key), val] for key,val in Counter([tuple(c) for c in chords if len(c) > 1]).most_common()], reverse=True, key = lambda x: x[1])\n",
|
400 |
-
"
|
|
|
|
|
|
|
|
|
401 |
" tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])\n",
|
402 |
" \n",
|
403 |
-
"
|
404 |
-
"
|
405 |
"\n",
|
406 |
" data = []\n",
|
407 |
" data.append(['total_number_of_tracks', itrack])\n",
|
@@ -410,19 +414,18 @@
|
|
410 |
" data.append(['average_median_mode_time_ms', [avg_time, median_time, mode_time]])\n",
|
411 |
" data.append(['average_median_mode_dur_ms', [avg_dur, median_dur, mode_dur]])\n",
|
412 |
" data.append(['average_median_mode_vel', [avg_vel, median_vel, mode_vel]])\n",
|
413 |
-
" data.append(['total_number_of_chords',
|
414 |
" data.append(['total_number_of_chords_ms', len(times)])\n",
|
415 |
" data.append(['ms_chords_counts', ms_chords_counts])\n",
|
416 |
" data.append(['pitches_times_sum_ms', times_sum])\n",
|
417 |
" data.append(['total_pitches_counts', pitches_counts])\n",
|
418 |
-
" data.append(['total_patches_counts', patches_counts])\n",
|
419 |
" data.append(['midi_patches', midi_patches])\n",
|
420 |
-
" data.append(['
|
421 |
" data.append(['tempo_change_count', tempo_change_count])\n",
|
422 |
" data.append(['text_events_count', text_events_count])\n",
|
423 |
" data.append(['lyric_events_count', lyric_events_count])\n",
|
424 |
" data.append(['midi_ticks', score[0]])\n",
|
425 |
-
" data.extend(full_events_matrix[:
|
426 |
" data.append(full_events_matrix[-1])\n",
|
427 |
" \n",
|
428 |
" melody_chords_f.append([fn1, data])\n",
|
@@ -441,7 +444,7 @@
|
|
441 |
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
442 |
" print('=' * 70)\n",
|
443 |
" count = str(files_count)\n",
|
444 |
-
" TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/
|
445 |
" melody_chords_f = []\n",
|
446 |
" print('=' * 70)\n",
|
447 |
"\n",
|
@@ -464,7 +467,7 @@
|
|
464 |
"print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
465 |
"print('=' * 70)\n",
|
466 |
"count = str(files_count)\n",
|
467 |
-
"TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/
|
468 |
"\n",
|
469 |
"# Displaying resulting processing stats...\n",
|
470 |
"print('=' * 70)\n",
|
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
+
"# Los Angeles MIDI Dataset Metadata Maker (ver. 3.0)\n",
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
|
|
286 |
" # Convering MIDI to score with MIDI.py module\n",
|
287 |
" score = TMIDIX.opus2score(opus)\n",
|
288 |
"\n",
|
289 |
+
" # INSTRUMENTS CONVERSION CYCLE\n",
|
290 |
+
"\n",
|
291 |
" events_matrix = []\n",
|
292 |
" full_events_matrix = []\n",
|
293 |
" \n",
|
|
|
314 |
" event.extend([patches[event[3]]])\n",
|
315 |
" events_matrix1.append(event)\n",
|
316 |
"\n",
|
317 |
+
" if len(events_matrix1) > 32: \n",
|
318 |
" \n",
|
319 |
" events_matrix1.sort(key=lambda x: x[1])\n",
|
320 |
"\n",
|
|
|
327 |
"\n",
|
328 |
" pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]\n",
|
329 |
" pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
|
|
|
|
|
|
|
330 |
" \n",
|
331 |
+
" patches = sorted([y[6] for y in events_matrix1])\n",
|
332 |
+
" patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]\n",
|
333 |
+
" patches_counts.sort(key = lambda x: x[0])\n",
|
334 |
" \n",
|
335 |
" midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
|
336 |
" if len(midi_patches) == 0:\n",
|
337 |
+
" midi_patches = [0]\n",
|
338 |
" \n",
|
339 |
" times = []\n",
|
340 |
" pt = ms_events_matrix[0][1]\n",
|
|
|
345 |
" start = False\n",
|
346 |
" pt = e[1]\n",
|
347 |
" \n",
|
348 |
+
" times_sum = min(10000000, sum(times))\n",
|
349 |
" \n",
|
350 |
" durs = [e[2] for e in ms_events_matrix]\n",
|
351 |
" vels = [e[5] for e in ms_events_matrix]\n",
|
|
|
363 |
" median_vel = int(statistics.median(vels))\n",
|
364 |
" \n",
|
365 |
" text_events_list = ['text_event', \n",
|
366 |
+
" 'text_event_08', \n",
|
367 |
+
" 'text_event_09', \n",
|
368 |
+
" 'text_event_0a', \n",
|
369 |
+
" 'text_event_0b', \n",
|
370 |
+
" 'text_event_0c',\n",
|
371 |
+
" 'text_event_0d',\n",
|
372 |
+
" 'text_event_0e',\n",
|
373 |
+
" 'text_event_0f']\n",
|
374 |
" \n",
|
375 |
" text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])\n",
|
376 |
" lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])\n",
|
|
|
397 |
" chords.append(sorted(cho))\n",
|
398 |
"\n",
|
399 |
" ms_chords_counts = sorted([[list(key), val] for key,val in Counter([tuple(c) for c in chords if len(c) > 1]).most_common()], reverse=True, key = lambda x: x[1])\n",
|
400 |
+
" if len(ms_chords_counts) == 0:\n",
|
401 |
+
" ms_chords_counts = [[[0, 0], 0]]\n",
|
402 |
+
" \n",
|
403 |
+
" total_number_of_chords = len(set([y[1] for y in events_matrix1]))\n",
|
404 |
+
" \n",
|
405 |
" tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])\n",
|
406 |
" \n",
|
407 |
+
" thirty_second_note = [e for e in events_matrix1][32]\n",
|
408 |
+
" thirty_second_note_idx = full_events_matrix.index(thirty_second_note)\n",
|
409 |
"\n",
|
410 |
" data = []\n",
|
411 |
" data.append(['total_number_of_tracks', itrack])\n",
|
|
|
414 |
" data.append(['average_median_mode_time_ms', [avg_time, median_time, mode_time]])\n",
|
415 |
" data.append(['average_median_mode_dur_ms', [avg_dur, median_dur, mode_dur]])\n",
|
416 |
" data.append(['average_median_mode_vel', [avg_vel, median_vel, mode_vel]])\n",
|
417 |
+
" data.append(['total_number_of_chords', total_number_of_chords])\n",
|
418 |
" data.append(['total_number_of_chords_ms', len(times)])\n",
|
419 |
" data.append(['ms_chords_counts', ms_chords_counts])\n",
|
420 |
" data.append(['pitches_times_sum_ms', times_sum])\n",
|
421 |
" data.append(['total_pitches_counts', pitches_counts])\n",
|
|
|
422 |
" data.append(['midi_patches', midi_patches])\n",
|
423 |
+
" data.append(['total_patches_counts', patches_counts])\n",
|
424 |
" data.append(['tempo_change_count', tempo_change_count])\n",
|
425 |
" data.append(['text_events_count', text_events_count])\n",
|
426 |
" data.append(['lyric_events_count', lyric_events_count])\n",
|
427 |
" data.append(['midi_ticks', score[0]])\n",
|
428 |
+
" data.extend(full_events_matrix[:thirty_second_note_idx])\n",
|
429 |
" data.append(full_events_matrix[-1])\n",
|
430 |
" \n",
|
431 |
" melody_chords_f.append([fn1, data])\n",
|
|
|
444 |
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
445 |
" print('=' * 70)\n",
|
446 |
" count = str(files_count)\n",
|
447 |
+
" TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/LAMD_META_DATA_'+count)\n",
|
448 |
" melody_chords_f = []\n",
|
449 |
" print('=' * 70)\n",
|
450 |
"\n",
|
|
|
467 |
"print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
468 |
"print('=' * 70)\n",
|
469 |
"count = str(files_count)\n",
|
470 |
+
"TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/LAMD_META_DATA_'+count)\n",
|
471 |
"\n",
|
472 |
"# Displaying resulting processing stats...\n",
|
473 |
"print('=' * 70)\n",
|
los_angeles_midi_dataset_maker.py
CHANGED
@@ -4,9 +4,9 @@
|
|
4 |
Automatically generated by Colaboratory.
|
5 |
|
6 |
Original file is located at
|
7 |
-
https://colab.research.google.com/
|
8 |
|
9 |
-
# Los Angeles MIDI Dataset Maker (ver.
|
10 |
|
11 |
***
|
12 |
|
@@ -30,7 +30,7 @@ Powered by tegridy-tools: https://github.com/asigalov61/tegridy-tools
|
|
30 |
|
31 |
#@title Import all needed modules
|
32 |
|
33 |
-
print('Loading
|
34 |
import os
|
35 |
|
36 |
import math
|
@@ -38,15 +38,23 @@ import statistics
|
|
38 |
import random
|
39 |
from collections import Counter
|
40 |
import shutil
|
41 |
-
import
|
42 |
from tqdm import tqdm
|
43 |
|
|
|
|
|
44 |
if not os.path.exists('/content/Dataset'):
|
45 |
os.makedirs('/content/Dataset')
|
46 |
|
47 |
if not os.path.exists('/content/Output'):
|
48 |
os.makedirs('/content/Output')
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
print('Loading TMIDIX module...')
|
51 |
os.chdir('/content/tegridy-tools/tegridy-tools')
|
52 |
|
@@ -118,12 +126,10 @@ files_count = LAST_SAVED_BATCH_COUNT
|
|
118 |
|
119 |
melody_chords_f = []
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
stats = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
127 |
|
128 |
print('Processing MIDI files. Please wait...')
|
129 |
print('=' * 70)
|
@@ -133,85 +139,86 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
133 |
input_files_count += 1
|
134 |
|
135 |
fn = os.path.basename(f)
|
136 |
-
|
|
|
|
|
137 |
|
138 |
-
|
139 |
-
|
|
|
140 |
|
141 |
-
|
142 |
-
score = TMIDIX.midi2ms_score(open(f, 'rb').read())
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
|
160 |
events_matrix.sort(key=lambda x: x[1])
|
161 |
|
162 |
-
|
163 |
-
durs = [e[2] for e in events_matrix]
|
164 |
-
|
165 |
-
if min(times) >= 0 and min(durs) >= 0:
|
166 |
-
if len([k for k,v in Counter(times).items() if v>1]) != 0:
|
167 |
-
|
168 |
-
pitches = [e[4] for e in events_matrix]
|
169 |
-
pitches_sum = sum(pitches)
|
170 |
-
pitches_number = len(pitches)
|
171 |
-
|
172 |
-
if pitches_sum not in pitches_sums:
|
173 |
-
pitches_count = sorted([[key, val] for key,val in Counter(pitches).most_common()], reverse=True)
|
174 |
-
#=======================================================
|
175 |
-
|
176 |
-
if [y[1] for y in pitches_count] not in pitches_counts:
|
177 |
-
|
178 |
-
# Saving every 5000 processed files
|
179 |
-
if files_count % 50000 == 0:
|
180 |
-
dir_count = ((files_count // 50000)+1) * 50000
|
181 |
-
dir_count_str = str(dir_count).zfill(7)
|
182 |
-
copy_path = '/content/Output/'+dir_count_str
|
183 |
-
if not os.path.exists(copy_path):
|
184 |
-
os.mkdir(copy_path)
|
185 |
-
print('SAVING !!!')
|
186 |
-
print('=' * 70)
|
187 |
-
print('Saving processed files...')
|
188 |
-
print('=' * 70)
|
189 |
-
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
190 |
-
print('=' * 70)
|
191 |
-
|
192 |
-
if files_count % 5000 == 0:
|
193 |
-
print('=' * 70)
|
194 |
-
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
195 |
-
print('=' * 70)
|
196 |
-
TMIDIX.Tegridy_Any_Pickle_File_Writer(pitches_data, '/content/Output/pitches_data')
|
197 |
-
|
198 |
-
shutil.copy2(f, copy_path+'/'+fn)
|
199 |
-
|
200 |
-
# Processed files counter
|
201 |
-
files_count += 1
|
202 |
-
|
203 |
-
data = []
|
204 |
-
|
205 |
-
data = [fn.split('.mid')[0], times[-1], len(set(times))]
|
206 |
-
for p in pitches_count:
|
207 |
-
data.extend(p)
|
208 |
-
|
209 |
-
pitches_data.append(data)
|
210 |
-
|
211 |
-
pitches_sums.append(pitches_sum)
|
212 |
-
pitches_counts.append([y[1] for y in pitches_count])
|
213 |
|
|
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
except KeyboardInterrupt:
|
216 |
print('Saving current progress and quitting...')
|
217 |
break
|
@@ -224,15 +231,13 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
224 |
print('=' * 70)
|
225 |
continue
|
226 |
|
227 |
-
# Saving last processed
|
228 |
print('=' * 70)
|
229 |
-
print('Saving processed
|
230 |
print('=' * 70)
|
231 |
-
|
232 |
print('=' * 70)
|
233 |
-
|
234 |
-
|
235 |
-
# Displaying resulting processing stats...
|
236 |
print('=' * 70)
|
237 |
print('Done!')
|
238 |
print('=' * 70)
|
|
|
4 |
Automatically generated by Colaboratory.
|
5 |
|
6 |
Original file is located at
|
7 |
+
https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Los_Angeles_MIDI_Dataset_Maker.ipynb
|
8 |
|
9 |
+
# Los Angeles MIDI Dataset Maker (ver. 3.0)
|
10 |
|
11 |
***
|
12 |
|
|
|
30 |
|
31 |
#@title Import all needed modules
|
32 |
|
33 |
+
print('Loading core modules... Please wait...')
|
34 |
import os
|
35 |
|
36 |
import math
|
|
|
38 |
import random
|
39 |
from collections import Counter
|
40 |
import shutil
|
41 |
+
import hashlib
|
42 |
from tqdm import tqdm
|
43 |
|
44 |
+
print('Creating IO dirs...')
|
45 |
+
|
46 |
if not os.path.exists('/content/Dataset'):
|
47 |
os.makedirs('/content/Dataset')
|
48 |
|
49 |
if not os.path.exists('/content/Output'):
|
50 |
os.makedirs('/content/Output')
|
51 |
|
52 |
+
output_dirs_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']
|
53 |
+
|
54 |
+
for o in output_dirs_list:
|
55 |
+
if not os.path.exists('/content/Output/'+str(o)+'/'):
|
56 |
+
os.makedirs('/content/Output/'+str(o)+'/')
|
57 |
+
|
58 |
print('Loading TMIDIX module...')
|
59 |
os.chdir('/content/tegridy-tools/tegridy-tools')
|
60 |
|
|
|
126 |
|
127 |
melody_chords_f = []
|
128 |
|
129 |
+
all_md5_names = []
|
130 |
+
all_pitches_sums = []
|
131 |
+
all_pitches_counts = []
|
132 |
+
all_pitches_and_counts = []
|
|
|
|
|
133 |
|
134 |
print('Processing MIDI files. Please wait...')
|
135 |
print('=' * 70)
|
|
|
139 |
input_files_count += 1
|
140 |
|
141 |
fn = os.path.basename(f)
|
142 |
+
|
143 |
+
# Filtering out giant MIDIs
|
144 |
+
file_size = os.path.getsize(f)
|
145 |
|
146 |
+
if file_size <= 1000000:
|
147 |
+
|
148 |
+
fdata = open(f, 'rb').read()
|
149 |
|
150 |
+
md5sum = hashlib.md5(fdata).hexdigest()
|
|
|
151 |
|
152 |
+
md5name = str(md5sum) + '.mid'
|
153 |
+
|
154 |
+
#=======================================================
|
155 |
+
# START PROCESSING
|
156 |
+
|
157 |
+
# Convering MIDI to ms score with MIDI.py module
|
158 |
+
score = TMIDIX.midi2score(fdata)
|
159 |
+
|
160 |
+
events_matrix = []
|
161 |
+
itrack = 1
|
162 |
+
|
163 |
+
while itrack < len(score):
|
164 |
+
for event in score[itrack]:
|
165 |
+
events_matrix.append(event)
|
166 |
+
itrack += 1
|
167 |
|
168 |
events_matrix.sort(key=lambda x: x[1])
|
169 |
|
170 |
+
notes = [y for y in events_matrix if y[0] == 'note']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
+
if len(notes) >= 256:
|
173 |
|
174 |
+
times = [n[1] for n in notes]
|
175 |
+
durs = [n[2] for n in notes]
|
176 |
+
|
177 |
+
if min(times) >= 0 and min(durs) >= 0:
|
178 |
+
if len(times) > len(set(times)):
|
179 |
+
|
180 |
+
if str(md5sum) not in all_md5_names:
|
181 |
+
|
182 |
+
pitches = [n[4] for n in notes]
|
183 |
+
pitches_sum = sum(pitches)
|
184 |
+
|
185 |
+
if pitches_sum not in all_pitches_sums:
|
186 |
+
pitches_and_counts = sorted([[key, val] for key,val in Counter(pitches).most_common()], reverse=True, key = lambda x: x[1])
|
187 |
+
pitches_counts = [p[1] for p in pitches_and_counts]
|
188 |
+
|
189 |
+
#=======================================================
|
190 |
+
|
191 |
+
if pitches_counts not in all_pitches_counts:
|
192 |
+
|
193 |
+
# Saving data every 50000 processed files
|
194 |
+
if files_count % 50000 == 0:
|
195 |
+
print('SAVING !!!')
|
196 |
+
print('=' * 70)
|
197 |
+
print('Saving processed data...')
|
198 |
+
print('=' * 70)
|
199 |
+
TMIDIX.Tegridy_Any_Pickle_File_Writer([all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')
|
200 |
+
print('=' * 70)
|
201 |
+
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
202 |
+
print('=' * 70)
|
203 |
+
|
204 |
+
|
205 |
+
shutil.copy2(f, '/content/Output/'+str(md5name[0])+'/'+md5name)
|
206 |
+
|
207 |
+
all_md5_names.append(str(md5sum))
|
208 |
+
all_pitches_sums.append(pitches_sum)
|
209 |
+
all_pitches_counts.append(pitches_counts)
|
210 |
+
all_pitches_and_counts.append(pitches_and_counts)
|
211 |
+
|
212 |
+
if files_count % 1000 == 0:
|
213 |
+
print('=' * 70)
|
214 |
+
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
215 |
+
print('=' * 70)
|
216 |
+
|
217 |
+
# Processed files counter
|
218 |
+
files_count += 1
|
219 |
+
|
220 |
+
#=======================================================
|
221 |
+
|
222 |
except KeyboardInterrupt:
|
223 |
print('Saving current progress and quitting...')
|
224 |
break
|
|
|
231 |
print('=' * 70)
|
232 |
continue
|
233 |
|
234 |
+
# Saving last processed data...
|
235 |
print('=' * 70)
|
236 |
+
print('Saving processed data...')
|
237 |
print('=' * 70)
|
238 |
+
TMIDIX.Tegridy_Any_Pickle_File_Writer([all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')
|
239 |
print('=' * 70)
|
240 |
+
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
|
|
|
|
241 |
print('=' * 70)
|
242 |
print('Done!')
|
243 |
print('=' * 70)
|
los_angeles_midi_dataset_metadata_maker.py
CHANGED
@@ -4,9 +4,9 @@
|
|
4 |
Automatically generated by Colaboratory.
|
5 |
|
6 |
Original file is located at
|
7 |
-
https://colab.research.google.com/
|
8 |
|
9 |
-
# Los Angeles MIDI Dataset Metadata Maker (ver.
|
10 |
|
11 |
***
|
12 |
|
@@ -165,6 +165,8 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
165 |
# Convering MIDI to score with MIDI.py module
|
166 |
score = TMIDIX.opus2score(opus)
|
167 |
|
|
|
|
|
168 |
events_matrix = []
|
169 |
full_events_matrix = []
|
170 |
|
@@ -191,7 +193,7 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
191 |
event.extend([patches[event[3]]])
|
192 |
events_matrix1.append(event)
|
193 |
|
194 |
-
if len(events_matrix1) >
|
195 |
|
196 |
events_matrix1.sort(key=lambda x: x[1])
|
197 |
|
@@ -204,16 +206,14 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
204 |
|
205 |
pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]
|
206 |
pitches_counts.sort(key=lambda x: x[0], reverse=True)
|
207 |
-
|
208 |
-
patches_counts = [[y[0],y[1]] for y in Counter([y[6] for y in events_matrix1]).most_common()]
|
209 |
-
patches_counts.sort(key=lambda x: x[1], reverse=True)
|
210 |
|
211 |
-
|
212 |
-
|
|
|
213 |
|
214 |
midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))
|
215 |
if len(midi_patches) == 0:
|
216 |
-
midi_patches = [
|
217 |
|
218 |
times = []
|
219 |
pt = ms_events_matrix[0][1]
|
@@ -224,7 +224,7 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
224 |
start = False
|
225 |
pt = e[1]
|
226 |
|
227 |
-
times_sum = sum(times)
|
228 |
|
229 |
durs = [e[2] for e in ms_events_matrix]
|
230 |
vels = [e[5] for e in ms_events_matrix]
|
@@ -242,14 +242,14 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
242 |
median_vel = int(statistics.median(vels))
|
243 |
|
244 |
text_events_list = ['text_event',
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
|
254 |
text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])
|
255 |
lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])
|
@@ -276,11 +276,15 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
276 |
chords.append(sorted(cho))
|
277 |
|
278 |
ms_chords_counts = sorted([[list(key), val] for key,val in Counter([tuple(c) for c in chords if len(c) > 1]).most_common()], reverse=True, key = lambda x: x[1])
|
279 |
-
|
|
|
|
|
|
|
|
|
280 |
tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])
|
281 |
|
282 |
-
|
283 |
-
|
284 |
|
285 |
data = []
|
286 |
data.append(['total_number_of_tracks', itrack])
|
@@ -289,19 +293,18 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
289 |
data.append(['average_median_mode_time_ms', [avg_time, median_time, mode_time]])
|
290 |
data.append(['average_median_mode_dur_ms', [avg_dur, median_dur, mode_dur]])
|
291 |
data.append(['average_median_mode_vel', [avg_vel, median_vel, mode_vel]])
|
292 |
-
data.append(['total_number_of_chords',
|
293 |
data.append(['total_number_of_chords_ms', len(times)])
|
294 |
data.append(['ms_chords_counts', ms_chords_counts])
|
295 |
data.append(['pitches_times_sum_ms', times_sum])
|
296 |
data.append(['total_pitches_counts', pitches_counts])
|
297 |
-
data.append(['total_patches_counts', patches_counts])
|
298 |
data.append(['midi_patches', midi_patches])
|
299 |
-
data.append(['
|
300 |
data.append(['tempo_change_count', tempo_change_count])
|
301 |
data.append(['text_events_count', text_events_count])
|
302 |
data.append(['lyric_events_count', lyric_events_count])
|
303 |
data.append(['midi_ticks', score[0]])
|
304 |
-
data.extend(full_events_matrix[:
|
305 |
data.append(full_events_matrix[-1])
|
306 |
|
307 |
melody_chords_f.append([fn1, data])
|
@@ -320,7 +323,7 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
320 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
321 |
print('=' * 70)
|
322 |
count = str(files_count)
|
323 |
-
TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/
|
324 |
melody_chords_f = []
|
325 |
print('=' * 70)
|
326 |
|
@@ -343,7 +346,7 @@ print('=' * 70)
|
|
343 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
344 |
print('=' * 70)
|
345 |
count = str(files_count)
|
346 |
-
TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/
|
347 |
|
348 |
# Displaying resulting processing stats...
|
349 |
print('=' * 70)
|
|
|
4 |
Automatically generated by Colaboratory.
|
5 |
|
6 |
Original file is located at
|
7 |
+
https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/META-DATA/Los_Angeles_MIDI_Dataset_Metadata_Maker.ipynb
|
8 |
|
9 |
+
# Los Angeles MIDI Dataset Metadata Maker (ver. 3.0)
|
10 |
|
11 |
***
|
12 |
|
|
|
165 |
# Convering MIDI to score with MIDI.py module
|
166 |
score = TMIDIX.opus2score(opus)
|
167 |
|
168 |
+
# INSTRUMENTS CONVERSION CYCLE
|
169 |
+
|
170 |
events_matrix = []
|
171 |
full_events_matrix = []
|
172 |
|
|
|
193 |
event.extend([patches[event[3]]])
|
194 |
events_matrix1.append(event)
|
195 |
|
196 |
+
if len(events_matrix1) > 32:
|
197 |
|
198 |
events_matrix1.sort(key=lambda x: x[1])
|
199 |
|
|
|
206 |
|
207 |
pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]
|
208 |
pitches_counts.sort(key=lambda x: x[0], reverse=True)
|
|
|
|
|
|
|
209 |
|
210 |
+
patches = sorted([y[6] for y in events_matrix1])
|
211 |
+
patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]
|
212 |
+
patches_counts.sort(key = lambda x: x[0])
|
213 |
|
214 |
midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))
|
215 |
if len(midi_patches) == 0:
|
216 |
+
midi_patches = [0]
|
217 |
|
218 |
times = []
|
219 |
pt = ms_events_matrix[0][1]
|
|
|
224 |
start = False
|
225 |
pt = e[1]
|
226 |
|
227 |
+
times_sum = min(10000000, sum(times))
|
228 |
|
229 |
durs = [e[2] for e in ms_events_matrix]
|
230 |
vels = [e[5] for e in ms_events_matrix]
|
|
|
242 |
median_vel = int(statistics.median(vels))
|
243 |
|
244 |
text_events_list = ['text_event',
|
245 |
+
'text_event_08',
|
246 |
+
'text_event_09',
|
247 |
+
'text_event_0a',
|
248 |
+
'text_event_0b',
|
249 |
+
'text_event_0c',
|
250 |
+
'text_event_0d',
|
251 |
+
'text_event_0e',
|
252 |
+
'text_event_0f']
|
253 |
|
254 |
text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])
|
255 |
lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])
|
|
|
276 |
chords.append(sorted(cho))
|
277 |
|
278 |
ms_chords_counts = sorted([[list(key), val] for key,val in Counter([tuple(c) for c in chords if len(c) > 1]).most_common()], reverse=True, key = lambda x: x[1])
|
279 |
+
if len(ms_chords_counts) == 0:
|
280 |
+
ms_chords_counts = [[[0, 0], 0]]
|
281 |
+
|
282 |
+
total_number_of_chords = len(set([y[1] for y in events_matrix1]))
|
283 |
+
|
284 |
tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])
|
285 |
|
286 |
+
thirty_second_note = [e for e in events_matrix1][32]
|
287 |
+
thirty_second_note_idx = full_events_matrix.index(thirty_second_note)
|
288 |
|
289 |
data = []
|
290 |
data.append(['total_number_of_tracks', itrack])
|
|
|
293 |
data.append(['average_median_mode_time_ms', [avg_time, median_time, mode_time]])
|
294 |
data.append(['average_median_mode_dur_ms', [avg_dur, median_dur, mode_dur]])
|
295 |
data.append(['average_median_mode_vel', [avg_vel, median_vel, mode_vel]])
|
296 |
+
data.append(['total_number_of_chords', total_number_of_chords])
|
297 |
data.append(['total_number_of_chords_ms', len(times)])
|
298 |
data.append(['ms_chords_counts', ms_chords_counts])
|
299 |
data.append(['pitches_times_sum_ms', times_sum])
|
300 |
data.append(['total_pitches_counts', pitches_counts])
|
|
|
301 |
data.append(['midi_patches', midi_patches])
|
302 |
+
data.append(['total_patches_counts', patches_counts])
|
303 |
data.append(['tempo_change_count', tempo_change_count])
|
304 |
data.append(['text_events_count', text_events_count])
|
305 |
data.append(['lyric_events_count', lyric_events_count])
|
306 |
data.append(['midi_ticks', score[0]])
|
307 |
+
data.extend(full_events_matrix[:thirty_second_note_idx])
|
308 |
data.append(full_events_matrix[-1])
|
309 |
|
310 |
melody_chords_f.append([fn1, data])
|
|
|
323 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
324 |
print('=' * 70)
|
325 |
count = str(files_count)
|
326 |
+
TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/LAMD_META_DATA_'+count)
|
327 |
melody_chords_f = []
|
328 |
print('=' * 70)
|
329 |
|
|
|
346 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
347 |
print('=' * 70)
|
348 |
count = str(files_count)
|
349 |
+
TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/LAMD_META_DATA_'+count)
|
350 |
|
351 |
# Displaying resulting processing stats...
|
352 |
print('=' * 70)
|