Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Beats::findNthBeat fuzzy behavior #4099

Merged
merged 5 commits into from
Jul 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/track/beatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,21 @@ audio::FramePos BeatMap::findNthBeat(audio::FramePos position, int n) const {
return audio::kInvalidFramePos;
}

const bool searchForward = n > 0;
int numBeatsLeft = std::abs(n);

const auto searchFromPosition = (n > 0) ? position.toUpperFrameBoundary()
: position.toLowerFrameBoundary();
// Beats are stored as full frame positions, so when search forward, the
// smalled possible beat we can find is the upper frame boundary of the
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
// search position.
//
// For searching backwards, the same applies for the lower frame boundary.
const auto searchFromPosition = searchForward
? position.toUpperFrameBoundary()
: position.toLowerFrameBoundary();
const Beat searchFromBeat = beatFromFramePos(searchFromPosition);
auto it = std::lower_bound(m_beats.cbegin(), m_beats.cend(), searchFromBeat, beatLessThan);

if (n > 0) {
if (searchForward) {
// Search in forward direction
numBeatsLeft--;

Expand Down Expand Up @@ -359,8 +366,8 @@ audio::FramePos BeatMap::findNthBeat(audio::FramePos position, int n) const {

const auto foundBeatPosition = mixxx::audio::FramePos(it->frame_position());

DEBUG_ASSERT(foundBeatPosition >= searchFromPosition || n < 0);
DEBUG_ASSERT(foundBeatPosition <= searchFromPosition || n > 0);
DEBUG_ASSERT(foundBeatPosition >= searchFromPosition || !searchForward);
DEBUG_ASSERT(foundBeatPosition <= searchFromPosition || searchForward);
return foundBeatPosition;
}

Expand Down