asigalov61
commited on
Commit
•
f7f27b0
1
Parent(s):
57440b4
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, melody_patch):
|
32 |
|
33 |
print('*' * 70)
|
34 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
@@ -48,6 +48,7 @@ def render_midi(input_midi, render_type, soundfont_bank, melody_patch):
|
|
48 |
print('Input MIDI md5 hash', input_midi_md5hash)
|
49 |
print('Render type:', render_type)
|
50 |
print('Soudnfont bank', soundfont_bank)
|
|
|
51 |
print('Melody patch', melody_patch)
|
52 |
|
53 |
print('=' * 70)
|
@@ -93,7 +94,7 @@ def render_midi(input_midi, render_type, soundfont_bank, melody_patch):
|
|
93 |
e[6] = max(0, min(127, melody_patch))
|
94 |
|
95 |
if e[4] < 60:
|
96 |
-
e[4] = (e[4] % 12) +
|
97 |
|
98 |
elif render_type == "Transform":
|
99 |
output_score = copy.deepcopy(escore)
|
@@ -149,10 +150,16 @@ def render_midi(input_midi, render_type, soundfont_bank, melody_patch):
|
|
149 |
|
150 |
else:
|
151 |
sf2bank = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
audio = midi_to_colab_audio(new_fn,
|
154 |
soundfont_path=soundfonts[sf2bank],
|
155 |
-
sample_rate=
|
156 |
volume_scale=10,
|
157 |
output_for_gradio=True
|
158 |
)
|
@@ -168,7 +175,7 @@ def render_midi(input_midi, render_type, soundfont_bank, melody_patch):
|
|
168 |
output_midi_title = str(fn1)
|
169 |
output_midi_summary = str(meta_data)
|
170 |
output_midi = str(new_fn)
|
171 |
-
output_audio = (
|
172 |
output_plot = TMIDIX.plot_ms_SONG(output_score, plot_title=output_midi)
|
173 |
|
174 |
print('Output MIDI file name:', output_midi)
|
@@ -228,6 +235,8 @@ if __name__ == "__main__":
|
|
228 |
|
229 |
soundfont_bank = gr.Radio(["General MIDI", "Nice strings plus orchestra", "Real choir"], label="SoundFont bank", value="General MIDI")
|
230 |
|
|
|
|
|
231 |
melody_patch = gr.Slider(0, 127, value=40, label="Melody MIDI Patch")
|
232 |
|
233 |
submit = gr.Button()
|
@@ -241,7 +250,7 @@ if __name__ == "__main__":
|
|
241 |
output_plot = gr.Plot(label="Output MIDI score plot")
|
242 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
243 |
|
244 |
-
run_event = submit.click(render_midi, [input_midi, render_type, soundfont_bank, melody_patch],
|
245 |
[output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
246 |
|
247 |
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, melody_patch):
|
32 |
|
33 |
print('*' * 70)
|
34 |
print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
|
|
48 |
print('Input MIDI md5 hash', input_midi_md5hash)
|
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)
|
|
|
94 |
e[6] = max(0, min(127, melody_patch))
|
95 |
|
96 |
if e[4] < 60:
|
97 |
+
e[4] = (e[4] % 12) + 72
|
98 |
|
99 |
elif render_type == "Transform":
|
100 |
output_score = copy.deepcopy(escore)
|
|
|
150 |
|
151 |
else:
|
152 |
sf2bank = 0
|
153 |
+
|
154 |
+
if render_sample_rate in ["16000", "32000", "44100"]:
|
155 |
+
srate = int(render_sample_rate)
|
156 |
+
|
157 |
+
else:
|
158 |
+
srate = 16000
|
159 |
|
160 |
audio = midi_to_colab_audio(new_fn,
|
161 |
soundfont_path=soundfonts[sf2bank],
|
162 |
+
sample_rate=srate,
|
163 |
volume_scale=10,
|
164 |
output_for_gradio=True
|
165 |
)
|
|
|
175 |
output_midi_title = str(fn1)
|
176 |
output_midi_summary = str(meta_data)
|
177 |
output_midi = str(new_fn)
|
178 |
+
output_audio = (srate, audio)
|
179 |
output_plot = TMIDIX.plot_ms_SONG(output_score, plot_title=output_midi)
|
180 |
|
181 |
print('Output MIDI file name:', output_midi)
|
|
|
235 |
|
236 |
soundfont_bank = gr.Radio(["General MIDI", "Nice strings plus orchestra", "Real choir"], label="SoundFont bank", value="General MIDI")
|
237 |
|
238 |
+
render_sample_rate = gr.Radio(["16000", "32000", "44100"], label="MIDI audio render sample rate", value="16000")
|
239 |
+
|
240 |
melody_patch = gr.Slider(0, 127, value=40, label="Melody MIDI Patch")
|
241 |
|
242 |
submit = gr.Button()
|
|
|
250 |
output_plot = gr.Plot(label="Output MIDI score plot")
|
251 |
output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
|
252 |
|
253 |
+
run_event = submit.click(render_midi, [input_midi, render_type, soundfont_bank, render_sample_rate, melody_patch],
|
254 |
[output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
|
255 |
|
256 |
app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
|