Update app.py
Browse files
app.py
CHANGED
|
@@ -122,9 +122,9 @@ def Mix_Melody(input_midi,
|
|
| 122 |
input_find_best_match,
|
| 123 |
input_adjust_melody_notes_durations,
|
| 124 |
input_adjust_accompaniment_notes_durations,
|
| 125 |
-
input_match_source_MIDI_average_time,
|
| 126 |
input_output_as_solo_piano,
|
| 127 |
-
input_remove_drums
|
|
|
|
| 128 |
):
|
| 129 |
|
| 130 |
print('=' * 70)
|
|
@@ -143,6 +143,7 @@ def Mix_Melody(input_midi,
|
|
| 143 |
print('Adjust accompaniment notes durations:', input_adjust_accompaniment_notes_durations)
|
| 144 |
print('Output as Solo Piano:', input_output_as_solo_piano)
|
| 145 |
print('Remove drums:', input_remove_drums)
|
|
|
|
| 146 |
print('-' * 70)
|
| 147 |
|
| 148 |
#===============================================================================
|
|
@@ -160,11 +161,11 @@ def Mix_Melody(input_midi,
|
|
| 160 |
|
| 161 |
src_escore = TMIDIX.recalculate_score_timings(TMIDIX.augment_enhanced_score_notes([e for e in raw_escore if e[6] < 80]))
|
| 162 |
|
| 163 |
-
src_avg_time = TMIDIX.escore_notes_averages(src_escore)[0]
|
| 164 |
-
|
| 165 |
src_cscore = TMIDIX.chordify_score([1000, src_escore])
|
| 166 |
|
| 167 |
src_melody = [c[0] for c in src_cscore][:256]
|
|
|
|
|
|
|
| 168 |
|
| 169 |
src_melody_pitches = [p[4] for p in src_melody]
|
| 170 |
|
|
@@ -201,6 +202,10 @@ def Mix_Melody(input_midi,
|
|
| 201 |
trg_patch = new_song[1]
|
| 202 |
|
| 203 |
trg_song = copy.deepcopy(new_song[3])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
TMIDIX.adjust_score_velocities(trg_song, 95)
|
| 205 |
|
| 206 |
cscore = TMIDIX.chordify_score([1000, trg_song])
|
|
@@ -283,14 +288,18 @@ def Mix_Melody(input_midi,
|
|
| 283 |
if input_remove_drums:
|
| 284 |
mixed_song = [e for e in mixed_song if e[3] != 9]
|
| 285 |
|
| 286 |
-
if
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
time_k = src_avg_time / trg_avg_time
|
| 291 |
|
| 292 |
mixed_song = TMIDIX.adjust_escore_notes_timings(mixed_song, time_k)
|
| 293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
#===============================================================================
|
| 295 |
print('Rendering results...')
|
| 296 |
|
|
@@ -380,9 +389,9 @@ if __name__ == "__main__":
|
|
| 380 |
input_find_best_match = gr.Checkbox(label="Find best match", value=True)
|
| 381 |
input_adjust_melody_notes_durations = gr.Checkbox(label="Adjust melody notes durations", value=False)
|
| 382 |
input_adjust_accompaniment_notes_durations = gr.Checkbox(label="Adjust accompaniment notes durations", value=False)
|
| 383 |
-
input_match_source_MIDI_average_time = gr.Checkbox(label="Match source MIDI average time", value=False)
|
| 384 |
input_output_as_solo_piano = gr.Checkbox(label="Output as Solo Piano", value=False)
|
| 385 |
input_remove_drums = gr.Checkbox(label="Remove drums from output", value=False)
|
|
|
|
| 386 |
|
| 387 |
run_btn = gr.Button("mix melody", variant="primary")
|
| 388 |
|
|
@@ -399,23 +408,23 @@ if __name__ == "__main__":
|
|
| 399 |
input_find_best_match,
|
| 400 |
input_adjust_melody_notes_durations,
|
| 401 |
input_adjust_accompaniment_notes_durations,
|
| 402 |
-
input_match_source_MIDI_average_time,
|
| 403 |
input_output_as_solo_piano,
|
| 404 |
-
input_remove_drums
|
|
|
|
| 405 |
],
|
| 406 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
| 407 |
|
| 408 |
gr.Examples(
|
| 409 |
-
[["Abracadabra-Sample-Melody.mid", True, True, True, False, False,
|
| 410 |
-
["Sparks-Fly-Sample-Melody.mid", True, True, True, False, False,
|
| 411 |
],
|
| 412 |
[input_midi,
|
| 413 |
input_find_best_match,
|
| 414 |
input_adjust_melody_notes_durations,
|
| 415 |
input_adjust_accompaniment_notes_durations,
|
| 416 |
-
input_match_source_MIDI_average_time,
|
| 417 |
input_output_as_solo_piano,
|
| 418 |
-
input_remove_drums
|
|
|
|
| 419 |
],
|
| 420 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
| 421 |
Mix_Melody,
|
|
|
|
| 122 |
input_find_best_match,
|
| 123 |
input_adjust_melody_notes_durations,
|
| 124 |
input_adjust_accompaniment_notes_durations,
|
|
|
|
| 125 |
input_output_as_solo_piano,
|
| 126 |
+
input_remove_drums,
|
| 127 |
+
input_output_tempo
|
| 128 |
):
|
| 129 |
|
| 130 |
print('=' * 70)
|
|
|
|
| 143 |
print('Adjust accompaniment notes durations:', input_adjust_accompaniment_notes_durations)
|
| 144 |
print('Output as Solo Piano:', input_output_as_solo_piano)
|
| 145 |
print('Remove drums:', input_remove_drums)
|
| 146 |
+
print('Output tempo:', input_output_tempo)
|
| 147 |
print('-' * 70)
|
| 148 |
|
| 149 |
#===============================================================================
|
|
|
|
| 161 |
|
| 162 |
src_escore = TMIDIX.recalculate_score_timings(TMIDIX.augment_enhanced_score_notes([e for e in raw_escore if e[6] < 80]))
|
| 163 |
|
|
|
|
|
|
|
| 164 |
src_cscore = TMIDIX.chordify_score([1000, src_escore])
|
| 165 |
|
| 166 |
src_melody = [c[0] for c in src_cscore][:256]
|
| 167 |
+
|
| 168 |
+
mel_avg_time = TMIDIX.escore_notes_averages(src_melody)[0]
|
| 169 |
|
| 170 |
src_melody_pitches = [p[4] for p in src_melody]
|
| 171 |
|
|
|
|
| 202 |
trg_patch = new_song[1]
|
| 203 |
|
| 204 |
trg_song = copy.deepcopy(new_song[3])
|
| 205 |
+
|
| 206 |
+
mix_avg_time = TMIDIX.escore_notes_averages(trg_song)[0]
|
| 207 |
+
mix_mel_avg_time = TMIDIX.escore_notes_averages([e for e in trg_song if e[6] == trg_patch])[0]
|
| 208 |
+
|
| 209 |
TMIDIX.adjust_score_velocities(trg_song, 95)
|
| 210 |
|
| 211 |
cscore = TMIDIX.chordify_score([1000, trg_song])
|
|
|
|
| 288 |
if input_remove_drums:
|
| 289 |
mixed_song = [e for e in mixed_song if e[3] != 9]
|
| 290 |
|
| 291 |
+
if input_output_tempo == 'Source Melody':
|
| 292 |
|
| 293 |
+
time_k = mel_avg_time / mix_avg_time
|
|
|
|
|
|
|
| 294 |
|
| 295 |
mixed_song = TMIDIX.adjust_escore_notes_timings(mixed_song, time_k)
|
| 296 |
|
| 297 |
+
elif input_output_tempo == 'Mix Melody':
|
| 298 |
+
|
| 299 |
+
time_k = mel_avg_time / mix_mel_avg_time
|
| 300 |
+
|
| 301 |
+
mixed_song = TMIDIX.adjust_escore_notes_timings(mixed_song, time_k)
|
| 302 |
+
|
| 303 |
#===============================================================================
|
| 304 |
print('Rendering results...')
|
| 305 |
|
|
|
|
| 389 |
input_find_best_match = gr.Checkbox(label="Find best match", value=True)
|
| 390 |
input_adjust_melody_notes_durations = gr.Checkbox(label="Adjust melody notes durations", value=False)
|
| 391 |
input_adjust_accompaniment_notes_durations = gr.Checkbox(label="Adjust accompaniment notes durations", value=False)
|
|
|
|
| 392 |
input_output_as_solo_piano = gr.Checkbox(label="Output as Solo Piano", value=False)
|
| 393 |
input_remove_drums = gr.Checkbox(label="Remove drums from output", value=False)
|
| 394 |
+
input_output_tempo = gr.Radio(["Mix", "Source Melody", "Mix Melody"], value="Mix", label="Output tempo")
|
| 395 |
|
| 396 |
run_btn = gr.Button("mix melody", variant="primary")
|
| 397 |
|
|
|
|
| 408 |
input_find_best_match,
|
| 409 |
input_adjust_melody_notes_durations,
|
| 410 |
input_adjust_accompaniment_notes_durations,
|
|
|
|
| 411 |
input_output_as_solo_piano,
|
| 412 |
+
input_remove_drums,
|
| 413 |
+
input_output_tempo
|
| 414 |
],
|
| 415 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
| 416 |
|
| 417 |
gr.Examples(
|
| 418 |
+
[["Abracadabra-Sample-Melody.mid", True, True, True, False, False, "Mix"],
|
| 419 |
+
["Sparks-Fly-Sample-Melody.mid", True, True, True, False, False, "Mix"],
|
| 420 |
],
|
| 421 |
[input_midi,
|
| 422 |
input_find_best_match,
|
| 423 |
input_adjust_melody_notes_durations,
|
| 424 |
input_adjust_accompaniment_notes_durations,
|
|
|
|
| 425 |
input_output_as_solo_piano,
|
| 426 |
+
input_remove_drums,
|
| 427 |
+
input_output_tempo
|
| 428 |
],
|
| 429 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
| 430 |
Mix_Melody,
|