asigalov61
commited on
Commit
•
ae02a8a
1
Parent(s):
88ee285
Update app.py
Browse files
app.py
CHANGED
@@ -120,7 +120,7 @@ def mix_chord(chord, tones_chord, mel_patch, mel_pitch, next_note_dtime):
|
|
120 |
|
121 |
# =================================================================================================
|
122 |
|
123 |
-
def MixMelody(input_midi, input_find_best_match):
|
124 |
print('=' * 70)
|
125 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
126 |
start_time = reqtime.time()
|
@@ -133,6 +133,8 @@ def MixMelody(input_midi, input_find_best_match):
|
|
133 |
print('-' * 70)
|
134 |
print('Input file name:', fn)
|
135 |
print('Find best matches', input_find_best_match)
|
|
|
|
|
136 |
print('-' * 70)
|
137 |
|
138 |
#===============================================================================
|
@@ -200,6 +202,7 @@ def MixMelody(input_midi, input_find_best_match):
|
|
200 |
mixed_song = []
|
201 |
|
202 |
midx = 0
|
|
|
203 |
|
204 |
for i, c in enumerate(cscore):
|
205 |
cho = copy.deepcopy(c)
|
@@ -208,21 +211,22 @@ def MixMelody(input_midi, input_find_best_match):
|
|
208 |
|
209 |
if trg_patch in patches:
|
210 |
|
211 |
-
if
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
215 |
|
216 |
mixed_song.extend(mix_chord(c, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx], next_note_dtime))
|
217 |
|
218 |
midx += 1
|
219 |
|
220 |
else:
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
|
227 |
mixed_song.extend(mix_chord(cho, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx], next_note_dtime))
|
228 |
|
@@ -320,6 +324,8 @@ if __name__ == "__main__":
|
|
320 |
|
321 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
322 |
input_find_best_match = gr.Checkbox(label="Find best match", value=True)
|
|
|
|
|
323 |
|
324 |
run_btn = gr.Button("mix melody", variant="primary")
|
325 |
|
@@ -332,14 +338,14 @@ if __name__ == "__main__":
|
|
332 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
333 |
|
334 |
|
335 |
-
run_event = run_btn.click(MixMelody, [input_midi, input_find_best_match],
|
336 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
337 |
|
338 |
gr.Examples(
|
339 |
-
[["Abracadabra-Sample-Melody.mid", True],
|
340 |
-
["Sparks-Fly-Sample-Melody.mid", True],
|
341 |
],
|
342 |
-
[input_midi, input_find_best_match],
|
343 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
344 |
MixMelody,
|
345 |
cache_examples=True,
|
|
|
120 |
|
121 |
# =================================================================================================
|
122 |
|
123 |
+
def MixMelody(input_midi, input_find_best_match, input_adjust_melody_notes_durations, input_adjust_accompaniment_notes_durations):
|
124 |
print('=' * 70)
|
125 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
126 |
start_time = reqtime.time()
|
|
|
133 |
print('-' * 70)
|
134 |
print('Input file name:', fn)
|
135 |
print('Find best matches', input_find_best_match)
|
136 |
+
print('Adjust melody notes durations:', input_adjust_melody_notes_durations)
|
137 |
+
print('Adjust accompaniment notes durations:', input_adjust_accompaniment_notes_durations)
|
138 |
print('-' * 70)
|
139 |
|
140 |
#===============================================================================
|
|
|
202 |
mixed_song = []
|
203 |
|
204 |
midx = 0
|
205 |
+
next_note_dtime = 255
|
206 |
|
207 |
for i, c in enumerate(cscore):
|
208 |
cho = copy.deepcopy(c)
|
|
|
211 |
|
212 |
if trg_patch in patches:
|
213 |
|
214 |
+
if input_adjust_melody_notes_durations:
|
215 |
+
if midx < len(src_melody)-1:
|
216 |
+
next_note_dtime = src_melody[midx+1][1] - src_melody[midx][1]
|
217 |
+
else:
|
218 |
+
next_note_dtime = 255
|
219 |
|
220 |
mixed_song.extend(mix_chord(c, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx], next_note_dtime))
|
221 |
|
222 |
midx += 1
|
223 |
|
224 |
else:
|
225 |
+
if input_adjust_accompaniment_notes_durations:
|
226 |
+
if i < len(cscore)-1:
|
227 |
+
next_note_dtime = cscore[i+1][0][1] - cscore[i][0][1]
|
228 |
+
else:
|
229 |
+
next_note_dtime = 255
|
230 |
|
231 |
mixed_song.extend(mix_chord(cho, src_harm_tones_chords[midx], trg_patch, src_melody_pitches[midx], next_note_dtime))
|
232 |
|
|
|
324 |
|
325 |
input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
|
326 |
input_find_best_match = gr.Checkbox(label="Find best match", value=True)
|
327 |
+
input_adjust_melody_notes_durations = gr.Checkbox(label="Adjust melody notes durations", value=True)
|
328 |
+
input_adjust_accompaniment_notes_durations = gr.Checkbox(label="Adjust accompaniment notes durations", value=True)
|
329 |
|
330 |
run_btn = gr.Button("mix melody", variant="primary")
|
331 |
|
|
|
338 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
339 |
|
340 |
|
341 |
+
run_event = run_btn.click(MixMelody, [input_midi, input_find_best_match, input_adjust_melody_notes_durations, input_adjust_accompaniment_notes_durations],
|
342 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
343 |
|
344 |
gr.Examples(
|
345 |
+
[["Abracadabra-Sample-Melody.mid", True, True, True],
|
346 |
+
["Sparks-Fly-Sample-Melody.mid", True, True, True],
|
347 |
],
|
348 |
+
[input_midi, input_find_best_match, input_adjust_melody_notes_durations, input_adjust_accompaniment_notes_durations],
|
349 |
[output_midi_title, output_midi_summary, output_midi, output_audio, output_plot],
|
350 |
MixMelody,
|
351 |
cache_examples=True,
|