asigalov61 commited on
Commit
74c42ea
·
verified ·
1 Parent(s): b0f6cb7

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +95 -2
TMIDIX.py CHANGED
@@ -1471,6 +1471,8 @@ import csv
1471
 
1472
  import tqdm
1473
 
 
 
1474
  from itertools import zip_longest
1475
  from itertools import groupby
1476
  from collections import Counter
@@ -5589,7 +5591,7 @@ def split_melody(enhanced_melody_score_notes,
5589
  for e in enhanced_melody_score_notes:
5590
  dtime = max(0, min(max_score_time, e[1]-pe[1]))
5591
 
5592
- if dtime > max(durs):
5593
  if chu:
5594
  mel_chunks.append(chu)
5595
  chu = []
@@ -9603,7 +9605,7 @@ def escore_notes_to_text_description(escore_notes,
9603
 
9604
  all_patches = [e[6] for e in escore_notes]
9605
 
9606
- patches = ordered_set(all_patches)
9607
 
9608
  instruments = [alpha_str(Number2patch[p]) for p in patches if p < 128]
9609
 
@@ -11088,6 +11090,97 @@ def escore_notes_pitches_range(escore_notes,
11088
  else:
11089
  return [ -1] * 6
11090
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11091
  ###################################################################################
11092
  #
11093
  # This is the end of the TMIDI X Python module
 
1471
 
1472
  import tqdm
1473
 
1474
+ import multiprocessing
1475
+
1476
  from itertools import zip_longest
1477
  from itertools import groupby
1478
  from collections import Counter
 
5591
  for e in enhanced_melody_score_notes:
5592
  dtime = max(0, min(max_score_time, e[1]-pe[1]))
5593
 
5594
+ if dtime > stime:
5595
  if chu:
5596
  mel_chunks.append(chu)
5597
  chu = []
 
9605
 
9606
  all_patches = [e[6] for e in escore_notes]
9607
 
9608
+ patches = ordered_set(all_patches)[:16]
9609
 
9610
  instruments = [alpha_str(Number2patch[p]) for p in patches if p < 128]
9611
 
 
11090
  else:
11091
  return [ -1] * 6
11092
 
11093
+ ###################################################################################
11094
+
11095
+ def escore_notes_core(escore_notes, core_len=128):
11096
+
11097
+ cscore = chordify_score([1000, escore_notes])
11098
+
11099
+ chords = []
11100
+ chords_idxs = []
11101
+
11102
+ for i, c in enumerate(cscore):
11103
+
11104
+ pitches = [e[4] for e in c if e[3] != 9]
11105
+
11106
+ if pitches:
11107
+ tones_chord = sorted(set([p % 12 for p in pitches]))
11108
+
11109
+ if tones_chord not in ALL_CHORDS_SORTED:
11110
+ tones_chord = check_and_fix_tones_chord(tones_chord)
11111
+
11112
+ chords.append(ALL_CHORDS_SORTED.index(tones_chord))
11113
+ chords_idxs.append(i)
11114
+
11115
+ mid = len(chords_idxs) // 2
11116
+ clen = core_len // 2
11117
+
11118
+ sidx = chords_idxs[mid-clen]
11119
+ eidx = chords_idxs[mid+clen]
11120
+
11121
+ core_chords = chords[mid-clen:mid+clen]
11122
+ core_score = flatten(cscore[sidx:eidx])
11123
+
11124
+ return core_score, core_chords
11125
+
11126
+ ###################################################################################
11127
+
11128
+ def multiprocessing_wrapper(function, data_list):
11129
+
11130
+ with multiprocessing.Pool() as pool:
11131
+
11132
+ results = []
11133
+
11134
+ for result in tqdm.tqdm(pool.imap_unordered(function, data_list), total=len(data_list)):
11135
+ results.append(result)
11136
+
11137
+ return results
11138
+
11139
+ ###################################################################################
11140
+
11141
+ def rle_encode_ones(matrix, div_mod=-1):
11142
+
11143
+ flat_list = [val for row in matrix for val in row]
11144
+
11145
+ encoding = []
11146
+ i = 0
11147
+
11148
+ while i < len(flat_list):
11149
+
11150
+ if flat_list[i] == 1:
11151
+
11152
+ start_index = i
11153
+ count = 1
11154
+ i += 1
11155
+
11156
+ while i < len(flat_list) and flat_list[i] == 1:
11157
+ count += 1
11158
+ i += 1
11159
+
11160
+ if div_mod > 0:
11161
+ encoding.append((start_index // div_mod, start_index % div_mod))
11162
+
11163
+ else:
11164
+ encoding.append(start_index)
11165
+
11166
+ else:
11167
+ i += 1
11168
+
11169
+ return encoding
11170
+
11171
+ ###################################################################################
11172
+
11173
+ def rle_decode_ones(encoding, size=(128, 128)):
11174
+
11175
+ flat_list = [0] * (size[0] * size[1])
11176
+
11177
+ for start_index in encoding:
11178
+ flat_list[start_index] = 1
11179
+
11180
+ matrix = [flat_list[i * size[1]:(i + 1) * size[1]] for i in range(size[0])]
11181
+
11182
+ return matrix
11183
+
11184
  ###################################################################################
11185
  #
11186
  # This is the end of the TMIDI X Python module