Skip to content

Commit

Permalink
Track/BPM: add bpmlock control ...
Browse files Browse the repository at this point in the history
replaces recently introduced `bpm_toggle_lock`, allows to bind GUI controls for toggle and feedback
  • Loading branch information
ronso0 committed May 3, 2024
1 parent 92b9aad commit 5e39867
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ BpmControl::BpmControl(const QString& group,
this, &BpmControl::slotTapFilter,
Qt::DirectConnection);

m_pToggleBpmLock = std::make_unique<ControlPushButton>(
ConfigKey(group, "bpm_toggle_lock"), false);
connect(m_pToggleBpmLock.get(),
&ControlObject::valueChanged,
m_pBpmLock = std::make_unique<ControlPushButton>(
ConfigKey(group, "bpmlock"), false);
m_pBpmLock->setButtonMode(ControlPushButton::TOGGLE);
m_pBpmLock->connectValueChangeRequest(
this,
&BpmControl::slotToggleBpmLock,
Qt::DirectConnection);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/engine/controls/bpmcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -146,7 +147,7 @@ class BpmControl : public EngineControl {
ControlPushButton* m_pTranslateBeatsLater;
ControlEncoder* m_pTranslateBeatsMove;

std::unique_ptr<ControlPushButton> m_pToggleBpmLock;
std::unique_ptr<ControlPushButton> m_pBpmLock;

// The current effective BPM of the engine
ControlLinPotmeter* m_pEngineBpm;
Expand Down
10 changes: 8 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/track/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5e39867

Please sign in to comment.