From 3801b5cc0f6aafe89608863dca4a65eb9b22e756 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Tue, 8 Jun 2021 14:50:24 -0400 Subject: [PATCH 1/4] Make sure the first beat in a const beat grid is as close to the start of the track as possible. --- src/track/beatutils.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/track/beatutils.cpp b/src/track/beatutils.cpp index 531ea218509..0d03634961d 100644 --- a/src/track/beatutils.cpp +++ b/src/track/beatutils.cpp @@ -298,7 +298,12 @@ double BeatUtils::makeConstBpm( const double roundBpm = roundBpmWithinRange(minRoundBpm, centerBpm, maxRoundBpm); if (pFirstBeat) { + // 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. *pFirstBeat = constantRegions[startRegionIndex].firstBeat; + const double beatsBeforeFirst = std::floor(*pFirstBeat / longestRegionBeatLength); + *pFirstBeat -= (longestRegionBeatLength * beatsBeforeFirst); } return roundBpm; } From ffb0c3fbbda056967d18008b82432b1344a5089e Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Tue, 8 Jun 2021 14:58:35 -0400 Subject: [PATCH 2/4] Use the beatlength of the rounded bpm, not the center. --- src/track/beatutils.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/track/beatutils.cpp b/src/track/beatutils.cpp index 0d03634961d..a8ccf791e8a 100644 --- a/src/track/beatutils.cpp +++ b/src/track/beatutils.cpp @@ -289,9 +289,9 @@ 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; @@ -302,8 +302,9 @@ double BeatUtils::makeConstBpm( // a constant beatgrid so "first beat" only affects the anchor point where // bpm adjustments are made. *pFirstBeat = constantRegions[startRegionIndex].firstBeat; - const double beatsBeforeFirst = std::floor(*pFirstBeat / longestRegionBeatLength); - *pFirstBeat -= (longestRegionBeatLength * beatsBeforeFirst); + const double roundedBeatLength = 60.0 * sampleRate / roundBpm; + const double beatsBeforeFirst = std::floor(*pFirstBeat / roundedBeatLength); + *pFirstBeat -= (roundedBeatLength * beatsBeforeFirst); } return roundBpm; } From 43556116a95d3a69bbb857df7610641afd772e98 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Wed, 9 Jun 2021 12:30:18 -0400 Subject: [PATCH 3/4] Add comment --- src/track/beatutils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/track/beatutils.cpp b/src/track/beatutils.cpp index a8ccf791e8a..fcea41d4a12 100644 --- a/src/track/beatutils.cpp +++ b/src/track/beatutils.cpp @@ -301,6 +301,8 @@ double BeatUtils::makeConstBpm( // 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. *pFirstBeat = constantRegions[startRegionIndex].firstBeat; const double roundedBeatLength = 60.0 * sampleRate / roundBpm; const double beatsBeforeFirst = std::floor(*pFirstBeat / roundedBeatLength); From 554c2f085657dfb754ea8aa77903f215c185d74b Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Wed, 9 Jun 2021 19:03:02 -0400 Subject: [PATCH 4/4] fix first beat: Use fmod --- src/track/beatutils.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/track/beatutils.cpp b/src/track/beatutils.cpp index fcea41d4a12..68f0962f1c2 100644 --- a/src/track/beatutils.cpp +++ b/src/track/beatutils.cpp @@ -303,10 +303,9 @@ double BeatUtils::makeConstBpm( // 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. - *pFirstBeat = constantRegions[startRegionIndex].firstBeat; const double roundedBeatLength = 60.0 * sampleRate / roundBpm; - const double beatsBeforeFirst = std::floor(*pFirstBeat / roundedBeatLength); - *pFirstBeat -= (roundedBeatLength * beatsBeforeFirst); + *pFirstBeat = fmod(constantRegions[startRegionIndex].firstBeat, + roundedBeatLength); } return roundBpm; }