fix(rendering): prevent index error on empty midi processing
Browse filesThe `Render_MIDI` function would crash with an `IndexError` if it received a MIDI with no notes, typically from a failed transcription.
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 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|