diff --git a/src/engine/controls/bpmcontrol.cpp b/src/engine/controls/bpmcontrol.cpp index f116f1be92c..a4d37e0ac65 100644 --- a/src/engine/controls/bpmcontrol.cpp +++ b/src/engine/controls/bpmcontrol.cpp @@ -130,10 +130,10 @@ BpmControl::BpmControl(const QString& group, this, &BpmControl::slotTapFilter, Qt::DirectConnection); - m_pToggleBpmLock = std::make_unique( - ConfigKey(group, "bpm_toggle_lock"), false); - connect(m_pToggleBpmLock.get(), - &ControlObject::valueChanged, + m_pBpmLock = std::make_unique( + ConfigKey(group, "bpmlock"), false); + m_pBpmLock->setButtonMode(ControlPushButton::TOGGLE); + m_pBpmLock->connectValueChangeRequest( this, &BpmControl::slotToggleBpmLock, Qt::DirectConnection); @@ -983,6 +983,10 @@ void BpmControl::trackBeatsUpdated(mixxx::BeatsPointer pBeats) { resetSyncAdjustment(); } +void BpmControl::trackBpmLockChanged(bool locked) { + m_pBpmLock->setAndConfirm(locked); +} + void BpmControl::notifySeek(mixxx::audio::FramePos position) { updateBeatDistance(position); } @@ -1030,15 +1034,14 @@ void BpmControl::slotBeatsTranslateMatchAlignment(double v) { } void BpmControl::slotToggleBpmLock(double v) { - if (v <= 0) { - return; - } + Q_UNUSED(v); const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack(); if (!pTrack) { return; } bool locked = pTrack->isBpmLocked(); pTrack->setBpmLocked(!locked); + // The pushbutton is updated in trackBpmLockChanged() via bpmLockChanged() signal. } mixxx::Bpm BpmControl::updateLocalBpm() { diff --git a/src/engine/controls/bpmcontrol.h b/src/engine/controls/bpmcontrol.h index af174cf9d27..9344e7475cd 100644 --- a/src/engine/controls/bpmcontrol.h +++ b/src/engine/controls/bpmcontrol.h @@ -94,6 +94,7 @@ class BpmControl : public EngineControl { double getRateRatio() const; void trackLoaded(TrackPointer pNewTrack) override; void trackBeatsUpdated(mixxx::BeatsPointer pBeats) override; + void trackBpmLockChanged(bool locked); void notifySeek(mixxx::audio::FramePos position) override; private slots: @@ -146,7 +147,7 @@ class BpmControl : public EngineControl { ControlPushButton* m_pTranslateBeatsLater; ControlEncoder* m_pTranslateBeatsMove; - std::unique_ptr m_pToggleBpmLock; + std::unique_ptr m_pBpmLock; // The current effective BPM of the engine ControlLinPotmeter* m_pEngineBpm; diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index f4ab6cfe7cd..3f767a20c15 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -651,12 +651,18 @@ void EngineBuffer::notifyTrackLoaded( } if (pNewTrack) { - connect( - pNewTrack.get(), + connect(pNewTrack.get(), &Track::beatsUpdated, this, &EngineBuffer::slotUpdatedTrackBeats, Qt::DirectConnection); + connect(pNewTrack.get(), + &Track::bpmLockChanged, + m_pBpmControl, + &BpmControl::trackBpmLockChanged, + Qt::DirectConnection); + bool bpmLocked = pNewTrack.get()->isBpmLocked(); + m_pBpmControl->trackBpmLockChanged(bpmLocked); } // Inform BaseTrackPlayer via a queued connection diff --git a/src/track/track.cpp b/src/track/track.cpp index 659f37ce717..bb8cf0e4ee9 100644 --- a/src/track/track.cpp +++ b/src/track/track.cpp @@ -1426,6 +1426,7 @@ void Track::setBpmLocked(bool bpmLocked) { auto locked = lockMutex(&m_qMutex); if (compareAndSet(m_record.ptrBpmLocked(), bpmLocked)) { markDirtyAndUnlock(&locked); + emit bpmLockChanged(bpmLocked); } } diff --git a/src/track/track.h b/src/track/track.h index 17ecb259242..e89c7e506a7 100644 --- a/src/track/track.h +++ b/src/track/track.h @@ -425,6 +425,7 @@ class Track : public QObject { void trackTotalChanged(const QString&); void commentChanged(const QString&); void bpmChanged(); + void bpmLockChanged(bool locked); void keyChanged(); void timesPlayedChanged(); void durationChanged();