asigalov61 commited on
Commit
275b000
·
verified ·
1 Parent(s): 0c2c10c

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +165 -7
TMIDIX.py CHANGED
@@ -9677,16 +9677,41 @@ def escore_notes_to_text_description(escore_notes,
9677
  elif escore_averages[2] > 70:
9678
  tone = 'treble'
9679
 
9680
- if escore_averages[3] < 80:
9681
  dynamics = 'quiet'
9682
 
9683
- elif 80 <= escore_averages[3] <= 100:
9684
  dynamics = 'average'
9685
 
9686
- elif escore_averages[3] > 100:
9687
  dynamics = 'loud'
9688
 
9689
  #==============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9690
 
9691
  description = ''
9692
 
@@ -9770,12 +9795,96 @@ def escore_notes_to_text_description(escore_notes,
9770
  if instruments[0] != dominant_instrument:
9771
  description += 'The song opens with ' + instruments[0]
9772
 
9773
- description += ' and performed on ' + dominant_instrument + '.'
9774
-
9775
- description += '\n'
9776
 
9777
  else:
9778
  description += 'The song opens with and performed on ' + instruments[0] + '.'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9779
 
9780
  if drums_present and most_common_drums:
9781
 
@@ -10933,8 +11042,57 @@ ALL_MOOD_TYPES_LABELS = ['Happy Major',
10933
  'Sad Minor'
10934
  ]
10935
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10936
  ###################################################################################
10937
  #
10938
  # This is the end of the TMIDI X Python module
10939
  #
10940
- ###################################################################################
 
9677
  elif escore_averages[2] > 70:
9678
  tone = 'treble'
9679
 
9680
+ if escore_averages[3] < 64:
9681
  dynamics = 'quiet'
9682
 
9683
+ elif 64 <= escore_averages[3] <= 96:
9684
  dynamics = 'average'
9685
 
9686
+ elif escore_averages[3] > 96:
9687
  dynamics = 'loud'
9688
 
9689
  #==============================================================================
9690
+
9691
+ mono_melodies = escore_notes_monoponic_melodies([e for e in escore_notes if e[6] < 88])
9692
+
9693
+ lead_melodies = []
9694
+ base_melodies = []
9695
+
9696
+ if mono_melodies:
9697
+
9698
+ for mel in mono_melodies:
9699
+
9700
+ escore_avgs = escore_notes_pitches_range(escore_notes, range_patch = mel[0])
9701
+
9702
+ if mel[0] in LEAD_INSTRUMENTS and escore_avgs[3] > 60:
9703
+ lead_melodies.append([Number2patch[mel[0]], mel[1]])
9704
+
9705
+ elif mel[0] in BASE_INSTRUMENTS and escore_avgs[3] <= 60:
9706
+ base_melodies.append([Number2patch[mel[0]], mel[1]])
9707
+
9708
+ if lead_melodies:
9709
+ lead_melodies.sort(key=lambda x: x[1], reverse=True)
9710
+
9711
+ if base_melodies:
9712
+ base_melodies.sort(key=lambda x: x[1], reverse=True)
9713
+
9714
+ #==============================================================================
9715
 
9716
  description = ''
9717
 
 
9795
  if instruments[0] != dominant_instrument:
9796
  description += 'The song opens with ' + instruments[0]
9797
 
9798
+ description += ' and primarily performed on ' + dominant_instrument + '.'
 
 
9799
 
9800
  else:
9801
  description += 'The song opens with and performed on ' + instruments[0] + '.'
9802
+
9803
+ description += '\n'
9804
+
9805
+ if lead_melodies or base_melodies:
9806
+
9807
+ tm_count = len(lead_melodies + base_melodies)
9808
+
9809
+ if tm_count == 1:
9810
+
9811
+ if lead_melodies:
9812
+ description += 'The song has one distinct lead melody played on ' + lead_melodies[0][0] + '.'
9813
+
9814
+ else:
9815
+ description += 'The song has one distinct base melody played on ' + base_melodies[0][0] + '.'
9816
+
9817
+ description += '\n'
9818
+
9819
+ else:
9820
+
9821
+ if lead_melodies and not base_melodies:
9822
+
9823
+ if len(lead_melodies) == 1:
9824
+ mword = 'melody'
9825
+
9826
+ else:
9827
+ mword = 'melodies'
9828
+
9829
+ description += 'The song has ' + NUMERALS[len(lead_melodies)-1] + ' distinct lead ' + mword + ' played on '
9830
+
9831
+ if len(lead_melodies) > 1:
9832
+ description += ', '.join(lead_melodies[:-1][0]) + ' and ' + lead_melodies[-1][0] + '.'
9833
+
9834
+ else:
9835
+ description += lead_melodies[0][0] + '.'
9836
+
9837
+ description += '\n'
9838
+
9839
+ elif base_melodies and not lead_melodies:
9840
+
9841
+ if len(base_melodies) == 1:
9842
+ mword = 'melody'
9843
+
9844
+ else:
9845
+ mword = 'melodies'
9846
+
9847
+ description += 'The song has ' + NUMERALS[len(base_melodies)-1] + ' distinct base ' + mword + ' played on '
9848
+
9849
+ if len(base_melodies) > 1:
9850
+ description += ', '.join(base_melodies[:-1][0]) + ' and ' + base_melodies[-1][0] + '.'
9851
+
9852
+ else:
9853
+ description += base_melodies[0][0] + '.'
9854
+
9855
+ description += '\n'
9856
+
9857
+ elif lead_melodies and base_melodies:
9858
+
9859
+ if len(lead_melodies) == 1:
9860
+ lmword = 'melody'
9861
+
9862
+ else:
9863
+ lmword = 'melodies'
9864
+
9865
+ description += 'The song has ' + NUMERALS[len(lead_melodies)-1] + ' distinct lead ' + lmword + ' played on '
9866
+
9867
+ if len(lead_melodies) > 1:
9868
+ description += ', '.join(lead_melodies[:-1][0]) + ' and ' + lead_melodies[-1][0] + '.'
9869
+
9870
+ else:
9871
+ description += lead_melodies[0][0] + '.'
9872
+
9873
+ if len(base_melodies) == 1:
9874
+ bmword = 'melody'
9875
+
9876
+ else:
9877
+ bmword = 'melodies'
9878
+
9879
+ description += ' And ' + NUMERALS[len(base_melodies)-1] + ' distinct base ' + bmword + ' played on '
9880
+
9881
+ if len(base_melodies) > 1:
9882
+ description += ', '.join(base_melodies[:-1][0]) + ' and ' + base_melodies[-1][0] + '.'
9883
+
9884
+ else:
9885
+ description += base_melodies[0][0] + '.'
9886
+
9887
+ description += '\n'
9888
 
9889
  if drums_present and most_common_drums:
9890
 
 
11042
  'Sad Minor'
11043
  ]
11044
 
11045
+ ###################################################################################
11046
+
11047
+ LEAD_INSTRUMENTS = [0, 1, 2, 3, 4, 5, 6, 7, # Piano
11048
+ 8, 9, 10, 11, 12, 13, 14, 15, # Chromatic Percussion
11049
+ 16, 17, 18, 19, 20, 21, 22, 23, # Organ
11050
+ 24, 25, 26, 27, 28, 29, 30, 31, # Guitar
11051
+ 40, 41, # Strings
11052
+ 52, 53, 54, # Ensemble
11053
+ 56, 57, 59, 60, # Brass
11054
+ 64, 65, 66, 67, 68, 69, 70, 71, # Reed
11055
+ 72, 73, 74, 75, 76, 77, 78, 79, # Pipe
11056
+ 80, 81, 87 # Synth Lead
11057
+ ]
11058
+
11059
+ ###################################################################################
11060
+
11061
+ BASE_INSTRUMENTS = [32, 33, 34, 35, 36, 37, 38, 39, # Bass
11062
+ 42, 43, # Strings
11063
+ 58, 61, 62, 63, # Brass
11064
+ 87 # Synth Lead
11065
+ ]
11066
+
11067
+ ###################################################################################
11068
+
11069
+ def escore_notes_pitches_range(escore_notes,
11070
+ range_patch=-1,
11071
+ pitches_idx=4,
11072
+ patches_idx=6
11073
+ ):
11074
+
11075
+ pitches = []
11076
+
11077
+ if -1 < range_patch < 129:
11078
+ pitches = [e[pitches_idx] for e in escore_notes if e[patches_idx] == range_patch]
11079
+
11080
+ else:
11081
+ pitches = [e[pitches_idx] for e in escore_notes]
11082
+
11083
+ if pitches:
11084
+ min_pitch = min(pitches)
11085
+ avg_pitch = sum(pitches) / len(pitches)
11086
+ mode_pitch = statistics.mode(pitches)
11087
+ max_pitch = max(pitches)
11088
+
11089
+ return [max_pitch-min_pitch, min_pitch, max_pitch, avg_pitch, mode_pitch]
11090
+
11091
+ else:
11092
+ return [ -1] * 6
11093
+
11094
  ###################################################################################
11095
  #
11096
  # This is the end of the TMIDI X Python module
11097
  #
11098
+ ###################################################################################