From 7d95e3d3b85055944da0d196ede421c103db4296 Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Wed, 5 Aug 2020 16:53:08 +0200 Subject: [PATCH 1/2] EngineBuffer: Clean up signatures & order methods --- src/engine/enginebuffer.cpp | 80 ++++++++++++++++++++----------------- src/engine/enginebuffer.h | 20 +++++----- 2 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index cc08b50d618..ed88d87beb5 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -304,13 +304,8 @@ EngineBuffer::~EngineBuffer() { qDeleteAll(m_engineControls); } -double EngineBuffer::fractionalPlayposFromAbsolute(double absolutePlaypos) { - double fFractionalPlaypos = 0.0; - if (m_trackSamplesOld) { - fFractionalPlaypos = math_min(absolutePlaypos, m_trackSamplesOld); - fFractionalPlaypos /= m_trackSamplesOld; - } - return fFractionalPlaypos; +void EngineBuffer::bindWorkers(EngineWorkerScheduler* pWorkerScheduler) { + m_pReader->setScheduler(pWorkerScheduler); } void EngineBuffer::enableIndependentPitchTempoScaling(bool bEnable, @@ -348,12 +343,11 @@ void EngineBuffer::enableIndependentPitchTempoScaling(bool bEnable, } } -double EngineBuffer::getBpm() -{ +double EngineBuffer::getBpm() const { return m_pBpmControl->getBpm(); } -double EngineBuffer::getLocalBpm() { +double EngineBuffer::getLocalBpm() const { return m_pBpmControl->getLocalBpm(); } @@ -467,18 +461,26 @@ void EngineBuffer::setNewPlaypos(double newpos) { verifyPlay(); // verify or update play button and indicator } -QString EngineBuffer::getGroup() { +QString EngineBuffer::getGroup() const { return m_group; } -double EngineBuffer::getSpeed() { +double EngineBuffer::getSpeed() const { return m_speed_old; } -bool EngineBuffer::getScratching() { +bool EngineBuffer::getScratching() const { return m_scratching_old; } +bool EngineBuffer::isReverse() const { + return m_reverse_old; +} + +TrackPointer EngineBuffer::getLoadedTrack() const { + return m_pCurrentTrack; +} + // WARNING: Always called from the EngineWorker thread pool void EngineBuffer::slotTrackLoading() { // Pause EngineBuffer from processing frames @@ -509,19 +511,22 @@ void EngineBuffer::slotTrackLoaded(TrackPointer pTrack, kLogger.trace() << getGroup() << "EngineBuffer::slotTrackLoaded"; } TrackPointer pOldTrack = m_pCurrentTrack; - m_pause.lock(); + m_visualPlayPos->setInvalid(); m_filepos_play = DBL_MIN; // for execute seeks to 0.0 + m_pCurrentTrack = pTrack; m_pTrackSamples->set(iTrackNumSamples); m_pTrackSampleRate->set(iTrackSampleRate); + m_pTrackLoaded->forceSet(1); + // Reset slip mode m_pSlipButton->set(0); m_bSlipEnabledProcessing = false; m_dSlipPosition = 0.; m_dSlipRate = 0; - m_pTrackLoaded->forceSet(1); + // Reset the pitch value for the new track. m_pause.unlock(); @@ -541,39 +546,35 @@ void EngineBuffer::slotTrackLoadFailed(TrackPointer pTrack, emit trackLoadFailed(pTrack, reason); } -TrackPointer EngineBuffer::getLoadedTrack() const { - return m_pCurrentTrack; -} - -bool EngineBuffer::isReverse() { - return m_reverse_old; -} - void EngineBuffer::ejectTrack() { - // clear track values in any case, this may fix Bug #1450424 + // clear track values in any case, may fix https://bugs.launchpad.net/mixxx/+bug/1450424 if (kLogger.traceEnabled()) { kLogger.trace() << "EngineBuffer::ejectTrack()"; } + TrackPointer pOldTrack = m_pCurrentTrack; m_pause.lock(); - m_iTrackLoading = 0; - m_pTrackLoaded->forceSet(0); - m_pTrackSamples->set(0); - m_pTrackSampleRate->set(0); + m_visualPlayPos->set(0.0, 0.0, 0.0, 0.0, 0.0); - TrackPointer pTrack = m_pCurrentTrack; + doSeekPlayPos(0.0, SEEK_EXACT); + m_pCurrentTrack.reset(); + m_pTrackSamples->set(0); + m_pTrackSampleRate->set(0); + m_pTrackLoaded->forceSet(0); + m_playButton->set(0.0); m_playposSlider->set(0); m_pCueControl->resetIndicators(); - doSeekPlayPos(0.0, SEEK_EXACT); + m_pause.unlock(); // Close open file handles by unloading the current track m_pReader->newTrack(TrackPointer()); - if (pTrack) { - notifyTrackLoaded(TrackPointer(), pTrack); + if (pOldTrack) { + notifyTrackLoaded(TrackPointer(), pOldTrack); } + m_iTrackLoading = 0; } void EngineBuffer::slotPassthroughChanged(double enabled) { @@ -598,6 +599,15 @@ void EngineBuffer::slotControlSeekExact(double playPosition) { doSeekPlayPos(playPosition, SEEK_EXACT); } +double EngineBuffer::fractionalPlayposFromAbsolute(double absolutePlaypos) { + double fFractionalPlaypos = 0.0; + if (m_trackSamplesOld) { + fFractionalPlaypos = math_min(absolutePlaypos, m_trackSamplesOld); + fFractionalPlaypos /= m_trackSamplesOld; + } + return fFractionalPlaypos; +} + void EngineBuffer::doSeekFractional(double fractionalPos, enum SeekRequest seekType) { // Prevent NaN's from sneaking into the engine. if (isnan(fractionalPos)) { @@ -1327,11 +1337,7 @@ void EngineBuffer::addControl(EngineControl* pControl) { pControl->setEngineBuffer(this); } -void EngineBuffer::bindWorkers(EngineWorkerScheduler* pWorkerScheduler) { - m_pReader->setScheduler(pWorkerScheduler); -} - -bool EngineBuffer::isTrackLoaded() { +bool EngineBuffer::isTrackLoaded() const { if (m_pCurrentTrack) { return true; } diff --git a/src/engine/enginebuffer.h b/src/engine/enginebuffer.h index b61ba894d8c..51d19f13bec 100644 --- a/src/engine/enginebuffer.h +++ b/src/engine/enginebuffer.h @@ -116,13 +116,15 @@ class EngineBuffer : public EngineObject { void bindWorkers(EngineWorkerScheduler* pWorkerScheduler); + QString getGroup() const; // Return the current rate (not thread-safe) - double getSpeed(); - bool getScratching(); + double getSpeed() const; + bool getScratching() const; + bool isReverse() const; // Returns current bpm value (not thread-safe) - double getBpm(); + double getBpm() const; // Returns the BPM of the loaded track around the current position (not thread-safe) - double getLocalBpm(); + double getLocalBpm() const; // Sets pointer to other engine buffer/channel void setEngineMaster(EngineMaster*); @@ -138,14 +140,12 @@ class EngineBuffer : public EngineObject { void processSlip(int iBufferSize); void postProcess(const int iBufferSize); - QString getGroup(); - bool isTrackLoaded(); - // return true if a seek is currently cueued but not yet processed, false otherwise - // if no seek was queued, the seek position is set to -1 - bool getQueuedSeekPosition(double* pSeekPosition); + bool isTrackLoaded() const; TrackPointer getLoadedTrack() const; - bool isReverse(); + /// Return true iff a seek is currently queued but not yet processed + /// If no seek was queued, the seek position is set to -1 + bool getQueuedSeekPosition(double* pSeekPosition); double getExactPlayPos(); double getVisualPlayPos(); From b2ccf6e1c084667050ecb1dd496a41625478fe39 Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Wed, 5 Aug 2020 17:02:33 +0200 Subject: [PATCH 2/2] EngineBuffer: Order methods & add const --- src/engine/enginebuffer.cpp | 121 ++++++++++++++++++------------------ src/engine/enginebuffer.h | 22 +++---- 2 files changed, 71 insertions(+), 72 deletions(-) diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index ed88d87beb5..968ed0f7099 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -477,10 +477,6 @@ bool EngineBuffer::isReverse() const { return m_reverse_old; } -TrackPointer EngineBuffer::getLoadedTrack() const { - return m_pCurrentTrack; -} - // WARNING: Always called from the EngineWorker thread pool void EngineBuffer::slotTrackLoading() { // Pause EngineBuffer from processing frames @@ -577,6 +573,35 @@ void EngineBuffer::ejectTrack() { m_iTrackLoading = 0; } +void EngineBuffer::notifyTrackLoaded( + TrackPointer pNewTrack, TrackPointer pOldTrack) { + if (pOldTrack) { + disconnect( + pOldTrack.get(), + &Track::beatsUpdated, + this, + &EngineBuffer::slotUpdatedTrackBeats); + } + + // First inform engineControls directly + // Note: we are still in a worker thread. + for (const auto& pControl : qAsConst(m_engineControls)) { + pControl->trackLoaded(pNewTrack); + } + + if (pNewTrack) { + connect( + pNewTrack.get(), + &Track::beatsUpdated, + this, + &EngineBuffer::slotUpdatedTrackBeats, + Qt::DirectConnection); + } + + // Inform BaseTrackPlayer via a queued connection + emit trackLoaded(pNewTrack, pOldTrack); +} + void EngineBuffer::slotPassthroughChanged(double enabled) { if (enabled) { // If passthrough was enabled, stop playing the current track. @@ -1153,7 +1178,7 @@ void EngineBuffer::processSyncRequests() { void EngineBuffer::processSeek(bool paused) { // Check if we are cloning another channel before doing any seeking. - EngineChannel* pChannel = m_pChannelToCloneFrom.fetchAndStoreRelaxed(NULL); + EngineChannel* pChannel = m_pChannelToCloneFrom.fetchAndStoreRelaxed(nullptr); if (pChannel) { seekCloneBuffer(pChannel->getEngineBuffer()); } @@ -1248,6 +1273,16 @@ void EngineBuffer::postProcess(const int iBufferSize) { updateIndicators(m_speed_old, iBufferSize); } +bool EngineBuffer::getQueuedSeekPosition(double* pSeekPosition) const { + bool isSeekQueued = m_iSeekQueued.loadAcquire() != SEEK_NONE; + if (isSeekQueued) { + *pSeekPosition = m_queuedSeekPosition.getValue(); + } else { + *pSeekPosition = -1; + } + return isSeekQueued; +} + void EngineBuffer::updateIndicators(double speed, int iBufferSize) { if (!m_trackSampleRateOld) { // This happens if Deck Passthrough is active but no track is loaded. @@ -1344,14 +1379,8 @@ bool EngineBuffer::isTrackLoaded() const { return false; } -bool EngineBuffer::getQueuedSeekPosition(double* pSeekPosition) { - bool isSeekQueued = m_iSeekQueued.loadAcquire() != SEEK_NONE; - if (isSeekQueued) { - *pSeekPosition = m_queuedSeekPosition.getValue(); - } else { - *pSeekPosition = -1; - } - return isSeekQueued; +TrackPointer EngineBuffer::getLoadedTrack() const { + return m_pCurrentTrack; } void EngineBuffer::slotEjectTrack(double v) { @@ -1365,7 +1394,7 @@ void EngineBuffer::slotEjectTrack(double v) { } } -double EngineBuffer::getExactPlayPos() { +double EngineBuffer::getExactPlayPos() const { double visualPlayPos = getVisualPlayPos(); if (visualPlayPos > 0) { return getVisualPlayPos() * getTrackSamples(); @@ -1376,65 +1405,25 @@ double EngineBuffer::getExactPlayPos() { } } -double EngineBuffer::getVisualPlayPos() { +double EngineBuffer::getVisualPlayPos() const { return m_visualPlayPos->getEnginePlayPos(); } -double EngineBuffer::getTrackSamples() { +double EngineBuffer::getTrackSamples() const { return m_pTrackSamples->get(); } -void EngineBuffer::setScalerForTest(EngineBufferScale* pScaleVinyl, - EngineBufferScale* pScaleKeylock) { - m_pScaleVinyl = pScaleVinyl; - m_pScaleKeylock = pScaleKeylock; - m_pScale = m_pScaleVinyl; - m_pScale->clear(); - m_bScalerChanged = true; - // This bool is permanently set and can't be undone. - m_bScalerOverride = true; -} - -void EngineBuffer::collectFeatures(GroupFeatureState* pGroupFeatures) const { - if (m_pBpmControl != NULL) { - m_pBpmControl->collectFeatures(pGroupFeatures); - } -} - double EngineBuffer::getRateRatio() const { - if (m_pBpmControl != NULL) { + if (m_pBpmControl != nullptr) { return m_pBpmControl->getRateRatio(); } return 1.0; } -void EngineBuffer::notifyTrackLoaded( - TrackPointer pNewTrack, TrackPointer pOldTrack) { - if (pOldTrack) { - disconnect( - pOldTrack.get(), - &Track::beatsUpdated, - this, - &EngineBuffer::slotUpdatedTrackBeats); - } - - // First inform engineControls directly - // Note: we are still in a worker thread. - for (const auto& pControl: qAsConst(m_engineControls)) { - pControl->trackLoaded(pNewTrack); - } - - if (pNewTrack) { - connect( - pNewTrack.get(), - &Track::beatsUpdated, - this, - &EngineBuffer::slotUpdatedTrackBeats, - Qt::DirectConnection); +void EngineBuffer::collectFeatures(GroupFeatureState* pGroupFeatures) const { + if (m_pBpmControl != nullptr) { + m_pBpmControl->collectFeatures(pGroupFeatures); } - - // Inform BaseTrackPlayer via a queued connection - emit trackLoaded(pNewTrack, pOldTrack); } void EngineBuffer::slotUpdatedTrackBeats() { @@ -1445,3 +1434,15 @@ void EngineBuffer::slotUpdatedTrackBeats() { } } } + +void EngineBuffer::setScalerForTest( + EngineBufferScale* pScaleVinyl, + EngineBufferScale* pScaleKeylock) { + m_pScaleVinyl = pScaleVinyl; + m_pScaleKeylock = pScaleKeylock; + m_pScale = m_pScaleVinyl; + m_pScale->clear(); + m_bScalerChanged = true; + // This bool is permanently set and can't be undone. + m_bScalerOverride = true; +} diff --git a/src/engine/enginebuffer.h b/src/engine/enginebuffer.h index 51d19f13bec..7dc1b02edf1 100644 --- a/src/engine/enginebuffer.h +++ b/src/engine/enginebuffer.h @@ -140,27 +140,25 @@ class EngineBuffer : public EngineObject { void processSlip(int iBufferSize); void postProcess(const int iBufferSize); - bool isTrackLoaded() const; - TrackPointer getLoadedTrack() const; - /// Return true iff a seek is currently queued but not yet processed /// If no seek was queued, the seek position is set to -1 - bool getQueuedSeekPosition(double* pSeekPosition); + bool getQueuedSeekPosition(double* pSeekPosition) const; - double getExactPlayPos(); - double getVisualPlayPos(); - double getTrackSamples(); + bool isTrackLoaded() const; + TrackPointer getLoadedTrack() const; - void collectFeatures(GroupFeatureState* pGroupFeatures) const; + double getExactPlayPos() const; + double getVisualPlayPos() const; + double getTrackSamples() const; double getRateRatio() const; - // For dependency injection of readers. - //void setReader(CachingReader* pReader); + void collectFeatures(GroupFeatureState* pGroupFeatures) const; // For dependency injection of scalers. - void setScalerForTest(EngineBufferScale* pScaleVinyl, - EngineBufferScale* pScaleKeylock); + void setScalerForTest( + EngineBufferScale* pScaleVinyl, + EngineBufferScale* pScaleKeylock); // For injection of fake tracks. void loadFakeTrack(TrackPointer pTrack, bool bPlay);