Skip to content

Commit

Permalink
Refactor: Add EngineBuffer::setPlaybackSpeedFromBpm
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed Nov 1, 2024
1 parent 5999aa5 commit ce078f5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/engine/controls/bpm/bpmtapcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 8 additions & 0 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/engine/controls/bpmcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/engine/enginebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ce078f5

Please sign in to comment.