Skip to content

Commit

Permalink
Merge pull request #1818 from daschuer/lp1784185
Browse files Browse the repository at this point in the history
Sync to the loaded deck with the lowest index if no track is playing
  • Loading branch information
daschuer authored Jan 1, 2019
2 parents 9546953 + d643464 commit 965aa92
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
26 changes: 14 additions & 12 deletions src/engine/sync/enginesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,34 @@ void EngineSync::requestEnableSync(Syncable* pSyncable, bool bEnabled) {
double targetBeatDistance = 0.0;
double targetBaseBpm = 0.0;

foreach (const Syncable* other_deck, m_syncables) {
if (other_deck == pSyncable) {
for (const auto& pOtherSyncable: m_syncables) {
if (pOtherSyncable == pSyncable) {
// skip this deck
continue;
}
if (!other_deck->getChannel()->isMasterEnabled()) {
if (!pOtherSyncable->getChannel()->isMasterEnabled()) {
// skip non-master decks, like preview decks.
continue;
}

double otherDeckBpm = other_deck->getBpm();
if (otherDeckBpm > 0.0) {
// If the requesting deck is playing, but the other deck
// is not, do not sync.
if (pSyncable->isPlaying() && !other_deck->isPlaying()) {
double otherBpm = pOtherSyncable->getBpm();
bool otherIsPlaying = pOtherSyncable->isPlaying();
if (otherBpm > 0.0) {
// If the requesting deck is playing, or we have already a
// non playing deck found, only watch out for playing decks.
if ((foundTargetBpm || pSyncable->isPlaying())
&& !otherIsPlaying) {
continue;
}
foundTargetBpm = true;
targetBpm = otherDeckBpm;
targetBaseBpm = other_deck->getBaseBpm();
targetBeatDistance = other_deck->getBeatDistance();
targetBpm = otherBpm;
targetBaseBpm = pOtherSyncable->getBaseBpm();
targetBeatDistance = pOtherSyncable->getBeatDistance();

// If the other deck is playing we stop looking
// immediately. Otherwise continue looking for a playing
// deck with bpm > 0.0.
if (other_deck->isPlaying()) {
if (otherIsPlaying) {
foundPlayingDeck = true;
break;
}
Expand Down
22 changes: 18 additions & 4 deletions src/test/enginesynctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,26 +1320,40 @@ TEST_F(EngineSyncTest, SyncPhaseToPlayingNonSyncDeck) {
EXPECT_LT(0.8, ControlObject::getControl(ConfigKey(m_sInternalClockGroup,
"beat_distance"))->get());

// But if there is a third deck that is sync-enabled, we match that.
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(0.0);
pButtonSyncEnabled1->set(0.0);
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))->set(getRateSliderValue(1.0));

ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(0.0);
pButtonSyncEnabled2->set(0.0);
ControlObject::getControl(ConfigKey(m_sGroup2, "rate"))->set(getRateSliderValue(1.0));

// But if there is a third deck that is sync-enabled, we match that.
auto pButtonSyncEnabled3 = std::make_unique<ControlProxy>(m_sGroup3, "sync_enabled");
auto pFileBpm3 = std::make_unique<ControlProxy>(m_sGroup3, "file_bpm");
ControlObject::getControl(ConfigKey(m_sGroup3, "beat_distance"))->set(0.6);
ControlObject::getControl(ConfigKey(m_sGroup3, "rate"))->set(getRateSliderValue(1.0));
BeatsPointer pBeats3 = BeatFactory::makeBeatGrid(*m_pTrack3, 140, 0.0);
m_pTrack3->setBeats(pBeats3);
pFileBpm3->set(140.0);
pButtonSyncEnabled1->set(0.0);
// This will sync to the first deck here and not the second (lp1784185)
pButtonSyncEnabled3->set(1.0);
ProcessBuffer();
EXPECT_FLOAT_EQ(130.0, ControlObject::getControl(ConfigKey(m_sGroup3, "bpm"))->get());
// revert that
ControlObject::getControl(ConfigKey(m_sGroup3, "rate"))->set(getRateSliderValue(1.0));
ProcessBuffer();
EXPECT_FLOAT_EQ(140.0, ControlObject::getControl(ConfigKey(m_sGroup3, "bpm"))->get());
// now we have Deck 3 with 140 bpm and sync enabled

pButtonSyncEnabled1->set(1.0);
pButtonSyncEnabled3->set(1.0);
ProcessBuffer();

ControlObject::getControl(ConfigKey(m_sGroup3, "play"))->set(1.0);
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0);
ProcessBuffer();

// We expect Deck 1 is Deck 3 bpm
EXPECT_FLOAT_EQ(140.0,
ControlObject::getControl(ConfigKey(m_sInternalClockGroup, "bpm"))->get());
EXPECT_FLOAT_EQ(140.0, ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get());
Expand Down

0 comments on commit 965aa92

Please sign in to comment.