CPJKU / partitura

A python package for handling modern staff notation of music
https://partitura.readthedocs.io
Apache License 2.0
227 stars 15 forks source link

Empty note array to piano roll leads to ValueError on empty sequence. #356

Closed lmartak closed 1 month ago

lmartak commented 3 months ago

For an empty MIDI file pred_MIDI (e.g. transcription gone real bad):

import partitura as pt
PERF_PIANO_ROLL_PARAMS = {"time_unit": "sec", "time_div": 100, "onset_only": False, "piano_range": True, "time_margin": 0, "return_idxs": False}

pred_perf = pt.load_performance_midi(pred_MIDI)
pred_na = pred_perf.note_array()
pred_pr = pt.utils.compute_pianoroll(pred_na, **PERF_PIANO_ROLL_PARAMS)

fails on the following line: https://github.com/CPJKU/partitura/blob/8812ca6be13f1dc362c9634a7fc8edc3eaac1d3b/partitura/utils/music.py#L1379 with ValueError: min() arg is an empty sequence.

Probably just cosmetics of exception handling, just thought I'd report (close if irrelevant).

sildater commented 1 month ago

Hi @lmartak thanks for the issue! I added a PR with proper handling here #361