projectlosangeles commited on
Commit
5c7902a
1 Parent(s): 7fb4dfd

Upload 5 files

Browse files
Files changed (2) hide show
  1. TMIDIX.py +329 -98
  2. fluidsynth-master.zip +3 -0
TMIDIX.py CHANGED
@@ -174,7 +174,7 @@ Translates a "score" into MIDI, using score2opus() then opus2midi()
174
 
175
  #--------------------------- Decoding stuff ------------------------
176
 
177
- def midi2opus(midi=b''):
178
  r'''Translates MIDI into a "opus". For a description of the
179
  "opus" format, see opus2midi()
180
  '''
@@ -186,7 +186,8 @@ def midi2opus(midi=b''):
186
  if id != b'MThd':
187
  _warn("midi2opus: midi starts with "+str(id)+" instead of 'MThd'")
188
  _clean_up_warnings()
189
- return [1000,[],]
 
190
  [length, format, tracks_expected, ticks] = struct.unpack(
191
  '>IHHH', bytes(my_midi[4:14]))
192
  if length != 6:
@@ -266,27 +267,38 @@ see opus2midi() and score2opus().
266
  _clean_up_warnings()
267
  return score
268
 
269
- def midi2score(midi=b''):
270
  r'''
271
  Translates MIDI into a "score", using midi2opus() then opus2score()
272
  '''
273
- return opus2score(midi2opus(midi))
274
 
275
- def midi2ms_score(midi=b''):
276
  r'''
277
  Translates MIDI into a "score" with one beat per second and one
278
  tick per millisecond, using midi2opus() then to_millisecs()
279
  then opus2score()
280
  '''
281
- return opus2score(to_millisecs(midi2opus(midi)))
282
-
283
- def midi2single_track_ms_score(midi=b'', recalculate_channels = True, pass_old_timings_events= False, verbose = False):
 
 
 
 
 
284
  r'''
285
  Translates MIDI into a single track "score" with 16 instruments and one beat per second and one
286
  tick per millisecond
287
  '''
288
 
289
- score = midi2score(midi)
 
 
 
 
 
 
290
 
291
  if recalculate_channels:
292
 
@@ -1736,7 +1748,9 @@ def plot_ms_SONG(ms_song,
1736
  drums_color_num=128,
1737
  plot_size=(11,4),
1738
  note_height = 0.75,
1739
- show_grid_lines=False):
 
 
1740
 
1741
  '''Tegridy ms SONG plotter/vizualizer'''
1742
 
