projectlosangeles
commited on
Commit
•
9543c4a
1
Parent(s):
f0bae44
Upload 10 files
Browse files- Los_Angeles_MIDI_Dataset_Maker.ipynb +17 -14
- Los_Angeles_MIDI_Dataset_Metadata_Maker.ipynb +42 -42
- Los_Angeles_MIDI_Dataset_Search_and_Explore.ipynb +3 -3
- Master_MIDI_Dataset_Search_and_Filter.ipynb +3 -3
- TMIDIX.py +121 -4
- los_angeles_midi_dataset_maker.py +17 -14
- los_angeles_midi_dataset_metadata_maker.py +42 -42
- los_angeles_midi_dataset_search_and_explore.py +3 -3
- master_midi_dataset_search_and_filter.py +3 -3
Los_Angeles_MIDI_Dataset_Maker.ipynb
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
-
"# Los Angeles MIDI Dataset Maker (ver. 3.
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
@@ -244,12 +244,12 @@
|
|
244 |
" input_files_count += 1\n",
|
245 |
"\n",
|
246 |
" fn = os.path.basename(f)\n",
|
247 |
-
"
|
248 |
" # Filtering out giant MIDIs\n",
|
249 |
" file_size = os.path.getsize(f)\n",
|
250 |
"\n",
|
251 |
" if file_size <= 1000000:\n",
|
252 |
-
"
|
253 |
" fdata = open(f, 'rb').read()\n",
|
254 |
"\n",
|
255 |
" md5sum = hashlib.md5(fdata).hexdigest()\n",
|
@@ -266,7 +266,7 @@
|
|
266 |
" itrack = 1\n",
|
267 |
"\n",
|
268 |
" while itrack < len(score):\n",
|
269 |
-
" for event in score[itrack]
|
270 |
" events_matrix.append(event)\n",
|
271 |
" itrack += 1\n",
|
272 |
"\n",
|
@@ -284,13 +284,18 @@
|
|
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 |
-
"
|
294 |
" #=======================================================\n",
|
295 |
"\n",
|
296 |
" if pitches_counts not in all_pitches_counts:\n",
|
@@ -301,19 +306,17 @@
|
|
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 |
-
"
|
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 |
-
"
|
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",
|
@@ -323,10 +326,10 @@
|
|
323 |
" files_count += 1\n",
|
324 |
"\n",
|
325 |
" #=======================================================\n",
|
326 |
-
"
|
327 |
" except KeyboardInterrupt:\n",
|
328 |
" print('Saving current progress and quitting...')\n",
|
329 |
-
" break
|
330 |
"\n",
|
331 |
" except Exception as ex:\n",
|
332 |
" print('WARNING !!!')\n",
|
@@ -340,11 +343,11 @@
|
|
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!')
|
348 |
"print('=' * 70)\n",
|
349 |
"\n",
|
350 |
"print('Resulting Stats:')\n",
|
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
+
"# Los Angeles MIDI Dataset Maker (ver. 3.1)\n",
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\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",
|
|
|
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",
|
|
|
284 |
"\n",
|
285 |
" if str(md5sum) not in all_md5_names:\n",
|
286 |
"\n",
|
287 |
+
" all_md5_names.append(str(md5sum))\n",
|
288 |
+
"\n",
|
289 |
" pitches = [n[4] for n in notes]\n",
|
290 |
" pitches_sum = sum(pitches)\n",
|
291 |
"\n",
|
292 |
" if pitches_sum not in all_pitches_sums:\n",
|
293 |
+
"\n",
|
294 |
+
" all_pitches_sums.append(pitches_sum)\n",
|
295 |
+
"\n",
|
296 |
" pitches_and_counts = sorted([[key, val] for key,val in Counter(pitches).most_common()], reverse=True, key = lambda x: x[1])\n",
|
297 |
" pitches_counts = [p[1] for p in pitches_and_counts]\n",
|
298 |
+
"\n",
|
299 |
" #=======================================================\n",
|
300 |
"\n",
|
301 |
" if pitches_counts not in all_pitches_counts:\n",
|
|
|
306 |
" print('=' * 70)\n",
|
307 |
" print('Saving processed data...')\n",
|
308 |
" print('=' * 70)\n",
|
309 |
+
" TMIDIX.Tegridy_Any_Pickle_File_Writer([filez, all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')\n",
|
310 |
" print('=' * 70)\n",
|
311 |
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
312 |
" print('=' * 70)\n",
|
313 |
+
"\n",
|
314 |
"\n",
|
315 |
" shutil.copy2(f, '/content/Output/'+str(md5name[0])+'/'+md5name)\n",
|
316 |
"\n",
|
|
|
|
|
317 |
" all_pitches_counts.append(pitches_counts)\n",
|
318 |
" all_pitches_and_counts.append(pitches_and_counts)\n",
|
319 |
+
"\n",
|
320 |
" if files_count % 1000 == 0:\n",
|
321 |
" print('=' * 70)\n",
|
322 |
" print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
|
|
326 |
" files_count += 1\n",
|
327 |
"\n",
|
328 |
" #=======================================================\n",
|
329 |
+
"\n",
|
330 |
" except KeyboardInterrupt:\n",
|
331 |
" print('Saving current progress and quitting...')\n",
|
332 |
+
" break\n",
|
333 |
"\n",
|
334 |
" except Exception as ex:\n",
|
335 |
" print('WARNING !!!')\n",
|
|
|
343 |
"print('=' * 70)\n",
|
344 |
"print('Saving processed data...')\n",
|
345 |
"print('=' * 70)\n",
|
346 |
+
"TMIDIX.Tegridy_Any_Pickle_File_Writer([filez, all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')\n",
|
347 |
"print('=' * 70)\n",
|
348 |
"print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')\n",
|
349 |
"print('=' * 70)\n",
|
350 |
+
"print('Done!')\n",
|
351 |
"print('=' * 70)\n",
|
352 |
"\n",
|
353 |
"print('Resulting Stats:')\n",
|
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. 3.
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
@@ -254,34 +254,34 @@
|
|
254 |
"\n",
|
255 |
" #=======================================================\n",
|
256 |
" # START PROCESSING\n",
|
257 |
-
"
|
258 |
" opus = TMIDIX.midi2opus(open(f, 'rb').read())\n",
|
259 |
-
"
|
260 |
" opus_events_matrix = []\n",
|
261 |
-
"
|
262 |
" itrack0 = 1\n",
|
263 |
-
"
|
264 |
" while itrack0 < len(opus):\n",
|
265 |
-
" for event in opus[itrack0]
|
266 |
" opus_events_matrix.append(event)\n",
|
267 |
" itrack0 += 1\n",
|
268 |
-
"
|
269 |
" #=======================================================\n",
|
270 |
-
"
|
271 |
" ms_score = TMIDIX.opus2score(TMIDIX.to_millisecs(opus))\n",
|
272 |
"\n",
|
273 |
" ms_events_matrix = []\n",
|
274 |
-
"
|
275 |
" itrack1 = 1\n",
|
276 |
-
"
|
277 |
" while itrack1 < len(ms_score):\n",
|
278 |
-
" for event in ms_score[itrack1]
|
279 |
" if event[0] == 'note':\n",
|
280 |
" ms_events_matrix.append(event)\n",
|
281 |
" itrack1 += 1\n",
|
282 |
"\n",
|
283 |
" ms_events_matrix.sort(key=lambda x: x[1])\n",
|
284 |
-
"
|
285 |
" #=======================================================\n",
|
286 |
"\n",
|
287 |
" # Convering MIDI to score with MIDI.py module\n",
|
@@ -291,20 +291,20 @@
|
|
291 |
"\n",
|
292 |
" events_matrix = []\n",
|
293 |
" full_events_matrix = []\n",
|
294 |
-
"
|
295 |
" itrack = 1\n",
|
296 |
" patches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
|
297 |
"\n",
|
298 |
" while itrack < len(score):\n",
|
299 |
-
" for event in score[itrack]
|
300 |
" if event[0] == 'note' or event[0] == 'patch_change':\n",
|
301 |
" events_matrix.append(event)\n",
|
302 |
" full_events_matrix.append(event)\n",
|
303 |
" itrack += 1\n",
|
304 |
-
"
|
305 |
" full_events_matrix.sort(key=lambda x: x[1])\n",
|
306 |
" events_matrix.sort(key=lambda x: x[1])\n",
|
307 |
-
"
|
308 |
" events_matrix1 = []\n",
|
309 |
"\n",
|
310 |
" for event in events_matrix:\n",
|
@@ -315,8 +315,8 @@
|
|
315 |
" event.extend([patches[event[3]]])\n",
|
316 |
" events_matrix1.append(event)\n",
|
317 |
"\n",
|
318 |
-
" if len(events_matrix1) > 32
|
319 |
-
"
|
320 |
" events_matrix1.sort(key=lambda x: x[1])\n",
|
321 |
"\n",
|
322 |
" for e in events_matrix1:\n",
|
@@ -328,15 +328,15 @@
|
|
328 |
"\n",
|
329 |
" pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]\n",
|
330 |
" pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
|
331 |
-
"
|
332 |
" patches = sorted([y[6] for y in events_matrix1])\n",
|
333 |
" patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]\n",
|
334 |
" patches_counts.sort(key = lambda x: x[0])\n",
|
335 |
-
"
|
336 |
" midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
|
337 |
" if len(midi_patches) == 0:\n",
|
338 |
" midi_patches = [0]\n",
|
339 |
-
"
|
340 |
" times = []\n",
|
341 |
" pt = ms_events_matrix[0][1]\n",
|
342 |
" start = True\n",
|
@@ -345,37 +345,37 @@
|
|
345 |
" times.append((e[1]-pt))\n",
|
346 |
" start = False\n",
|
347 |
" pt = e[1]\n",
|
348 |
-
"
|
349 |
" times_sum = min(10000000, sum(times))\n",
|
350 |
-
"
|
351 |
" durs = [e[2] for e in ms_events_matrix]\n",
|
352 |
" vels = [e[5] for e in ms_events_matrix]\n",
|
353 |
-
"
|
354 |
" avg_time = int(sum(times) / len(times))\n",
|
355 |
" avg_dur = int(sum(durs) / len(durs))\n",
|
356 |
" avg_vel = int(sum(vels) / len(vels))\n",
|
357 |
-
"
|
358 |
" mode_time = statistics.mode(times)\n",
|
359 |
" mode_dur = statistics.mode(durs)\n",
|
360 |
" mode_vel = statistics.mode(vels)\n",
|
361 |
-
"
|
362 |
" median_time = int(statistics.median(times))\n",
|
363 |
" median_dur = int(statistics.median(durs))\n",
|
364 |
" median_vel = int(statistics.median(vels))\n",
|
365 |
-
"
|
366 |
-
" text_events_list = ['text_event'
|
367 |
-
" 'text_event_08'
|
368 |
-
" 'text_event_09'
|
369 |
-
" 'text_event_0a'
|
370 |
-
" 'text_event_0b'
|
371 |
" 'text_event_0c',\n",
|
372 |
" 'text_event_0d',\n",
|
373 |
" 'text_event_0e',\n",
|
374 |
" 'text_event_0f']\n",
|
375 |
-
"
|
376 |
" text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])\n",
|
377 |
" lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])\n",
|
378 |
-
"
|
379 |
" chords = []\n",
|
380 |
" pe = ms_events_matrix[0]\n",
|
381 |
" cho = []\n",
|
@@ -393,18 +393,18 @@
|
|
393 |
" cho.append(e[4] % 12)\n",
|
394 |
"\n",
|
395 |
" pe = e\n",
|
396 |
-
"
|
397 |
" if len(cho) > 0:\n",
|
398 |
" chords.append(sorted(cho))\n",
|
399 |
"\n",
|
400 |
" 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",
|
401 |
" if len(ms_chords_counts) == 0:\n",
|
402 |
" ms_chords_counts = [[[0, 0], 0]]\n",
|
403 |
-
"
|
404 |
" total_number_of_chords = len(set([y[1] for y in events_matrix1]))\n",
|
405 |
-
"
|
406 |
" tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])\n",
|
407 |
-
"
|
408 |
" thirty_second_note = [e for e in events_matrix1][32]\n",
|
409 |
" thirty_second_note_idx = full_events_matrix.index(thirty_second_note)\n",
|
410 |
"\n",
|
@@ -428,7 +428,7 @@
|
|
428 |
" data.append(['midi_ticks', score[0]])\n",
|
429 |
" data.extend(full_events_matrix[:thirty_second_note_idx])\n",
|
430 |
" data.append(full_events_matrix[-1])\n",
|
431 |
-
"
|
432 |
" melody_chords_f.append([fn1, data])\n",
|
433 |
"\n",
|
434 |
" #=======================================================\n",
|
@@ -451,7 +451,7 @@
|
|
451 |
"\n",
|
452 |
" except KeyboardInterrupt:\n",
|
453 |
" print('Saving current progress and quitting...')\n",
|
454 |
-
" break
|
455 |
"\n",
|
456 |
" except Exception as ex:\n",
|
457 |
" print('WARNING !!!')\n",
|
@@ -472,7 +472,7 @@
|
|
472 |
"\n",
|
473 |
"# Displaying resulting processing stats...\n",
|
474 |
"print('=' * 70)\n",
|
475 |
-
"print('Done!')
|
476 |
"print('=' * 70)\n",
|
477 |
"\n",
|
478 |
"print('Resulting Stats:')\n",
|
@@ -520,7 +520,7 @@
|
|
520 |
" print('=' * 70)\n",
|
521 |
" print('Loaded file:', f)\n",
|
522 |
" print('=' * 70)\n",
|
523 |
-
"
|
524 |
"print('Done!')\n",
|
525 |
"print('=' * 70)\n",
|
526 |
"print('Randomizing metadata entries order...')\n",
|
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
+
"# Los Angeles MIDI Dataset Metadata Maker (ver. 3.1)\n",
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
|
|
254 |
"\n",
|
255 |
" #=======================================================\n",
|
256 |
" # START PROCESSING\n",
|
257 |
+
"\n",
|
258 |
" opus = TMIDIX.midi2opus(open(f, 'rb').read())\n",
|
259 |
+
"\n",
|
260 |
" opus_events_matrix = []\n",
|
261 |
+
"\n",
|
262 |
" itrack0 = 1\n",
|
263 |
+
"\n",
|
264 |
" while itrack0 < len(opus):\n",
|
265 |
+
" for event in opus[itrack0]:\n",
|
266 |
" opus_events_matrix.append(event)\n",
|
267 |
" itrack0 += 1\n",
|
268 |
+
"\n",
|
269 |
" #=======================================================\n",
|
270 |
+
"\n",
|
271 |
" ms_score = TMIDIX.opus2score(TMIDIX.to_millisecs(opus))\n",
|
272 |
"\n",
|
273 |
" ms_events_matrix = []\n",
|
274 |
+
"\n",
|
275 |
" itrack1 = 1\n",
|
276 |
+
"\n",
|
277 |
" while itrack1 < len(ms_score):\n",
|
278 |
+
" for event in ms_score[itrack1]:\n",
|
279 |
" if event[0] == 'note':\n",
|
280 |
" ms_events_matrix.append(event)\n",
|
281 |
" itrack1 += 1\n",
|
282 |
"\n",
|
283 |
" ms_events_matrix.sort(key=lambda x: x[1])\n",
|
284 |
+
"\n",
|
285 |
" #=======================================================\n",
|
286 |
"\n",
|
287 |
" # Convering MIDI to score with MIDI.py module\n",
|
|
|
291 |
"\n",
|
292 |
" events_matrix = []\n",
|
293 |
" full_events_matrix = []\n",
|
294 |
+
"\n",
|
295 |
" itrack = 1\n",
|
296 |
" patches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
|
297 |
"\n",
|
298 |
" while itrack < len(score):\n",
|
299 |
+
" for event in score[itrack]:\n",
|
300 |
" if event[0] == 'note' or event[0] == 'patch_change':\n",
|
301 |
" events_matrix.append(event)\n",
|
302 |
" full_events_matrix.append(event)\n",
|
303 |
" itrack += 1\n",
|
304 |
+
"\n",
|
305 |
" full_events_matrix.sort(key=lambda x: x[1])\n",
|
306 |
" events_matrix.sort(key=lambda x: x[1])\n",
|
307 |
+
"\n",
|
308 |
" events_matrix1 = []\n",
|
309 |
"\n",
|
310 |
" for event in events_matrix:\n",
|
|
|
315 |
" event.extend([patches[event[3]]])\n",
|
316 |
" events_matrix1.append(event)\n",
|
317 |
"\n",
|
318 |
+
" if len(events_matrix1) > 32:\n",
|
319 |
+
"\n",
|
320 |
" events_matrix1.sort(key=lambda x: x[1])\n",
|
321 |
"\n",
|
322 |
" for e in events_matrix1:\n",
|
|
|
328 |
"\n",
|
329 |
" pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]\n",
|
330 |
" pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
|
331 |
+
"\n",
|
332 |
" patches = sorted([y[6] for y in events_matrix1])\n",
|
333 |
" patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]\n",
|
334 |
" patches_counts.sort(key = lambda x: x[0])\n",
|
335 |
+
"\n",
|
336 |
" midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
|
337 |
" if len(midi_patches) == 0:\n",
|
338 |
" midi_patches = [0]\n",
|
339 |
+
"\n",
|
340 |
" times = []\n",
|
341 |
" pt = ms_events_matrix[0][1]\n",
|
342 |
" start = True\n",
|
|
|
345 |
" times.append((e[1]-pt))\n",
|
346 |
" start = False\n",
|
347 |
" pt = e[1]\n",
|
348 |
+
"\n",
|
349 |
" times_sum = min(10000000, sum(times))\n",
|
350 |
+
"\n",
|
351 |
" durs = [e[2] for e in ms_events_matrix]\n",
|
352 |
" vels = [e[5] for e in ms_events_matrix]\n",
|
353 |
+
"\n",
|
354 |
" avg_time = int(sum(times) / len(times))\n",
|
355 |
" avg_dur = int(sum(durs) / len(durs))\n",
|
356 |
" avg_vel = int(sum(vels) / len(vels))\n",
|
357 |
+
"\n",
|
358 |
" mode_time = statistics.mode(times)\n",
|
359 |
" mode_dur = statistics.mode(durs)\n",
|
360 |
" mode_vel = statistics.mode(vels)\n",
|
361 |
+
"\n",
|
362 |
" median_time = int(statistics.median(times))\n",
|
363 |
" median_dur = int(statistics.median(durs))\n",
|
364 |
" median_vel = int(statistics.median(vels))\n",
|
365 |
+
"\n",
|
366 |
+
" text_events_list = ['text_event',\n",
|
367 |
+
" 'text_event_08',\n",
|
368 |
+
" 'text_event_09',\n",
|
369 |
+
" 'text_event_0a',\n",
|
370 |
+
" 'text_event_0b',\n",
|
371 |
" 'text_event_0c',\n",
|
372 |
" 'text_event_0d',\n",
|
373 |
" 'text_event_0e',\n",
|
374 |
" 'text_event_0f']\n",
|
375 |
+
"\n",
|
376 |
" text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])\n",
|
377 |
" lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])\n",
|
378 |
+
"\n",
|
379 |
" chords = []\n",
|
380 |
" pe = ms_events_matrix[0]\n",
|
381 |
" cho = []\n",
|
|
|
393 |
" cho.append(e[4] % 12)\n",
|
394 |
"\n",
|
395 |
" pe = e\n",
|
396 |
+
"\n",
|
397 |
" if len(cho) > 0:\n",
|
398 |
" chords.append(sorted(cho))\n",
|
399 |
"\n",
|
400 |
" 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",
|
401 |
" if len(ms_chords_counts) == 0:\n",
|
402 |
" ms_chords_counts = [[[0, 0], 0]]\n",
|
403 |
+
"\n",
|
404 |
" total_number_of_chords = len(set([y[1] for y in events_matrix1]))\n",
|
405 |
+
"\n",
|
406 |
" tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])\n",
|
407 |
+
"\n",
|
408 |
" thirty_second_note = [e for e in events_matrix1][32]\n",
|
409 |
" thirty_second_note_idx = full_events_matrix.index(thirty_second_note)\n",
|
410 |
"\n",
|
|
|
428 |
" data.append(['midi_ticks', score[0]])\n",
|
429 |
" data.extend(full_events_matrix[:thirty_second_note_idx])\n",
|
430 |
" data.append(full_events_matrix[-1])\n",
|
431 |
+
"\n",
|
432 |
" melody_chords_f.append([fn1, data])\n",
|
433 |
"\n",
|
434 |
" #=======================================================\n",
|
|
|
451 |
"\n",
|
452 |
" except KeyboardInterrupt:\n",
|
453 |
" print('Saving current progress and quitting...')\n",
|
454 |
+
" break\n",
|
455 |
"\n",
|
456 |
" except Exception as ex:\n",
|
457 |
" print('WARNING !!!')\n",
|
|
|
472 |
"\n",
|
473 |
"# Displaying resulting processing stats...\n",
|
474 |
"print('=' * 70)\n",
|
475 |
+
"print('Done!')\n",
|
476 |
"print('=' * 70)\n",
|
477 |
"\n",
|
478 |
"print('Resulting Stats:')\n",
|
|
|
520 |
" print('=' * 70)\n",
|
521 |
" print('Loaded file:', f)\n",
|
522 |
" print('=' * 70)\n",
|
523 |
+
"\n",
|
524 |
"print('Done!')\n",
|
525 |
"print('=' * 70)\n",
|
526 |
"print('Randomizing metadata entries order...')\n",
|
Los_Angeles_MIDI_Dataset_Search_and_Explore.ipynb
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
-
"# Los Angeles MIDI Dataset: Search and Explore (ver. 3.
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
@@ -207,7 +207,7 @@
|
|
207 |
"print('=' * 70)\n",
|
208 |
"\n",
|
209 |
"hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',\n",
|
210 |
-
" filename='Los-Angeles-MIDI-Dataset-Ver-3-
|
211 |
" repo_type=\"dataset\",\n",
|
212 |
" local_dir='/content/LAMD',\n",
|
213 |
" local_dir_use_symlinks=False)\n",
|
@@ -230,7 +230,7 @@
|
|
230 |
"\n",
|
231 |
"print('=' * 70)\n",
|
232 |
"print('Unzipping Los Angeles MIDI Dataset...Please wait...')\n",
|
233 |
-
"!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-
|
234 |
"print('=' * 70)\n",
|
235 |
"\n",
|
236 |
"print('Done! Enjoy! :)')\n",
|
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
+
"# Los Angeles MIDI Dataset: Search and Explore (ver. 3.1)\n",
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
|
|
207 |
"print('=' * 70)\n",
|
208 |
"\n",
|
209 |
"hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',\n",
|
210 |
+
" filename='Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip',\n",
|
211 |
" repo_type=\"dataset\",\n",
|
212 |
" local_dir='/content/LAMD',\n",
|
213 |
" local_dir_use_symlinks=False)\n",
|
|
|
230 |
"\n",
|
231 |
"print('=' * 70)\n",
|
232 |
"print('Unzipping Los Angeles MIDI Dataset...Please wait...')\n",
|
233 |
+
"!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip'\n",
|
234 |
"print('=' * 70)\n",
|
235 |
"\n",
|
236 |
"print('Done! Enjoy! :)')\n",
|
Master_MIDI_Dataset_Search_and_Filter.ipynb
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
-
"# Master MIDI Dataset Search and Filter (ver. 3.
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
@@ -135,7 +135,7 @@
|
|
135 |
"print('=' * 70)\n",
|
136 |
"\n",
|
137 |
"hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',\n",
|
138 |
-
" filename='Los-Angeles-MIDI-Dataset-Ver-3-
|
139 |
" repo_type=\"dataset\",\n",
|
140 |
" local_dir='/content/Main-MIDI-Dataset',\n",
|
141 |
" local_dir_use_symlinks=False)\n",
|
@@ -158,7 +158,7 @@
|
|
158 |
"\n",
|
159 |
"print('=' * 70)\n",
|
160 |
"print('Unzipping Los Angeles MIDI Dataset...Please wait...')\n",
|
161 |
-
"!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-
|
162 |
"print('=' * 70)\n",
|
163 |
"\n",
|
164 |
"print('Done! Enjoy! :)')\n",
|
|
|
11 |
"id": "SiTIpPjArIyr"
|
12 |
},
|
13 |
"source": [
|
14 |
+
"# Master MIDI Dataset Search and Filter (ver. 3.1)\n",
|
15 |
"\n",
|
16 |
"***\n",
|
17 |
"\n",
|
|
|
135 |
"print('=' * 70)\n",
|
136 |
"\n",
|
137 |
"hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',\n",
|
138 |
+
" filename='Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip',\n",
|
139 |
" repo_type=\"dataset\",\n",
|
140 |
" local_dir='/content/Main-MIDI-Dataset',\n",
|
141 |
" local_dir_use_symlinks=False)\n",
|
|
|
158 |
"\n",
|
159 |
"print('=' * 70)\n",
|
160 |
"print('Unzipping Los Angeles MIDI Dataset...Please wait...')\n",
|
161 |
+
"!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip'\n",
|
162 |
"print('=' * 70)\n",
|
163 |
"\n",
|
164 |
"print('Done! Enjoy! :)')\n",
|
TMIDIX.py
CHANGED
@@ -278,6 +278,73 @@ then opus2score()
|
|
278 |
'''
|
279 |
return opus2score(to_millisecs(midi2opus(midi)))
|
280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
#------------------------ Other Transformations ---------------------
|
282 |
|
283 |
def to_millisecs(old_opus=None, desired_time_in_ms=1):
|
@@ -1499,7 +1566,8 @@ def Tegridy_SONG_to_MIDI_Converter(SONG,
|
|
1499 |
number_of_ticks_per_quarter = 425,
|
1500 |
list_of_MIDI_patches = [0, 24, 32, 40, 42, 46, 56, 71, 73, 0, 0, 0, 0, 0, 0, 0],
|
1501 |
output_file_name = 'TMIDI-Composition',
|
1502 |
-
text_encoding='ISO-8859-1'
|
|
|
1503 |
|
1504 |
'''Tegridy SONG to MIDI Converter
|
1505 |
|
@@ -1516,8 +1584,9 @@ def Tegridy_SONG_to_MIDI_Converter(SONG,
|
|
1516 |
|
1517 |
Project Los Angeles
|
1518 |
Tegridy Code 2020'''
|
1519 |
-
|
1520 |
-
|
|
|
1521 |
|
1522 |
output_header = [number_of_ticks_per_quarter,
|
1523 |
[['track_name', 0, bytes(output_signature, text_encoding)]]]
|
@@ -1549,7 +1618,55 @@ def Tegridy_SONG_to_MIDI_Converter(SONG,
|
|
1549 |
midi_file.write(midi_data)
|
1550 |
midi_file.close()
|
1551 |
|
1552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1553 |
|
1554 |
return detailed_MIDI_stats
|
1555 |
|
|
|
278 |
'''
|
279 |
return opus2score(to_millisecs(midi2opus(midi)))
|
280 |
|
281 |
+
def midi2single_track_ms_score(midi=b'', recalculate_channels = True, verbose = False):
|
282 |
+
r'''
|
283 |
+
Translates MIDI into a single track "score" with 16 instruments and one beat per second and one
|
284 |
+
tick per millisecond
|
285 |
+
'''
|
286 |
+
|
287 |
+
score = midi2score(midi)
|
288 |
+
|
289 |
+
if recalculate_channels:
|
290 |
+
|
291 |
+
events_matrixes = []
|
292 |
+
|
293 |
+
itrack = 1
|
294 |
+
events_matrixes_channels = []
|
295 |
+
while itrack < len(score):
|
296 |
+
events_matrix = []
|
297 |
+
for event in score[itrack]:
|
298 |
+
if event[0] == 'note' and event[3] != 9:
|
299 |
+
event[3] = (16 * (itrack-1)) + event[3]
|
300 |
+
if event[3] not in events_matrixes_channels:
|
301 |
+
events_matrixes_channels.append(event[3])
|
302 |
+
|
303 |
+
events_matrix.append(event)
|
304 |
+
events_matrixes.append(events_matrix)
|
305 |
+
itrack += 1
|
306 |
+
|
307 |
+
events_matrix1 = []
|
308 |
+
for e in events_matrixes:
|
309 |
+
events_matrix1.extend(e)
|
310 |
+
|
311 |
+
if verbose:
|
312 |
+
if len(events_matrixes_channels) > 16:
|
313 |
+
print('MIDI has', len(events_matrixes_channels), 'instruments!', len(events_matrixes_channels) - 16, 'instrument(s) will be removed!')
|
314 |
+
|
315 |
+
for e in events_matrix1:
|
316 |
+
if e[0] == 'note' and e[3] != 9:
|
317 |
+
if e[3] in events_matrixes_channels[:15]:
|
318 |
+
if events_matrixes_channels[:15].index(e[3]) < 9:
|
319 |
+
e[3] = events_matrixes_channels[:15].index(e[3])
|
320 |
+
else:
|
321 |
+
e[3] = events_matrixes_channels[:15].index(e[3])+1
|
322 |
+
else:
|
323 |
+
events_matrix1.remove(e)
|
324 |
+
|
325 |
+
if e[0] in ['patch_change', 'control_change', 'channel_after_touch', 'key_after_touch', 'pitch_wheel_change'] and e[2] != 9:
|
326 |
+
if e[2] in [e % 16 for e in events_matrixes_channels[:15]]:
|
327 |
+
if [e % 16 for e in events_matrixes_channels[:15]].index(e[2]) < 9:
|
328 |
+
e[2] = [e % 16 for e in events_matrixes_channels[:15]].index(e[2])
|
329 |
+
else:
|
330 |
+
e[2] = [e % 16 for e in events_matrixes_channels[:15]].index(e[2])+1
|
331 |
+
else:
|
332 |
+
events_matrix1.remove(e)
|
333 |
+
|
334 |
+
else:
|
335 |
+
events_matrix1 = []
|
336 |
+
itrack = 1
|
337 |
+
|
338 |
+
while itrack < len(score):
|
339 |
+
for event in score[itrack]:
|
340 |
+
events_matrix1.append(event)
|
341 |
+
itrack += 1
|
342 |
+
|
343 |
+
opus = score2opus([score[0], events_matrix1])
|
344 |
+
ms_score = opus2score(to_millisecs(opus))
|
345 |
+
|
346 |
+
return ms_score
|
347 |
+
|
348 |
#------------------------ Other Transformations ---------------------
|
349 |
|
350 |
def to_millisecs(old_opus=None, desired_time_in_ms=1):
|
|
|
1566 |
number_of_ticks_per_quarter = 425,
|
1567 |
list_of_MIDI_patches = [0, 24, 32, 40, 42, 46, 56, 71, 73, 0, 0, 0, 0, 0, 0, 0],
|
1568 |
output_file_name = 'TMIDI-Composition',
|
1569 |
+
text_encoding='ISO-8859-1',
|
1570 |
+
verbose=True):
|
1571 |
|
1572 |
'''Tegridy SONG to MIDI Converter
|
1573 |
|
|
|
1584 |
|
1585 |
Project Los Angeles
|
1586 |
Tegridy Code 2020'''
|
1587 |
+
|
1588 |
+
if verbose:
|
1589 |
+
print('Converting to MIDI. Please stand-by...')
|
1590 |
|
1591 |
output_header = [number_of_ticks_per_quarter,
|
1592 |
[['track_name', 0, bytes(output_signature, text_encoding)]]]
|
|
|
1618 |
midi_file.write(midi_data)
|
1619 |
midi_file.close()
|
1620 |
|
1621 |
+
if verbose:
|
1622 |
+
print('Done! Enjoy! :)')
|
1623 |
+
|
1624 |
+
return detailed_MIDI_stats
|
1625 |
+
###################################################################################
|
1626 |
+
|
1627 |
+
def Tegridy_SONG_to_Full_MIDI_Converter(SONG,
|
1628 |
+
output_signature = 'Tegridy TMIDI Module',
|
1629 |
+
track_name = 'Composition Track',
|
1630 |
+
number_of_ticks_per_quarter = 1000,
|
1631 |
+
output_file_name = 'TMIDI-Composition',
|
1632 |
+
text_encoding='ISO-8859-1',
|
1633 |
+
verbose=True):
|
1634 |
+
|
1635 |
+
'''Tegridy SONG to Full MIDI Converter
|
1636 |
+
|
1637 |
+
Input: Input SONG in Full TMIDI SONG/MIDI.py Score format
|
1638 |
+
Output MIDI Track 0 name / MIDI Signature
|
1639 |
+
Output MIDI Track 1 name / Composition track name
|
1640 |
+
Number of ticks per quarter for the output MIDI
|
1641 |
+
Output file name w/o .mid extension.
|
1642 |
+
Optional text encoding if you are working with text_events/lyrics. This is especially useful for Karaoke. Please note that anything but ISO-8859-1 is a non-standard way of encoding text_events according to MIDI specs.
|
1643 |
+
|
1644 |
+
Output: MIDI File
|
1645 |
+
Detailed MIDI stats
|
1646 |
+
|
1647 |
+
Project Los Angeles
|
1648 |
+
Tegridy Code 2023'''
|
1649 |
+
|
1650 |
+
if verbose:
|
1651 |
+
print('Converting to MIDI. Please stand-by...')
|
1652 |
+
|
1653 |
+
output_header = [number_of_ticks_per_quarter,
|
1654 |
+
[['set_tempo', 0, 1000000],
|
1655 |
+
['track_name', 0, bytes(output_signature, text_encoding)]]]
|
1656 |
+
|
1657 |
+
song_track = [['track_name', 0, bytes(track_name, text_encoding)]]
|
1658 |
+
|
1659 |
+
output = output_header + [song_track + SONG]
|
1660 |
+
|
1661 |
+
midi_data = score2midi(output, text_encoding)
|
1662 |
+
detailed_MIDI_stats = score2stats(output)
|
1663 |
+
|
1664 |
+
with open(output_file_name + '.mid', 'wb') as midi_file:
|
1665 |
+
midi_file.write(midi_data)
|
1666 |
+
midi_file.close()
|
1667 |
+
|
1668 |
+
if verbose:
|
1669 |
+
print('Done! Enjoy! :)')
|
1670 |
|
1671 |
return detailed_MIDI_stats
|
1672 |
|
los_angeles_midi_dataset_maker.py
CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
|
|
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.
|
10 |
|
11 |
***
|
12 |
|
@@ -139,12 +139,12 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
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()
|
@@ -161,7 +161,7 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
161 |
itrack = 1
|
162 |
|
163 |
while itrack < len(score):
|
164 |
-
for event in score[itrack]:
|
165 |
events_matrix.append(event)
|
166 |
itrack += 1
|
167 |
|
@@ -179,13 +179,18 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
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:
|
@@ -196,19 +201,17 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
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')
|
@@ -218,10 +221,10 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
218 |
files_count += 1
|
219 |
|
220 |
#=======================================================
|
221 |
-
|
222 |
except KeyboardInterrupt:
|
223 |
print('Saving current progress and quitting...')
|
224 |
-
break
|
225 |
|
226 |
except Exception as ex:
|
227 |
print('WARNING !!!')
|
@@ -235,11 +238,11 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
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)
|
244 |
|
245 |
print('Resulting Stats:')
|
|
|
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.1)
|
10 |
|
11 |
***
|
12 |
|
|
|
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()
|
|
|
161 |
itrack = 1
|
162 |
|
163 |
while itrack < len(score):
|
164 |
+
for event in score[itrack]:
|
165 |
events_matrix.append(event)
|
166 |
itrack += 1
|
167 |
|
|
|
179 |
|
180 |
if str(md5sum) not in all_md5_names:
|
181 |
|
182 |
+
all_md5_names.append(str(md5sum))
|
183 |
+
|
184 |
pitches = [n[4] for n in notes]
|
185 |
pitches_sum = sum(pitches)
|
186 |
|
187 |
if pitches_sum not in all_pitches_sums:
|
188 |
+
|
189 |
+
all_pitches_sums.append(pitches_sum)
|
190 |
+
|
191 |
pitches_and_counts = sorted([[key, val] for key,val in Counter(pitches).most_common()], reverse=True, key = lambda x: x[1])
|
192 |
pitches_counts = [p[1] for p in pitches_and_counts]
|
193 |
+
|
194 |
#=======================================================
|
195 |
|
196 |
if pitches_counts not in all_pitches_counts:
|
|
|
201 |
print('=' * 70)
|
202 |
print('Saving processed data...')
|
203 |
print('=' * 70)
|
204 |
+
TMIDIX.Tegridy_Any_Pickle_File_Writer([filez, all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')
|
205 |
print('=' * 70)
|
206 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
207 |
print('=' * 70)
|
208 |
+
|
209 |
|
210 |
shutil.copy2(f, '/content/Output/'+str(md5name[0])+'/'+md5name)
|
211 |
|
|
|
|
|
212 |
all_pitches_counts.append(pitches_counts)
|
213 |
all_pitches_and_counts.append(pitches_and_counts)
|
214 |
+
|
215 |
if files_count % 1000 == 0:
|
216 |
print('=' * 70)
|
217 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
|
|
221 |
files_count += 1
|
222 |
|
223 |
#=======================================================
|
224 |
+
|
225 |
except KeyboardInterrupt:
|
226 |
print('Saving current progress and quitting...')
|
227 |
+
break
|
228 |
|
229 |
except Exception as ex:
|
230 |
print('WARNING !!!')
|
|
|
238 |
print('=' * 70)
|
239 |
print('Saving processed data...')
|
240 |
print('=' * 70)
|
241 |
+
TMIDIX.Tegridy_Any_Pickle_File_Writer([filez, all_md5_names, all_pitches_sums, all_pitches_and_counts], '/content/Output/all_files_data')
|
242 |
print('=' * 70)
|
243 |
print('Processed so far:', files_count, 'out of', input_files_count, '===', files_count / input_files_count, 'good files ratio')
|
244 |
print('=' * 70)
|
245 |
+
print('Done!')
|
246 |
print('=' * 70)
|
247 |
|
248 |
print('Resulting Stats:')
|
los_angeles_midi_dataset_metadata_maker.py
CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
|
|
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.
|
10 |
|
11 |
***
|
12 |
|
@@ -133,34 +133,34 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
133 |
|
134 |
#=======================================================
|
135 |
# START PROCESSING
|
136 |
-
|
137 |
opus = TMIDIX.midi2opus(open(f, 'rb').read())
|
138 |
-
|
139 |
opus_events_matrix = []
|
140 |
-
|
141 |
itrack0 = 1
|
142 |
-
|
143 |
while itrack0 < len(opus):
|
144 |
-
for event in opus[itrack0]:
|
145 |
opus_events_matrix.append(event)
|
146 |
itrack0 += 1
|
147 |
-
|
148 |
#=======================================================
|
149 |
-
|
150 |
ms_score = TMIDIX.opus2score(TMIDIX.to_millisecs(opus))
|
151 |
|
152 |
ms_events_matrix = []
|
153 |
-
|
154 |
itrack1 = 1
|
155 |
-
|
156 |
while itrack1 < len(ms_score):
|
157 |
-
for event in ms_score[itrack1]:
|
158 |
if event[0] == 'note':
|
159 |
ms_events_matrix.append(event)
|
160 |
itrack1 += 1
|
161 |
|
162 |
ms_events_matrix.sort(key=lambda x: x[1])
|
163 |
-
|
164 |
#=======================================================
|
165 |
|
166 |
# Convering MIDI to score with MIDI.py module
|
@@ -170,20 +170,20 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
170 |
|
171 |
events_matrix = []
|
172 |
full_events_matrix = []
|
173 |
-
|
174 |
itrack = 1
|
175 |
patches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
176 |
|
177 |
while itrack < len(score):
|
178 |
-
for event in score[itrack]:
|
179 |
if event[0] == 'note' or event[0] == 'patch_change':
|
180 |
events_matrix.append(event)
|
181 |
full_events_matrix.append(event)
|
182 |
itrack += 1
|
183 |
-
|
184 |
full_events_matrix.sort(key=lambda x: x[1])
|
185 |
events_matrix.sort(key=lambda x: x[1])
|
186 |
-
|
187 |
events_matrix1 = []
|
188 |
|
189 |
for event in events_matrix:
|
@@ -194,8 +194,8 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
194 |
event.extend([patches[event[3]]])
|
195 |
events_matrix1.append(event)
|
196 |
|
197 |
-
if len(events_matrix1) > 32:
|
198 |
-
|
199 |
events_matrix1.sort(key=lambda x: x[1])
|
200 |
|
201 |
for e in events_matrix1:
|
@@ -207,15 +207,15 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
207 |
|
208 |
pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]
|
209 |
pitches_counts.sort(key=lambda x: x[0], reverse=True)
|
210 |
-
|
211 |
patches = sorted([y[6] for y in events_matrix1])
|
212 |
patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]
|
213 |
patches_counts.sort(key = lambda x: x[0])
|
214 |
-
|
215 |
midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))
|
216 |
if len(midi_patches) == 0:
|
217 |
midi_patches = [0]
|
218 |
-
|
219 |
times = []
|
220 |
pt = ms_events_matrix[0][1]
|
221 |
start = True
|
@@ -224,37 +224,37 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
224 |
times.append((e[1]-pt))
|
225 |
start = False
|
226 |
pt = e[1]
|
227 |
-
|
228 |
times_sum = min(10000000, sum(times))
|
229 |
-
|
230 |
durs = [e[2] for e in ms_events_matrix]
|
231 |
vels = [e[5] for e in ms_events_matrix]
|
232 |
-
|
233 |
avg_time = int(sum(times) / len(times))
|
234 |
avg_dur = int(sum(durs) / len(durs))
|
235 |
avg_vel = int(sum(vels) / len(vels))
|
236 |
-
|
237 |
mode_time = statistics.mode(times)
|
238 |
mode_dur = statistics.mode(durs)
|
239 |
mode_vel = statistics.mode(vels)
|
240 |
-
|
241 |
median_time = int(statistics.median(times))
|
242 |
median_dur = int(statistics.median(durs))
|
243 |
median_vel = int(statistics.median(vels))
|
244 |
-
|
245 |
-
text_events_list = ['text_event',
|
246 |
-
'text_event_08',
|
247 |
-
'text_event_09',
|
248 |
-
'text_event_0a',
|
249 |
-
'text_event_0b',
|
250 |
'text_event_0c',
|
251 |
'text_event_0d',
|
252 |
'text_event_0e',
|
253 |
'text_event_0f']
|
254 |
-
|
255 |
text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])
|
256 |
lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])
|
257 |
-
|
258 |
chords = []
|
259 |
pe = ms_events_matrix[0]
|
260 |
cho = []
|
@@ -272,18 +272,18 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
272 |
cho.append(e[4] % 12)
|
273 |
|
274 |
pe = e
|
275 |
-
|
276 |
if len(cho) > 0:
|
277 |
chords.append(sorted(cho))
|
278 |
|
279 |
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])
|
280 |
if len(ms_chords_counts) == 0:
|
281 |
ms_chords_counts = [[[0, 0], 0]]
|
282 |
-
|
283 |
total_number_of_chords = len(set([y[1] for y in events_matrix1]))
|
284 |
-
|
285 |
tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])
|
286 |
-
|
287 |
thirty_second_note = [e for e in events_matrix1][32]
|
288 |
thirty_second_note_idx = full_events_matrix.index(thirty_second_note)
|
289 |
|
@@ -307,7 +307,7 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
307 |
data.append(['midi_ticks', score[0]])
|
308 |
data.extend(full_events_matrix[:thirty_second_note_idx])
|
309 |
data.append(full_events_matrix[-1])
|
310 |
-
|
311 |
melody_chords_f.append([fn1, data])
|
312 |
|
313 |
#=======================================================
|
@@ -330,7 +330,7 @@ for f in tqdm(filez[START_FILE_NUMBER:]):
|
|
330 |
|
331 |
except KeyboardInterrupt:
|
332 |
print('Saving current progress and quitting...')
|
333 |
-
break
|
334 |
|
335 |
except Exception as ex:
|
336 |
print('WARNING !!!')
|
@@ -351,7 +351,7 @@ TMIDIX.Tegridy_Any_Pickle_File_Writer(melody_chords_f, '/content/drive/MyDrive/L
|
|
351 |
|
352 |
# Displaying resulting processing stats...
|
353 |
print('=' * 70)
|
354 |
-
print('Done!')
|
355 |
print('=' * 70)
|
356 |
|
357 |
print('Resulting Stats:')
|
@@ -388,7 +388,7 @@ for f in tqdm(filez):
|
|
388 |
print('=' * 70)
|
389 |
print('Loaded file:', f)
|
390 |
print('=' * 70)
|
391 |
-
|
392 |
print('Done!')
|
393 |
print('=' * 70)
|
394 |
print('Randomizing metadata entries order...')
|
|
|
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.1)
|
10 |
|
11 |
***
|
12 |
|
|
|
133 |
|
134 |
#=======================================================
|
135 |
# START PROCESSING
|
136 |
+
|
137 |
opus = TMIDIX.midi2opus(open(f, 'rb').read())
|
138 |
+
|
139 |
opus_events_matrix = []
|
140 |
+
|
141 |
itrack0 = 1
|
142 |
+
|
143 |
while itrack0 < len(opus):
|
144 |
+
for event in opus[itrack0]:
|
145 |
opus_events_matrix.append(event)
|
146 |
itrack0 += 1
|
147 |
+
|
148 |
#=======================================================
|
149 |
+
|
150 |
ms_score = TMIDIX.opus2score(TMIDIX.to_millisecs(opus))
|
151 |
|
152 |
ms_events_matrix = []
|
153 |
+
|
154 |
itrack1 = 1
|
155 |
+
|
156 |
while itrack1 < len(ms_score):
|
157 |
+
for event in ms_score[itrack1]:
|
158 |
if event[0] == 'note':
|
159 |
ms_events_matrix.append(event)
|
160 |
itrack1 += 1
|
161 |
|
162 |
ms_events_matrix.sort(key=lambda x: x[1])
|
163 |
+
|
164 |
#=======================================================
|
165 |
|
166 |
# Convering MIDI to score with MIDI.py module
|
|
|
170 |
|
171 |
events_matrix = []
|
172 |
full_events_matrix = []
|
173 |
+
|
174 |
itrack = 1
|
175 |
patches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
176 |
|
177 |
while itrack < len(score):
|
178 |
+
for event in score[itrack]:
|
179 |
if event[0] == 'note' or event[0] == 'patch_change':
|
180 |
events_matrix.append(event)
|
181 |
full_events_matrix.append(event)
|
182 |
itrack += 1
|
183 |
+
|
184 |
full_events_matrix.sort(key=lambda x: x[1])
|
185 |
events_matrix.sort(key=lambda x: x[1])
|
186 |
+
|
187 |
events_matrix1 = []
|
188 |
|
189 |
for event in events_matrix:
|
|
|
194 |
event.extend([patches[event[3]]])
|
195 |
events_matrix1.append(event)
|
196 |
|
197 |
+
if len(events_matrix1) > 32:
|
198 |
+
|
199 |
events_matrix1.sort(key=lambda x: x[1])
|
200 |
|
201 |
for e in events_matrix1:
|
|
|
207 |
|
208 |
pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix1]).most_common()]
|
209 |
pitches_counts.sort(key=lambda x: x[0], reverse=True)
|
210 |
+
|
211 |
patches = sorted([y[6] for y in events_matrix1])
|
212 |
patches_counts = [[y[0], y[1]] for y in Counter(patches).most_common()]
|
213 |
patches_counts.sort(key = lambda x: x[0])
|
214 |
+
|
215 |
midi_patches = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))
|
216 |
if len(midi_patches) == 0:
|
217 |
midi_patches = [0]
|
218 |
+
|
219 |
times = []
|
220 |
pt = ms_events_matrix[0][1]
|
221 |
start = True
|
|
|
224 |
times.append((e[1]-pt))
|
225 |
start = False
|
226 |
pt = e[1]
|
227 |
+
|
228 |
times_sum = min(10000000, sum(times))
|
229 |
+
|
230 |
durs = [e[2] for e in ms_events_matrix]
|
231 |
vels = [e[5] for e in ms_events_matrix]
|
232 |
+
|
233 |
avg_time = int(sum(times) / len(times))
|
234 |
avg_dur = int(sum(durs) / len(durs))
|
235 |
avg_vel = int(sum(vels) / len(vels))
|
236 |
+
|
237 |
mode_time = statistics.mode(times)
|
238 |
mode_dur = statistics.mode(durs)
|
239 |
mode_vel = statistics.mode(vels)
|
240 |
+
|
241 |
median_time = int(statistics.median(times))
|
242 |
median_dur = int(statistics.median(durs))
|
243 |
median_vel = int(statistics.median(vels))
|
244 |
+
|
245 |
+
text_events_list = ['text_event',
|
246 |
+
'text_event_08',
|
247 |
+
'text_event_09',
|
248 |
+
'text_event_0a',
|
249 |
+
'text_event_0b',
|
250 |
'text_event_0c',
|
251 |
'text_event_0d',
|
252 |
'text_event_0e',
|
253 |
'text_event_0f']
|
254 |
+
|
255 |
text_events_count = len([e for e in full_events_matrix if e[0] in text_events_list])
|
256 |
lyric_events_count = len([e for e in full_events_matrix if e[0] == 'lyric'])
|
257 |
+
|
258 |
chords = []
|
259 |
pe = ms_events_matrix[0]
|
260 |
cho = []
|
|
|
272 |
cho.append(e[4] % 12)
|
273 |
|
274 |
pe = e
|
275 |
+
|
276 |
if len(cho) > 0:
|
277 |
chords.append(sorted(cho))
|
278 |
|
279 |
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])
|
280 |
if len(ms_chords_counts) == 0:
|
281 |
ms_chords_counts = [[[0, 0], 0]]
|
282 |
+
|
283 |
total_number_of_chords = len(set([y[1] for y in events_matrix1]))
|
284 |
+
|
285 |
tempo_change_count = len([f for f in full_events_matrix if f[0] == 'set_tempo'])
|
286 |
+
|
287 |
thirty_second_note = [e for e in events_matrix1][32]
|
288 |
thirty_second_note_idx = full_events_matrix.index(thirty_second_note)
|
289 |
|
|
|
307 |
data.append(['midi_ticks', score[0]])
|
308 |
data.extend(full_events_matrix[:thirty_second_note_idx])
|
309 |
data.append(full_events_matrix[-1])
|
310 |
+
|
311 |
melody_chords_f.append([fn1, data])
|
312 |
|
313 |
#=======================================================
|
|
|
330 |
|
331 |
except KeyboardInterrupt:
|
332 |
print('Saving current progress and quitting...')
|
333 |
+
break
|
334 |
|
335 |
except Exception as ex:
|
336 |
print('WARNING !!!')
|
|
|
351 |
|
352 |
# Displaying resulting processing stats...
|
353 |
print('=' * 70)
|
354 |
+
print('Done!')
|
355 |
print('=' * 70)
|
356 |
|
357 |
print('Resulting Stats:')
|
|
|
388 |
print('=' * 70)
|
389 |
print('Loaded file:', f)
|
390 |
print('=' * 70)
|
391 |
+
|
392 |
print('Done!')
|
393 |
print('=' * 70)
|
394 |
print('Randomizing metadata entries order...')
|
los_angeles_midi_dataset_search_and_explore.py
CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
|
|
6 |
Original file is located at
|
7 |
https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Los_Angeles_MIDI_Dataset_Search_and_Explore.ipynb
|
8 |
|
9 |
-
# Los Angeles MIDI Dataset: Search and Explore (ver. 3.
|
10 |
|
11 |
***
|
12 |
|
@@ -124,7 +124,7 @@ print('Downloading Los Angeles MIDI Dataset...Please wait...')
|
|
124 |
print('=' * 70)
|
125 |
|
126 |
hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',
|
127 |
-
filename='Los-Angeles-MIDI-Dataset-Ver-3-
|
128 |
repo_type="dataset",
|
129 |
local_dir='/content/LAMD',
|
130 |
local_dir_use_symlinks=False)
|
@@ -138,7 +138,7 @@ print('=' * 70)
|
|
138 |
|
139 |
print('=' * 70)
|
140 |
print('Unzipping Los Angeles MIDI Dataset...Please wait...')
|
141 |
-
!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-
|
142 |
print('=' * 70)
|
143 |
|
144 |
print('Done! Enjoy! :)')
|
|
|
6 |
Original file is located at
|
7 |
https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Los_Angeles_MIDI_Dataset_Search_and_Explore.ipynb
|
8 |
|
9 |
+
# Los Angeles MIDI Dataset: Search and Explore (ver. 3.1)
|
10 |
|
11 |
***
|
12 |
|
|
|
124 |
print('=' * 70)
|
125 |
|
126 |
hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',
|
127 |
+
filename='Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip',
|
128 |
repo_type="dataset",
|
129 |
local_dir='/content/LAMD',
|
130 |
local_dir_use_symlinks=False)
|
|
|
138 |
|
139 |
print('=' * 70)
|
140 |
print('Unzipping Los Angeles MIDI Dataset...Please wait...')
|
141 |
+
!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip'
|
142 |
print('=' * 70)
|
143 |
|
144 |
print('Done! Enjoy! :)')
|
master_midi_dataset_search_and_filter.py
CHANGED
@@ -6,7 +6,7 @@ Automatically generated by Colaboratory.
|
|
6 |
Original file is located at
|
7 |
https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Extras/Master_MIDI_Dataset_Search_and_Filter.ipynb
|
8 |
|
9 |
-
# Master MIDI Dataset Search and Filter (ver. 3.
|
10 |
|
11 |
***
|
12 |
|
@@ -73,7 +73,7 @@ print('Downloading Los Angeles MIDI Dataset...Please wait...')
|
|
73 |
print('=' * 70)
|
74 |
|
75 |
hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',
|
76 |
-
filename='Los-Angeles-MIDI-Dataset-Ver-3-
|
77 |
repo_type="dataset",
|
78 |
local_dir='/content/Main-MIDI-Dataset',
|
79 |
local_dir_use_symlinks=False)
|
@@ -87,7 +87,7 @@ print('=' * 70)
|
|
87 |
|
88 |
print('=' * 70)
|
89 |
print('Unzipping Los Angeles MIDI Dataset...Please wait...')
|
90 |
-
!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-
|
91 |
print('=' * 70)
|
92 |
|
93 |
print('Done! Enjoy! :)')
|
|
|
6 |
Original file is located at
|
7 |
https://colab.research.google.com/github/asigalov61/Los-Angeles-MIDI-Dataset/blob/main/Extras/Master_MIDI_Dataset_Search_and_Filter.ipynb
|
8 |
|
9 |
+
# Master MIDI Dataset Search and Filter (ver. 3.1)
|
10 |
|
11 |
***
|
12 |
|
|
|
73 |
print('=' * 70)
|
74 |
|
75 |
hf_hub_download(repo_id='projectlosangeles/Los-Angeles-MIDI-Dataset',
|
76 |
+
filename='Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip',
|
77 |
repo_type="dataset",
|
78 |
local_dir='/content/Main-MIDI-Dataset',
|
79 |
local_dir_use_symlinks=False)
|
|
|
87 |
|
88 |
print('=' * 70)
|
89 |
print('Unzipping Los Angeles MIDI Dataset...Please wait...')
|
90 |
+
!unzip 'Los-Angeles-MIDI-Dataset-Ver-3-1-CC-BY-NC-SA.zip'
|
91 |
print('=' * 70)
|
92 |
|
93 |
print('Done! Enjoy! :)')
|