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

Fix debug assertion in BeatFactory::makePreferredBeats() #4270

Merged
merged 6 commits into from
Sep 16, 2021
Next Next commit
Fix debug assertion in BeatFactory::makePreferredBeats()
  • Loading branch information
uklotzde committed Sep 7, 2021
commit ce865c71dbbe67db1126dee78b6d6ccda207f502
12 changes: 8 additions & 4 deletions src/track/beatfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,19 @@ mixxx::BeatsPointer BeatFactory::makePreferredBeats(
const mixxx::Bpm constBPM = BeatUtils::makeConstBpm(
constantRegions, sampleRate, &firstBeat);
firstBeat = BeatUtils::adjustPhase(firstBeat, constBPM, sampleRate, beats);
auto pGrid = mixxx::BeatGrid::makeBeatGrid(
sampleRate, constBPM, firstBeat.toNearestFrameBoundary(), subVersion);
return pGrid;
if (firstBeat.isValid()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is only called by analyzerbeats. Can we move the check there and leave the debug assertion intact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I only wonder why the assertion was triggered by firstBeat.toNearestFrameBoundary(), because adjustPhase() already requires a valid value? firstBeat is invalidated by makeConstBpm().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em, no, I don't think we can't move this check out of BeatFactory::makePreferredBeats(). Will test again.

Also edge cases with a single beat are not handled correctly. It doesn't make any sense to infer a tempo for less than 2 beats.

auto pGrid = mixxx::BeatGrid::makeBeatGrid(
sampleRate, constBPM, firstBeat.toNearestFrameBoundary(), subVersion);
return pGrid;
} else {
qWarning() << "Failed to create beat grid: Invalid first beat";
}
} else if (version == BEAT_MAP_VERSION) {
QVector<mixxx::audio::FramePos> ironedBeats = BeatUtils::getBeats(constantRegions);
auto pBeatMap = mixxx::BeatMap::makeBeatMap(sampleRate, subVersion, ironedBeats);
return pBeatMap;
} else {
qDebug() << "ERROR: Could not determine what type of beatgrid to create.";
return mixxx::BeatsPointer();
}
return nullptr;
}