asigalov61 commited on
Commit
4299f7c
·
verified ·
1 Parent(s): 6f0f783

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -7
app.py CHANGED
@@ -1,4 +1,6 @@
 
1
  # https://huggingface.co/spaces/asigalov61/Advanced-MIDI-Renderer
 
2
 
3
  import os.path
4
  import hashlib
@@ -16,8 +18,6 @@ from collections import Counter
16
  import random
17
  import statistics
18
 
19
- import matplotlib.pyplot as plt
20
-
21
  #==========================================================================================================
22
 
23
  def render_midi(input_midi,
@@ -135,6 +135,16 @@ def render_midi(input_midi,
135
  elif render_align == "Start Times and Split Durations":
136
  output_score = TMIDIX.recalculate_score_timings(output_score)
137
  output_score = TMIDIX.align_escore_notes_to_bars(output_score, split_durations=True)
 
 
 
 
 
 
 
 
 
 
138
 
139
  SONG, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(output_score)
140
 
@@ -237,19 +247,51 @@ if __name__ == "__main__":
237
 
238
  gr.Markdown("## Select desired render type")
239
 
240
- render_type = gr.Radio(["Render as-is", "Custom render", "Extract melody", "Flip", "Reverse", "Repair"], label="Render type", value="Render as-is")
 
 
 
 
 
 
 
 
 
 
241
 
242
  gr.Markdown("## Select desired render options")
243
 
244
- soundfont_bank = gr.Radio(["General MIDI", "Nice strings plus orchestra", "Real choir", "Orpheus", "Super Game Boy", "Proto Square"], label="SoundFont bank", value="General MIDI")
245
-
246
- render_sample_rate = gr.Radio(["16000", "32000", "44100"], label="MIDI audio render sample rate", value="16000")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  custom_render_patch = gr.Slider(-1, 127, value=-1, label="Custom render MIDI patch")
249
 
250
  render_transpose_value = gr.Slider(-12, 12, value=0, step=1, label="Transpose value")
251
  render_transpose_to_C4 = gr.Checkbox(label="Transpose to C4", value=False)
252
- render_align = gr.Radio(["Do not align", "Start Times", "Start Times and Durations", "Start Times and Split Durations"], label="Align output to bars", value="Do not align")
 
 
 
 
 
 
 
253
 
254
  submit = gr.Button()
255
 
 
1
+ #================================================================
2
  # https://huggingface.co/spaces/asigalov61/Advanced-MIDI-Renderer
3
+ #================================================================
4
 
5
  import os.path
6
  import hashlib
 
18
  import random
19
  import statistics
20
 
 
 
21
  #==========================================================================================================
22
 
23
  def render_midi(input_midi,
 
135
  elif render_align == "Start Times and Split Durations":
136
  output_score = TMIDIX.recalculate_score_timings(output_score)
137
  output_score = TMIDIX.align_escore_notes_to_bars(output_score, split_durations=True)
138
+
139
+ if render_type == "Summarize":
140
+ sp_escore_notes = TMIDIX.solo_piano_escore_notes(output_score)
141
+ bmatrix = TMIDIX.escore_notes_to_binary_matrix(sp_escore_notes)
142
+ smatrix = TMIDIX.square_binary_matrix(bmatrix)
143
+ output_score = TMIDIX.binary_matrix_to_original_escore_notes(smatrix)
144
+
145
+ for o in output_score:
146
+ o[1] *= 2560
147
+ o[2] *= 2560
148
 
149
  SONG, patches, overflow_patches = TMIDIX.patch_enhanced_score_notes(output_score)
150
 
 
247
 
248
  gr.Markdown("## Select desired render type")
249
 
250
+ render_type = gr.Radio(["Render as-is",
251
+ "Custom render",
252
+ "Extract melody",
253
+ "Flip",
254
+ "Reverse",
255
+ "Repair"
256
+ "Summarize"
257
+ ],
258
+ label="Render type",
259
+ value="Render as-is"
260
+ )
261
 
262
  gr.Markdown("## Select desired render options")
263
 
264
+ soundfont_bank = gr.Radio(["General MIDI",
265
+ "Nice strings plus orchestra",
266
+ "Real choir",
267
+ "Orpheus",
268
+ "Super Game Boy",
269
+ "Proto Square"
270
+ ],
271
+ label="SoundFont bank",
272
+ value="General MIDI"
273
+ )
274
+
275
+ render_sample_rate = gr.Radio(["16000",
276
+ "32000",
277
+ "44100"
278
+ ],
279
+ label="MIDI audio render sample rate",
280
+ value="16000"
281
+ )
282
 
283
  custom_render_patch = gr.Slider(-1, 127, value=-1, label="Custom render MIDI patch")
284
 
285
  render_transpose_value = gr.Slider(-12, 12, value=0, step=1, label="Transpose value")
286
  render_transpose_to_C4 = gr.Checkbox(label="Transpose to C4", value=False)
287
+ render_align = gr.Radio(["Do not align",
288
+ "Start Times",
289
+ "Start Times and Durations",
290
+ "Start Times and Split Durations"
291
+ ],
292
+ label="Align output to bars",
293
+ value="Do not align"
294
+ )
295
 
296
  submit = gr.Button()
297