Upload TMIDIX.py
Browse files
TMIDIX.py
CHANGED
|
@@ -9552,7 +9552,7 @@ MOOD_SCALES = ['Major', 'Minor', 'Major Minor']
|
|
| 9552 |
###################################################################################
|
| 9553 |
|
| 9554 |
def alpha_str(string):
|
| 9555 |
-
astr = re.sub(r'[^a-zA-Z ()]', '', string).strip()
|
| 9556 |
return re.sub(r'\s+', ' ', astr).strip()
|
| 9557 |
|
| 9558 |
###################################################################################
|
|
@@ -9585,15 +9585,19 @@ def escore_notes_to_text_description(escore_notes,
|
|
| 9585 |
if len(escore_times) > 0:
|
| 9586 |
if len(escore_times) == len(set(escore_times)):
|
| 9587 |
comp_type = 'monophonic melody'
|
|
|
|
| 9588 |
|
| 9589 |
elif len(escore_times) >= len(set(escore_times)) and 1 in Counter(escore_times).values():
|
| 9590 |
comp_type = 'melody and accompaniment'
|
|
|
|
| 9591 |
|
| 9592 |
elif len(escore_times) >= len(set(escore_times)) and 1 not in Counter(escore_times).values():
|
| 9593 |
comp_type = 'accompaniment'
|
|
|
|
| 9594 |
|
| 9595 |
else:
|
| 9596 |
-
comp_type = '
|
|
|
|
| 9597 |
|
| 9598 |
#==============================================================================
|
| 9599 |
|
|
@@ -9602,20 +9606,22 @@ def escore_notes_to_text_description(escore_notes,
|
|
| 9602 |
patches = ordered_set(all_patches)
|
| 9603 |
|
| 9604 |
instruments = [alpha_str(Number2patch[p]) for p in patches if p < 128]
|
|
|
|
|
|
|
| 9605 |
|
| 9606 |
-
|
| 9607 |
|
| 9608 |
-
|
| 9609 |
|
| 9610 |
if 128 in patches:
|
| 9611 |
drums_present = True
|
| 9612 |
|
| 9613 |
-
|
| 9614 |
-
drums_present = False
|
| 9615 |
|
| 9616 |
-
|
| 9617 |
|
| 9618 |
-
|
|
|
|
| 9619 |
|
| 9620 |
#==============================================================================
|
| 9621 |
|
|
@@ -9681,7 +9687,7 @@ def escore_notes_to_text_description(escore_notes,
|
|
| 9681 |
description = ''
|
| 9682 |
|
| 9683 |
if song_name != '':
|
| 9684 |
-
description = '
|
| 9685 |
|
| 9686 |
if artist_name != '':
|
| 9687 |
description += ' by ' + artist_name
|
|
@@ -9719,41 +9725,70 @@ def escore_notes_to_text_description(escore_notes,
|
|
| 9719 |
|
| 9720 |
if pitches:
|
| 9721 |
|
| 9722 |
-
if
|
| 9723 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9725 |
else:
|
| 9726 |
-
description += '
|
| 9727 |
-
|
| 9728 |
description += rythm + ' rythm, '
|
| 9729 |
description += tempo + ' tempo, '
|
| 9730 |
description += tone + ' tone and '
|
| 9731 |
description += dynamics + ' dynamics.'
|
| 9732 |
|
| 9733 |
description += '\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9734 |
|
| 9735 |
-
|
| 9736 |
-
|
| 9737 |
-
|
| 9738 |
-
|
| 9739 |
-
|
| 9740 |
-
else:
|
| 9741 |
-
description += 'features ' + NUMERALS[max(0, min(15, len(instruments)-1))] + ' instruments: '
|
| 9742 |
-
description += ', '.join(instruments[:-1]) + ' and ' + instruments[-1] + '.'
|
| 9743 |
-
|
| 9744 |
-
description += '\n'
|
| 9745 |
-
|
| 9746 |
-
description += 'The song starts with ' + instruments[0] + '.'
|
| 9747 |
|
| 9748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9749 |
|
| 9750 |
-
|
| 9751 |
|
| 9752 |
-
|
|
|
|
|
|
|
|
|
|
| 9753 |
|
| 9754 |
if drums_present and most_common_drums:
|
| 9755 |
-
|
| 9756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9757 |
|
| 9758 |
description += '\n'
|
| 9759 |
|
|
|
|
| 9552 |
###################################################################################
|
| 9553 |
|
| 9554 |
def alpha_str(string):
|
| 9555 |
+
astr = re.sub(r'[^a-zA-Z ()0-9]', '', string).strip()
|
| 9556 |
return re.sub(r'\s+', ' ', astr).strip()
|
| 9557 |
|
| 9558 |
###################################################################################
|
|
|
|
| 9585 |
if len(escore_times) > 0:
|
| 9586 |
if len(escore_times) == len(set(escore_times)):
|
| 9587 |
comp_type = 'monophonic melody'
|
| 9588 |
+
ctype = 'melody'
|
| 9589 |
|
| 9590 |
elif len(escore_times) >= len(set(escore_times)) and 1 in Counter(escore_times).values():
|
| 9591 |
comp_type = 'melody and accompaniment'
|
| 9592 |
+
ctype = 'song'
|
| 9593 |
|
| 9594 |
elif len(escore_times) >= len(set(escore_times)) and 1 not in Counter(escore_times).values():
|
| 9595 |
comp_type = 'accompaniment'
|
| 9596 |
+
ctype = 'song'
|
| 9597 |
|
| 9598 |
else:
|
| 9599 |
+
comp_type = 'drum track'
|
| 9600 |
+
ctype = 'drum track'
|
| 9601 |
|
| 9602 |
#==============================================================================
|
| 9603 |
|
|
|
|
| 9606 |
patches = ordered_set(all_patches)
|
| 9607 |
|
| 9608 |
instruments = [alpha_str(Number2patch[p]) for p in patches if p < 128]
|
| 9609 |
+
|
| 9610 |
+
if instruments:
|
| 9611 |
|
| 9612 |
+
nd_patches_counts = Counter([p for p in all_patches if p < 128]).most_common()
|
| 9613 |
|
| 9614 |
+
dominant_instrument = alpha_str(Number2patch[nd_patches_counts[0][0]])
|
| 9615 |
|
| 9616 |
if 128 in patches:
|
| 9617 |
drums_present = True
|
| 9618 |
|
| 9619 |
+
drums_pitches = [e[4] for e in escore_notes if e[3] == 9]
|
|
|
|
| 9620 |
|
| 9621 |
+
most_common_drums = [alpha_str(Notenum2percussion[p[0]]) for p in Counter(drums_pitches).most_common(3) if p[0] in Notenum2percussion]
|
| 9622 |
|
| 9623 |
+
else:
|
| 9624 |
+
drums_present = False
|
| 9625 |
|
| 9626 |
#==============================================================================
|
| 9627 |
|
|
|
|
| 9687 |
description = ''
|
| 9688 |
|
| 9689 |
if song_name != '':
|
| 9690 |
+
description = 'The song "' + song_name + '"'
|
| 9691 |
|
| 9692 |
if artist_name != '':
|
| 9693 |
description += ' by ' + artist_name
|
|
|
|
| 9725 |
|
| 9726 |
if pitches:
|
| 9727 |
|
| 9728 |
+
if comp_type not in ['monophonic melody', 'drum track']:
|
| 9729 |
+
|
| 9730 |
+
if mood == 'Major':
|
| 9731 |
+
description += 'This uplifting song has '
|
| 9732 |
+
|
| 9733 |
+
else:
|
| 9734 |
+
description += 'This reflective song has '
|
| 9735 |
+
|
| 9736 |
+
elif comp_type == 'monophonic melody':
|
| 9737 |
|
| 9738 |
+
if mood == 'Major':
|
| 9739 |
+
description += 'This uplifting melody has '
|
| 9740 |
+
|
| 9741 |
+
else:
|
| 9742 |
+
description += 'This reflective melody has '
|
| 9743 |
+
|
| 9744 |
else:
|
| 9745 |
+
description += 'TThis drum track has '
|
| 9746 |
+
|
| 9747 |
description += rythm + ' rythm, '
|
| 9748 |
description += tempo + ' tempo, '
|
| 9749 |
description += tone + ' tone and '
|
| 9750 |
description += dynamics + ' dynamics.'
|
| 9751 |
|
| 9752 |
description += '\n'
|
| 9753 |
+
|
| 9754 |
+
if instruments:
|
| 9755 |
+
|
| 9756 |
+
if comp_type not in ['monophonic melody', 'drum track']:
|
| 9757 |
+
description += 'The song '
|
| 9758 |
+
|
| 9759 |
+
else:
|
| 9760 |
+
description += 'The melody '
|
| 9761 |
|
| 9762 |
+
if len(instruments) == 1:
|
| 9763 |
+
description += 'is played on a solo ' + instruments[0] + '.'
|
| 9764 |
+
|
| 9765 |
+
description += '\n'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9766 |
|
| 9767 |
+
else:
|
| 9768 |
+
description += 'features ' + NUMERALS[max(0, min(15, len(instruments)-1))] + ' instruments: '
|
| 9769 |
+
description += ', '.join(instruments[:-1]) + ' and ' + instruments[-1] + '.'
|
| 9770 |
+
|
| 9771 |
+
description += '\n'
|
| 9772 |
+
|
| 9773 |
+
if instruments[0] != dominant_instrument:
|
| 9774 |
+
description += 'The song opens with ' + instruments[0]
|
| 9775 |
|
| 9776 |
+
description += ' and performed on ' + dominant_instrument + '.'
|
| 9777 |
|
| 9778 |
+
description += '\n'
|
| 9779 |
+
|
| 9780 |
+
else:
|
| 9781 |
+
description += 'The song opens with and performed on ' + instruments[0] + '.'
|
| 9782 |
|
| 9783 |
if drums_present and most_common_drums:
|
| 9784 |
+
|
| 9785 |
+
if len(most_common_drums) > 1:
|
| 9786 |
+
description += 'The drum track has predominant '
|
| 9787 |
+
description += ', '.join(most_common_drums[:-1]) + ' and ' + most_common_drums[-1] + '.'
|
| 9788 |
+
|
| 9789 |
+
else:
|
| 9790 |
+
description += 'The drum track is a solo '
|
| 9791 |
+
description += most_common_drums[0] + '.'
|
| 9792 |
|
| 9793 |
description += '\n'
|
| 9794 |
|