From 1bf238960435bfe4bc04edc1cba7ee345e7af069 Mon Sep 17 00:00:00 2001 From: Colin Raffel Date: Mon, 8 Aug 2016 17:35:41 -0400 Subject: [PATCH] Update current BPM at the end of each loop iteration 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. --- pretty_midi/pretty_midi.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pretty_midi/pretty_midi.py b/pretty_midi/pretty_midi.py index 7d6ae16..8fa0174 100644 --- a/pretty_midi/pretty_midi.py +++ b/pretty_midi/pretty_midi.py @@ -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) @@ -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: