From 6976fae03ed9db2f0e3444e42cd20c9c729c59cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 23 Sep 2018 02:17:40 +0200 Subject: [PATCH 1/4] Sync to the loaded deck with the lowest index if no track is playing --- src/engine/sync/enginesync.cpp | 21 +++++++++++---------- src/test/enginesynctest.cpp | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp index 9b0436e95e3..79b1c0b5c9e 100644 --- a/src/engine/sync/enginesync.cpp +++ b/src/engine/sync/enginesync.cpp @@ -110,32 +110,33 @@ 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(); + double otherDeckBpm = pOtherSyncable->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()) { + // If the requesting deck is playing, or we have already a + // non plaing deck found, only watch out for playing decks. + if ((foundTargetBpm || pSyncable->isPlaying()) + && !pOtherSyncable->isPlaying()) { continue; } foundTargetBpm = true; targetBpm = otherDeckBpm; - targetBaseBpm = other_deck->getBaseBpm(); - targetBeatDistance = other_deck->getBeatDistance(); + 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 (pOtherSyncable->isPlaying()) { foundPlayingDeck = true; break; } diff --git a/src/test/enginesynctest.cpp b/src/test/enginesynctest.cpp index 99ef7cc609f..744ce56cb0c 100644 --- a/src/test/enginesynctest.cpp +++ b/src/test/enginesynctest.cpp @@ -1340,9 +1340,9 @@ TEST_F(EngineSyncTest, SyncPhaseToPlayingNonSyncDeck) { ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0); ProcessBuffer(); - EXPECT_FLOAT_EQ(140.0, + EXPECT_FLOAT_EQ(100.0, ControlObject::getControl(ConfigKey(m_sInternalClockGroup, "bpm"))->get()); - EXPECT_FLOAT_EQ(140.0, ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get()); + EXPECT_FLOAT_EQ(100.0, ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get()); // The exact beat distance will be one buffer past .6, but this is good // enough to confirm that it worked. EXPECT_GT(0.7, ControlObject::getControl(ConfigKey(m_sGroup1, "beat_distance"))->get()); From 345905f6da1bea0f804bf2b9ce68cbe5fc8d0025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 19 Dec 2018 22:01:41 +0100 Subject: [PATCH 2/4] Fix typo --- src/engine/sync/enginesync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp index 79b1c0b5c9e..db3c80a6cb7 100644 --- a/src/engine/sync/enginesync.cpp +++ b/src/engine/sync/enginesync.cpp @@ -123,7 +123,7 @@ void EngineSync::requestEnableSync(Syncable* pSyncable, bool bEnabled) { double otherDeckBpm = pOtherSyncable->getBpm(); if (otherDeckBpm > 0.0) { // If the requesting deck is playing, or we have already a - // non plaing deck found, only watch out for playing decks. + // non playing deck found, only watch out for playing decks. if ((foundTargetBpm || pSyncable->isPlaying()) && !pOtherSyncable->isPlaying()) { continue; From 2ba470b308e77081ad44301a893ddbf8a7ebbc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 19 Dec 2018 23:08:18 +0100 Subject: [PATCH 3/4] Fix the test for matching the orignal intention, and added an itermediates step to explicite test for lp1784185 --- src/test/enginesynctest.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/test/enginesynctest.cpp b/src/test/enginesynctest.cpp index 744ce56cb0c..10a08eded7e 100644 --- a/src/test/enginesynctest.cpp +++ b/src/test/enginesynctest.cpp @@ -1320,29 +1320,43 @@ 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(m_sGroup3, "sync_enabled"); auto pFileBpm3 = std::make_unique(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(); - EXPECT_FLOAT_EQ(100.0, + // We expect Deck 1 is Deck 3 bpm + EXPECT_FLOAT_EQ(140.0, ControlObject::getControl(ConfigKey(m_sInternalClockGroup, "bpm"))->get()); - EXPECT_FLOAT_EQ(100.0, ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get()); + EXPECT_FLOAT_EQ(140.0, ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get()); // The exact beat distance will be one buffer past .6, but this is good // enough to confirm that it worked. EXPECT_GT(0.7, ControlObject::getControl(ConfigKey(m_sGroup1, "beat_distance"))->get()); From d6434642463837ca8bf97d3d27249f8ee4bed0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 20 Dec 2018 07:23:12 +0100 Subject: [PATCH 4/4] cache playing state --- src/engine/sync/enginesync.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp index db3c80a6cb7..fd8e689de9f 100644 --- a/src/engine/sync/enginesync.cpp +++ b/src/engine/sync/enginesync.cpp @@ -120,23 +120,24 @@ void EngineSync::requestEnableSync(Syncable* pSyncable, bool bEnabled) { continue; } - double otherDeckBpm = pOtherSyncable->getBpm(); - if (otherDeckBpm > 0.0) { + 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()) - && !pOtherSyncable->isPlaying()) { + && !otherIsPlaying) { continue; } foundTargetBpm = true; - targetBpm = otherDeckBpm; + 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 (pOtherSyncable->isPlaying()) { + if (otherIsPlaying) { foundPlayingDeck = true; break; }