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

Beats: Use enum class for BpmScale #4092

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,42 +518,42 @@ void DlgTrackInfo::clear() {
}

void DlgTrackInfo::slotBpmDouble() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::DOUBLE);
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::BpmScale::Double);
// read back the actual value
mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.value());
}

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

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

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

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

void DlgTrackInfo::slotBpmThreeHalves() {
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::THREEHALVES);
m_pBeatsClone = m_pBeatsClone->scale(mixxx::Beats::BpmScale::ThreeHalves);
// read back the actual value
const mixxx::Bpm newValue = m_pBeatsClone->getBpm();
spinBpm->setValue(newValue.value());
Expand Down
12 changes: 6 additions & 6 deletions src/test/beatgridtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ TEST(BeatGridTest, Scale) {
mixxx::audio::kStartFramePos);

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

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

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

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

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

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

Expand Down
12 changes: 6 additions & 6 deletions src/test/beatmaptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ TEST_F(BeatMapTest, Scale) {
auto pMap = BeatMap::makeBeatMap(m_pTrack->getSampleRate(), QString(), beats);

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

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

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

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

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

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

Expand Down
14 changes: 7 additions & 7 deletions src/track/beatgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,27 +315,27 @@ BeatsPointer BeatGrid::translate(audio::FrameDiff_t offset) const {
return BeatsPointer(new BeatGrid(*this, grid, m_beatLengthFrames));
}

BeatsPointer BeatGrid::scale(enum BPMScale scale) const {
BeatsPointer BeatGrid::scale(BpmScale scale) const {
mixxx::track::io::BeatGrid grid = m_grid;
auto bpm = mixxx::Bpm(grid.bpm().bpm());

switch (scale) {
case DOUBLE:
case BpmScale::Double:
bpm *= 2;
break;
case HALVE:
case BpmScale::Halve:
bpm *= 1.0 / 2;
break;
case TWOTHIRDS:
case BpmScale::TwoThirds:
bpm *= 2.0 / 3;
break;
case THREEFOURTHS:
case BpmScale::ThreeFourths:
bpm *= 3.0 / 4;
break;
case FOURTHIRDS:
case BpmScale::FourThirds:
bpm *= 4.0 / 3;
break;
case THREEHALVES:
case BpmScale::ThreeHalves:
bpm *= 3.0 / 2;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/track/beatgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BeatGrid final : public Beats {
////////////////////////////////////////////////////////////////////////////

BeatsPointer translate(audio::FrameDiff_t offset) const override;
BeatsPointer scale(enum BPMScale scale) const override;
BeatsPointer scale(BpmScale scale) const override;
BeatsPointer setBpm(mixxx::Bpm bpm) override;

private:
Expand Down
14 changes: 7 additions & 7 deletions src/track/beatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,40 +588,40 @@ BeatsPointer BeatMap::translate(audio::FrameDiff_t offset) const {
return BeatsPointer(new BeatMap(*this, beats, m_nominalBpm));
}

BeatsPointer BeatMap::scale(enum BPMScale scale) const {
BeatsPointer BeatMap::scale(BpmScale scale) const {
if (!isValid() || m_beats.isEmpty()) {
return BeatsPointer(new BeatMap(*this));
}

BeatList beats = m_beats;
switch (scale) {
case DOUBLE:
case BpmScale::Double:
// introduce a new beat into every gap
scaleDouble(&beats);
break;
case HALVE:
case BpmScale::Halve:
// remove every second beat
scaleHalve(&beats);
break;
case TWOTHIRDS:
case BpmScale::TwoThirds:
// introduce a new beat into every gap
scaleDouble(&beats);
// remove every second and third beat
scaleThird(&beats);
break;
case THREEFOURTHS:
case BpmScale::ThreeFourths:
// introduce two beats into every gap
scaleTriple(&beats);
// remove every second third and forth beat
scaleFourth(&beats);
break;
case FOURTHIRDS:
case BpmScale::FourThirds:
// introduce three beats into every gap
scaleQuadruple(&beats);
// remove every second third and forth beat
scaleThird(&beats);
break;
case THREEHALVES:
case BpmScale::ThreeHalves:
// introduce two beats into every gap
scaleTriple(&beats);
// remove every second beat
Expand Down
2 changes: 1 addition & 1 deletion src/track/beatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BeatMap final : public Beats {
////////////////////////////////////////////////////////////////////////////

BeatsPointer translate(audio::FrameDiff_t offset) const override;
BeatsPointer scale(enum BPMScale scale) const override;
BeatsPointer scale(BpmScale scale) const override;
BeatsPointer setBpm(mixxx::Bpm bpm) override;

private:
Expand Down
16 changes: 8 additions & 8 deletions src/track/beats.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class Beats {
/// Allows us to do ORing
typedef int CapabilitiesFlags;

enum BPMScale {
DOUBLE,
HALVE,
TWOTHIRDS,
THREEFOURTHS,
FOURTHIRDS,
THREEHALVES,
enum class BpmScale {
Double,
Halve,
TwoThirds,
ThreeFourths,
FourThirds,
ThreeHalves,
};

/// Retrieve the capabilities supported by the beats implementation.
Expand Down Expand Up @@ -159,7 +159,7 @@ class Beats {

/// Scale the position of every beat in the song by `scale`. The `Beats`
/// class must have the capability `BEATSCAP_SCALE`.
virtual BeatsPointer scale(enum BPMScale scale) const = 0;
virtual BeatsPointer scale(BpmScale scale) const = 0;

/// Adjust the beats so the global average BPM matches `bpm`. The `Beats`
/// class must have the capability `BEATSCAP_SET`.
Expand Down
21 changes: 10 additions & 11 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,22 @@ void WTrackMenu::createActions() {
m_pBpmThreeHalvesAction = new QAction(tr("3/2 BPM"), m_pBPMMenu);

connect(m_pBpmDoubleAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::DOUBLE);
slotScaleBpm(mixxx::Beats::BpmScale::Double);
});
connect(m_pBpmHalveAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::HALVE);
slotScaleBpm(mixxx::Beats::BpmScale::Halve);
});
connect(m_pBpmTwoThirdsAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::TWOTHIRDS);
slotScaleBpm(mixxx::Beats::BpmScale::TwoThirds);
});
connect(m_pBpmThreeFourthsAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::THREEFOURTHS);
slotScaleBpm(mixxx::Beats::BpmScale::ThreeFourths);
});
connect(m_pBpmFourThirdsAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::FOURTHIRDS);
slotScaleBpm(mixxx::Beats::BpmScale::FourThirds);
});
connect(m_pBpmThreeHalvesAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::THREEHALVES);
slotScaleBpm(mixxx::Beats::BpmScale::ThreeHalves);
});

m_pBpmResetAction = new QAction(tr("Reset BPM"), m_pBPMMenu);
Expand Down Expand Up @@ -1192,7 +1192,7 @@ namespace {

class ScaleBpmTrackPointerOperation : public mixxx::TrackPointerOperation {
public:
explicit ScaleBpmTrackPointerOperation(mixxx::Beats::BPMScale bpmScale)
explicit ScaleBpmTrackPointerOperation(mixxx::Beats::BpmScale bpmScale)
: m_bpmScale(bpmScale) {
}

Expand All @@ -1209,17 +1209,16 @@ class ScaleBpmTrackPointerOperation : public mixxx::TrackPointerOperation {
pTrack->trySetBeats(pBeats->scale(m_bpmScale));
}

const mixxx::Beats::BPMScale m_bpmScale;
const mixxx::Beats::BpmScale m_bpmScale;
};

} // anonymous namespace

void WTrackMenu::slotScaleBpm(int scale) {
void WTrackMenu::slotScaleBpm(mixxx::Beats::BpmScale scale) {
const auto progressLabelText =
tr("Scaling BPM of %n track(s)", "", getTrackCount());
const auto trackOperator =
ScaleBpmTrackPointerOperation(
static_cast<mixxx::Beats::BPMScale>(scale));
ScaleBpmTrackPointerOperation(scale);
applyTrackPointerOperation(
progressLabelText,
&trackOperator);
Expand Down
3 changes: 2 additions & 1 deletion src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "library/dao/playlistdao.h"
#include "library/trackprocessing.h"
#include "preferences/usersettings.h"
#include "track/beats.h"
#include "track/trackref.h"
#include "util/color/rgbcolor.h"
#include "util/parented_ptr.h"
Expand Down Expand Up @@ -102,7 +103,7 @@ class WTrackMenu : public QMenu {
// BPM
void slotLockBpm();
void slotUnlockBpm();
void slotScaleBpm(int);
void slotScaleBpm(mixxx::Beats::BpmScale scale);

// Info and metadata
void slotShowDlgTagFetcher();
Expand Down