Skip to content

Commit

Permalink
Merge pull request #78 from craffel/edge_cases
Browse files Browse the repository at this point in the history
Raise when requiring IOIs with too few notes
  • Loading branch information
craffel authored Aug 3, 2016
2 parents 0039778 + b733357 commit c959eca
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pretty_midi/pretty_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ def estimate_tempo(self):
Estimated tempo, in bpm
"""
return self.estimate_tempi()[0][0]
tempi = self.estimate_tempi()[0]
if tempi.size == 0:
raise ValueError("Can't provide a global tempo estimate when there"
" are fewer than two notes.")
return tempi[0][0]

def get_beats(self, start_time=0.):
"""Return a list of beat locations, according to MIDI tempo changes.
Expand Down Expand Up @@ -592,6 +596,9 @@ def estimate_beat_start(self, candidates=10, tolerance=.025):
"""
# Get a sorted list of all notes from all instruments
note_list = [n for i in self.instruments for n in i.notes]
if not note_list:
raise ValueError(
"Can't estimate beat start when there are no notes.")
note_list.sort(key=lambda note: note.start)
# List of possible beat trackings
beat_candidates = []
Expand Down

0 comments on commit c959eca

Please sign in to comment.