Skip to content

Commit

Permalink
Update current BPM at the end of each loop iteration
Browse files Browse the repository at this point in the history
With get_current_bpm at the top of this loop iteration, the conditional
was being tested on the old BPM and the new tempo change time.  This
probably wasn't a big deal when the tempo was not changing a lot, but
when it does change a lot, this would create the wrong behavior.  It
should be at the bottom, after the tempo index is updated.  And, with it
here, we don't need to udpate the tempo after we exit the loop.
  • Loading branch information
craffel committed Aug 9, 2016
1 parent a615cea commit 1bf2389
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pretty_midi/pretty_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ def gt_or_close(a, b):
while (tempo_idx < tempo_change_times.shape[0] - 1 and
next_beat + beat_remaining*60.0/bpm >=
tempo_change_times[tempo_idx + 1]):
# Update the current bpm
bpm = get_current_bpm()
# Compute the amount the beat location overshoots
overshot_ratio = (tempo_change_times[tempo_idx + 1] -
next_beat)/(60.0/bpm)
Expand All @@ -551,8 +549,9 @@ def gt_or_close(a, b):
beat_remaining -= overshot_ratio
# Increment the tempo index
tempo_idx = tempo_idx + 1
# Update the current bpm
bpm = get_current_bpm()
# Update the current bpm
bpm = get_current_bpm()
# Add in the remainder of the beat at the current tempo
next_beat += beat_remaining*60./bpm
# Check if we have just passed the first time signature change
if self.time_signature_changes and ts_idx == 0:
Expand Down

0 comments on commit 1bf2389

Please sign in to comment.