Skip to content

Commit

Permalink
Merge pull request #3965 from ywwg/fix-first-beat
Browse files Browse the repository at this point in the history
Fix const beat grid first beat placement
  • Loading branch information
daschuer authored Jun 10, 2021
2 parents 1dd3dec + 554c2f0 commit f535bcb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/track/beatutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,23 @@ double BeatUtils::makeConstBpm(

// Create a const region region form the first beat of the first region to the last beat of the last region.

const double minRoundBpm = 60 * sampleRate / longestRegionBeatLengthMax;
const double maxRoundBpm = 60 * sampleRate / longestRegionBeatLengthMin;
const double centerBpm = 60 * sampleRate / longestRegionBeatLength;
const double minRoundBpm = 60.0 * sampleRate / longestRegionBeatLengthMax;
const double maxRoundBpm = 60.0 * sampleRate / longestRegionBeatLengthMin;
const double centerBpm = 60.0 * sampleRate / longestRegionBeatLength;

//qDebug() << "minRoundBpm" << minRoundBpm;
//qDebug() << "maxRoundBpm" << maxRoundBpm;
const double roundBpm = roundBpmWithinRange(minRoundBpm, centerBpm, maxRoundBpm);

if (pFirstBeat) {
*pFirstBeat = constantRegions[startRegionIndex].firstBeat;
// Move the first beat as close to the start of the track as we can. This is
// a constant beatgrid so "first beat" only affects the anchor point where
// bpm adjustments are made.
// This is a temporary fix, ideally the anchor point for the BPM grid should
// be the first proper downbeat, or perhaps the CUE point.
const double roundedBeatLength = 60.0 * sampleRate / roundBpm;
*pFirstBeat = fmod(constantRegions[startRegionIndex].firstBeat,
roundedBeatLength);
}
return roundBpm;
}
Expand Down

0 comments on commit f535bcb

Please sign in to comment.