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

Sync to the loaded deck with the lowest index if no track is playing #1818

Merged
merged 4 commits into from
Jan 1, 2019
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
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())
Copy link
Member

@ywwg ywwg Dec 18, 2018

Choose a reason for hiding this comment

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

I think the original logic was right. The bug is that if we go through all the decks and we don't find a syncable playing deck, we end up falling back to the last-seen deck.

I think the correct fix could be:

if (pSyncable->isPlaying() && !other_deck->isPlaying()) {
 continue;
}

// Only update the target bpm if we haven't already got one, or we found a playing syncable deck
if (!foundTargetBpm || pOtherSyncable->isPlaying()) {
  foundTargetBpm = true;
  targetBpm = otherDeckBpm;
  targetBaseBpm = pOtherSyncable->getBaseBpm();
  targetBeatDistance = pOtherSyncable->getBeatDistance();
}

if (pOtherSyncable->isPlaying()) {...

Copy link
Member Author

@daschuer daschuer Dec 18, 2018

Choose a reason for hiding this comment

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

Edit: (missread your code before)
Both versions behave the same, right?
In this case I would prefere mine, because it has a single continue to reject a syncable. On the other hand I don't really mind ... Or is there an issue with my code?

Copy link
Member

Choose a reason for hiding this comment

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

ok I see how it's changed around. I think this is fine, thanks!

&& !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