Skip to content

Commit

Permalink
Make get_end_time aware of all event types
Browse files Browse the repository at this point in the history
  • Loading branch information
craffel committed Aug 15, 2016
1 parent 29603ad commit 22fea72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pretty_midi/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def get_end_time(self):
"""
# Cycle through all note ends and all pitch bends and find the largest
events = ([n.end for n in self.notes] +
[b.time for b in self.pitch_bends])
[b.time for b in self.pitch_bends] +
[c.time for c in self.control_changes])
# If there are no events, just return 0
if len(events) == 0:
return 0.
Expand Down
13 changes: 8 additions & 5 deletions pretty_midi/pretty_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,17 @@ def get_end_time(self):
Time, in seconds, where this MIDI file ends.
"""
# Cycle through all notes from all instruments and find the largest
events = ([n.end for i in self.instruments for n in i.notes] +
[b.time for i in self.instruments for b in i.pitch_bends])
# Get end times from all instruments, and times of all meta-events
meta_events = [self.time_signature_changes, self.key_signature_changes,
self.lyrics]
times = ([i.get_end_time() for i in self.instruments] +
[e.time for m in meta_events for e in m] +
self.get_tempo_changes()[0].tolist())
# If there are no events, return 0
if len(events) == 0:
if len(times) == 0:
return 0.
else:
return max(events)
return max(times)

def estimate_tempi(self):
"""Return an empirical estimate of tempos and each tempo's probability.
Expand Down

0 comments on commit 22fea72

Please sign in to comment.