Skip to content

Commit

Permalink
Bpm: Improve method naming (hasValue/getValue -> isValid/value)
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jul 2, 2021
1 parent 11d316f commit 31d50dc
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/analyzer/analyzerbeats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool AnalyzerBeats::shouldAnalyze(TrackPointer pTrack) const {
if (!pBeats) {
return true;
}
if (!pBeats->getBpm().hasValue()) {
if (!pBeats->getBpm().isValid()) {
// Tracks with an invalid bpm <= 0 should be re-analyzed,
// independent of the preference settings. We expect that
// all tracks have a bpm > 0 when analyzed. Users that want
Expand Down
6 changes: 3 additions & 3 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void BpmControl::adjustBeatsBpm(double deltaBpm) {
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats && (pBeats->getCapabilities() & mixxx::Beats::BEATSCAP_SETBPM)) {
mixxx::Bpm bpm = pBeats->getBpm();
const auto centerBpm = mixxx::Bpm(math_max(kBpmAdjustMin, bpm.getValue() + deltaBpm));
const auto centerBpm = mixxx::Bpm(math_max(kBpmAdjustMin, bpm.value() + deltaBpm));
mixxx::Bpm adjustedBpm = BeatUtils::roundBpmWithinRange(
centerBpm - kBpmAdjustStep / 2, centerBpm, centerBpm + kBpmAdjustStep / 2);
pTrack->trySetBeats(pBeats->setBpm(adjustedBpm));
Expand Down Expand Up @@ -1071,15 +1071,15 @@ mixxx::Bpm BpmControl::updateLocalBpm() {
if (pBeats) {
localBpm = pBeats->getBpmAroundPosition(
getSampleOfTrack().current, kLocalBpmSpan);
if (!localBpm.hasValue()) {
if (!localBpm.isValid()) {
localBpm = pBeats->getBpm();
}
}
if (localBpm != prevLocalBpm) {
if (kLogger.traceEnabled()) {
kLogger.trace() << getGroup() << "BpmControl::updateLocalBpm" << localBpm;
}
m_pLocalBpm->set(localBpm.getValue());
m_pLocalBpm->set(localBpm.value());
slotUpdateEngineBpm();
}
return localBpm;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ void EngineBuffer::postProcess(const int iBufferSize) {
}
const mixxx::Bpm localBpm = m_pBpmControl->updateLocalBpm();
double beatDistance = m_pBpmControl->updateBeatDistance();
m_pSyncControl->setLocalBpm(localBpm.getValue());
m_pSyncControl->setLocalBpm(localBpm.value());
m_pSyncControl->updateAudible();
SyncMode mode = m_pSyncControl->getSyncMode();
if (isMaster(mode)) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sync/synccontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void SyncControl::notifySeek(double dNewPlaypos) {
double SyncControl::fileBpm() const {
mixxx::BeatsPointer pBeats = m_pBeats;
if (pBeats) {
return pBeats->getBpm().getValue();
return pBeats->getBpm().value();
}
return 0.0;
}
8 changes: 4 additions & 4 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,11 @@ QVariant BaseTrackTableModel::roleValue(
bpm = mixxx::Bpm(bpmValue);
}
}
if (bpm.hasValue()) {
if (bpm.isValid()) {
if (role == Qt::ToolTipRole || role == kDataExportRole) {
return QString::number(bpm.getValue(), 'f', 4);
return QString::number(bpm.value(), 'f', 4);
} else {
return QString::number(bpm.getValue(), 'f', 1);
return QString::number(bpm.value(), 'f', 1);
}
} else {
return QChar('-');
Expand Down Expand Up @@ -782,7 +782,7 @@ QVariant BaseTrackTableModel::roleValue(
case ColumnCache::COLUMN_LIBRARYTABLE_BPM: {
bool ok;
const auto bpmValue = rawValue.toDouble(&ok);
return ok ? bpmValue : mixxx::Bpm().getValue();
return ok ? bpmValue : mixxx::Bpm().value();
}
case ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED:
return index.sibling(
Expand Down
2 changes: 1 addition & 1 deletion src/library/browse/browsethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void BrowseThread::populateModel() {

item = new QStandardItem(trackMetadata.getTrackInfo().getBpmText());
item->setToolTip(item->text());
item->setData(trackMetadata.getTrackInfo().getBpm().getValue(), Qt::UserRole);
item->setData(trackMetadata.getTrackInfo().getBpm().value(), Qt::UserRole);
row_data.insert(COLUMN_BPM, item);

item = new QStandardItem(trackMetadata.getTrackInfo().getKey());
Expand Down
2 changes: 1 addition & 1 deletion src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void bindTrackLibraryValues(
beatsSubVersion = pBeats->getSubVersion();
bpm = pBeats->getBpm();
}
pTrackLibraryQuery->bindValue(":bpm", bpm.getValue());
pTrackLibraryQuery->bindValue(":bpm", bpm.value());
pTrackLibraryQuery->bindValue(":beats_version", beatsVersion);
pTrackLibraryQuery->bindValue(":beats_sub_version", beatsSubVersion);
pTrackLibraryQuery->bindValue(":beats", beatsBlob);
Expand Down
20 changes: 10 additions & 10 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void DlgTrackInfo::updateTrackMetadataFields() {
void DlgTrackInfo::reloadTrackBeats(const Track& track) {
m_pBeatsClone = track.getBeats();
if (m_pBeatsClone) {
spinBpm->setValue(m_pBeatsClone->getBpm().getValue());
spinBpm->setValue(m_pBeatsClone->getBpm().value());
} else {
spinBpm->setValue(0.0);
}
Expand Down Expand Up @@ -521,42 +521,42 @@ void DlgTrackInfo::slotBpmDouble() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::DOUBLE);
// read back the actual value
mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

void DlgTrackInfo::slotBpmHalve() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::HALVE);
// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

void DlgTrackInfo::slotBpmTwoThirds() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::TWOTHIRDS);
// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

void DlgTrackInfo::slotBpmThreeFourth() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::THREEFOURTHS);
// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

void DlgTrackInfo::slotBpmFourThirds() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::FOURTHIRDS);
// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

void DlgTrackInfo::slotBpmThreeHalves() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::THREEHALVES);
// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

void DlgTrackInfo::slotBpmClear() {
Expand Down Expand Up @@ -607,13 +607,13 @@ void DlgTrackInfo::slotBpmTap(double averageLength, int numSamples) {
averageBpm + kBpmTabRounding);
if (averageBpm != m_lastTapedBpm) {
m_lastTapedBpm = averageBpm;
spinBpm->setValue(averageBpm.getValue());
spinBpm->setValue(averageBpm.value());
}
}

void DlgTrackInfo::slotSpinBpmValueChanged(double value) {
const auto bpm = mixxx::Bpm(value);
if (!bpm.hasValue()) {
if (!bpm.isValid()) {
m_pBeatsClone.clear();
return;
}
Expand All @@ -637,7 +637,7 @@ void DlgTrackInfo::slotSpinBpmValueChanged(double value) {

// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.getValue());
spinBpm->setValue(newValue.value());
}

mixxx::UpdateResult DlgTrackInfo::updateKeyText() {
Expand Down
26 changes: 13 additions & 13 deletions src/test/beatgridtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ TEST(BeatGridTest, Scale) {
TrackPointer pTrack = newTrack(sampleRate);

constexpr mixxx::Bpm bpm(60.0);
pTrack->trySetBpm(bpm.getValue());
pTrack->trySetBpm(bpm.value());

auto pGrid = BeatGrid::makeBeatGrid(pTrack->getSampleRate(),
QString(),
mixxx::Bpm(bpm),
mixxx::audio::kStartFramePos);

EXPECT_DOUBLE_EQ(bpm.getValue(), pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pGrid->getBpm().value());
pGrid = pGrid->scale(Beats::DOUBLE);
EXPECT_DOUBLE_EQ(2 * bpm.getValue(), pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(2 * bpm.value(), pGrid->getBpm().value());

pGrid = pGrid->scale(Beats::HALVE);
EXPECT_DOUBLE_EQ(bpm.getValue(), pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pGrid->getBpm().value());

pGrid = pGrid->scale(Beats::TWOTHIRDS);
EXPECT_DOUBLE_EQ(bpm.getValue() * 2 / 3, pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value() * 2 / 3, pGrid->getBpm().value());

pGrid = pGrid->scale(Beats::THREEHALVES);
EXPECT_DOUBLE_EQ(bpm.getValue(), pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pGrid->getBpm().value());

pGrid = pGrid->scale(Beats::THREEFOURTHS);
EXPECT_DOUBLE_EQ(bpm.getValue() * 3 / 4, pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value() * 3 / 4, pGrid->getBpm().value());

pGrid = pGrid->scale(Beats::FOURTHIRDS);
EXPECT_DOUBLE_EQ(bpm.getValue(), pGrid->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pGrid->getBpm().value());
}

TEST(BeatGridTest, TestNthBeatWhenOnBeat) {
Expand Down Expand Up @@ -190,8 +190,8 @@ TEST(BeatGridTest, TestNthBeatWhenNotOnBeat) {

const auto bpm = mixxx::Bpm(60.1);
const int kFrameSize = 2;
pTrack->trySetBpm(bpm.getValue());
double beatLength = (60.0 * sampleRate / bpm.getValue()) * kFrameSize;
pTrack->trySetBpm(bpm.value());
double beatLength = (60.0 * sampleRate / bpm.value()) * kFrameSize;

auto pGrid = BeatGrid::makeBeatGrid(pTrack->getSampleRate(),
QString(),
Expand Down Expand Up @@ -230,11 +230,11 @@ TEST(BeatGridTest, FromMetadata) {
TrackPointer pTrack = newTrack(sampleRate);

constexpr mixxx::Bpm bpm(60.1);
ASSERT_TRUE(pTrack->trySetBpm(bpm.getValue()));
EXPECT_DOUBLE_EQ(pTrack->getBpm(), bpm.getValue());
ASSERT_TRUE(pTrack->trySetBpm(bpm.value()));
EXPECT_DOUBLE_EQ(pTrack->getBpm(), bpm.value());

auto pBeats = pTrack->getBeats();
EXPECT_DOUBLE_EQ(pBeats->getBpm().getValue(), bpm.getValue());
EXPECT_DOUBLE_EQ(pBeats->getBpm().value(), bpm.value());

// Invalid bpm resets the bpm
ASSERT_TRUE(pTrack->trySetBpm(-60.1));
Expand Down
42 changes: 21 additions & 21 deletions src/test/beatmaptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BeatMapTest : public testing::Test {
}

mixxx::audio::FrameDiff_t getBeatLengthFrames(mixxx::Bpm bpm) {
return (60.0 * m_iSampleRate / bpm.getValue());
return (60.0 * m_iSampleRate / bpm.value());
}

double getBeatLengthSamples(mixxx::Bpm bpm) {
Expand All @@ -48,7 +48,7 @@ class BeatMapTest : public testing::Test {

TEST_F(BeatMapTest, Scale) {
constexpr mixxx::Bpm bpm(60.0);
m_pTrack->trySetBpm(bpm.getValue());
m_pTrack->trySetBpm(bpm.value());
mixxx::audio::FrameDiff_t beatLengthFrames = getBeatLengthFrames(bpm);
const auto startOffsetFrames = mixxx::audio::FramePos(7);
const int numBeats = 100;
Expand All @@ -57,29 +57,29 @@ TEST_F(BeatMapTest, Scale) {
createBeatVector(startOffsetFrames, numBeats, beatLengthFrames);
auto pMap = BeatMap::makeBeatMap(m_pTrack->getSampleRate(), QString(), beats);

EXPECT_DOUBLE_EQ(bpm.getValue(), pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pMap->getBpm().value());
pMap = pMap->scale(Beats::DOUBLE);
EXPECT_DOUBLE_EQ(2 * bpm.getValue(), pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(2 * bpm.value(), pMap->getBpm().value());

pMap = pMap->scale(Beats::HALVE);
EXPECT_DOUBLE_EQ(bpm.getValue(), pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pMap->getBpm().value());

pMap = pMap->scale(Beats::TWOTHIRDS);
EXPECT_DOUBLE_EQ(bpm.getValue() * 2 / 3, pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value() * 2 / 3, pMap->getBpm().value());

pMap = pMap->scale(Beats::THREEHALVES);
EXPECT_DOUBLE_EQ(bpm.getValue(), pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pMap->getBpm().value());

pMap = pMap->scale(Beats::THREEFOURTHS);
EXPECT_DOUBLE_EQ(bpm.getValue() * 3 / 4, pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value() * 3 / 4, pMap->getBpm().value());

pMap = pMap->scale(Beats::FOURTHIRDS);
EXPECT_DOUBLE_EQ(bpm.getValue(), pMap->getBpm().getValue());
EXPECT_DOUBLE_EQ(bpm.value(), pMap->getBpm().value());
}

TEST_F(BeatMapTest, TestNthBeat) {
constexpr mixxx::Bpm bpm(60.0);
m_pTrack->trySetBpm(bpm.getValue());
m_pTrack->trySetBpm(bpm.value());
mixxx::audio::FrameDiff_t beatLengthFrames = getBeatLengthFrames(bpm);
const auto startOffsetFrames = mixxx::audio::FramePos(7);
double beatLengthSamples = getBeatLengthSamples(bpm);
Expand Down Expand Up @@ -112,7 +112,7 @@ TEST_F(BeatMapTest, TestNthBeat) {

TEST_F(BeatMapTest, TestNthBeatWhenOnBeat) {
constexpr mixxx::Bpm bpm(60.0);
m_pTrack->trySetBpm(bpm.getValue());
m_pTrack->trySetBpm(bpm.value());
mixxx::audio::FrameDiff_t beatLengthFrames = getBeatLengthFrames(bpm);
const auto startOffsetFrames = mixxx::audio::FramePos(7);
double beatLengthSamples = getBeatLengthSamples(bpm);
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_F(BeatMapTest, TestNthBeatWhenOnBeat) {

TEST_F(BeatMapTest, TestNthBeatWhenOnBeat_BeforeEpsilon) {
constexpr mixxx::Bpm bpm(60.0);
m_pTrack->trySetBpm(bpm.getValue());
m_pTrack->trySetBpm(bpm.value());
mixxx::audio::FrameDiff_t beatLengthFrames = getBeatLengthFrames(bpm);
const auto startOffsetFrames = mixxx::audio::FramePos(7);
double beatLengthSamples = getBeatLengthSamples(bpm);
Expand Down Expand Up @@ -200,7 +200,7 @@ TEST_F(BeatMapTest, TestNthBeatWhenOnBeat_BeforeEpsilon) {

TEST_F(BeatMapTest, TestNthBeatWhenOnBeat_AfterEpsilon) {
constexpr mixxx::Bpm bpm(60.0);
m_pTrack->trySetBpm(bpm.getValue());
m_pTrack->trySetBpm(bpm.value());
mixxx::audio::FrameDiff_t beatLengthFrames = getBeatLengthFrames(bpm);
const auto startOffsetFrames = mixxx::audio::FramePos(7);
double beatLengthSamples = getBeatLengthSamples(bpm);
Expand Down Expand Up @@ -246,7 +246,7 @@ TEST_F(BeatMapTest, TestNthBeatWhenOnBeat_AfterEpsilon) {

TEST_F(BeatMapTest, TestNthBeatWhenNotOnBeat) {
constexpr mixxx::Bpm bpm(60.0);
m_pTrack->trySetBpm(bpm.getValue());
m_pTrack->trySetBpm(bpm.value());
mixxx::audio::FrameDiff_t beatLengthFrames = getBeatLengthFrames(bpm);
const auto startOffsetFrames = mixxx::audio::FramePos(7);
double beatLengthSamples = getBeatLengthSamples(bpm);
Expand Down Expand Up @@ -289,7 +289,7 @@ TEST_F(BeatMapTest, TestNthBeatWhenNotOnBeat) {
TEST_F(BeatMapTest, TestBpmAround) {
constexpr mixxx::Bpm filebpm(60.0);
double approx_beat_length = getBeatLengthSamples(filebpm);
m_pTrack->trySetBpm(filebpm.getValue());
m_pTrack->trySetBpm(filebpm.value());
const int numBeats = 64;

QVector<mixxx::audio::FramePos> beats;
Expand All @@ -305,21 +305,21 @@ TEST_F(BeatMapTest, TestBpmAround) {
// The average of the first 8 beats should be different than the average
// of the last 8 beats.
EXPECT_DOUBLE_EQ(63.937645572318047,
pMap->getBpmAroundPosition(4 * approx_beat_length, 4).getValue());
pMap->getBpmAroundPosition(4 * approx_beat_length, 4).value());
EXPECT_DOUBLE_EQ(118.96668932698844,
pMap->getBpmAroundPosition(60 * approx_beat_length, 4).getValue());
pMap->getBpmAroundPosition(60 * approx_beat_length, 4).value());
// Also test at the beginning and end of the track
EXPECT_DOUBLE_EQ(62.937377309576974,
pMap->getBpmAroundPosition(0, 4).getValue());
pMap->getBpmAroundPosition(0, 4).value());
EXPECT_DOUBLE_EQ(118.96668932698844,
pMap->getBpmAroundPosition(65 * approx_beat_length, 4).getValue());
pMap->getBpmAroundPosition(65 * approx_beat_length, 4).value());

// Try a really, really short track
constexpr auto startFramePos = mixxx::audio::FramePos(10);
beats = createBeatVector(startFramePos, 3, getBeatLengthFrames(filebpm));
pMap = BeatMap::makeBeatMap(m_pTrack->getSampleRate(), QString(), beats);
EXPECT_DOUBLE_EQ(filebpm.getValue(),
pMap->getBpmAroundPosition(1 * approx_beat_length, 4).getValue());
EXPECT_DOUBLE_EQ(filebpm.value(),
pMap->getBpmAroundPosition(1 * approx_beat_length, 4).value());
}

} // namespace
4 changes: 2 additions & 2 deletions src/test/beatstranslatetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ TEST_F(BeatsTranslateTest, SimpleTranslateMatch) {
// doesn't get set naturally, but this will do for now.
auto pBpm1 = std::make_unique<ControlProxy>(m_sGroup1, "bpm");
auto pBpm2 = std::make_unique<ControlProxy>(m_sGroup1, "bpm");
pBpm1->set(bpm.getValue());
pBpm2->set(bpm.getValue());
pBpm1->set(bpm.value());
pBpm2->set(bpm.value());
ProcessBuffer();

// Push the button on deck 2.
Expand Down
2 changes: 1 addition & 1 deletion src/test/bpmcontrol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST_F(BpmControlTest, BeatContext_BeatGrid) {

const auto bpm = mixxx::Bpm(60.0);
const int kFrameSize = 2;
const double expectedBeatLength = (60.0 * sampleRate / bpm.getValue()) * kFrameSize;
const double expectedBeatLength = (60.0 * sampleRate / bpm.value()) * kFrameSize;

const mixxx::BeatsPointer pBeats = BeatFactory::makeBeatGrid(
pTrack->getSampleRate(), bpm, mixxx::audio::kStartFramePos);
Expand Down
Loading

0 comments on commit 31d50dc

Please sign in to comment.