Skip to content

Commit

Permalink
Merge pull request #7 from daschuer/hotcue-quantize
Browse files Browse the repository at this point in the history
Only use the other syncable when it plays as well
  • Loading branch information
ywwg authored Apr 29, 2020
2 parents fc4bb21 + 3b8e4c8 commit 7c8e047
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
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();
}
} 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

0 comments on commit 7c8e047

Please sign in to comment.