asigalov61 commited on
Commit
410f581
1 Parent(s): 7a7d25f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -44,13 +44,12 @@ import statistics
44
 
45
  #==========================================================================================================
46
 
47
- def render_midi(input_midi,
48
  render_type,
49
  soundfont_bank,
50
  render_sample_rate,
51
  custom_render_patch,
52
  render_align,
53
- render_summary_type,
54
  render_transpose_value,
55
  render_transpose_to_C4,
56
  render_output_as_solo_piano,
@@ -82,7 +81,6 @@ def render_midi(input_midi,
82
  print('Audio render sample rate', render_sample_rate)
83
  print('Custom MIDI render patch', custom_render_patch)
84
  print('Align to bars:', render_align)
85
- print('Summary type:', render_summary_type)
86
  print('Transpose value:', render_transpose_value)
87
  print('Transpose to C4', render_transpose_to_C4)
88
  print('Output as Solo Piano', render_output_as_solo_piano)
@@ -111,13 +109,10 @@ def render_midi(input_midi,
111
  print('=' * 70)
112
  print('Processing...Please wait...')
113
 
114
- if render_type == 'Render as-is' or render_type == "Summarize":
115
- output_score = copy.deepcopy(escore)
116
 
117
- elif render_type == "Custom render" or not render_type:
118
- output_score = copy.deepcopy(escore)
119
 
120
- elif render_type == "Extract melody":
121
  output_score = TMIDIX.add_melody_to_enhanced_score_notes(escore, return_melody=True)
122
  output_score = TMIDIX.recalculate_score_timings(output_score)
123
 
@@ -171,7 +166,7 @@ def render_midi(input_midi,
171
  output_score = TMIDIX.recalculate_score_timings(output_score)
172
  output_score = TMIDIX.align_escore_notes_to_bars(output_score, split_durations=True)
173
 
174
- if render_type == "Summarize" and render_summary_type == "Longest Repeating Phrase":
175
  zscore = TMIDIX.recalculate_score_timings(output_score)
176
  lrno_score = TMIDIX.escore_notes_lrno_pattern(zscore)
177
 
@@ -181,7 +176,7 @@ def render_midi(input_midi,
181
  else:
182
  output_score = TMIDIX.recalculate_score_timings(TMIDIX.escore_notes_middle(output_score, 50))
183
 
184
- if render_type == "Summarize" and render_summary_type == "Multi-Instrumental":
185
  zscore = TMIDIX.recalculate_score_timings(output_score)
186
  c_escore_notes = TMIDIX.compress_patches_in_escore_notes_chords(zscore)
187
  cmatrix = TMIDIX.escore_notes_to_image_matrix(c_escore_notes, filter_out_zero_rows=True, filter_out_duplicate_rows=True)
@@ -198,7 +193,7 @@ def render_midi(input_midi,
198
  if render_remove_drums:
199
  output_score = TMIDIX.strip_drums_from_escore_notes(output_score)
200
 
201
- if render_type == "Summarize" and render_summary_type == "Solo Piano":
202
  sp_escore_notes = TMIDIX.solo_piano_escore_notes(output_score, keep_drums=False)
203
  zscore = TMIDIX.recalculate_score_timings(sp_escore_notes)
204
  bmatrix = TMIDIX.escore_notes_to_binary_matrix(zscore)
@@ -359,8 +354,10 @@ if __name__ == "__main__":
359
  "Extract melody",
360
  "Flip",
361
  "Reverse",
362
- "Repair",
363
- "Summarize",
 
 
364
  ],
365
  label="Render type",
366
  value="Render as-is"
@@ -369,14 +366,6 @@ if __name__ == "__main__":
369
  gr.Markdown("## Select custom render options")
370
 
371
  custom_render_patch = gr.Slider(-1, 127, value=-1, label="Custom render MIDI patch")
372
-
373
- render_summary_type = gr.Radio(["Multi-Instrumental",
374
- "Solo Piano",
375
- "Longest Repeating Phrase",
376
- ],
377
- label="Summary type",
378
- value="Multi-Instrumental"
379
- )
380
 
381
  render_align = gr.Radio(["Do not align",
382
  "Start Times",
@@ -405,13 +394,12 @@ if __name__ == "__main__":
405
  output_plot = gr.Plot(label="Output MIDI score plot")
406
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
407
 
408
- run_event = submit.click(render_midi, [input_midi,
409
  render_type,
410
  soundfont_bank,
411
  render_sample_rate,
412
  custom_render_patch,
413
  render_align,
414
- render_summary_type,
415
  render_transpose_value,
416
  render_transpose_to_C4,
417
  render_output_as_solo_piano,
 
44
 
45
  #==========================================================================================================
46
 
47
+ def Render_MIDI(input_midi,
48
  render_type,
49
  soundfont_bank,
50
  render_sample_rate,
51
  custom_render_patch,
52
  render_align,
 
53
  render_transpose_value,
54
  render_transpose_to_C4,
55
  render_output_as_solo_piano,
 
81
  print('Audio render sample rate', render_sample_rate)
82
  print('Custom MIDI render patch', custom_render_patch)
83
  print('Align to bars:', render_align)
 
84
  print('Transpose value:', render_transpose_value)
85
  print('Transpose to C4', render_transpose_to_C4)
86
  print('Output as Solo Piano', render_output_as_solo_piano)
 
109
  print('=' * 70)
110
  print('Processing...Please wait...')
111
 
 
 
112
 
113
+ output_score = copy.deepcopy(escore)
 
114
 
115
+ if render_type == "Extract melody":
116
  output_score = TMIDIX.add_melody_to_enhanced_score_notes(escore, return_melody=True)
117
  output_score = TMIDIX.recalculate_score_timings(output_score)
118
 
 
166
  output_score = TMIDIX.recalculate_score_timings(output_score)
167
  output_score = TMIDIX.align_escore_notes_to_bars(output_score, split_durations=True)
168
 
169
+ if render_type == "Longest Repeating Phrase":
170
  zscore = TMIDIX.recalculate_score_timings(output_score)
171
  lrno_score = TMIDIX.escore_notes_lrno_pattern(zscore)
172
 
 
176
  else:
177
  output_score = TMIDIX.recalculate_score_timings(TMIDIX.escore_notes_middle(output_score, 50))
178
 
179
+ if render_type == "Multi-Instrumental Summary":
180
  zscore = TMIDIX.recalculate_score_timings(output_score)
181
  c_escore_notes = TMIDIX.compress_patches_in_escore_notes_chords(zscore)
182
  cmatrix = TMIDIX.escore_notes_to_image_matrix(c_escore_notes, filter_out_zero_rows=True, filter_out_duplicate_rows=True)
 
193
  if render_remove_drums:
194
  output_score = TMIDIX.strip_drums_from_escore_notes(output_score)
195
 
196
+ if render_type == "Solo Piano Summary":
197
  sp_escore_notes = TMIDIX.solo_piano_escore_notes(output_score, keep_drums=False)
198
  zscore = TMIDIX.recalculate_score_timings(sp_escore_notes)
199
  bmatrix = TMIDIX.escore_notes_to_binary_matrix(zscore)
 
354
  "Extract melody",
355
  "Flip",
356
  "Reverse",
357
+ "Repair Chords",
358
+ "Longest Repeating Phrase"
359
+ "Multi-Instrumental Summary",
360
+ "Solo Piano Summary"
361
  ],
362
  label="Render type",
363
  value="Render as-is"
 
366
  gr.Markdown("## Select custom render options")
367
 
368
  custom_render_patch = gr.Slider(-1, 127, value=-1, label="Custom render MIDI patch")
 
 
 
 
 
 
 
 
369
 
370
  render_align = gr.Radio(["Do not align",
371
  "Start Times",
 
394
  output_plot = gr.Plot(label="Output MIDI score plot")
395
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
396
 
397
+ run_event = submit.click(Render_MIDI, [input_midi,
398
  render_type,
399
  soundfont_bank,
400
  render_sample_rate,
401
  custom_render_patch,
402
  render_align,
 
403
  render_transpose_value,
404
  render_transpose_to_C4,
405
  render_output_as_solo_piano,