asigalov61
commited on
Commit
•
5ac52bd
1
Parent(s):
bcc6615
Upload TMIDIX.py
Browse files
TMIDIX.py
CHANGED
@@ -1816,7 +1816,7 @@ def plot_ms_SONG(ms_song,
|
|
1816 |
plt.title(plot_title)
|
1817 |
|
1818 |
if return_plt:
|
1819 |
-
return
|
1820 |
|
1821 |
plt.show()
|
1822 |
|
@@ -4999,6 +4999,98 @@ def patch_enhanced_score_notes(enhanced_score_notes,
|
|
4999 |
|
5000 |
###################################################################################
|
5001 |
|
5002 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5003 |
|
5004 |
###################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1816 |
plt.title(plot_title)
|
1817 |
|
1818 |
if return_plt:
|
1819 |
+
return plt
|
1820 |
|
1821 |
plt.show()
|
1822 |
|
|
|
4999 |
|
5000 |
###################################################################################
|
5001 |
|
5002 |
+
def create_enhanced_monophonic_melody(monophonic_melody):
|
5003 |
+
|
5004 |
+
enhanced_monophonic_melody = []
|
5005 |
+
|
5006 |
+
for i, note in enumerate(monophonic_melody[:-1]):
|
5007 |
+
|
5008 |
+
enhanced_monophonic_melody.append(note)
|
5009 |
+
|
5010 |
+
if note[1]+note[2] < monophonic_melody[i+1][1]:
|
5011 |
+
|
5012 |
+
delta_time = monophonic_melody[i+1][1] - (note[1]+note[2])
|
5013 |
+
enhanced_monophonic_melody.append(['silence', note[1]+note[2], delta_time, note[3], 0, 0, note[6]])
|
5014 |
+
|
5015 |
+
enhanced_monophonic_melody.append(monophonic_melody[-1])
|
5016 |
+
|
5017 |
+
return enhanced_monophonic_melody
|
5018 |
|
5019 |
###################################################################################
|
5020 |
+
|
5021 |
+
def frame_monophonic_melody(monophonic_melody, min_frame_time_threshold=10):
|
5022 |
+
|
5023 |
+
mzip = list(zip(monophonic_melody[:-1], monophonic_melody[1:]))
|
5024 |
+
|
5025 |
+
times_counts = Counter([(b[1]-a[1]) for a, b in mzip]).most_common()
|
5026 |
+
|
5027 |
+
mc_time = next((item for item, count in times_counts if item >= min_frame_time_threshold), min_frame_time_threshold)
|
5028 |
+
|
5029 |
+
times = [(b[1]-a[1]) // mc_time for a, b in mzip] + [monophonic_melody[-1][2] // mc_time]
|
5030 |
+
|
5031 |
+
framed_melody = []
|
5032 |
+
|
5033 |
+
for i, note in enumerate(monophonic_melody):
|
5034 |
+
|
5035 |
+
stime = note[1]
|
5036 |
+
count = times[i]
|
5037 |
+
|
5038 |
+
if count != 0:
|
5039 |
+
for j in range(count):
|
5040 |
+
|
5041 |
+
new_note = copy.deepcopy(note)
|
5042 |
+
new_note[1] = stime + (j * mc_time)
|
5043 |
+
new_note[2] = mc_time
|
5044 |
+
framed_melody.append(new_note)
|
5045 |
+
|
5046 |
+
else:
|
5047 |
+
framed_melody.append(note)
|
5048 |
+
|
5049 |
+
return [framed_melody, mc_time]
|
5050 |
+
|
5051 |
+
###################################################################################
|
5052 |
+
|
5053 |
+
def delta_score_notes(score_notes,
|
5054 |
+
timings_clip_value=255,
|
5055 |
+
even_timings=False,
|
5056 |
+
compress_timings=False
|
5057 |
+
):
|
5058 |
+
|
5059 |
+
delta_score = []
|
5060 |
+
|
5061 |
+
pe = score_notes[0]
|
5062 |
+
|
5063 |
+
for n in score_notes:
|
5064 |
+
|
5065 |
+
note = copy.deepcopy(n)
|
5066 |
+
|
5067 |
+
time = n[1] - pe[1]
|
5068 |
+
dur = n[2]
|
5069 |
+
|
5070 |
+
if even_timings:
|
5071 |
+
if time != 0 and time % 2 != 0:
|
5072 |
+
time += 1
|
5073 |
+
if dur % 2 != 0:
|
5074 |
+
dur += 1
|
5075 |
+
|
5076 |
+
time = max(0, min(timings_clip_value, time))
|
5077 |
+
dur = max(0, min(timings_clip_value, dur))
|
5078 |
+
|
5079 |
+
if compress_timings:
|
5080 |
+
time /= 2
|
5081 |
+
dur /= 2
|
5082 |
+
|
5083 |
+
note[1] = int(time)
|
5084 |
+
note[2] = int(dur)
|
5085 |
+
|
5086 |
+
delta_score.append(note)
|
5087 |
+
|
5088 |
+
pe = n
|
5089 |
+
|
5090 |
+
return delta_score
|
5091 |
+
|
5092 |
+
###################################################################################
|
5093 |
+
|
5094 |
+
# This is the end of the TMIDI X Python module
|
5095 |
+
|
5096 |
+
###################################################################################
|