Skip to content

Commit

Permalink
Merge pull request #12376 from mxmilkiib/beats_translate_move
Browse files Browse the repository at this point in the history
add beats_translate_move ControlEncoder
  • Loading branch information
JoergAtGithub authored Dec 7, 2023
2 parents dabca58 + 63602be commit 42762b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 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
34 changes: 18 additions & 16 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "engine/controls/bpmcontrol.h"

#include "control/controlencoder.h"
#include "control/controllinpotmeter.h"
#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "control/controlpushbutton.h"
#include "engine/effects/groupfeaturestate.h"
Expand Down Expand Up @@ -87,6 +87,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 @@ -127,7 +133,6 @@ BpmControl::BpmControl(const QString& group,
// Measures distance from last beat in percentage: 0.5 = half-beat away.
m_pThisBeatDistance = new ControlProxy(group, "beat_distance", this);
m_pSyncMode = new ControlProxy(group, "sync_mode", this);
m_pSyncEnabled = new ControlProxy(group, "sync_enabled", this);
}

BpmControl::~BpmControl() {
Expand All @@ -138,6 +143,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 +193,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
4 changes: 3 additions & 1 deletion 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 All @@ -162,7 +165,6 @@ class BpmControl : public EngineControl {
ControlValueAtomic<double> m_dUserOffset;
QAtomicInt m_resetSyncAdjustment;
ControlProxy* m_pSyncMode;
ControlProxy* m_pSyncEnabled;

TapFilter m_tapFilter; // threadsafe

Expand Down

0 comments on commit 42762b3

Please sign in to comment.