projectlosangeles commited on
Commit
968d976
1 Parent(s): b6d498e

Upload 2 files

Browse files
Los_Angeles_MIDI_Dataset_Search_and_Explore.ipynb CHANGED
@@ -519,13 +519,21 @@
519
  " \n",
520
  "events_matrix.sort(key=lambda x: x[1])\n",
521
  "\n",
522
- "for e in events_matrix:\n",
523
- " if e[0] == 'note':\n",
524
- " if e[3] == 9:\n",
525
- " e[4] = ((e[4] % 128) + 128)\n",
526
  "\n",
527
- "pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix if y[0] == 'note']).most_common()]\n",
528
- "pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
 
 
 
 
 
 
 
 
 
 
 
529
  "\n",
530
  "patches_list = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
531
  "\n",
@@ -881,6 +889,7 @@
881
  "\n",
882
  "maximum_match_ratio_to_search_for = 1 #@param {type:\"slider\", min:0, max:1, step:0.01}\n",
883
  "pitches_counts_cutoff_threshold_ratio = 0.2 #@param {type:\"slider\", min:0, max:1, step:0.05}\n",
 
884
  "skip_exact_matches = False #@param {type:\"boolean\"}\n",
885
  "render_MIDI_to_audio = False #@param {type:\"boolean\"}\n",
886
  "\n",
@@ -897,22 +906,33 @@
897
  " p_counts.sort(reverse = True, key = lambda x: x[1])\n",
898
  " max_p_count = p_counts[1][0]\n",
899
  " trimmed_p_counts = [y for y in p_counts if y[1] >= (max_p_count * pitches_counts_cutoff_threshold_ratio)] \n",
 
 
 
 
 
 
 
900
  "\n",
901
- " pitches_counts.sort(reverse = True, key = lambda x: x[1])\n",
902
- " max_pitches_count = pitches_counts[1][0]\n",
903
- " trimmed_pitches_counts = [y for y in pitches_counts if y[1] >= (max_pitches_count * pitches_counts_cutoff_threshold_ratio)] \n",
904
  "\n",
905
- " num_same_pitches = len(set([T[0] for T in trimmed_p_counts]) & set([m[0] for m in trimmed_pitches_counts]))\n",
906
- " same_pitches_ratio = (num_same_pitches / len(set([m[0] for m in trimmed_p_counts]+[T[0] for T in trimmed_pitches_counts])))\n",
 
907
  "\n",
908
- " if skip_exact_matches:\n",
909
- " if same_pitches_ratio == 1:\n",
 
 
 
 
 
 
910
  " same_pitches_ratio = 0\n",
911
  "\n",
912
- " if same_pitches_ratio > maximum_match_ratio_to_search_for:\n",
913
- " same_pitches_ratio = 0\n",
914
- " \n",
915
- " ratios.append(same_pitches_ratio)\n",
916
  " \n",
917
  " except KeyboardInterrupt:\n",
918
  " break\n",
 
519
  " \n",
520
  "events_matrix.sort(key=lambda x: x[1])\n",
521
  "\n",
522
+ "mult_pitches_counts = []\n",
 
 
 
523
  "\n",
524
+ "for i in range(-6, 6):\n",
525
+ "\n",
526
+ " for e in events_matrix:\n",
527
+ " if e[0] == 'note':\n",
528
+ " if e[3] == 9:\n",
529
+ " e[4] = ((e[4] % 128) + 128)\n",
530
+ " else:\n",
531
+ " e[4] = ((e[4] % 128) + i)\n",
532
+ "\n",
533
+ " pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix if y[0] == 'note']).most_common()]\n",
534
+ " pitches_counts.sort(key=lambda x: x[0], reverse=True)\n",
535
+ " \n",
536
+ " mult_pitches_counts.append(pitches_counts)\n",
537
  "\n",
538
  "patches_list = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))\n",
539
  "\n",
 
889
  "\n",