@@ -1784,11 +1798,14 @@ def plot_ms_SONG(ms_song,
1784
  if show_grid_lines:
1785
  ax.grid(color='white')
1786
 
1787
- plt.xlabel('Time', c='black')
1788
- plt.ylabel('Pitch', c='black')
1789
 
1790
  plt.title(plot_title)
1791
 
 
 
 
1792
  plt.show()
1793
 
1794
  ###################################################################################
@@ -3780,19 +3797,41 @@ def fix_monophonic_score_durations(monophonic_score):
3780
 
3781
  fixed_score = []
3782
 
3783
- for i in range(len(monophonic_score)-1):
3784
- note = monophonic_score[i]
3785
 
3786
- nmt = monophonic_score[i+1][1]
 
3787
 
3788
- if note[1]+note[2] >= nmt:
3789
- note_dur = nmt-note[1]-1
3790
- else:
3791
- note_dur = note[2]
 
 
 
 
3792
 
3793
- fixed_score.append([note[0], note[1], note_dur, note[3], note[4], note[5]])
3794
 
3795
- fixed_score.append(monophonic_score[-1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3796
 
3797
  return fixed_score
3798
 
@@ -3983,64 +4022,63 @@ def analyze_score_pitches(score, channels_to_analyze=[0]):
3983
 
3984
  ###################################################################################
3985
 
3986
- ALL_CHORDS_GROUPED = [[[1, 3, 5, 7, 9, 11], [0, 2, 4, 6, 8, 10]],
3987
- [[0, 2, 5, 7, 10], [0, 2, 4, 7, 9], [0, 2, 5, 7, 9], [1, 4, 6, 9, 11],
3988
- [1, 3, 6, 8, 11], [1, 3, 6, 8, 10], [1, 4, 6, 8, 11], [1, 3, 5, 8, 10],
3989
- [2, 4, 6, 9, 11], [2, 4, 7, 9, 11], [0, 3, 5, 7, 10], [0, 3, 5, 8, 10],
3990
- [0, 3, 6, 8, 10], [0, 2, 4, 6, 9], [1, 4, 7, 9, 11], [2, 4, 6, 8, 11],
3991
- [1, 3, 6, 9, 11], [1, 3, 5, 8, 11], [0, 2, 5, 8, 10], [1, 4, 6, 8, 10],
3992
- [0, 3, 5, 7, 9], [2, 5, 7, 9, 11], [1, 3, 5, 7, 10], [0, 2, 4, 7, 10],
3993
- [1, 3, 5, 7, 9], [1, 3, 5, 9, 11], [1, 5, 7, 9, 11], [1, 3, 7, 9, 11],
3994
- [3, 5, 7, 9, 11], [2, 4, 6, 8, 10], [0, 4, 6, 8, 10], [0, 2, 6, 8, 10],
3995
- [1, 3, 5, 7, 11], [0, 2, 4, 8, 10], [0, 2, 4, 6, 8], [0, 2, 4, 6, 10]],
3996
- [[2, 5, 7, 10], [0, 3, 7, 10], [1, 4, 8, 11], [2, 4, 7, 11], [0, 4, 7, 9],
3997
- [0, 2, 5, 9], [2, 6, 9, 11], [1, 5, 8, 10], [0, 3, 5, 8], [3, 6, 8, 11],
3998
- [1, 3, 6, 10], [1, 4, 6, 9], [0, 3, 6, 9], [2, 5, 8, 11], [1, 4, 7, 10],
3999
- [2, 5, 7, 11], [0, 2, 6, 9], [0, 4, 7, 10], [2, 4, 8, 11], [0, 3, 5, 9],
4000
- [1, 4, 7, 9], [3, 6, 9, 11], [2, 5, 8, 10], [1, 4, 6, 10], [0, 3, 6, 8],
4001
- [1, 3, 7, 10], [1, 5, 8, 11], [0, 2, 5, 10], [0, 5, 7, 9], [0, 3, 8, 10],
4002
- [0, 2, 4, 7], [4, 6, 8, 11], [3, 5, 7, 10], [2, 7, 9, 11], [2, 4, 6, 9],
4003
- [1, 6, 8, 10], [1, 4, 9, 11], [1, 3, 5, 8], [1, 3, 6, 11], [2, 5, 9, 11],
4004
- [2, 4, 7, 10], [0, 2, 5, 8], [1, 5, 7, 10], [0, 4, 6, 9], [1, 3, 6, 9],
4005
- [0, 3, 6, 10], [2, 6, 8, 11], [0, 2, 7, 9], [1, 4, 8, 10], [0, 3, 7, 9],
4006
- [3, 5, 8, 11], [0, 5, 7, 10], [0, 2, 5, 7], [1, 4, 7, 11], [2, 4, 7, 9],
4007
- [0, 3, 5, 10], [4, 6, 9, 11], [1, 4, 6, 11], [2, 4, 9, 11], [1, 6, 8, 11],
4008
- [1, 3, 6, 8], [1, 3, 8, 10], [3, 5, 8, 10], [4, 7, 9, 11], [0, 2, 7, 10],
4009
- [2, 5, 7, 9], [0, 2, 4, 9], [1, 6, 9, 11], [2, 4, 6, 11], [0, 3, 5, 7],
4010
- [0, 5, 8, 10], [1, 4, 6, 8], [1, 3, 5, 10], [1, 3, 8, 11], [3, 6, 8, 10],
4011
- [1, 3, 7, 9], [3, 5, 9, 11], [2, 4, 8, 10], [1, 5, 7, 11], [0, 2, 6, 8],
4012
- [0, 4, 6, 10], [1, 3, 5, 9], [1, 5, 7, 9], [2, 6, 8, 10], [3, 7, 9, 11],
4013
- [0, 2, 4, 8], [0, 4, 6, 8], [0, 4, 8, 10], [2, 4, 6, 10], [1, 3, 7, 11],
4014
- [0, 2, 6, 10], [1, 5, 9, 11], [3, 5, 7, 11], [1, 7, 9, 11], [0, 2, 4, 6],
4015
- [1, 3, 9, 11], [0, 2, 4, 10], [5, 7, 9, 11], [2, 4, 6, 8], [0, 2, 8, 10],
4016
- [3, 5, 7, 9], [1, 3, 5, 7], [4, 6, 8, 10], [0, 6, 8, 10], [1, 3, 5, 11]],
4017
- [[2, 7, 11], [0, 4, 7], [0, 5, 9], [2, 6, 9], [2, 5, 10], [1, 4, 9],
4018
- [4, 8, 11], [3, 7, 10], [0, 3, 8], [3, 6, 11], [1, 5, 8], [1, 6, 10],
4019
- [0, 4, 9], [2, 5, 9], [4, 7, 11], [2, 7, 10], [2, 6, 11], [0, 3, 7],
4020
- [0, 5, 8], [1, 4, 8], [1, 6, 9], [3, 8, 11], [1, 5, 10], [3, 6, 10],
4021
- [2, 5, 11], [4, 7, 10], [3, 6, 9], [0, 6, 9], [0, 3, 9], [2, 8, 11],
4022
- [2, 5, 8], [1, 7, 10], [1, 4, 7], [0, 3, 6], [1, 4, 10], [5, 8, 11],
4023
- [2, 5, 7], [0, 7, 10], [0, 2, 9], [0, 3, 5], [6, 9, 11], [4, 7, 9],
4024
- [2, 4, 11], [5, 8, 10], [1, 3, 10], [1, 4, 6], [3, 6, 8], [1, 8, 11],
4025
- [5, 7, 11], [0, 4, 10], [3, 5, 9], [0, 2, 6], [1, 7, 9], [0, 7, 9],
4026
- [5, 7, 10], [2, 8, 10], [3, 9, 11], [0, 2, 5], [2, 4, 8], [2, 4, 7],
4027
- [0, 2, 7], [2, 7, 9], [4, 9, 11], [4, 6, 9], [1, 3, 7], [2, 4, 9], [0, 5, 7],
4028
- [0, 3, 10], [2, 9, 11], [0, 5, 10], [0, 6, 8], [4, 6, 10], [4, 6, 11],
4029
- [1, 4, 11], [6, 8, 11], [1, 5, 11], [1, 6, 11], [1, 8, 10], [1, 6, 8],
4030
- [3, 5, 8], [3, 8, 10], [1, 3, 8], [3, 5, 10], [1, 3, 6], [1, 5, 9], [0, 4, 8],
4031
- [2, 6, 10], [3, 7, 11], [2, 4, 10], [5, 9, 11], [1, 5, 7], [0, 2, 8],
4032
- [0, 4, 6], [1, 7, 11], [3, 7, 9], [1, 3, 9], [7, 9, 11], [5, 7, 9],
4033
- [0, 6, 10], [0, 2, 10], [2, 6, 8], [0, 2, 4], [4, 8, 10], [1, 9, 11],
4034
- [2, 4, 6], [3, 5, 11], [3, 5, 7], [0, 8, 10], [4, 6, 8], [1, 3, 11],
4035
- [6, 8, 10], [1, 3, 5]],
4036
- [[0, 9], [2, 5], [4, 7], [7, 10], [2, 11], [0, 3], [6, 9], [1, 4], [8, 11],
4037
- [5, 8], [1, 10], [3, 6], [0, 4], [5, 9], [7, 11], [0, 7], [0, 5], [2, 10],
4038
- [2, 7], [2, 9], [2, 6], [4, 11], [4, 9], [3, 7], [5, 10], [1, 9], [0, 8],
4039
- [6, 11], [3, 11], [4, 8], [3, 10], [3, 8], [1, 5], [1, 8], [1, 6], [6, 10],
4040
- [3, 9], [4, 10], [1, 7], [0, 6], [2, 8], [5, 11], [5, 7], [0, 10], [0, 2],
4041
- [9, 11], [7, 9], [2, 4], [4, 6], [3, 5], [8, 10], [6, 8], [1, 3], [1, 11]],
4042
- [[0], [7], [5], [9], [2], [4], [11], [10], [8], [6], [3], [1]]
4043
- ]
4044
 
4045
  def group_sublists_by_length(lst):
4046
  unique_lengths = sorted(list(set(map(len, lst))), reverse=True)
@@ -4056,10 +4094,10 @@ def tones_chord_to_pitches(tones_chord, base_pitch=60):
4056
 
4057
  def advanced_score_processor(raw_score,
4058
  patches_to_analyze=list(range(129)),
4059
- return_score_analysis=True,
4060
  return_enhanced_score=False,
4061
  return_enhanced_score_notes=False,
4062
- return_enhanced_monophonic_melody=False,
4063
  return_chordified_enhanced_score=False,
4064
  return_chordified_enhanced_score_with_lyrics=False,
4065
  return_score_tones_chords=False,
@@ -4327,30 +4365,42 @@ def replace_bad_tones_chord(bad_tones_chord):
4327
  ###################################################################################
4328
 
4329
  def check_and_fix_chord(chord,
4330
- channel_index=3,
4331
- pitch_index=4):
 
4332
 
4333
- chord_notes = [x for x in chord if x[channel_index] != 9]
4334
- chord_drums = [x for x in chord if x[channel_index] == 9]
4335
- chord_pitches = [x[pitch_index] for x in chord_notes]
4336
- tones_chord = sorted(set([x % 12 for x in chord_pitches]))
4337
- good_tones_chord = replace_bad_tones_chord(tones_chord)[0]
4338
- bad_tones = list(set(tones_chord) ^ set(good_tones_chord))
4339
 
4340
- if bad_tones:
 
4341
 
4342
- fixed_chord = []
4343
 
4344
- for c in chord_notes:
4345
- if (c[pitch_index] % 12) not in bad_tones:
4346
- fixed_chord.append(c)
4347
 
4348
- fixed_chord += chord_drums
 
 
4349
 
4350
- return fixed_chord
4351
 
4352
- else:
4353
- return chord
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4354
 
4355
  ###################################################################################
4356
 
@@ -4539,6 +4589,64 @@ def check_and_fix_tones_chord(tones_chord):
4539
 
4540
  ###################################################################################
4541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4542
  def create_similarity_matrix(list_of_values, matrix_length=0):
4543
 
4544
  counts = Counter(list_of_values).items()
@@ -4562,6 +4670,129 @@ def create_similarity_matrix(list_of_values, matrix_length=0):
4562
 
4563
  ###################################################################################
4564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4565
  # This is the end of the TMIDI X Python module
4566
 
4567
  ###################################################################################
 
174
 
175
  #--------------------------- Decoding stuff ------------------------
176
 
177
+ def midi2opus(midi=b'', do_not_check_MIDI_signature=False):
178
  r'''Translates MIDI into a "opus". For a description of the
179
  "opus" format, see opus2midi()
180
  '''
 
186
  if id != b'MThd':
187
  _warn("midi2opus: midi starts with "+str(id)+" instead of 'MThd'")
188
  _clean_up_warnings()
189
+ if do_not_check_MIDI_signature == False:
190
+ return [1000,[],]
191
  [length, format, tracks_expected, ticks] = struct.unpack(
192
  '>IHHH', bytes(my_midi[4:14]))
193
  if length != 6:
 
267
  _clean_up_warnings()
268
  return score
269
 
270
+ def midi2score(midi=b'', do_not_check_MIDI_signature=False):
271
  r'''
272
  Translates MIDI into a "score", using midi2opus() then opus2score()
273
  '''
274
+ return opus2score(midi2opus(midi, do_not_check_MIDI_signature))
275
 
276
+ def midi2ms_score(midi=b'', do_not_check_MIDI_signature=False):
277
  r'''
278
  Translates MIDI into a "score" with one beat per second and one
279
  tick per millisecond, using midi2opus() then to_millisecs()
280
  then opus2score()
281
  '''
282
+ return opus2score(to_millisecs(midi2opus(midi, do_not_check_MIDI_signature)))
283
+
284
+ def midi2single_track_ms_score(midi_path_or_bytes,
285
+ recalculate_channels = False,
286
+ pass_old_timings_events= False,
287
+ verbose = False,
288
+ do_not_check_MIDI_signature=False
289
+ ):
290
  r'''
291
  Translates MIDI into a single track "score" with 16 instruments and one beat per second and one
292
  tick per millisecond
293
  '''
294
 
295
+ if type(midi_path_or_bytes) == bytes:
296
+ midi_data = midi_path_or_bytes
297
+
298
+ elif type(midi_path_or_bytes) == str:
299
+ midi_data = open(midi_path_or_bytes, 'rb').read()
300
+
301
+ score = midi2score(midi_data, do_not_check_MIDI_signature)
302
 
303
  if recalculate_channels:
304
 
 
1748
  drums_color_num=128,
1749
  plot_size=(11,4),
1750
  note_height = 0.75,
1751
+ show_grid_lines=False,
1752
+ return_plt = False
1753
+ ):
1754
 
1755
  '''Tegridy ms SONG plotter/vizualizer'''
1756
 
 
1798
  if show_grid_lines:
1799
  ax.grid(color='white')
1800
 
1801
+ plt.xlabel('Time (s)', c='black')
1802
+ plt.ylabel('MIDI Pitch', c='black')
1803
 
1804
  plt.title(plot_title)
1805
 
1806
+ if return_plt:
1807
+ return plt
1808
+
1809
  plt.show()
1810
 
1811
  ###################################################################################
 
3797
 
3798
  fixed_score = []
3799
 
3800
+ if monophonic_score[0][0] == 'note':
 
3801
 
3802
+ for i in range(len(monophonic_score)-1):
3803
+ note = monophonic_score[i]
3804
 
3805
+ nmt = monophonic_score[i+1][1]
3806
+
3807
+ if note[1]+note[2] >= nmt:
3808
+ note_dur = nmt-note[1]-1
3809
+ else:
3810
+ note_dur = note[2]
3811
+
3812
+ new_note = [note[0], note[1], note_dur] + note[3:]
3813
 
3814
+ fixed_score.append(new_note)
3815
 
3816
+ fixed_score.append(monophonic_score[-1])
3817
+
3818
+ elif type(monophonic_score[0][0]) == int:
3819
+
3820
+ for i in range(len(monophonic_score)-1):
3821
+ note = monophonic_score[i]
3822
+
3823
+ nmt = monophonic_score[i+1][0]
3824
+
3825
+ if note[0]+note[1] >= nmt:
3826
+ note_dur = nmt-note[0]-1
3827
+ else:
3828
+ note_dur = note[1]
3829
+
3830
+ new_note = [note[0], note_dur] + note[2:]
3831
+
3832
+ fixed_score.append(new_note)
3833
+
3834
+ fixed_score.append(monophonic_score[-1])
3835
 
3836
  return fixed_score
3837
 
 
4022
 
4023
  ###################################################################################
4024
 
4025
+ ALL_CHORDS_GROUPED = [[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]],
4026
+ [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10],
4027
+ [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11],
4028
+ [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [3, 5],
4029
+ [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [4, 6], [4, 7], [4, 8],
4030
+ [4, 9], [4, 10], [4, 11], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [6, 8],
4031
+ [6, 9], [6, 10], [6, 11], [7, 9], [7, 10], [7, 11], [8, 10], [8, 11],
4032
+ [9, 11]],
4033
+ [[0, 2, 4], [0, 2, 5], [0, 3, 5], [0, 2, 6], [0, 3, 6], [0, 4, 6], [0, 2, 7],
4034
+ [0, 3, 7], [0, 4, 7], [0, 5, 7], [0, 2, 8], [0, 3, 8], [0, 4, 8], [0, 5, 8],
4035
+ [0, 6, 8], [0, 2, 9], [0, 3, 9], [0, 4, 9], [0, 5, 9], [0, 6, 9], [0, 7, 9],
4036
+ [0, 2, 10], [0, 3, 10], [0, 4, 10], [0, 5, 10], [0, 6, 10], [0, 7, 10],
4037
+ [0, 8, 10], [1, 3, 5], [1, 3, 6], [1, 4, 6], [1, 3, 7], [1, 4, 7], [1, 5, 7],
4038
+ [1, 3, 8], [1, 4, 8], [1, 5, 8], [1, 6, 8], [1, 3, 9], [1, 4, 9], [1, 5, 9],
4039
+ [1, 6, 9], [1, 7, 9], [1, 3, 10], [1, 4, 10], [1, 5, 10], [1, 6, 10],
4040
+ [1, 7, 10], [1, 8, 10], [1, 3, 11], [1, 4, 11], [1, 5, 11], [1, 6, 11],
4041
+ [1, 7, 11], [1, 8, 11], [1, 9, 11], [2, 4, 6], [2, 4, 7], [2, 5, 7],
4042
+ [2, 4, 8], [2, 5, 8], [2, 6, 8], [2, 4, 9], [2, 5, 9], [2, 6, 9], [2, 7, 9],
4043
+ [2, 4, 10], [2, 5, 10], [2, 6, 10], [2, 7, 10], [2, 8, 10], [2, 4, 11],
4044
+ [2, 5, 11], [2, 6, 11], [2, 7, 11], [2, 8, 11], [2, 9, 11], [3, 5, 7],
4045
+ [3, 5, 8], [3, 6, 8], [3, 5, 9], [3, 6, 9], [3, 7, 9], [3, 5, 10], [3, 6, 10],
4046
+ [3, 7, 10], [3, 8, 10], [3, 5, 11], [3, 6, 11], [3, 7, 11], [3, 8, 11],
4047
+ [3, 9, 11], [4, 6, 8], [4, 6, 9], [4, 7, 9], [4, 6, 10], [4, 7, 10],
4048
+ [4, 8, 10], [4, 6, 11], [4, 7, 11], [4, 8, 11], [4, 9, 11], [5, 7, 9],
4049
+ [5, 7, 10], [5, 8, 10], [5, 7, 11], [5, 8, 11], [5, 9, 11], [6, 8, 10],
4050
+ [6, 8, 11], [6, 9, 11], [7, 9, 11]],
4051
+ [[0, 2, 4, 6], [0, 2, 4, 7], [0, 2, 5, 7], [0, 3, 5, 7], [0, 2, 4, 8],
4052
+ [0, 2, 5, 8], [0, 2, 6, 8], [0, 3, 5, 8], [0, 3, 6, 8], [0, 4, 6, 8],
4053
+ [0, 2, 4, 9], [0, 2, 5, 9], [0, 2, 6, 9], [0, 2, 7, 9], [0, 3, 5, 9],
4054
+ [0, 3, 6, 9], [0, 3, 7, 9], [0, 4, 6, 9], [0, 4, 7, 9], [0, 5, 7, 9],
4055
+ [0, 2, 4, 10], [0, 2, 5, 10], [0, 2, 6, 10], [0, 2, 7, 10], [0, 2, 8, 10],
4056
+ [0, 3, 5, 10], [0, 3, 6, 10], [0, 3, 7, 10], [0, 3, 8, 10], [0, 4, 6, 10],
4057
+ [0, 4, 7, 10], [0, 4, 8, 10], [0, 5, 7, 10], [0, 5, 8, 10], [0, 6, 8, 10],
4058
+ [1, 3, 5, 7], [1, 3, 5, 8], [1, 3, 6, 8], [1, 4, 6, 8], [1, 3, 5, 9],
4059
+ [1, 3, 6, 9], [1, 3, 7, 9], [1, 4, 6, 9], [1, 4, 7, 9], [1, 5, 7, 9],
4060
+ [1, 3, 5, 10], [1, 3, 6, 10], [1, 3, 7, 10], [1, 3, 8, 10], [1, 4, 6, 10],
4061
+ [1, 4, 7, 10], [1, 4, 8, 10], [1, 5, 7, 10], [1, 5, 8, 10], [1, 6, 8, 10],
4062
+ [1, 3, 5, 11], [1, 3, 6, 11], [1, 3, 7, 11], [1, 3, 8, 11], [1, 3, 9, 11],
4063
+ [1, 4, 6, 11], [1, 4, 7, 11], [1, 4, 8, 11], [1, 4, 9, 11], [1, 5, 7, 11],
4064
+ [1, 5, 8, 11], [1, 5, 9, 11], [1, 6, 8, 11], [1, 6, 9, 11], [1, 7, 9, 11],
4065
+ [2, 4, 6, 8], [2, 4, 6, 9], [2, 4, 7, 9], [2, 5, 7, 9], [2, 4, 6, 10],
4066
+ [2, 4, 7, 10], [2, 4, 8, 10], [2, 5, 7, 10], [2, 5, 8, 10], [2, 6, 8, 10],
4067
+ [2, 4, 6, 11], [2, 4, 7, 11], [2, 4, 8, 11], [2, 4, 9, 11], [2, 5, 7, 11],
4068
+ [2, 5, 8, 11], [2, 5, 9, 11], [2, 6, 8, 11], [2, 6, 9, 11], [2, 7, 9, 11],
4069
+ [3, 5, 7, 9], [3, 5, 7, 10], [3, 5, 8, 10], [3, 6, 8, 10], [3, 5, 7, 11],
4070
+ [3, 5, 8, 11], [3, 5, 9, 11], [3, 6, 8, 11], [3, 6, 9, 11], [3, 7, 9, 11],
4071
+ [4, 6, 8, 10], [4, 6, 8, 11], [4, 6, 9, 11], [4, 7, 9, 11], [5, 7, 9, 11]],
4072
+ [[0, 2, 4, 6, 8], [0, 2, 4, 6, 9], [0, 2, 4, 7, 9], [0, 2, 5, 7, 9],
4073
+ [0, 3, 5, 7, 9], [0, 2, 4, 6, 10], [0, 2, 4, 7, 10], [0, 2, 4, 8, 10],
4074
+ [0, 2, 5, 7, 10], [0, 2, 5, 8, 10], [0, 2, 6, 8, 10], [0, 3, 5, 7, 10],
4075
+ [0, 3, 5, 8, 10], [0, 3, 6, 8, 10], [0, 4, 6, 8, 10], [1, 3, 5, 7, 9],
4076
+ [1, 3, 5, 7, 10], [1, 3, 5, 8, 10], [1, 3, 6, 8, 10], [1, 4, 6, 8, 10],
4077
+ [1, 3, 5, 7, 11], [1, 3, 5, 8, 11], [1, 3, 5, 9, 11], [1, 3, 6, 8, 11],
4078
+ [1, 3, 6, 9, 11], [1, 3, 7, 9, 11], [1, 4, 6, 8, 11], [1, 4, 6, 9, 11],
4079
+ [1, 4, 7, 9, 11], [1, 5, 7, 9, 11], [2, 4, 6, 8, 10], [2, 4, 6, 8, 11],
4080
+ [2, 4, 6, 9, 11], [2, 4, 7, 9, 11], [2, 5, 7, 9, 11], [3, 5, 7, 9, 11]],
4081
+ [[0, 2, 4, 6, 8, 10], [1, 3, 5, 7, 9, 11]]]
 
4082
 
4083
  def group_sublists_by_length(lst):
4084
  unique_lengths = sorted(list(set(map(len, lst))), reverse=True)
 
4094
 
4095
  def advanced_score_processor(raw_score,
4096
  patches_to_analyze=list(range(129)),
4097
+ return_score_analysis=False,
4098
  return_enhanced_score=False,
4099
  return_enhanced_score_notes=False,
4100
+ return_enhanced_monophonic_melody=False,
4101
  return_chordified_enhanced_score=False,
4102
  return_chordified_enhanced_score_with_lyrics=False,
4103
  return_score_tones_chords=False,
 
4365
  ###################################################################################
4366
 
4367
  def check_and_fix_chord(chord,
4368
+ channel_index=3,
4369
+ pitch_index=4
4370
+ ):
4371
 
4372
+ tones_chord = sorted(set([t[pitch_index] % 12 for t in chord if t[channel_index] != 9]))
 
 
 
 
 
4373
 
4374
+ notes_events = [t for t in chord if t[channel_index] != 9]
4375
+ notes_events.sort(key=lambda x: x[pitch_index], reverse=True)
4376
 
4377
+ drums_events = [t for t in chord if t[channel_index] == 9]
4378
 
4379
+ checked_and_fixed_chord = []
 
 
4380
 
4381
+ if tones_chord:
4382
+
4383
+ new_tones_chord = advanced_check_and_fix_tones_chord(tones_chord, high_pitch=notes_events[0][pitch_index])
4384
 
4385
+ if new_tones_chord != tones_chord:
4386
 
4387
+ if len(notes_events) > 1:
4388
+ checked_and_fixed_chord.extend([notes_events[0]])
4389
+ for cc in notes_events[1:]:
4390
+ if cc[channel_index] != 9:
4391
+ if (cc[pitch_index] % 12) in new_tones_chord:
4392
+ checked_and_fixed_chord.extend([cc])
4393
+ checked_and_fixed_chord.extend(drums_events)
4394
+ else:
4395
+ checked_and_fixed_chord.extend([notes_events[0]])
4396
+ else:
4397
+ checked_and_fixed_chord.extend(chord)
4398
+ else:
4399
+ checked_and_fixed_chord.extend(chord)
4400
+
4401
+ checked_and_fixed_chord.sort(key=lambda x: x[pitch_index], reverse=True)
4402
+
4403
+ return checked_and_fixed_chord
4404
 
4405
  ###################################################################################
4406
 
 
4589
 
4590
  ###################################################################################
4591
 
4592
+ def find_closest_tone(tones, tone):
4593
+ return min(tones, key=lambda x:abs(x-tone))
4594
+
4595
+ def advanced_check_and_fix_tones_chord(tones_chord, high_pitch=0):
4596
+
4597
+ lst = tones_chord
4598
+
4599
+ if 0 < high_pitch < 128:
4600
+ ht = high_pitch % 12
4601
+ else:
4602
+ ht = 12
4603
+
4604
+ cht = find_closest_tone(lst, ht)
4605
+
4606
+ if len(lst) == 2:
4607
+ if lst[1] - lst[0] == 1:
4608
+ return [cht]
4609
+ else:
4610
+ if 0 in lst and 11 in lst:
4611
+ if find_closest_tone([0, 11], cht) == 11:
4612
+ lst.remove(0)
4613
+ else:
4614
+ lst.remove(11)
4615
+ return lst
4616
+
4617
+ non_consecutive = []
4618
+
4619
+ if len(lst) > 2:
4620
+ for i in range(0, len(lst) - 1):
4621
+ if lst[i] + 1 != lst[i+1]:
4622
+ non_consecutive.append(lst[i])
4623
+ if lst[-1] - lst[-2] > 1:
4624
+ non_consecutive.append(lst[-1])
4625
+
4626
+ if cht not in non_consecutive:
4627
+ non_consecutive.append(cht)
4628
+ non_consecutive.sort()
4629
+ if any(abs(non_consecutive[i+1] - non_consecutive[i]) == 1 for i in range(len(non_consecutive) - 1)):
4630
+ final_list = [x for x in non_consecutive if x == cht or abs(x - cht) > 1]
4631
+ else:
4632
+ final_list = non_consecutive
4633
+
4634
+ else:
4635
+ final_list = non_consecutive
4636
+
4637
+ if 0 in final_list and 11 in final_list:
4638
+ if find_closest_tone([0, 11], cht) == 11:
4639
+ final_list.remove(0)
4640
+ else:
4641
+ final_list.remove(11)
4642
+
4643
+ if cht in final_list or ht in final_list:
4644
+ return final_list
4645
+ else:
4646
+ return ['Error']
4647
+
4648
+ ###################################################################################
4649
+
4650
  def create_similarity_matrix(list_of_values, matrix_length=0):
4651
 
4652
  counts = Counter(list_of_values).items()
 
4670
 
4671
  ###################################################################################
4672
 
4673
+ def augment_enhanced_score_notes(enhanced_score_notes,
4674
+ timings_divider=16,
4675
+ full_sorting=True,
4676
+ timings_shift=0,
4677
+ pitch_shift=0
4678
+ ):
4679
+
4680
+ esn = copy.deepcopy(enhanced_score_notes)
4681
+
4682
+ for e in esn:
4683
+ e[1] = int(e[1] / timings_divider) + timings_shift
4684
+ e[2] = int(e[2] / timings_divider) + timings_shift
4685
+ e[4] = e[4] + pitch_shift
4686
+
4687
+ if full_sorting:
4688
+
4689
+ # Sorting by patch, pitch, then by start-time
4690
+ esn.sort(key=lambda x: x[6])
4691
+ esn.sort(key=lambda x: x[4], reverse=True)
4692
+ esn.sort(key=lambda x: x[1])
4693
+
4694
+ return esn
4695
+
4696
+ ###################################################################################
4697
+
4698
+ def extract_melody(chordified_enhanced_score,
4699
+ melody_range=[60, 84],
4700
+ melody_channel=0,
4701
+ melody_patch=0
4702
+ ):
4703
+
4704
+ melody_score = copy.deepcopy([c[0] for c in chordified_enhanced_score if c[0][3] != 9])
4705
+
4706
+ for e in melody_score:
4707
+ e[3] = melody_channel
4708
+ e[6] = melody_patch
4709
+
4710
+ if e[4] < melody_range[0]:
4711
+ e[4] = (e[4] % 12) + melody_range[0]
4712
+
4713
+ if e[4] > melody_range[1]:
4714
+ e[4] = (e[4] % 12) + melody_range[1]
4715
+
4716
+ return fix_monophonic_score_durations(melody_score)
4717
+
4718
+ ###################################################################################
4719
+
4720
+ def flip_enhanced_score_notes(enhanced_score_notes):
4721
+
4722
+ min_pitch = min([e[4] for e in enhanced_score_notes if e[3] != 9])
4723
+
4724
+ fliped_score_pitches = [127 - e[4]for e in enhanced_score_notes if e[3] != 9]
4725
+
4726
+ delta_min_pitch = min_pitch - min([p for p in fliped_score_pitches])
4727
+
4728
+ output_score = copy.deepcopy(enhanced_score_notes)
4729
+
4730
+ for e in output_score:
4731
+ if e[3] != 9:
4732
+ e[4] = (127 - e[4]) + delta_min_pitch
4733
+
4734
+ return output_score
4735
+
4736
+ ###################################################################################
4737
+
4738
+ ALL_CHORDS_SORTED = [[0], [0, 2], [0, 3], [0, 4], [0, 2, 4], [0, 5], [0, 2, 5], [0, 3, 5], [0, 6],
4739
+ [0, 2, 6], [0, 3, 6], [0, 4, 6], [0, 2, 4, 6], [0, 7], [0, 2, 7], [0, 3, 7],
4740
+ [0, 4, 7], [0, 5, 7], [0, 2, 4, 7], [0, 2, 5, 7], [0, 3, 5, 7], [0, 8],
4741
+ [0, 2, 8], [0, 3, 8], [0, 4, 8], [0, 5, 8], [0, 6, 8], [0, 2, 4, 8],
4742
+ [0, 2, 5, 8], [0, 2, 6, 8], [0, 3, 5, 8], [0, 3, 6, 8], [0, 4, 6, 8],
4743
+ [0, 2, 4, 6, 8], [0, 9], [0, 2, 9], [0, 3, 9], [0, 4, 9], [0, 5, 9], [0, 6, 9],
4744
+ [0, 7, 9], [0, 2, 4, 9], [0, 2, 5, 9], [0, 2, 6, 9], [0, 2, 7, 9],
4745
+ [0, 3, 5, 9], [0, 3, 6, 9], [0, 3, 7, 9], [0, 4, 6, 9], [0, 4, 7, 9],
4746
+ [0, 5, 7, 9], [0, 2, 4, 6, 9], [0, 2, 4, 7, 9], [0, 2, 5, 7, 9],
4747
+ [0, 3, 5, 7, 9], [0, 10], [0, 2, 10], [0, 3, 10], [0, 4, 10], [0, 5, 10],
4748
+ [0, 6, 10], [0, 7, 10], [0, 8, 10], [0, 2, 4, 10], [0, 2, 5, 10],
4749
+ [0, 2, 6, 10], [0, 2, 7, 10], [0, 2, 8, 10], [0, 3, 5, 10], [0, 3, 6, 10],
4750
+ [0, 3, 7, 10], [0, 3, 8, 10], [0, 4, 6, 10], [0, 4, 7, 10], [0, 4, 8, 10],
4751
+ [0, 5, 7, 10], [0, 5, 8, 10], [0, 6, 8, 10], [0, 2, 4, 6, 10],
4752
+ [0, 2, 4, 7, 10], [0, 2, 4, 8, 10], [0, 2, 5, 7, 10], [0, 2, 5, 8, 10],
4753
+ [0, 2, 6, 8, 10], [0, 3, 5, 7, 10], [0, 3, 5, 8, 10], [0, 3, 6, 8, 10],
4754
+ [0, 4, 6, 8, 10], [0, 2, 4, 6, 8, 10], [1], [1, 3], [1, 4], [1, 5], [1, 3, 5],
4755
+ [1, 6], [1, 3, 6], [1, 4, 6], [1, 7], [1, 3, 7], [1, 4, 7], [1, 5, 7],
4756
+ [1, 3, 5, 7], [1, 8], [1, 3, 8], [1, 4, 8], [1, 5, 8], [1, 6, 8], [1, 3, 5, 8],
4757
+ [1, 3, 6, 8], [1, 4, 6, 8], [1, 9], [1, 3, 9], [1, 4, 9], [1, 5, 9], [1, 6, 9],
4758
+ [1, 7, 9], [1, 3, 5, 9], [1, 3, 6, 9], [1, 3, 7, 9], [1, 4, 6, 9],
4759
+ [1, 4, 7, 9], [1, 5, 7, 9], [1, 3, 5, 7, 9], [1, 10], [1, 3, 10], [1, 4, 10],
4760
+ [1, 5, 10], [1, 6, 10], [1, 7, 10], [1, 8, 10], [1, 3, 5, 10], [1, 3, 6, 10],
4761
+ [1, 3, 7, 10], [1, 3, 8, 10], [1, 4, 6, 10], [1, 4, 7, 10], [1, 4, 8, 10],
4762
+ [1, 5, 7, 10], [1, 5, 8, 10], [1, 6, 8, 10], [1, 3, 5, 7, 10],
4763
+ [1, 3, 5, 8, 10], [1, 3, 6, 8, 10], [1, 4, 6, 8, 10], [1, 11], [1, 3, 11],
4764
+ [1, 4, 11], [1, 5, 11], [1, 6, 11], [1, 7, 11], [1, 8, 11], [1, 9, 11],
4765
+ [1, 3, 5, 11], [1, 3, 6, 11], [1, 3, 7, 11], [1, 3, 8, 11], [1, 3, 9, 11],
4766
+ [1, 4, 6, 11], [1, 4, 7, 11], [1, 4, 8, 11], [1, 4, 9, 11], [1, 5, 7, 11],
4767
+ [1, 5, 8, 11], [1, 5, 9, 11], [1, 6, 8, 11], [1, 6, 9, 11], [1, 7, 9, 11],
4768
+ [1, 3, 5, 7, 11], [1, 3, 5, 8, 11], [1, 3, 5, 9, 11], [1, 3, 6, 8, 11],
4769
+ [1, 3, 6, 9, 11], [1, 3, 7, 9, 11], [1, 4, 6, 8, 11], [1, 4, 6, 9, 11],
4770
+ [1, 4, 7, 9, 11], [1, 5, 7, 9, 11], [1, 3, 5, 7, 9, 11], [2], [2, 4], [2, 5],
4771
+ [2, 6], [2, 4, 6], [2, 7], [2, 4, 7], [2, 5, 7], [2, 8], [2, 4, 8], [2, 5, 8],
4772
+ [2, 6, 8], [2, 4, 6, 8], [2, 9], [2, 4, 9], [2, 5, 9], [2, 6, 9], [2, 7, 9],
4773
+ [2, 4, 6, 9], [2, 4, 7, 9], [2, 5, 7, 9], [2, 10], [2, 4, 10], [2, 5, 10],
4774
+ [2, 6, 10], [2, 7, 10], [2, 8, 10], [2, 4, 6, 10], [2, 4, 7, 10],
4775
+ [2, 4, 8, 10], [2, 5, 7, 10], [2, 5, 8, 10], [2, 6, 8, 10], [2, 4, 6, 8, 10],
4776
+ [2, 11], [2, 4, 11], [2, 5, 11], [2, 6, 11], [2, 7, 11], [2, 8, 11],
4777
+ [2, 9, 11], [2, 4, 6, 11], [2, 4, 7, 11], [2, 4, 8, 11], [2, 4, 9, 11],
4778
+ [2, 5, 7, 11], [2, 5, 8, 11], [2, 5, 9, 11], [2, 6, 8, 11], [2, 6, 9, 11],
4779
+ [2, 7, 9, 11], [2, 4, 6, 8, 11], [2, 4, 6, 9, 11], [2, 4, 7, 9, 11],
4780
+ [2, 5, 7, 9, 11], [3], [3, 5], [3, 6], [3, 7], [3, 5, 7], [3, 8], [3, 5, 8],
4781
+ [3, 6, 8], [3, 9], [3, 5, 9], [3, 6, 9], [3, 7, 9], [3, 5, 7, 9], [3, 10],
4782
+ [3, 5, 10], [3, 6, 10], [3, 7, 10], [3, 8, 10], [3, 5, 7, 10], [3, 5, 8, 10],
4783
+ [3, 6, 8, 10], [3, 11], [3, 5, 11], [3, 6, 11], [3, 7, 11], [3, 8, 11],
4784
+ [3, 9, 11], [3, 5, 7, 11], [3, 5, 8, 11], [3, 5, 9, 11], [3, 6, 8, 11],
4785
+ [3, 6, 9, 11], [3, 7, 9, 11], [3, 5, 7, 9, 11], [4], [4, 6], [4, 7], [4, 8],
4786
+ [4, 6, 8], [4, 9], [4, 6, 9], [4, 7, 9], [4, 10], [4, 6, 10], [4, 7, 10],
4787
+ [4, 8, 10], [4, 6, 8, 10], [4, 11], [4, 6, 11], [4, 7, 11], [4, 8, 11],
4788
+ [4, 9, 11], [4, 6, 8, 11], [4, 6, 9, 11], [4, 7, 9, 11], [5], [5, 7], [5, 8],
4789
+ [5, 9], [5, 7, 9], [5, 10], [5, 7, 10], [5, 8, 10], [5, 11], [5, 7, 11],
4790
+ [5, 8, 11], [5, 9, 11], [5, 7, 9, 11], [6], [6, 8], [6, 9], [6, 10],
4791
+ [6, 8, 10], [6, 11], [6, 8, 11], [6, 9, 11], [7], [7, 9], [7, 10], [7, 11],
4792
+ [7, 9, 11], [8], [8, 10], [8, 11], [9], [9, 11], [10], [11]]
4793
+
4794
+ ###################################################################################
4795
+
4796
  # This is the end of the TMIDI X Python module
4797
 
4798
  ###################################################################################
fluidsynth-master.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d1af8f1d50572e1e161ab1af5f511c22e7f916df8633756ef34fa3abc14a4db
3
+ size 1958466