asigalov61 commited on
Commit
8b1d953
1 Parent(s): cfd62d1

Upload 2 files

Browse files
Files changed (2) hide show
  1. TMIDIX.py +85 -37
  2. TPLOTS.py +40 -0
TMIDIX.py CHANGED
@@ -4953,25 +4953,26 @@ def patch_list_from_enhanced_score_notes(enhanced_score_notes,
4953
  patches = [-1] * 16
4954
 
4955
  for idx, e in enumerate(enhanced_score_notes):
4956
- if e[3] != 9:
4957
- if patches[e[3]] == -1:
4958
- patches[e[3]] = e[6]
4959
- else:
4960
- if patches[e[3]] != e[6]:
4961
- if e[6] in patches:
4962
- e[3] = patches.index(e[6])
4963
- else:
4964
- if -1 in patches:
4965
- patches[patches.index(-1)] = e[6]
4966
  else:
4967
- patches[-1] = e[6]
 
 
 
4968
 
4969
- if verbose:
4970
- print('=' * 70)
4971
- print('WARNING! Composition has more than 15 patches!')
4972
- print('Conflict note number:', idx)
4973
- print('Conflict channel number:', e[3])
4974
- print('Conflict patch number:', e[6])
4975
 
4976
  patches = [p if p != -1 else default_patch for p in patches]
4977
 
@@ -5004,19 +5005,20 @@ def patch_enhanced_score_notes(enhanced_score_notes,
5004
  overflow_idx = -1
5005
 
5006
  for idx, e in enumerate(enhanced_score_notes):
5007
- if e[3] != 9:
5008
- if patches[e[3]] == -1:
5009
- patches[e[3]] = e[6]
5010
- else:
5011
- if patches[e[3]] != e[6]:
5012
- if e[6] in patches:
5013
- e[3] = patches.index(e[6])
5014
- else:
5015
- if -1 in patches:
5016
- patches[patches.index(-1)] = e[6]
5017
  else:
5018
- overflow_idx = idx
5019
- break
 
 
 
5020
 
5021
  enhanced_score_notes_with_patch_changes.append(e)
5022
 
@@ -5026,15 +5028,16 @@ def patch_enhanced_score_notes(enhanced_score_notes,
5026
 
5027
  if overflow_idx != -1:
5028
  for idx, e in enumerate(enhanced_score_notes[overflow_idx:]):
5029
- if e[3] != 9:
5030
- if e[6] not in patches:
5031
- if e[6] not in overflow_patches:
5032
- overflow_patches.append(e[6])
5033
- enhanced_score_notes_with_patch_changes.append(['patch_change', e[1], e[3], e[6]])
5034
- else:
5035
- e[3] = patches.index(e[6])
 
5036
 
5037
- enhanced_score_notes_with_patch_changes.append(e)
5038
 
5039
  #===========================================================================
5040
 
@@ -8375,6 +8378,51 @@ def monophonic_check(escore_notes, times_index=1):
8375
  def count_escore_notes_patches(escore_notes, patches_index=6):
8376
  return [list(c) for c in Counter([e[patches_index] for e in escore_notes]).most_common()]
8377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8378
  ###################################################################################
8379
  #
8380
  # This is the end of the TMIDI X Python module
 
4953
  patches = [-1] * 16
4954
 
4955
  for idx, e in enumerate(enhanced_score_notes):
4956
+ if e[0] == 'note':
4957
+ if e[3] != 9:
4958
+ if patches[e[3]] == -1:
4959
+ patches[e[3]] = e[6]
4960
+ else:
4961
+ if patches[e[3]] != e[6]:
4962
+ if e[6] in patches:
4963
+ e[3] = patches.index(e[6])
 
 
4964
  else:
4965
+ if -1 in patches:
4966
+ patches[patches.index(-1)] = e[6]
4967
+ else:
4968
+ patches[-1] = e[6]
4969
 
4970
+ if verbose:
4971
+ print('=' * 70)
4972
+ print('WARNING! Composition has more than 15 patches!')
4973
+ print('Conflict note number:', idx)
4974
+ print('Conflict channel number:', e[3])
4975
+ print('Conflict patch number:', e[6])
4976
 
4977
  patches = [p if p != -1 else default_patch for p in patches]
4978
 
 
5005
  overflow_idx = -1
5006
 
5007
  for idx, e in enumerate(enhanced_score_notes):
5008
+ if e[0] == 'note':
5009
+ if e[3] != 9:
5010
+ if patches[e[3]] == -1:
5011
+ patches[e[3]] = e[6]
5012
+ else:
5013
+ if patches[e[3]] != e[6]:
5014
+ if e[6] in patches:
5015
+ e[3] = patches.index(e[6])
 
 
5016
  else:
5017
+ if -1 in patches:
5018
+ patches[patches.index(-1)] = e[6]
5019
+ else:
5020
+ overflow_idx = idx
5021
+ break
5022
 
5023
  enhanced_score_notes_with_patch_changes.append(e)
5024
 
 
5028
 
5029
  if overflow_idx != -1:
5030
  for idx, e in enumerate(enhanced_score_notes[overflow_idx:]):
5031
+ if e[0] == 'note':
5032
+ if e[3] != 9:
5033
+ if e[6] not in patches:
5034
+ if e[6] not in overflow_patches:
5035
+ overflow_patches.append(e[6])
5036
+ enhanced_score_notes_with_patch_changes.append(['patch_change', e[1], e[3], e[6]])
5037
+ else:
5038
+ e[3] = patches.index(e[6])
5039
 
5040
+ enhanced_score_notes_with_patch_changes.append(e)
5041
 
5042
  #===========================================================================
5043
 
 
8378
  def count_escore_notes_patches(escore_notes, patches_index=6):
8379
  return [list(c) for c in Counter([e[patches_index] for e in escore_notes]).most_common()]
8380
 
8381
+ ###################################################################################
8382
+
8383
+ def escore_notes_medley(list_of_escore_notes,
8384
+ list_of_labels=None,
8385
+ pause_time_value=255
8386
+ ):
8387
+
8388
+ if list_of_labels is not None:
8389
+ labels = [str(l) for l in list_of_labels] + ['No label'] * (len(list_of_escore_notes)-len(list_of_labels))
8390
+
8391
+ medley = []
8392
+
8393
+ time = 0
8394
+
8395
+ for i, m in enumerate(list_of_escore_notes):
8396
+
8397
+ if list_of_labels is not None:
8398
+ medley.append(['text_event', time, labels[i]])
8399
+
8400
+ pe = m[0]
8401
+
8402
+ for mm in m:
8403
+
8404
+ time += mm[1] - pe[1]
8405
+
8406
+ mmm = copy.deepcopy(mm)
8407
+ mmm[1] = time
8408
+
8409
+ medley.append(mmm)
8410
+
8411
+ pe = mm
8412
+
8413
+ time += pause_time_value
8414
+
8415
+ return medley
8416
+
8417
+ ###################################################################################
8418
+
8419
+ def proportions_counter(list_of_values):
8420
+
8421
+ counts = Counter(list_of_values).most_common()
8422
+ clen = sum([c[1] for c in counts])
8423
+
8424
+ return [[c[0], c[1], c[1] / clen] for c in counts]
8425
+
8426
  ###################################################################################
8427
  #
8428
  # This is the end of the TMIDI X Python module
TPLOTS.py CHANGED
@@ -1090,6 +1090,46 @@ def images_to_image_matrix(list_of_images,
1090
 
1091
  return original_matrix
1092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1093
  ################################################################################
1094
  # [WIP] Future dev functions
1095
  ################################################################################
 
1090
 
1091
  return original_matrix
1092
 
1093
+ ################################################################################
1094
+
1095
+ def square_matrix_to_RGB_matrix(square_matrix):
1096
+
1097
+ smatrix = np.array(square_matrix)
1098
+ sq_matrix = smatrix[:smatrix.shape[1]]
1099
+
1100
+ r = (sq_matrix // (256 ** 2)) % 256
1101
+ g = (sq_matrix // 256) % 256
1102
+ b = sq_matrix % 256
1103
+
1104
+ rgb_array = np.stack((r, g, b), axis=-1)
1105
+
1106
+ return rgb_array.tolist()
1107
+
1108
+ ################################################################################
1109
+
1110
+ def upsample_square_matrix(square_matrix, upsampling_factor=4):
1111
+
1112
+ smatrix = np.array(square_matrix)
1113
+ sq_matrix = smatrix[:smatrix.shape[1]]
1114
+
1115
+ scaling_array = np.ones((upsampling_factor, upsampling_factor))
1116
+ scaled_array = np.kron(sq_matrix, scaling_array)
1117
+ scaled_array = scaled_array.astype('int')
1118
+
1119
+ return scaled_array.tolist()
1120
+
1121
+ ################################################################################
1122
+
1123
+ def downsample_square_matrix(square_matrix, downsampling_factor=4):
1124
+
1125
+ smatrix = np.array(square_matrix)
1126
+ sq_matrix = smatrix[:smatrix.shape[1]]
1127
+
1128
+ dmatrix = sq_matrix[::downsampling_factor, ::downsampling_factor]
1129
+ dmatrix = dmatrix.astype('int')
1130
+
1131
+ return dmatrix.tolist()
1132
+
1133
  ################################################################################
1134
  # [WIP] Future dev functions
1135
  ################################################################################