890
  "maximum_match_ratio_to_search_for = 1 #@param {type:\"slider\", min:0, max:1, step:0.01}\n",
891
  "pitches_counts_cutoff_threshold_ratio = 0.2 #@param {type:\"slider\", min:0, max:1, step:0.05}\n",
892
+ "search_transposed_pitches = False #@param {type:\"boolean\"}\n",
893
  "skip_exact_matches = False #@param {type:\"boolean\"}\n",
894
  "render_MIDI_to_audio = False #@param {type:\"boolean\"}\n",
895
  "\n",
 
906
  " p_counts.sort(reverse = True, key = lambda x: x[1])\n",
907
  " max_p_count = p_counts[1][0]\n",
908
  " trimmed_p_counts = [y for y in p_counts if y[1] >= (max_p_count * pitches_counts_cutoff_threshold_ratio)] \n",
909
+ " \n",
910
+ " if search_transposed_pitches:\n",
911
+ " search_pitches = mult_pitches_counts\n",
912
+ " else:\n",
913
+ " search_pitches = [mult_pitches_counts[6]]\n",
914
+ " \n",
915
+ " rat = []\n",
916
  "\n",
917
+ " for m in search_pitches:\n",
 
 
918
  "\n",
919
+ " m.sort(reverse = True, key = lambda x: x[1])\n",
920
+ " max_pitches_count = m[1][0]\n",
921
+ " trimmed_pitches_counts = [y for y in m if y[1] >= (max_pitches_count * pitches_counts_cutoff_threshold_ratio)] \n",
922
  "\n",
923
+ " num_same_pitches = len(set([T[0] for T in trimmed_p_counts]) & set([m[0] for m in trimmed_pitches_counts]))\n",
924
+ " same_pitches_ratio = (num_same_pitches / len(set([m[0] for m in trimmed_p_counts]+[T[0] for T in trimmed_pitches_counts])))\n",
925
+ "\n",
926
+ " if skip_exact_matches:\n",
927
+ " if same_pitches_ratio == 1:\n",
928
+ " same_pitches_ratio = 0\n",
929
+ "\n",
930
+ " if same_pitches_ratio > maximum_match_ratio_to_search_for:\n",
931
  " same_pitches_ratio = 0\n",
932
  "\n",
933
+ " rat.append(same_pitches_ratio)\n",
934
+ "\n",
935
+ " ratios.append(max(rat))\n",
 
936
  " \n",
937
  " except KeyboardInterrupt:\n",
938
  " break\n",
los_angeles_midi_dataset_search_and_explore.py CHANGED
@@ -383,13 +383,21 @@ for s in score:
383
 
384
  events_matrix.sort(key=lambda x: x[1])
385
 
386
- for e in events_matrix:
387
- if e[0] == 'note':
388
- if e[3] == 9:
389
- e[4] = ((e[4] % 128) + 128)
390
 
391
- pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix if y[0] == 'note']).most_common()]
392
- pitches_counts.sort(key=lambda x: x[0], reverse=True)
 
 
 
 
 
 
 
 
 
 
 
393
 
394
  patches_list = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))
395
 
@@ -718,6 +726,7 @@ print('=' * 70)
718
 
719
  maximum_match_ratio_to_search_for = 1 #@param {type:"slider", min:0, max:1, step:0.01}
720
  pitches_counts_cutoff_threshold_ratio = 0.2 #@param {type:"slider", min:0, max:1, step:0.05}
 
721
  skip_exact_matches = False #@param {type:"boolean"}
722
  render_MIDI_to_audio = False #@param {type:"boolean"}
723
 
@@ -734,22 +743,33 @@ for d in tqdm(meta_data):
734
  p_counts.sort(reverse = True, key = lambda x: x[1])
735
  max_p_count = p_counts[1][0]
736
  trimmed_p_counts = [y for y in p_counts if y[1] >= (max_p_count * pitches_counts_cutoff_threshold_ratio)]
 
 
 
 
 
 
 
737
 
