asigalov61
commited on
Commit
•
0219c58
1
Parent(s):
ecd66de
Upload TMIDIX.py
Browse files
TMIDIX.py
CHANGED
@@ -6688,7 +6688,9 @@ def horizontal_ordered_list_search(list_of_lists,
|
|
6688 |
|
6689 |
###################################################################################
|
6690 |
|
6691 |
-
def escore_notes_to_escore_matrix(escore_notes
|
|
|
|
|
6692 |
|
6693 |
last_time = escore_notes[-1][1]
|
6694 |
last_notes = [e for e in escore_notes if e[1] == last_time]
|
@@ -6704,16 +6706,30 @@ def escore_notes_to_escore_matrix(escore_notes):
|
|
6704 |
|
6705 |
escore_matrix = [[[-1, -1]] * 128 for _ in range(time_range)]
|
6706 |
|
6707 |
-
|
|
|
|
|
6708 |
|
6709 |
etype, time, duration, channel, pitch, velocity, patch = note
|
6710 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6711 |
if channel == cha:
|
6712 |
|
6713 |
for t in range(time, min(time + duration, time_range)):
|
6714 |
|
6715 |
escore_matrix[t][pitch] = [velocity, patch]
|
6716 |
|
|
|
|
|
6717 |
escore_matrixes.append(escore_matrix)
|
6718 |
|
6719 |
return [channels_list, escore_matrixes]
|
@@ -6761,6 +6777,124 @@ def escore_matrix_to_merged_escore_notes(full_escore_matrix,
|
|
6761 |
|
6762 |
###################################################################################
|
6763 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6764 |
# This is the end of the TMIDI X Python module
|
6765 |
|
6766 |
###################################################################################
|
|
|
6688 |
|
6689 |
###################################################################################
|
6690 |
|
6691 |
+
def escore_notes_to_escore_matrix(escore_notes,
|
6692 |
+
alt_velocities=False
|
6693 |
+
):
|
6694 |
|
6695 |
last_time = escore_notes[-1][1]
|
6696 |
last_notes = [e for e in escore_notes if e[1] == last_time]
|
|
|
6706 |
|
6707 |
escore_matrix = [[[-1, -1]] * 128 for _ in range(time_range)]
|
6708 |
|
6709 |
+
pe = escore_notes[0]
|
6710 |
+
|
6711 |
+
for i, note in enumerate(escore_notes):
|
6712 |
|
6713 |
etype, time, duration, channel, pitch, velocity, patch = note
|
6714 |
|
6715 |
+
time = max(0, time)
|
6716 |
+
duration = max(2, duration)
|
6717 |
+
channel = max(0, min(15, channel))
|
6718 |
+
pitch = max(0, min(127, pitch))
|
6719 |
+
velocity = max(0, min(127, velocity))
|
6720 |
+
patch = max(0, min(128, patch))
|
6721 |
+
|
6722 |
+
if alt_velocities:
|
6723 |
+
velocity -= (i % 2)
|
6724 |
+
|
6725 |
if channel == cha:
|
6726 |
|
6727 |
for t in range(time, min(time + duration, time_range)):
|
6728 |
|
6729 |
escore_matrix[t][pitch] = [velocity, patch]
|
6730 |
|
6731 |
+
pe = note
|
6732 |
+
|
6733 |
escore_matrixes.append(escore_matrix)
|
6734 |
|
6735 |
return [channels_list, escore_matrixes]
|
|
|
6777 |
|
6778 |
###################################################################################
|
6779 |
|
6780 |
+
def escore_matrix_to_original_escore_notes(full_escore_matrix):
|
6781 |
+
|
6782 |
+
merged_escore_notes = []
|
6783 |
+
|
6784 |
+
mat_channels_list = full_escore_matrix[0]
|
6785 |
+
|
6786 |
+
for m, cha in enumerate(mat_channels_list):
|
6787 |
+
|
6788 |
+
escore_matrix = full_escore_matrix[1][m]
|
6789 |
+
|
6790 |
+
result = []
|
6791 |
+
|
6792 |
+
for j in range(len(escore_matrix[0])):
|
6793 |
+
|
6794 |
+
count = 1
|
6795 |
+
|
6796 |
+
for i in range(1, len(escore_matrix)):
|
6797 |
+
|
6798 |
+
if escore_matrix[i][j] != [-1, -1] and escore_matrix[i][j] == escore_matrix[i-1][j]:
|
6799 |
+
count += 1
|
6800 |
+
|
6801 |
+
else:
|
6802 |
+
if count > 1:
|
6803 |
+
result.append([i-count, count, j, escore_matrix[i-1][j]])
|
6804 |
+
|
6805 |
+
count = 1
|
6806 |
+
|
6807 |
+
if count > 1:
|
6808 |
+
result.append([len(escore_matrix)-count, count, j, escore_matrix[-1][j]])
|
6809 |
+
|
6810 |
+
result.sort(key=lambda x: (x[0], -x[2]))
|
6811 |
+
|
6812 |
+
for r in result:
|
6813 |
+
merged_escore_notes.append(['note', r[0], r[1], cha, r[2], r[3][0], r[3][1]])
|
6814 |
+
|
6815 |
+
return sorted(merged_escore_notes, key=lambda x: (x[1], -x[4], x[6]))
|
6816 |
+
|
6817 |
+
###################################################################################
|
6818 |
+
|
6819 |
+
def escore_notes_to_binary_matrix(escore_notes,
|
6820 |
+
channel=0,
|
6821 |
+
patch=0
|
6822 |
+
):
|
6823 |
+
|
6824 |
+
escore = [e for e in escore_notes if e[3] == channel and e[6] == patch]
|
6825 |
+
|
6826 |
+
if escore:
|
6827 |
+
last_time = escore[-1][1]
|
6828 |
+
last_notes = [e for e in escore if e[1] == last_time]
|
6829 |
+
max_last_dur = max([e[2] for e in last_notes])
|
6830 |
+
|
6831 |
+
time_range = last_time+max_last_dur
|
6832 |
+
|
6833 |
+
escore_matrix = []
|
6834 |
+
|
6835 |
+
escore_matrix = [[0] * 128 for _ in range(time_range)]
|
6836 |
+
|
6837 |
+
for note in escore:
|
6838 |
+
|
6839 |
+
etype, time, duration, chan, pitch, velocity, pat = note
|
6840 |
+
|
6841 |
+
time = max(0, time)
|
6842 |
+
duration = max(2, duration)
|
6843 |
+
chan = max(0, min(15, chan))
|
6844 |
+
pitch = max(0, min(127, pitch))
|
6845 |
+
velocity = max(0, min(127, velocity))
|
6846 |
+
pat = max(0, min(128, pat))
|
6847 |
+
|
6848 |
+
if channel == chan and patch == pat:
|
6849 |
+
|
6850 |
+
for t in range(time, min(time + duration, time_range)):
|
6851 |
+
|
6852 |
+
escore_matrix[t][pitch] = 1
|
6853 |
+
|
6854 |
+
return escore_matrix
|
6855 |
+
|
6856 |
+
else:
|
6857 |
+
return None
|
6858 |
+
|
6859 |
+
###################################################################################
|
6860 |
+
|
6861 |
+
def binary_matrix_to_original_escore_notes(binary_matrix,
|
6862 |
+
channel=0,
|
6863 |
+
patch=0,
|
6864 |
+
velocity=90
|
6865 |
+
):
|
6866 |
+
|
6867 |
+
result = []
|
6868 |
+
|
6869 |
+
for j in range(len(binary_matrix[0])):
|
6870 |
+
|
6871 |
+
count = 1
|
6872 |
+
|
6873 |
+
for i in range(1, len(binary_matrix)):
|
6874 |
+
|
6875 |
+
if binary_matrix[i][j] != 0 and binary_matrix[i][j] == binary_matrix[i-1][j]:
|
6876 |
+
count += 1
|
6877 |
+
|
6878 |
+
else:
|
6879 |
+
if count > 1:
|
6880 |
+
result.append([i-count, count, j, binary_matrix[i-1][j]])
|
6881 |
+
|
6882 |
+
count = 1
|
6883 |
+
|
6884 |
+
if count > 1:
|
6885 |
+
result.append([len(binary_matrix)-count, count, j, binary_matrix[-1][j]])
|
6886 |
+
|
6887 |
+
result.sort(key=lambda x: (x[0], -x[2]))
|
6888 |
+
|
6889 |
+
original_escore_notes = []
|
6890 |
+
|
6891 |
+
for r in result:
|
6892 |
+
original_escore_notes.append(['note', r[0], r[1], channel, r[2], velocity, patch])
|
6893 |
+
|
6894 |
+
return sorted(original_escore_notes, key=lambda x: (x[1], -x[4], x[6]))
|
6895 |
+
|
6896 |
+
###################################################################################
|
6897 |
+
|
6898 |
# This is the end of the TMIDI X Python module
|
6899 |
|
6900 |
###################################################################################
|