asigalov61 commited on
Commit
630dd48
·
verified ·
1 Parent(s): 10245a2

Upload TMIDIX.py

Browse files
Files changed (1) hide show
  1. TMIDIX.py +29 -30
TMIDIX.py CHANGED
@@ -6391,35 +6391,16 @@ def transpose_pitches(pitches, transpose_value=0):
6391
 
6392
  ###################################################################################
6393
 
6394
- def reverse_enhanced_score_notes(enhanced_score_notes):
6395
 
6396
- score = recalculate_score_timings(enhanced_score_notes)
6397
 
6398
- cscore = chordify_score([1000, score])
 
6399
 
6400
- abs_dtimes = []
6401
 
6402
- for i, t in enumerate(cscore[:-1]):
6403
- abs_dtimes.append(cscore[i+1][0][1])
6404
- abs_dtimes.append(cscore[-1][0][1]+cscore[-1][0][2])
6405
-
6406
- new_dtimes = []
6407
- pt = abs_dtimes[-1]
6408
-
6409
- for t in abs_dtimes[::-1]:
6410
- new_dtimes.append(abs(pt-t))
6411
- pt = t
6412
-
6413
- new_mel = copy.deepcopy(cscore[::-1])
6414
-
6415
- time = 0
6416
-
6417
- for i, t in enumerate(new_mel):
6418
- time += new_dtimes[i]
6419
- for tt in t:
6420
- tt[1] = time
6421
-
6422
- return recalculate_score_timings(flatten(new_mel))
6423
 
6424
  ###################################################################################
6425
 
@@ -6434,6 +6415,8 @@ def count_patterns(lst, sublist):
6434
  idx += 1
6435
  return count
6436
 
 
 
6437
  def find_lrno_patterns(seq):
6438
 
6439
  all_seqs = Counter()
@@ -6935,13 +6918,21 @@ def binary_matrix_to_original_escore_notes(binary_matrix,
6935
  count += 1
6936
 
6937
  else:
6938
- if count > 1:
 
 
 
 
6939
  result.append([i-count, count, j, binary_matrix[i-1][j]])
6940
 
6941
- count = 1
6942
 
6943
  if count > 1:
6944
  result.append([len(binary_matrix)-count, count, j, binary_matrix[-1][j]])
 
 
 
 
6945
 
6946
  result.sort(key=lambda x: (x[0], -x[2]))
6947
 
@@ -7776,9 +7767,9 @@ def fixed_escore_notes_timings(escore_notes,
7776
  def cubic_kernel(x):
7777
  abs_x = abs(x)
7778
  if abs_x <= 1:
7779
- return (1.5 * abs_x**3 - 2.5 * abs_x**2 + 1)
7780
  elif abs_x <= 2:
7781
- return (-0.5 * abs_x**3 + 2.5 * abs_x**2 - 4 * abs_x + 2)
7782
  else:
7783
  return 0
7784
 
@@ -7791,17 +7782,25 @@ def resize_matrix(matrix, new_height, new_width):
7791
 
7792
  for i in range(new_height):
7793
  for j in range(new_width):
7794
-
7795
  old_i = i * old_height / new_height
7796
  old_j = j * old_width / new_width
7797
 
7798
  value = 0
 
7799
  for m in range(-1, 3):
7800
  for n in range(-1, 3):
7801
  i_m = min(max(int(old_i) + m, 0), old_height - 1)
7802
  j_n = min(max(int(old_j) + n, 0), old_width - 1)
 
 
 
 
7803
  weight = cubic_kernel(old_i - i_m) * cubic_kernel(old_j - j_n)
7804
  value += matrix[i_m][j_n] * weight
 
 
 
 
7805
 
7806
  resized_matrix[i][j] = int(value > 0.5)
7807
 
 
6391
 
6392
  ###################################################################################
6393
 
6394
+ def reverse_enhanced_score_notes(escore_notes):
6395
 
6396
+ score = recalculate_score_timings(escore_notes)
6397
 
6398
+ ematrix = escore_notes_to_escore_matrix(score, reverse_matrix=True)
6399
+ e_score = escore_matrix_to_original_escore_notes(ematrix)
6400
 
6401
+ reversed_score = recalculate_score_timings(e_score)
6402
 
6403
+ return reversed_score
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6404
 
6405
  ###################################################################################
6406
 
 
6415
  idx += 1
6416
  return count
6417
 
6418
+ ###################################################################################
6419
+
6420
  def find_lrno_patterns(seq):
6421
 
6422
  all_seqs = Counter()
 
6918
  count += 1
6919
 
6920
  else:
6921
+ if count > 1:
6922
+ result.append([i-count, count, j, binary_matrix[i-1][j]])
6923
+
6924
+ else:
6925
+ if binary_matrix[i-1][j] != 0:
6926
  result.append([i-count, count, j, binary_matrix[i-1][j]])
6927
 
6928
+ count = 1
6929
 
6930
  if count > 1:
6931
  result.append([len(binary_matrix)-count, count, j, binary_matrix[-1][j]])
6932
+
6933
+ else:
6934
+ if binary_matrix[i-1][j] != 0:
6935
+ result.append([i-count, count, j, binary_matrix[i-1][j]])
6936
 
6937
  result.sort(key=lambda x: (x[0], -x[2]))
6938
 
 
7767
  def cubic_kernel(x):
7768
  abs_x = abs(x)
7769
  if abs_x <= 1:
7770
+ return 1.5 * abs_x**3 - 2.5 * abs_x**2 + 1
7771
  elif abs_x <= 2:
7772
+ return -0.5 * abs_x**3 + 2.5 * abs_x**2 - 4 * abs_x + 2
7773
  else:
7774
  return 0
7775
 
 
7782
 
7783
  for i in range(new_height):
7784
  for j in range(new_width):
 
7785
  old_i = i * old_height / new_height
7786
  old_j = j * old_width / new_width
7787
 
7788
  value = 0
7789
+ total_weight = 0
7790
  for m in range(-1, 3):
7791
  for n in range(-1, 3):
7792
  i_m = min(max(int(old_i) + m, 0), old_height - 1)
7793
  j_n = min(max(int(old_j) + n, 0), old_width - 1)
7794
+
7795
+ if matrix[i_m][j_n] == 0:
7796
+ continue
7797
+
7798
  weight = cubic_kernel(old_i - i_m) * cubic_kernel(old_j - j_n)
7799
  value += matrix[i_m][j_n] * weight
7800
+ total_weight += weight
7801
+
7802
+ if total_weight > 0:
7803
+ value /= total_weight
7804
 
7805
  resized_matrix[i][j] = int(value > 0.5)
7806