avans06 commited on
Commit
b101711
·
1 Parent(s): 2923df9

fix(rendering): prevent index error on empty midi processing

Browse files

The `Render_MIDI` function would crash with an `IndexError` if it received a MIDI with no notes, typically from a failed transcription.

Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -633,10 +633,21 @@ def Render_MIDI(input_midi_path,
633
  # --- MIDI Processing using TMIDIX ---
634
  print('Processing MIDI... Please wait...')
635
  raw_score = MIDI.midi2single_track_ms_score(fdata)
636
- escore = TMIDIX.advanced_score_processor(raw_score,
637
- return_enhanced_score_notes=True,
638
- apply_sustain=render_with_sustains
639
- )[0]
 
 
 
 
 
 
 
 
 
 
 
640
 
641
  # Handle cases where the MIDI might not contain any notes
642
  if not escore:
 
633
  # --- MIDI Processing using TMIDIX ---
634
  print('Processing MIDI... Please wait...')
635
  raw_score = MIDI.midi2single_track_ms_score(fdata)
636
+ # call the function and store the returned list in a variable.
637
+ processed_scores = TMIDIX.advanced_score_processor(raw_score,
638
+ return_enhanced_score_notes=True,
639
+ apply_sustain=render_with_sustains)
640
+ # check if the returned list is empty. This happens when transcription finds no notes.
641
+ # This check prevents the 'IndexError: list index out of range'.
642
+ if not processed_scores:
643
+ # If it is empty, print a warning and return a user-friendly error message.
644
+ print("Warning: MIDI file contains no processable notes.")
645
+ # The number of returned values must match the function's expected output.
646
+ # We return a tuple with empty or placeholder values for all 7 output components.
647
+ return ("N/A", fn1, "MIDI file contains no notes.", None, None, None, "No notes found.")
648
+
649
+ # If the list is not empty, it is now safe to get the first element.
650
+ escore = processed_scores[0]
651
 
652
  # Handle cases where the MIDI might not contain any notes
653
  if not escore: