Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use the other syncable when it plays as well #7

Merged
merged 1 commit into from
Apr 29, 2020
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
20 changes: 7 additions & 13 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,21 +763,15 @@ double BpmControl::getBeatMatchPosition(
double dOtherBeatFraction;
// If not, we have to figure it out
EngineBuffer* pOtherEngineBuffer = pickSyncTarget();
if (pOtherEngineBuffer == nullptr) {
if (playing) {
// Sync to itself if we are already playing
pOtherEngineBuffer = getEngineBuffer();
} else {
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;
if (!pOtherEngineBuffer || pOtherEngineBuffer->getSpeed() == 0.0) {
// "this" track is playing, or just starting
// only match phase if the sync target is playing as well
// else use the previous phase of "this" track before the seek
pOtherEngineBuffer = getEngineBuffer();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't setting pOtherEngineBuffer to ourselves mean there is no seek? how is this different from returning dThisPosition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dThisPosition returns the unchanged target position. If we sync to ourselfes it syncs to the position the deck was before the seek.

}
} else if (!pOtherEngineBuffer) {
return dThisPosition;
}

TrackPointer otherTrack = pOtherEngineBuffer->getLoadedTrack();
Expand Down
24 changes: 24 additions & 0 deletions src/test/enginesynctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,30 @@ TEST_F(EngineSyncTest, SeekStayInPhase) {
// We expect to be two buffers ahead in a beat near 0.2
EXPECT_DOUBLE_EQ(0.050309901738473183, ControlObject::get(ConfigKey(m_sGroup1, "beat_distance")));
EXPECT_DOUBLE_EQ(0.18925937554508981, ControlObject::get(ConfigKey(m_sGroup1, "playposition")));

// The same again with a stopped track loaded in Channel 2
ControlObject::set(ConfigKey(m_sGroup1, "playposition"), 0.0);
ControlObject::set(ConfigKey(m_sGroup1, "play"), 0.0);
ProcessBuffer();

BeatsPointer pBeats2 = BeatFactory::makeBeatGrid(*m_pTrack1, 130, 0.0);
m_pTrack2->setBeats(pBeats2);

ControlObject::set(ConfigKey(m_sGroup1, "play"), 1.0);
ProcessBuffer();

EXPECT_DOUBLE_EQ(0.025154950869236584,
ControlObject::get(ConfigKey(m_sGroup1, "beat_distance")));
EXPECT_DOUBLE_EQ(0.0023219954648526077,
ControlObject::get(ConfigKey(m_sGroup1, "playposition")));

ControlObject::set(ConfigKey(m_sGroup1, "playposition"), 0.2);
ProcessBuffer();

// We expect to be two buffers ahead in a beat near 0.2
EXPECT_DOUBLE_EQ(0.050309901738473183,
ControlObject::get(ConfigKey(m_sGroup1, "beat_distance")));
EXPECT_DOUBLE_EQ(0.18925937554508981, ControlObject::get(ConfigKey(m_sGroup1, "playposition")));
}

TEST_F(EngineSyncTest, SyncWithoutBeatgrid) {
Expand Down