asigalov61
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ in_space = os.getenv("SYSTEM") == "spaces"
|
|
28 |
|
29 |
#==========================================================================================================
|
30 |
|
31 |
-
def render_midi(input_midi, render_type, soundfont_bank, render_sample_rate, melody_patch):
|
32 |
|
33 |
print('*' * 70)
|
34 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
@@ -49,6 +49,7 @@ def render_midi(input_midi, render_type, soundfont_bank, render_sample_rate, mel
|
|
49 |
print('Render type:', render_type)
|
50 |
print('Soudnfont bank', soundfont_bank)
|
51 |
print('Audio render sample rate', render_sample_rate)
|
|
|
52 |
print('Melody patch', melody_patch)
|
53 |
|
54 |
print('=' * 70)
|
@@ -125,7 +126,8 @@ def render_midi(input_midi, render_type, soundfont_bank, render_sample_rate, mel
|
|
125 |
output_score = []
|
126 |
|
127 |
for c in cscore:
|
128 |
-
|
|
|
129 |
drums_events = [t for t in c if t[3] == 9]
|
130 |
|
131 |
if tones_chord:
|
@@ -144,7 +146,8 @@ def render_midi(input_midi, render_type, soundfont_bank, render_sample_rate, mel
|
|
144 |
output_score.extend([c[0]] + drums_events)
|
145 |
else:
|
146 |
output_score.extend(c)
|
147 |
-
|
|
|
148 |
print('Done processing!')
|
149 |
print('=' * 70)
|
150 |
|
@@ -154,6 +157,9 @@ def render_midi(input_midi, render_type, soundfont_bank, render_sample_rate, mel
|
|
154 |
for e in output_score:
|
155 |
e[1] = e[1] * 16
|
156 |
e[2] = e[2] * 16
|
|
|
|
|
|
|
157 |
|
158 |
print('Done recalculating timings!')
|
159 |
print('=' * 70)
|
@@ -279,7 +285,9 @@ if __name__ == "__main__":
|
|
279 |
|
280 |
render_sample_rate = gr.Radio(["16000", "32000", "44100"], label="MIDI audio render sample rate", value="16000")
|
281 |
|
282 |
-
|
|
|
|
|
283 |
|
284 |
submit = gr.Button()
|
285 |
|
@@ -292,7 +300,7 @@ if __name__ == "__main__":
|
|
292 |
output_plot = gr.Plot(label="Output MIDI score plot")
|
293 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
294 |
|
295 |
-
run_event = submit.click(render_midi, [input_midi, render_type, soundfont_bank, render_sample_rate, melody_patch],
|
296 |
[output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
297 |
|
298 |
app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
|
|
|
28 |
|
29 |
#==========================================================================================================
|
30 |
|
31 |
+
def render_midi(input_midi, render_type, soundfont_bank, render_sample_rate, custom_render_patch, melody_patch):
|
32 |
|
33 |
print('*' * 70)
|
34 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
|
|
49 |
print('Render type:', render_type)
|
50 |
print('Soudnfont bank', soundfont_bank)
|
51 |
print('Audio render sample rate', render_sample_rate)
|
52 |
+
print('Custom MIDI render patch', custom_render_patch)
|
53 |
print('Melody patch', melody_patch)
|
54 |
|
55 |
print('=' * 70)
|
|
|
126 |
output_score = []
|
127 |
|
128 |
for c in cscore:
|
129 |
+
output_score.extend(c)
|
130 |
+
''' tones_chord = sorted(set([t[4] % 12 for t in c if t[3] != 9]))
|
131 |
drums_events = [t for t in c if t[3] == 9]
|
132 |
|
133 |
if tones_chord:
|
|
|
146 |
output_score.extend([c[0]] + drums_events)
|
147 |
else:
|
148 |
output_score.extend(c)
|
149 |
+
'''
|
150 |
+
|
151 |
print('Done processing!')
|
152 |
print('=' * 70)
|
153 |
|
|
|
157 |
for e in output_score:
|
158 |
e[1] = e[1] * 16
|
159 |
e[2] = e[2] * 16
|
160 |
+
|
161 |
+
if -1 < custom_render_patch < 128:
|
162 |
+
e[6] = custom_render_patch
|
163 |
|
164 |
print('Done recalculating timings!')
|
165 |
print('=' * 70)
|
|
|
285 |
|
286 |
render_sample_rate = gr.Radio(["16000", "32000", "44100"], label="MIDI audio render sample rate", value="16000")
|
287 |
|
288 |
+
custom_render_patch = gr.Slider(-1, 127, value=-1, label="Custom MIDI render patch")
|
289 |
+
|
290 |
+
melody_patch = gr.Slider(0, 127, value=40, label="Melody MIDI patch")
|
291 |
|
292 |
submit = gr.Button()
|
293 |
|
|
|
300 |
output_plot = gr.Plot(label="Output MIDI score plot")
|
301 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
302 |
|
303 |
+
run_event = submit.click(render_midi, [input_midi, render_type, soundfont_bank, render_sample_rate, custom_render_patch, melody_patch],
|
304 |
[output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
305 |
|
306 |
app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
|