From faf5ed8b706272f97a6dbf64f3efbc500255f3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20P?= Date: Tue, 2 Apr 2024 17:52:07 +0200 Subject: [PATCH] Adding tempo locking/unlocking controls std:make_unique instead of new fix crash when channel/trackpointer is empty renaming the variables changing "tempo" for "bpm" "Toggle lock" instead of "lock"/"unlock" forgot to save the file lol Update src/engine/controls/bpmcontrol.cpp Co-authored-by: ronso0 fixing the description unnecessary comment more explicit command --- src/controllers/controlpickermenu.cpp | 4 ++++ src/engine/controls/bpmcontrol.cpp | 21 +++++++++++++++++++++ src/engine/controls/bpmcontrol.h | 3 +++ 3 files changed, 28 insertions(+) diff --git a/src/controllers/controlpickermenu.cpp b/src/controllers/controlpickermenu.cpp index c3a1c9b0666..42fbc0b8096 100644 --- a/src/controllers/controlpickermenu.cpp +++ b/src/controllers/controlpickermenu.cpp @@ -272,6 +272,10 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent) tr("Adjust Beatgrid - Match Alignment"), tr("Adjust beatgrid to match another playing deck."), pBpmMenu); + addDeckAndSamplerControl("bpm_toggle_lock", + tr("Toggle the BPM/beatgrid lock"), + tr("Toggle the BPM/beatgrid lock"), + pBpmMenu); pBpmMenu->addSeparator(); addDeckAndSamplerControl("quantize", tr("Quantize Mode"), tr("Toggle quantize mode"), pBpmMenu); diff --git a/src/engine/controls/bpmcontrol.cpp b/src/engine/controls/bpmcontrol.cpp index be5016938ee..52bef4ca3ba 100644 --- a/src/engine/controls/bpmcontrol.cpp +++ b/src/engine/controls/bpmcontrol.cpp @@ -130,6 +130,15 @@ BpmControl::BpmControl(const QString& group, this, &BpmControl::slotTapFilter, Qt::DirectConnection); + m_pToggleBpmLock = std::make_unique( + ConfigKey(group, "bpm_toggle_lock"), false); + m_pToggleBpmLock->setKbdRepeatable(true); + connect(m_pToggleBpmLock.get(), + &ControlObject::valueChanged, + this, + &BpmControl::slotToggleBpmLock, + Qt::DirectConnection); + // 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); @@ -1021,6 +1030,18 @@ void BpmControl::slotBeatsTranslateMatchAlignment(double v) { } } +void BpmControl::slotToggleBpmLock(double v) { + if (v <= 0) { + return; + } + const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack(); + if (!pTrack) { + return; + } + bool locked = pTrack->isBpmLocked(); + pTrack->setBpmLocked(!locked); +} + mixxx::Bpm BpmControl::updateLocalBpm() { mixxx::Bpm prevLocalBpm = mixxx::Bpm(m_pLocalBpm->get()); mixxx::Bpm localBpm; diff --git a/src/engine/controls/bpmcontrol.h b/src/engine/controls/bpmcontrol.h index e08a3164088..af174cf9d27 100644 --- a/src/engine/controls/bpmcontrol.h +++ b/src/engine/controls/bpmcontrol.h @@ -108,6 +108,7 @@ class BpmControl : public EngineControl { void slotUpdateEngineBpm(double v = 0.0); void slotBeatsTranslate(double); void slotBeatsTranslateMatchAlignment(double); + void slotToggleBpmLock(double); private: SyncMode getSyncMode() const { @@ -145,6 +146,8 @@ class BpmControl : public EngineControl { ControlPushButton* m_pTranslateBeatsLater; ControlEncoder* m_pTranslateBeatsMove; + std::unique_ptr m_pToggleBpmLock; + // The current effective BPM of the engine ControlLinPotmeter* m_pEngineBpm;