Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/engine/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/bpmcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sync/enginesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down