From ce078f5fdf21420e01b34a1ac3c9edd1c51e281e Mon Sep 17 00:00:00 2001 From: Lukas Waslowski Date: Fri, 1 Nov 2024 15:02:45 +0000 Subject: [PATCH] Refactor: Add EngineBuffer::setPlaybackSpeedFromBpm --- src/engine/controls/bpm/bpmtapcontrol.cpp | 6 +----- src/engine/controls/bpmcontrol.cpp | 8 ++++++++ src/engine/controls/bpmcontrol.h | 3 +++ src/engine/enginebuffer.cpp | 4 ++++ src/engine/enginebuffer.h | 2 ++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/engine/controls/bpm/bpmtapcontrol.cpp b/src/engine/controls/bpm/bpmtapcontrol.cpp index c9d239e9b6f..45c2679352a 100644 --- a/src/engine/controls/bpm/bpmtapcontrol.cpp +++ b/src/engine/controls/bpm/bpmtapcontrol.cpp @@ -128,9 +128,5 @@ void BpmTapControl::slotTempoTapFilter(double averageLength, int numSamples) { } auto averageBpm = averageBpmRoundedWithinRange(averageLength, 1.0); - m_pEngineBpm->set(averageBpm.value()); - // NOTE(ronso0) When setting the control, m_pEngineBpm->valueChanged() - // is not emitted (with Qt6) (it is when setting via a ControlProxy), - // so call the slot directly. - slotUpdateRateSlider(0.0 /* value is actually ignored */); + getEngineBuffer()->setPlaybackSpeedFromBpm(averageBpm); } diff --git a/src/engine/controls/bpmcontrol.cpp b/src/engine/controls/bpmcontrol.cpp index 01212fa8a40..54285c7dec0 100644 --- a/src/engine/controls/bpmcontrol.cpp +++ b/src/engine/controls/bpmcontrol.cpp @@ -217,6 +217,14 @@ mixxx::Bpm BpmControl::getBpm() const { return mixxx::Bpm(m_pEngineBpm->get()); } +void BpmControl::setPlaybackSpeedFromBpm(mixxx::Bpm desiredBpm) { + m_pEngineBpm->set(desiredBpm.value()); + // NOTE(ronso0) When setting the control, m_pEngineBpm->valueChanged() + // is not emitted (with Qt6) (it is when setting via a ControlProxy), + // so call the slot directly. + slotUpdateRateSlider(desiredBpm.value()); +} + void BpmControl::adjustBeatsBpm(double deltaBpm) { const TrackPointer pTrack = getEngineBuffer()->getLoadedTrack(); if (!pTrack) { diff --git a/src/engine/controls/bpmcontrol.h b/src/engine/controls/bpmcontrol.h index e157eec8378..fd56c55a015 100644 --- a/src/engine/controls/bpmcontrol.h +++ b/src/engine/controls/bpmcontrol.h @@ -27,6 +27,9 @@ class BpmControl : public EngineControl { return m_pLocalBpm ? mixxx::Bpm(m_pLocalBpm->get()) : mixxx::Bpm(); } + /// Sets the playback rate based on the desired BPM (not thread-safe) + void setPlaybackSpeedFromBpm(double desiredBpm); + // When in sync lock mode, ratecontrol calls calcSyncedRate to figure out // how fast the track should play back. The returned rate is usually just // the correct pitch to match bpms. The usertweak argument represents diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index d0c4f86aa9f..6b5e634cfc9 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -378,6 +378,10 @@ mixxx::Bpm EngineBuffer::getLocalBpm() const { return m_pBpmControl->getLocalBpm(); } +void EngineBuffer::setPlaybackSpeedFromBpm(mixxx::Bpm desiredBpm) { + m_pBpmControl->setPlaybackSpeedFromBpm(desiredBpm); +} + void EngineBuffer::setBeatLoop(mixxx::audio::FramePos startPosition, bool enabled) { m_pLoopingControl->setBeatLoop(startPosition, enabled); } diff --git a/src/engine/enginebuffer.h b/src/engine/enginebuffer.h index 2bfbdbf7c08..fecf1131b99 100644 --- a/src/engine/enginebuffer.h +++ b/src/engine/enginebuffer.h @@ -121,6 +121,8 @@ class EngineBuffer : public EngineObject { mixxx::Bpm getBpm() const; /// Returns the BPM of the loaded track around the current position (not thread-safe) mixxx::Bpm getLocalBpm() const; + /// Sets the playback rate based on the desired BPM (not thread-safe) + void setPlaybackSpeedFromBpm(mixxx::Bpm desiredBpm); /// Sets a beatloop for the loaded track (not thread safe) void setBeatLoop(mixxx::audio::FramePos startPosition, bool enabled); /// Sets a loop for the loaded track (not thread safe)