738
- pitches_counts.sort(reverse = True, key = lambda x: x[1])
739
- max_pitches_count = pitches_counts[1][0]
740
- trimmed_pitches_counts = [y for y in pitches_counts if y[1] >= (max_pitches_count * pitches_counts_cutoff_threshold_ratio)]
741
 
742
- num_same_pitches = len(set([T[0] for T in trimmed_p_counts]) & set([m[0] for m in trimmed_pitches_counts]))
743
- same_pitches_ratio = (num_same_pitches / len(set([m[0] for m in trimmed_p_counts]+[T[0] for T in trimmed_pitches_counts])))
 
744
 
745
- if skip_exact_matches:
746
- if same_pitches_ratio == 1:
 
 
 
 
 
 
747
  same_pitches_ratio = 0
748
 
749
- if same_pitches_ratio > maximum_match_ratio_to_search_for:
750
- same_pitches_ratio = 0
751
-
752
- ratios.append(same_pitches_ratio)
753
 
754
  except KeyboardInterrupt:
755
  break
 
383
 
384
  events_matrix.sort(key=lambda x: x[1])
385
 
386
+ mult_pitches_counts = []
 
 
 
387
 
388
+ for i in range(-6, 6):
389
+
390
+ for e in events_matrix:
391
+ if e[0] == 'note':
392
+ if e[3] == 9:
393
+ e[4] = ((e[4] % 128) + 128)
394
+ else:
395
+ e[4] = ((e[4] % 128) + i)
396
+
397
+ pitches_counts = [[y[0],y[1]] for y in Counter([y[4] for y in events_matrix if y[0] == 'note']).most_common()]
398
+ pitches_counts.sort(key=lambda x: x[0], reverse=True)
399
+
400
+ mult_pitches_counts.append(pitches_counts)
401
 
402
  patches_list = sorted(list(set([y[3] for y in events_matrix if y[0] == 'patch_change'])))
403
 
 
726
 
727
  maximum_match_ratio_to_search_for = 1 #@param {type:"slider", min:0, max:1, step:0.01}
728
  pitches_counts_cutoff_threshold_ratio = 0.2 #@param {type:"slider", min:0, max:1, step:0.05}
729
+ search_transposed_pitches = False #@param {type:"boolean"}
730
  skip_exact_matches = False #@param {type:"boolean"}
731
  render_MIDI_to_audio = False #@param {type:"boolean"}
732
 
 
743
  p_counts.sort(reverse = True, key = lambda x: x[1])
744
  max_p_count = p_counts[1][0]
745
  trimmed_p_counts = [y for y in p_counts if y[1] >= (max_p_count * pitches_counts_cutoff_threshold_ratio)]
746
+
747
+ if search_transposed_pitches:
748
+ search_pitches = mult_pitches_counts
749
+ else:
750
+ search_pitches = [mult_pitches_counts[6]]
751
+
752
+ rat = []
753
 
754
+ for m in search_pitches:
 
 
755
 
756
+ m.sort(reverse = True, key = lambda x: x[1])
757
+ max_pitches_count = m[1][0]
758
+ trimmed_pitches_counts = [y for y in m if y[1] >= (max_pitches_count * pitches_counts_cutoff_threshold_ratio)]
759
 
760
+ num_same_pitches = len(set([T[0] for T in trimmed_p_counts]) & set([m[0] for m in trimmed_pitches_counts]))
761
+ same_pitches_ratio = (num_same_pitches / len(set([m[0] for m in trimmed_p_counts]+[T[0] for T in trimmed_pitches_counts])))
762
+
763
+ if skip_exact_matches:
764
+ if same_pitches_ratio == 1:
765
+ same_pitches_ratio = 0
766
+
767
+ if same_pitches_ratio > maximum_match_ratio_to_search_for:
768
  same_pitches_ratio = 0
769
 
770
+ rat.append(same_pitches_ratio)
771
+
772
+ ratios.append(max(rat))
 
773
 
774
  except KeyboardInterrupt:
775
  break