Upload TMIDIX.py
Browse files
TMIDIX.py
CHANGED
@@ -4610,86 +4610,34 @@ def ascii_text_words_counter(ascii_text):
|
|
4610 |
|
4611 |
def check_and_fix_tones_chord(tones_chord):
|
4612 |
|
4613 |
-
|
4614 |
|
4615 |
-
|
4616 |
-
|
4617 |
-
|
4618 |
-
|
4619 |
-
if 0 in lst and 11 in lst:
|
4620 |
-
lst.remove(0)
|
4621 |
-
return lst
|
4622 |
-
|
4623 |
-
non_consecutive = [lst[0]]
|
4624 |
-
|
4625 |
-
if len(lst) > 2:
|
4626 |
-
for i in range(1, len(lst) - 1):
|
4627 |
-
if lst[i-1] + 1 != lst[i] and lst[i] + 1 != lst[i+1]:
|
4628 |
-
non_consecutive.append(lst[i])
|
4629 |
-
non_consecutive.append(lst[-1])
|
4630 |
-
|
4631 |
-
if 0 in non_consecutive and 11 in non_consecutive:
|
4632 |
-
non_consecutive.remove(0)
|
4633 |
|
4634 |
-
|
4635 |
|
4636 |
###################################################################################
|
4637 |
|
4638 |
def find_closest_tone(tones, tone):
|
4639 |
return min(tones, key=lambda x:abs(x-tone))
|
4640 |
|
4641 |
-
|
4642 |
-
|
4643 |
-
lst = tones_chord
|
4644 |
|
4645 |
-
|
4646 |
-
ht = high_pitch % 12
|
4647 |
-
else:
|
4648 |
-
ht = 12
|
4649 |
|
4650 |
-
|
4651 |
|
4652 |
-
|
4653 |
-
|
4654 |
-
|
4655 |
-
else:
|
4656 |
-
if 0 in lst and 11 in lst:
|
4657 |
-
if find_closest_tone([0, 11], cht) == 11:
|
4658 |
-
lst.remove(0)
|
4659 |
-
else:
|
4660 |
-
lst.remove(11)
|
4661 |
-
return lst
|
4662 |
-
|
4663 |
-
non_consecutive = []
|
4664 |
-
|
4665 |
-
if len(lst) > 2:
|
4666 |
-
for i in range(0, len(lst) - 1):
|
4667 |
-
if lst[i] + 1 != lst[i+1]:
|
4668 |
-
non_consecutive.append(lst[i])
|
4669 |
-
if lst[-1] - lst[-2] > 1:
|
4670 |
-
non_consecutive.append(lst[-1])
|
4671 |
-
|
4672 |
-
if cht not in non_consecutive:
|
4673 |
-
non_consecutive.append(cht)
|
4674 |
-
non_consecutive.sort()
|
4675 |
-
if any(abs(non_consecutive[i+1] - non_consecutive[i]) == 1 for i in range(len(non_consecutive) - 1)):
|
4676 |
-
final_list = [x for x in non_consecutive if x == cht or abs(x - cht) > 1]
|
4677 |
-
else:
|
4678 |
-
final_list = non_consecutive
|
4679 |
|
4680 |
-
|
4681 |
-
|
4682 |
|
4683 |
-
|
4684 |
-
if find_closest_tone([0, 11], cht) == 11:
|
4685 |
-
final_list.remove(0)
|
4686 |
-
else:
|
4687 |
-
final_list.remove(11)
|
4688 |
-
|
4689 |
-
if cht in final_list or ht in final_list:
|
4690 |
-
return final_list
|
4691 |
-
else:
|
4692 |
-
return ['Error']
|
4693 |
|
4694 |
###################################################################################
|
4695 |
|
@@ -5204,7 +5152,8 @@ def advanced_check_and_fix_chords_in_chordified_score(chordified_score,
|
|
5204 |
channels_index=3,
|
5205 |
pitches_index=4,
|
5206 |
patches_index=6,
|
5207 |
-
use_filtered_chords=
|
|
|
5208 |
remove_duplicate_pitches=True,
|
5209 |
skip_drums=False
|
5210 |
):
|
@@ -5218,6 +5167,9 @@ def advanced_check_and_fix_chords_in_chordified_score(chordified_score,
|
|
5218 |
else:
|
5219 |
CHORDS = ALL_CHORDS_SORTED
|
5220 |
|
|
|
|
|
|
|
5221 |
for c in chordified_score:
|
5222 |
|
5223 |
if remove_duplicate_pitches:
|
@@ -5476,11 +5428,11 @@ def harmonize_enhanced_melody_score_notes(enhanced_melody_score_notes):
|
|
5476 |
cur_chord.append(m)
|
5477 |
cc = sorted(set(cur_chord))
|
5478 |
|
5479 |
-
if cc in
|
5480 |
song.append(cc)
|
5481 |
|
5482 |
else:
|
5483 |
-
while sorted(set(cur_chord)) not in
|
5484 |
cur_chord.pop(0)
|
5485 |
cc = sorted(set(cur_chord))
|
5486 |
song.append(cc)
|
@@ -5680,7 +5632,8 @@ def basic_enhanced_delta_score_notes_detokenizer(tokenized_seq,
|
|
5680 |
def enhanced_chord_to_chord_token(enhanced_chord,
|
5681 |
channels_index=3,
|
5682 |
pitches_index=4,
|
5683 |
-
use_filtered_chords=
|
|
|
5684 |
):
|
5685 |
|
5686 |
bad_chords_counter = 0
|
@@ -5691,6 +5644,9 @@ def enhanced_chord_to_chord_token(enhanced_chord,
|
|
5691 |
else:
|
5692 |
CHORDS = ALL_CHORDS_SORTED
|
5693 |
|
|
|
|
|
|
|
5694 |
tones_chord = sorted(set([t[pitches_index] % 12 for t in enhanced_chord if t[channels_index] != 9]))
|
5695 |
|
5696 |
original_tones_chord = copy.deepcopy(tones_chord)
|
@@ -7134,7 +7090,8 @@ CHORDS_TYPES = ['WHITE', 'BLACK', 'UNKNOWN', 'MIXED WHITE', 'MIXED BLACK', 'MIXE
|
|
7134 |
|
7135 |
def tones_chord_type(tones_chord,
|
7136 |
return_chord_type_index=True,
|
7137 |
-
use_filtered_chords=
|
|
|
7138 |
):
|
7139 |
|
7140 |
WN = WHITE_NOTES
|
@@ -7147,6 +7104,9 @@ def tones_chord_type(tones_chord,
|
|
7147 |
else:
|
7148 |
CHORDS = ALL_CHORDS_SORTED
|
7149 |
|
|
|
|
|
|
|
7150 |
tones_chord = sorted(tones_chord)
|
7151 |
|
7152 |
ctype = 'UNKNOWN'
|
@@ -7237,7 +7197,8 @@ def find_best_tones_chord(src_tones_chords,
|
|
7237 |
def find_matching_tones_chords(tones_chord,
|
7238 |
matching_chord_length=-1,
|
7239 |
match_chord_type=True,
|
7240 |
-
use_filtered_chords=True
|
|
|
7241 |
):
|
7242 |
|
7243 |
if use_filtered_chords:
|
@@ -7245,6 +7206,9 @@ def find_matching_tones_chords(tones_chord,
|
|
7245 |
else:
|
7246 |
CHORDS = ALL_CHORDS_SORTED
|
7247 |
|
|
|
|
|
|
|
7248 |
tones_chord = sorted(tones_chord)
|
7249 |
|
7250 |
tclen = len(tones_chord)
|
@@ -7427,7 +7391,8 @@ def harmonize_enhanced_melody_score_notes_to_ms_SONG(escore_notes,
|
|
7427 |
###################################################################################
|
7428 |
|
7429 |
def check_and_fix_pitches_chord(pitches_chord,
|
7430 |
-
use_filtered_chords=
|
|
|
7431 |
):
|
7432 |
|
7433 |
pitches_chord = sorted(pitches_chord, reverse=True)
|
@@ -7437,6 +7402,9 @@ def check_and_fix_pitches_chord(pitches_chord,
|
|
7437 |
else:
|
7438 |
CHORDS = ALL_CHORDS_SORTED
|
7439 |
|
|
|
|
|
|
|
7440 |
tones_chord = sorted(set([p % 12 for p in pitches_chord]))
|
7441 |
|
7442 |
if tones_chord not in CHORDS:
|
@@ -7455,12 +7423,20 @@ def check_and_fix_pitches_chord(pitches_chord,
|
|
7455 |
if len(tones_chord) > 2:
|
7456 |
|
7457 |
tones_chord_combs = [list(comb) for i in range(len(tones_chord)-2, 0, -1) for comb in combinations(tones_chord, i+1)]
|
|
|
|
|
7458 |
|
7459 |
for co in tones_chord_combs:
|
7460 |
if co in CHORDS:
|
7461 |
-
|
7462 |
break
|
7463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7464 |
new_pitches_chord = []
|
7465 |
|
7466 |
for p in pitches_chord:
|
@@ -7658,7 +7634,8 @@ def tones_chords_to_types(tones_chords,
|
|
7658 |
|
7659 |
def morph_tones_chord(tones_chord,
|
7660 |
trg_tone,
|
7661 |
-
use_filtered_chords=True
|
|
|
7662 |
):
|
7663 |
|
7664 |
src_tones_chord = sorted(sorted(set(tones_chord)) + [trg_tone])
|
@@ -7673,6 +7650,9 @@ def morph_tones_chord(tones_chord,
|
|
7673 |
else:
|
7674 |
CHORDS = ALL_CHORDS_SORTED
|
7675 |
|
|
|
|
|
|
|
7676 |
for c in combs:
|
7677 |
if sorted(set(c)) in CHORDS:
|
7678 |
matches.append(sorted(set(c)))
|
@@ -8558,7 +8538,7 @@ def escore_notes_lrno_pattern(escore_notes, mode='chords'):
|
|
8558 |
if tchord:
|
8559 |
|
8560 |
if mode == 'chords':
|
8561 |
-
token =
|
8562 |
|
8563 |
elif mode == 'high pitches':
|
8564 |
token = pitches[0]
|
@@ -8567,7 +8547,7 @@ def escore_notes_lrno_pattern(escore_notes, mode='chords'):
|
|
8567 |
token = pitches[0] % 12
|
8568 |
|
8569 |
else:
|
8570 |
-
token =
|
8571 |
|
8572 |
chords_toks.append(token)
|
8573 |
chords_idxs.append(i)
|
@@ -8715,6 +8695,28 @@ def escore_notes_middle(escore_notes,
|
|
8715 |
else:
|
8716 |
return score[start_idx:end_idx]
|
8717 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8718 |
###################################################################################
|
8719 |
#
|
8720 |
# This is the end of the TMIDI X Python module
|
|
|
4610 |
|
4611 |
def check_and_fix_tones_chord(tones_chord):
|
4612 |
|
4613 |
+
tones_chord_combs = [list(comb) for i in range(len(tones_chord), 0, -1) for comb in combinations(tones_chord, i)]
|
4614 |
|
4615 |
+
for c in tones_chord_combs:
|
4616 |
+
if c in ALL_CHORDS_FULL:
|
4617 |
+
checked_tones_chord = c
|
4618 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4619 |
|
4620 |
+
return sorted(checked_tones_chord)
|
4621 |
|
4622 |
###################################################################################
|
4623 |
|
4624 |
def find_closest_tone(tones, tone):
|
4625 |
return min(tones, key=lambda x:abs(x-tone))
|
4626 |
|
4627 |
+
###################################################################################
|
|
|
|
|
4628 |
|
4629 |
+
def advanced_check_and_fix_tones_chord(tones_chord, high_pitch=0):
|
|
|
|
|
|
|
4630 |
|
4631 |
+
tones_chord_combs = [list(comb) for i in range(len(tones_chord), 0, -1) for comb in combinations(tones_chord, i)]
|
4632 |
|
4633 |
+
for c in tones_chord_combs:
|
4634 |
+
if c in ALL_CHORDS_FULL:
|
4635 |
+
tchord = c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4636 |
|
4637 |
+
if 0 < high_pitch < 128 and len(tchord) == 1:
|
4638 |
+
tchord = [high_pitch % 12]
|
4639 |
|
4640 |
+
return tchord
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4641 |
|
4642 |
###################################################################################
|
4643 |
|
|
|
5152 |
channels_index=3,
|
5153 |
pitches_index=4,
|
5154 |
patches_index=6,
|
5155 |
+
use_filtered_chords=False,
|
5156 |
+
use_full_chords=True,
|
5157 |
remove_duplicate_pitches=True,
|
5158 |
skip_drums=False
|
5159 |
):
|
|
|
5167 |
else:
|
5168 |
CHORDS = ALL_CHORDS_SORTED
|
5169 |
|
5170 |
+
if use_full_chords:
|
5171 |
+
CHORDS = ALL_CHORDS_FULL
|
5172 |
+
|
5173 |
for c in chordified_score:
|
5174 |
|
5175 |
if remove_duplicate_pitches:
|
|
|
5428 |
cur_chord.append(m)
|
5429 |
cc = sorted(set(cur_chord))
|
5430 |
|
5431 |
+
if cc in ALL_CHORDS_FULL:
|
5432 |
song.append(cc)
|
5433 |
|
5434 |
else:
|
5435 |
+
while sorted(set(cur_chord)) not in ALL_CHORDS_FULL:
|
5436 |
cur_chord.pop(0)
|
5437 |
cc = sorted(set(cur_chord))
|
5438 |
song.append(cc)
|
|
|
5632 |
def enhanced_chord_to_chord_token(enhanced_chord,
|
5633 |
channels_index=3,
|
5634 |
pitches_index=4,
|
5635 |
+
use_filtered_chords=False,
|
5636 |
+
use_full_chords=True
|
5637 |
):
|
5638 |
|
5639 |
bad_chords_counter = 0
|
|
|
5644 |
else:
|
5645 |
CHORDS = ALL_CHORDS_SORTED
|
5646 |
|
5647 |
+
if use_full_chords:
|
5648 |
+
CHORDS = ALL_CHORDS_FULL
|
5649 |
+
|
5650 |
tones_chord = sorted(set([t[pitches_index] % 12 for t in enhanced_chord if t[channels_index] != 9]))
|
5651 |
|
5652 |
original_tones_chord = copy.deepcopy(tones_chord)
|
|
|
7090 |
|
7091 |
def tones_chord_type(tones_chord,
|
7092 |
return_chord_type_index=True,
|
7093 |
+
use_filtered_chords=False,
|
7094 |
+
use_full_chords=True
|
7095 |
):
|
7096 |
|
7097 |
WN = WHITE_NOTES
|
|
|
7104 |
else:
|
7105 |
CHORDS = ALL_CHORDS_SORTED
|
7106 |
|
7107 |
+
if use_full_chords:
|
7108 |
+
CHORDS = ALL_CHORDS_FULL
|
7109 |
+
|
7110 |
tones_chord = sorted(tones_chord)
|
7111 |
|
7112 |
ctype = 'UNKNOWN'
|
|
|
7197 |
def find_matching_tones_chords(tones_chord,
|
7198 |
matching_chord_length=-1,
|
7199 |
match_chord_type=True,
|
7200 |
+
use_filtered_chords=True,
|
7201 |
+
use_full_chords=True
|
7202 |
):
|
7203 |
|
7204 |
if use_filtered_chords:
|
|
|
7206 |
else:
|
7207 |
CHORDS = ALL_CHORDS_SORTED
|
7208 |
|
7209 |
+
if use_full_chords:
|
7210 |
+
CHORDS = ALL_CHORDS_FULL
|
7211 |
+
|
7212 |
tones_chord = sorted(tones_chord)
|
7213 |
|
7214 |
tclen = len(tones_chord)
|
|
|
7391 |
###################################################################################
|
7392 |
|
7393 |
def check_and_fix_pitches_chord(pitches_chord,
|
7394 |
+
use_filtered_chords=False,
|
7395 |
+
use_full_chords=True
|
7396 |
):
|
7397 |
|
7398 |
pitches_chord = sorted(pitches_chord, reverse=True)
|
|
|
7402 |
else:
|
7403 |
CHORDS = ALL_CHORDS_SORTED
|
7404 |
|
7405 |
+
if use_full_chords:
|
7406 |
+
CHORDS = ALL_CHORDS_FULL
|
7407 |
+
|
7408 |
tones_chord = sorted(set([p % 12 for p in pitches_chord]))
|
7409 |
|
7410 |
if tones_chord not in CHORDS:
|
|
|
7423 |
if len(tones_chord) > 2:
|
7424 |
|
7425 |
tones_chord_combs = [list(comb) for i in range(len(tones_chord)-2, 0, -1) for comb in combinations(tones_chord, i+1)]
|
7426 |
+
|
7427 |
+
tchord = []
|
7428 |
|
7429 |
for co in tones_chord_combs:
|
7430 |
if co in CHORDS:
|
7431 |
+
tchord = co
|
7432 |
break
|
7433 |
|
7434 |
+
if tchord:
|
7435 |
+
tones_chord = tchord
|
7436 |
+
|
7437 |
+
else:
|
7438 |
+
tones_chord = [pitches_chord[0] % 12]
|
7439 |
+
|
7440 |
new_pitches_chord = []
|
7441 |
|
7442 |
for p in pitches_chord:
|
|
|
7634 |
|
7635 |
def morph_tones_chord(tones_chord,
|
7636 |
trg_tone,
|
7637 |
+
use_filtered_chords=True,
|
7638 |
+
use_full_chords=True
|
7639 |
):
|
7640 |
|
7641 |
src_tones_chord = sorted(sorted(set(tones_chord)) + [trg_tone])
|
|
|
7650 |
else:
|
7651 |
CHORDS = ALL_CHORDS_SORTED
|
7652 |
|
7653 |
+
if use_full_chords:
|
7654 |
+
CHORDS = ALL_CHORDS_FULL
|
7655 |
+
|
7656 |
for c in combs:
|
7657 |
if sorted(set(c)) in CHORDS:
|
7658 |
matches.append(sorted(set(c)))
|
|
|
8538 |
if tchord:
|
8539 |
|
8540 |
if mode == 'chords':
|
8541 |
+
token = ALL_CHORDS_FULL.index(tchord)
|
8542 |
|
8543 |
elif mode == 'high pitches':
|
8544 |
token = pitches[0]
|
|
|
8547 |
token = pitches[0] % 12
|
8548 |
|
8549 |
else:
|
8550 |
+
token = ALL_CHORDS_FULL.index(tchord)
|
8551 |
|
8552 |
chords_toks.append(token)
|
8553 |
chords_idxs.append(i)
|
|
|
8695 |
else:
|
8696 |
return score[start_idx:end_idx]
|
8697 |
|
8698 |
+
###################################################################################
|
8699 |
+
|
8700 |
+
ALL_CHORDS_FULL = [[0], [0, 3], [0, 3, 5], [0, 3, 5, 8], [0, 3, 5, 9], [0, 3, 5, 10], [0, 3, 6],
|
8701 |
+
[0, 3, 6, 9], [0, 3, 6, 10], [0, 3, 7], [0, 3, 7, 10], [0, 3, 8], [0, 3, 9],
|
8702 |
+
[0, 3, 10], [0, 4], [0, 4, 6], [0, 4, 6, 9], [0, 4, 6, 10], [0, 4, 7],
|
8703 |
+
[0, 4, 7, 10], [0, 4, 8], [0, 4, 9], [0, 4, 10], [0, 5], [0, 5, 8], [0, 5, 9],
|
8704 |
+
[0, 5, 10], [0, 6], [0, 6, 9], [0, 6, 10], [0, 7], [0, 7, 10], [0, 8], [0, 9],
|
8705 |
+
[0, 10], [1], [1, 4], [1, 4, 6], [1, 4, 6, 9], [1, 4, 6, 10], [1, 4, 6, 11],
|
8706 |
+
[1, 4, 7], [1, 4, 7, 10], [1, 4, 7, 11], [1, 4, 8], [1, 4, 8, 11], [1, 4, 9],
|
8707 |
+
[1, 4, 10], [1, 4, 11], [1, 5], [1, 5, 8], [1, 5, 8, 11], [1, 5, 9],
|
8708 |
+
[1, 5, 10], [1, 5, 11], [1, 6], [1, 6, 9], [1, 6, 10], [1, 6, 11], [1, 7],
|
8709 |
+
[1, 7, 10], [1, 7, 11], [1, 8], [1, 8, 11], [1, 9], [1, 10], [1, 11], [2],
|
8710 |
+
[2, 5], [2, 5, 8], [2, 5, 8, 11], [2, 5, 9], [2, 5, 10], [2, 5, 11], [2, 6],
|
8711 |
+
[2, 6, 9], [2, 6, 10], [2, 6, 11], [2, 7], [2, 7, 10], [2, 7, 11], [2, 8],
|
8712 |
+
[2, 8, 11], [2, 9], [2, 10], [2, 11], [3], [3, 5], [3, 5, 8], [3, 5, 8, 11],
|
8713 |
+
[3, 5, 9], [3, 5, 10], [3, 5, 11], [3, 6], [3, 6, 9], [3, 6, 10], [3, 6, 11],
|
8714 |
+
[3, 7], [3, 7, 10], [3, 7, 11], [3, 8], [3, 8, 11], [3, 9], [3, 10], [3, 11],
|
8715 |
+
[4], [4, 6], [4, 6, 9], [4, 6, 10], [4, 6, 11], [4, 7], [4, 7, 10], [4, 7, 11],
|
8716 |
+
[4, 8], [4, 8, 11], [4, 9], [4, 10], [4, 11], [5], [5, 8], [5, 8, 11], [5, 9],
|
8717 |
+
[5, 10], [5, 11], [6], [6, 9], [6, 10], [6, 11], [7], [7, 10], [7, 11], [8],
|
8718 |
+
[8, 11], [9], [10], [11]]
|
8719 |
+
|
8720 |
###################################################################################
|
8721 |
#
|
8722 |
# This is the end of the TMIDI X Python module
|