Upload TMIDIX.py
Browse files
TMIDIX.py
CHANGED
@@ -51,7 +51,7 @@ r'''############################################################################
|
|
51 |
|
52 |
###################################################################################
|
53 |
|
54 |
-
__version__ = "25.8.
|
55 |
|
56 |
print('=' * 70)
|
57 |
print('TMIDIX Python module')
|
@@ -14305,6 +14305,8 @@ def symmetric_match_ratio(list_a, list_b, threshold=0):
|
|
14305 |
|
14306 |
def escore_notes_to_chords(escore_notes,
|
14307 |
use_full_chords=False,
|
|
|
|
|
14308 |
convert_pitches=True,
|
14309 |
shift_chords=False,
|
14310 |
return_tones_chords=False
|
@@ -14327,10 +14329,12 @@ def escore_notes_to_chords(escore_notes,
|
|
14327 |
|
14328 |
tones_chord = sorted(set([p % 12 for p in pitches]))
|
14329 |
|
14330 |
-
if
|
14331 |
-
tones_chord
|
14332 |
-
|
14333 |
-
|
|
|
|
|
14334 |
if return_tones_chords:
|
14335 |
if convert_pitches:
|
14336 |
chords.append(tones_chord)
|
@@ -14343,24 +14347,41 @@ def escore_notes_to_chords(escore_notes,
|
|
14343 |
chords.append([-pitches[0]])
|
14344 |
|
14345 |
else:
|
14346 |
-
|
14347 |
-
|
14348 |
-
|
14349 |
-
if len(pitches) > 1:
|
14350 |
-
chords.append(cho_tok+12)
|
14351 |
|
14352 |
-
else:
|
14353 |
-
chords.append(pitches[0] % 12)
|
14354 |
-
|
14355 |
else:
|
|
|
|
|
|
|
14356 |
chords.append(cho_tok)
|
14357 |
|
14358 |
else:
|
14359 |
-
if
|
14360 |
-
|
14361 |
|
14362 |
else:
|
14363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14364 |
|
14365 |
return chords
|
14366 |
|
@@ -14626,6 +14647,75 @@ def strings_dict(list_of_strings,
|
|
14626 |
|
14627 |
###################################################################################
|
14628 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14629 |
print('Module loaded!')
|
14630 |
print('=' * 70)
|
14631 |
print('Enjoy! :)')
|
|
|
51 |
|
52 |
###################################################################################
|
53 |
|
54 |
+
__version__ = "25.8.31"
|
55 |
|
56 |
print('=' * 70)
|
57 |
print('TMIDIX Python module')
|
|
|
14305 |
|
14306 |
def escore_notes_to_chords(escore_notes,
|
14307 |
use_full_chords=False,
|
14308 |
+
repair_bad_chords=True,
|
14309 |
+
skip_pitches=False,
|
14310 |
convert_pitches=True,
|
14311 |
shift_chords=False,
|
14312 |
return_tones_chords=False
|
|
|
14329 |
|
14330 |
tones_chord = sorted(set([p % 12 for p in pitches]))
|
14331 |
|
14332 |
+
if repair_bad_chords:
|
14333 |
+
if tones_chord not in CHORDS:
|
14334 |
+
tones_chord = check_and_fix_tones_chord(tones_chord,
|
14335 |
+
use_full_chords=use_full_chords
|
14336 |
+
)
|
14337 |
+
|
14338 |
if return_tones_chords:
|
14339 |
if convert_pitches:
|
14340 |
chords.append(tones_chord)
|
|
|
14347 |
chords.append([-pitches[0]])
|
14348 |
|
14349 |
else:
|
14350 |
+
if skip_pitches:
|
14351 |
+
if tones_chord in CHORDS:
|
14352 |
+
cho_tok = CHORDS.index(tones_chord)
|
|
|
|
|
14353 |
|
|
|
|
|
|
|
14354 |
else:
|
14355 |
+
cho_tok = -1
|
14356 |
+
|
14357 |
+
if len(pitches) > 1:
|
14358 |
chords.append(cho_tok)
|
14359 |
|
14360 |
else:
|
14361 |
+
if tones_chord in CHORDS:
|
14362 |
+
cho_tok = CHORDS.index(tones_chord)
|
14363 |
|
14364 |
else:
|
14365 |
+
cho_tok = -1
|
14366 |
+
|
14367 |
+
if cho_tok != -1:
|
14368 |
+
if convert_pitches:
|
14369 |
+
if shift_chords:
|
14370 |
+
if len(pitches) > 1:
|
14371 |
+
chords.append(cho_tok+12)
|
14372 |
+
|
14373 |
+
else:
|
14374 |
+
chords.append(pitches[0] % 12)
|
14375 |
+
|
14376 |
+
else:
|
14377 |
+
chords.append(cho_tok)
|
14378 |
+
|
14379 |
+
else:
|
14380 |
+
if len(pitches) > 1:
|
14381 |
+
chords.append(cho_tok+128)
|
14382 |
+
|
14383 |
+
else:
|
14384 |
+
chords.append(pitches[0])
|
14385 |
|
14386 |
return chords
|
14387 |
|
|
|
14647 |
|
14648 |
###################################################################################
|
14649 |
|
14650 |
+
def chords_common_tones_chain(chords,
|
14651 |
+
use_full_chords=False
|
14652 |
+
):
|
14653 |
+
|
14654 |
+
if use_full_chords:
|
14655 |
+
CHORDS = ALL_CHORDS_FULL
|
14656 |
+
|
14657 |
+
else:
|
14658 |
+
CHORDS = ALL_CHORDS_SORTED
|
14659 |
+
|
14660 |
+
tones_chords = [CHORDS[c] for c in chords if 0 <= c < len(CHORDS)]
|
14661 |
+
|
14662 |
+
n = len(tones_chords)
|
14663 |
+
|
14664 |
+
if not tones_chords:
|
14665 |
+
return []
|
14666 |
+
|
14667 |
+
if n < 2:
|
14668 |
+
return tones_chords
|
14669 |
+
|
14670 |
+
result = []
|
14671 |
+
|
14672 |
+
for i in range(n):
|
14673 |
+
if i == 0:
|
14674 |
+
common = set(tones_chords[0]) & set(tones_chords[1])
|
14675 |
+
|
14676 |
+
elif i == n - 1:
|
14677 |
+
common = set(tones_chords[n - 2]) & set(tones_chords[n - 1])
|
14678 |
+
|
14679 |
+
else:
|
14680 |
+
common = set(tones_chords[i - 1]) & set(tones_chords[i]) & set(tones_chords[i + 1])
|
14681 |
+
|
14682 |
+
result.append(min(common) if common else -1)
|
14683 |
+
|
14684 |
+
return result
|
14685 |
+
|
14686 |
+
###################################################################################
|
14687 |
+
|
14688 |
+
def tones_chord_to_int(tones_chord,
|
14689 |
+
reverse_bits=True
|
14690 |
+
):
|
14691 |
+
|
14692 |
+
cbits = tones_chord_to_bits(tones_chord,
|
14693 |
+
reverse=reverse_bits
|
14694 |
+
)
|
14695 |
+
|
14696 |
+
cint = bits_to_int(cbits)
|
14697 |
+
|
14698 |
+
return cint
|
14699 |
+
|
14700 |
+
###################################################################################
|
14701 |
+
|
14702 |
+
def int_to_tones_chord(integer,
|
14703 |
+
reverse_bits=True
|
14704 |
+
):
|
14705 |
+
|
14706 |
+
integer = integer % 4096
|
14707 |
+
|
14708 |
+
cbits = int_to_bits(integer)
|
14709 |
+
|
14710 |
+
if reverse_bits:
|
14711 |
+
cbits.reverse()
|
14712 |
+
|
14713 |
+
tones_chord = bits_to_tones_chord(cbits)
|
14714 |
+
|
14715 |
+
return tones_chord
|
14716 |
+
|
14717 |
+
###################################################################################
|
14718 |
+
|
14719 |
print('Module loaded!')
|
14720 |
print('=' * 70)
|
14721 |
print('Enjoy! :)')
|