diff --git a/src/engine/bpmcontrol.cpp b/src/engine/bpmcontrol.cpp index db4c6a062888..7965ea013263 100644 --- a/src/engine/bpmcontrol.cpp +++ b/src/engine/bpmcontrol.cpp @@ -567,7 +567,7 @@ bool BpmControl::getBeatContextNoLookup( return true; } -double BpmControl::getNearestPositionInPhase(double dThisPosition, bool respectLoops) { +double BpmControl::getNearestPositionInPhase(double dThisPosition, bool respectLoops, bool playing) { // Without a beatgrid, we don't know the phase offset. if (!m_pBeats) { return dThisPosition; @@ -609,6 +609,14 @@ double BpmControl::getNearestPositionInPhase(double dThisPosition, bool respectL return dThisPosition; } + if (playing) { + // "this" track is playing, or just starting + // only match phase if the sync target is playing as well + if (pOtherEngineBuffer->getSpeed() == 0.0) { + return dThisPosition; + } + } + TrackPointer otherTrack = pOtherEngineBuffer->getLoadedTrack(); BeatsPointer otherBeats = otherTrack ? otherTrack->getBeats() : BeatsPointer(); @@ -693,7 +701,7 @@ double BpmControl::getNearestPositionInPhase(double dThisPosition, bool respectL // Move new position after loop jump into phase as well. // This is a recursive call, called only twice because of // respectLoops = false - dNewPlaypos = getNearestPositionInPhase(dNewPlaypos, false); + dNewPlaypos = getNearestPositionInPhase(dNewPlaypos, false, playing); } // Note: Syncing to before the loop beginning is allowed, because @@ -706,7 +714,7 @@ double BpmControl::getNearestPositionInPhase(double dThisPosition, bool respectL double BpmControl::getPhaseOffset(double dThisPosition) { // This does not respect looping - double dNewPlaypos = getNearestPositionInPhase(dThisPosition, false); + double dNewPlaypos = getNearestPositionInPhase(dThisPosition, false, false); return dNewPlaypos - dThisPosition; } diff --git a/src/engine/bpmcontrol.h b/src/engine/bpmcontrol.h index fc4bdfa077a2..38a8541555c8 100644 --- a/src/engine/bpmcontrol.h +++ b/src/engine/bpmcontrol.h @@ -33,7 +33,7 @@ class BpmControl : public EngineControl { // out of sync. double calcSyncedRate(double userTweak); // Get the phase offset from the specified position. - double getNearestPositionInPhase(double dThisPosition, bool respectLoops = true); + double getNearestPositionInPhase(double dThisPosition, bool respectLoops, bool playing); double getPhaseOffset(double dThisPosition); double getBeatDistance(double dThisPosition) const; double getPreviousSample() const { return m_dPreviousSample; } diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index 39de9556b8e9..fdc1efdbedb0 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -1165,7 +1165,7 @@ void EngineBuffer::processSeek(bool paused) { } if ((seekType & SEEK_PHASE) && !paused && m_pQuantize->toBool()) { - position = m_pBpmControl->getNearestPositionInPhase(position); + position = m_pBpmControl->getNearestPositionInPhase(position, true, true); } double newPlayFrame = position / kSamplesPerFrame; diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp index dd2e38aaea52..955ef7c52a2c 100644 --- a/src/engine/sync/enginesync.cpp +++ b/src/engine/sync/enginesync.cpp @@ -381,7 +381,7 @@ EngineChannel* EngineSync::pickNonSyncSyncTarget(EngineChannel* pDontPick) const EngineBuffer* pBuffer = pChannel->getEngineBuffer(); if (pBuffer && pBuffer->getBpm() > 0) { // If the deck is playing then go with it immediately. - if (fabs(pBuffer->getSpeed()) > 0) { + if (pBuffer->getSpeed() != 0.0) { return pChannel; } // Otherwise hold out for a deck that might be playing but