Skip to content

Commit

Permalink
Clang tidy and cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine C <[email protected]>
  • Loading branch information
acolombier committed Jun 6, 2024
1 parent 325e25e commit b1967d9
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 155 deletions.
84 changes: 39 additions & 45 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ constexpr double kBpmRangeMax = 200.0;
constexpr double kBpmRangeStep = 1.0;
constexpr double kBpmRangeSmallStep = 0.1;

constexpr double kBpmAdjustMin = kBpmRangeMin;
constexpr double kBpmAdjustStep = 0.01;
constexpr double kBpmAdjustLargeStep = 1.00;
constexpr double kBpmAdjustRepeatIntervalMs = 50;
constexpr double kBpmAdjustTimeBeforeRepeatMs = 500;
constexpr int kBpmAdjustRepeatIntervalMs = 50;
constexpr int kBpmAdjustTimeBeforeRepeatMs = 500;
constexpr double kBpmTapRounding = 1 / 12.0;

// Maximum allowed interval between beats (calculated from kBpmTapMin).
Expand Down Expand Up @@ -299,21 +296,32 @@ mixxx::Bpm BpmControl::getBpm() const {
return mixxx::Bpm(m_pEngineBpm->get());
}

void BpmControl::slotAdjustBeatsFaster(double v) {
if (v <= 0) {
m_repeatOperation.stop();
void BpmControl::clearActionRepeater() {
m_repeatOperation.stop();
m_repeatOperation.disconnect();
return;
}

void BpmControl::activateActionRepeater(const std::function<void()>& callback) {
VERIFY_OR_DEBUG_ASSERT(callback) {
clearActionRepeater();
return;
}

if (m_repeatOperation.isActive()) {
m_repeatOperation.setInterval(kBpmAdjustRepeatIntervalMs);
} else {
m_repeatOperation.disconnect();
connect(&m_repeatOperation, &QTimer::timeout, this, [this, v]() {
slotAdjustBeatsFaster(v);
});
connect(&m_repeatOperation, &QTimer::timeout, this, callback);
m_repeatOperation.start(kBpmAdjustTimeBeforeRepeatMs);
}
}

void BpmControl::slotAdjustBeatsFaster(double v) {
if (v <= 0) {
clearActionRepeater();
return;
}

const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack();
if (!pTrack) {
Expand All @@ -324,6 +332,10 @@ void BpmControl::slotAdjustBeatsFaster(double v) {
return;
}

activateActionRepeater([this, v]() {
slotAdjustBeatsFaster(v);
});

const auto adjustedBeats =
pBeats->tryAdjustTempo(frameInfo().currentPosition,
v > 1 ? mixxx::Beats::TempoAdjustment::MuchFaster
Expand All @@ -335,20 +347,10 @@ void BpmControl::slotAdjustBeatsFaster(double v) {

void BpmControl::slotAdjustBeatsSlower(double v) {
if (v <= 0) {
m_repeatOperation.stop();
clearActionRepeater();
return;
}

if (m_repeatOperation.isActive()) {
m_repeatOperation.setInterval(kBpmAdjustRepeatIntervalMs);
} else {
m_repeatOperation.disconnect();
connect(&m_repeatOperation, &QTimer::timeout, this, [this, v]() {
slotAdjustBeatsSlower(v);
});
m_repeatOperation.start(kBpmAdjustTimeBeforeRepeatMs);
}

const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack();
if (!pTrack) {
return;
Expand All @@ -358,6 +360,10 @@ void BpmControl::slotAdjustBeatsSlower(double v) {
return;
}

activateActionRepeater([this, v]() {
slotAdjustBeatsSlower(v);
});

const auto adjustedBeats =
pBeats->tryAdjustTempo(frameInfo().currentPosition,
v > 1 ? mixxx::Beats::TempoAdjustment::MuchSlower
Expand All @@ -369,37 +375,25 @@ void BpmControl::slotAdjustBeatsSlower(double v) {

void BpmControl::slotTranslateBeatsEarlier(double v) {
if (v <= 0) {
m_repeatOperation.stop();
clearActionRepeater();
return;
}

if (m_repeatOperation.isActive()) {
m_repeatOperation.setInterval(kBpmAdjustRepeatIntervalMs);
} else {
m_repeatOperation.disconnect();
connect(&m_repeatOperation, &QTimer::timeout, this, [this]() {
slotTranslateBeatsEarlier(1);
});
m_repeatOperation.start(kBpmAdjustTimeBeforeRepeatMs);
}
activateActionRepeater([this]() {
slotTranslateBeatsEarlier(1);
});
slotTranslateBeatsMove(-1);
}

void BpmControl::slotTranslateBeatsLater(double v) {
if (v <= 0) {
m_repeatOperation.stop();
clearActionRepeater();
return;
}

if (m_repeatOperation.isActive()) {
m_repeatOperation.setInterval(kBpmAdjustRepeatIntervalMs);
} else {
m_repeatOperation.disconnect();
connect(&m_repeatOperation, &QTimer::timeout, this, [this]() {
slotTranslateBeatsLater(1);
});
m_repeatOperation.start(kBpmAdjustTimeBeforeRepeatMs);
}
activateActionRepeater([this]() {
slotTranslateBeatsLater(1);
});
slotTranslateBeatsMove(1);
}

Expand All @@ -417,7 +411,7 @@ void BpmControl::slotTranslateBeatsMove(double v) {
// TODO(rryan): Track::frameInfo is possibly inaccurate!
const double sampleOffset = frameInfo().sampleRate * v * 0.01;
const mixxx::audio::FrameDiff_t frameOffset = sampleOffset / mixxx::kEngineChannelCount;
const auto translatedBeats = pBeats->tryTranslate(frameInfo().currentPosition, frameOffset);
const auto translatedBeats = pBeats->tryTranslate(frameOffset, frameInfo().currentPosition);
if (translatedBeats) {
pTrack->trySetBeats(*translatedBeats);
}
Expand Down Expand Up @@ -1284,7 +1278,7 @@ void BpmControl::slotBeatsTranslate(double v) {
const auto currentPosition = frameInfo().currentPosition.toLowerFrameBoundary();
const auto closestBeat = pBeats->findClosestBeat(currentPosition);
const mixxx::audio::FrameDiff_t frameOffset = currentPosition - closestBeat;
const auto translatedBeats = pBeats->tryTranslate(currentPosition, frameOffset);
const auto translatedBeats = pBeats->tryTranslate(frameOffset, currentPosition);
if (translatedBeats) {
pTrack->trySetBeats(*translatedBeats);
}
Expand All @@ -1306,7 +1300,7 @@ void BpmControl::slotBeatsTranslateMatchAlignment(double v) {
m_dUserOffset.setValue(0.0);

const mixxx::audio::FrameDiff_t frameOffset = -getPhaseOffset(frameInfo().currentPosition);
const auto translatedBeats = pBeats->tryTranslate(mixxx::audio::FramePos(), frameOffset);
const auto translatedBeats = pBeats->tryTranslate(frameOffset);
if (translatedBeats) {
pTrack->trySetBeats(*translatedBeats);
}
Expand Down
3 changes: 3 additions & 0 deletions src/engine/controls/bpmcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class BpmControl : public EngineControl {
void adjustBeatsBpm(double deltaBpm);
void slotScaleBpm(mixxx::Beats::BpmScale bpmScale);

void clearActionRepeater();
void activateActionRepeater(const std::function<void()>& = nullptr);

friend class SyncControl;

// ControlObjects that come from EngineBuffer
Expand Down
10 changes: 10 additions & 0 deletions src/skin/legacy/tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,21 @@ void Tooltips::addStandardTooltips() {
<< tr("When tapped, decrease the BPM of the region around the "
"current play position by a small amount.");

add("beats_adjust_much_slower")
<< tr("Adjust BPM Down")
<< tr("When tapped, decrease the BPM of the region around the "
"current play position by a large amount.");

add("beats_adjust_faster")
<< tr("Adjust BPM Up")
<< tr("When tapped, increases the BPM of the region around the "
"current play position by a small amount.");

add("beats_adjust_much_faster")
<< tr("Adjust BPM Up")
<< tr("When tapped, increases the BPM of the region around the "
"current play position by a large amount.");

add("beats_translate_earlier")
<< tr("Adjust Beats Earlier")
<< tr("When tapped, moves the beatgrid left by a small amount.");
Expand Down
Loading

0 comments on commit b1967d9

Please sign in to comment.