Skip to content

Commit

Permalink
add beats_translate_move to trigger beats_translate_earlier/_later
Browse files Browse the repository at this point in the history
Co-authored-by: ronso0 <[email protected]>
  • Loading branch information
mxmilkiib and ronso0 committed Dec 7, 2023
1 parent 6acfe63 commit 081015d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/controllers/controlpickermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent)
addDeckAndSamplerControl("beats_adjust_slower", tr("Adjust Beatgrid Slower -.01"), tr("Decrease track's average BPM by 0.01"), bpmMenu);
addDeckAndSamplerControl("beats_translate_earlier", tr("Move Beatgrid Earlier"), tr("Adjust the beatgrid to the left"), bpmMenu);
addDeckAndSamplerControl("beats_translate_later", tr("Move Beatgrid Later"), tr("Adjust the beatgrid to the right"), bpmMenu);
addDeckAndSamplerControl("beats_translate_move",
tr("Move Beatgrid"),
tr("Adjust the beatgrid to the left or right"),
bpmMenu);
addDeckControl("beats_translate_curpos",
tr("Adjust Beatgrid"),
tr("Align beatgrid to current position"),
Expand Down
32 changes: 18 additions & 14 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "engine/controls/bpmcontrol.h"

#include "control/controlencoder.h"
#include "control/controllinpotmeter.h"
#include "control/controlobject.h"
#include "control/controlproxy.h"
Expand Down Expand Up @@ -87,6 +88,12 @@ BpmControl::BpmControl(const QString& group,
connect(m_pTranslateBeatsLater, &ControlObject::valueChanged,
this, &BpmControl::slotTranslateBeatsLater,
Qt::DirectConnection);
m_pTranslateBeatsMove = new ControlEncoder(ConfigKey(group, "beats_translate_move"), false);
connect(m_pTranslateBeatsMove,
&ControlObject::valueChanged,
this,
&BpmControl::slotTranslateBeatsMove,
Qt::DirectConnection);

// Pick a wide range (kBpmRangeMin to kBpmRangeMax) and allow out of bounds sets. This lets you
// map a soft-takeover MIDI knob to the BPM. This also creates bpm_up and
Expand Down Expand Up @@ -138,6 +145,7 @@ BpmControl::~BpmControl() {
delete m_pBeatsTranslateMatchAlignment;
delete m_pTranslateBeatsEarlier;
delete m_pTranslateBeatsLater;
delete m_pTranslateBeatsMove;
delete m_pAdjustBeatsFaster;
delete m_pAdjustBeatsSlower;
}
Expand Down Expand Up @@ -187,33 +195,29 @@ void BpmControl::slotTranslateBeatsEarlier(double v) {
if (v <= 0) {
return;
}
const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack();
if (!pTrack) {
return;
}
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats) {
const double sampleOffset = frameInfo().sampleRate * -0.01;
const mixxx::audio::FrameDiff_t frameOffset = sampleOffset / mixxx::kEngineChannelCount;
const auto translatedBeats = pBeats->tryTranslate(frameOffset);
if (translatedBeats) {
pTrack->trySetBeats(*translatedBeats);
}
}
slotTranslateBeatsMove(-1);
}

void BpmControl::slotTranslateBeatsLater(double v) {
if (v <= 0) {
return;
}
slotTranslateBeatsMove(1);
}

void BpmControl::slotTranslateBeatsMove(double v) {
v = std::round(v);
if (v == 0) {
return;
}
const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack();
if (!pTrack) {
return;
}
const mixxx::BeatsPointer pBeats = pTrack->getBeats();
if (pBeats) {
// TODO(rryan): Track::frameInfo is possibly inaccurate!
const double sampleOffset = frameInfo().sampleRate * 0.01;
const double sampleOffset = frameInfo().sampleRate * v * 0.01;
const mixxx::audio::FrameDiff_t frameOffset = sampleOffset / mixxx::kEngineChannelCount;
const auto translatedBeats = pBeats->tryTranslate(frameOffset);
if (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 @@ -9,6 +9,7 @@
#include "track/beats.h"
#include "util/tapfilter.h"

class ControlEncoder;
class ControlLinPotmeter;
class ControlPushButton;

Expand Down Expand Up @@ -100,6 +101,7 @@ class BpmControl : public EngineControl {
void slotAdjustBeatsSlower(double);
void slotTranslateBeatsEarlier(double);
void slotTranslateBeatsLater(double);
void slotTranslateBeatsMove(double);
void slotTapFilter(double,int);
void slotBpmTap(double);
void slotUpdateRateSlider(double v = 0.0);
Expand Down Expand Up @@ -141,6 +143,7 @@ class BpmControl : public EngineControl {
ControlPushButton* m_pAdjustBeatsSlower;
ControlPushButton* m_pTranslateBeatsEarlier;
ControlPushButton* m_pTranslateBeatsLater;
ControlEncoder* m_pTranslateBeatsMove;

// The current effective BPM of the engine
ControlLinPotmeter* m_pEngineBpm;
Expand Down

0 comments on commit 081015d

Please sign in to comment.