Skip to content

Commit

Permalink
Sync Lock: When disabling explicit sync, make sure we pick a soft mas…
Browse files Browse the repository at this point in the history
…ter if there are two playing sync decks
  • Loading branch information
ywwg committed Mar 15, 2021
1 parent 62b257b commit fe05e22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/engine/sync/enginesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,14 @@ Syncable* EngineSync::pickMaster(Syncable* enabling_syncable) {
return m_pMasterSyncable;
}

Syncable* first_stopped_deck = nullptr;
// First preference: some other sync deck that is not playing.
Syncable* first_other_playing_deck = nullptr;
// Second preference: whatever the first playing sync deck is, even if it's us.
Syncable* first_playing_deck = nullptr;
// Third preference: the first stopped sync deck.
Syncable* first_stopped_deck = nullptr;
// Last resort: nullptr.

int stopped_deck_count = 0;
int playing_deck_count = 0;

Expand All @@ -219,6 +225,9 @@ Syncable* EngineSync::pickMaster(Syncable* enabling_syncable) {
if (playing_deck_count == 0) {
first_playing_deck = pSyncable;
}
if (!first_other_playing_deck && pSyncable != enabling_syncable) {
first_other_playing_deck = pSyncable;
}
playing_deck_count++;
} else {
if (stopped_deck_count == 0) {
Expand All @@ -231,7 +240,7 @@ Syncable* EngineSync::pickMaster(Syncable* enabling_syncable) {
if (playing_deck_count == 1) {
return first_playing_deck;
} else if (playing_deck_count > 1) {
return nullptr;
return first_other_playing_deck;
}

// No valid playing sync decks
Expand Down
6 changes: 3 additions & 3 deletions src/test/enginesynctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,14 @@ TEST_F(EngineSyncTest, SetExplicitMasterByLights) {
ASSERT_TRUE(isExplicitMaster(m_sGroup1));
ASSERT_TRUE(isFollower(m_sGroup2));

// Now set channel 1 to not-master, it will become a follower.
// master is handed over to Internal clock
// Now set channel 1 to not-master. The system will choose deck 2 as the next best
// option for soft master
pButtonSyncMaster1->slotSet(0);
ProcessBuffer();

ASSERT_TRUE(isFollower(m_sInternalClockGroup));
ASSERT_TRUE(isFollower(m_sGroup1));
ASSERT_TRUE(isFollower(m_sGroup2));
ASSERT_TRUE(isSoftMaster(m_sGroup2));
}

TEST_F(EngineSyncTest, SetExplicitMasterByLightsNoTracks) {
Expand Down

0 comments on commit fe05e22

Please sign in to comment.