From 85bbc6321547124ec3bd8f8dc4af4c91e5905edc Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Mon, 31 May 2021 22:58:19 -0400 Subject: [PATCH] Sync Lock: don't use c++17 inline conditional assignment (1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Schürmann --- src/engine/sync/enginesync.cpp | 22 +++++++++++++--------- src/engine/sync/enginesync.h | 6 +++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp index 1b8e876e010..4655286ccab 100644 --- a/src/engine/sync/enginesync.cpp +++ b/src/engine/sync/enginesync.cpp @@ -96,8 +96,9 @@ void EngineSync::requestSyncMode(Syncable* pSyncable, SyncMode mode) { } } - if (auto onlyPlayer = getOnlyPlayingSyncable(); onlyPlayer != nullptr) { - onlyPlayer->notifyOnlyPlayingSyncable(); + Syncable* pOnlyPlayer = getUniqueSyncDeck(); + if (pOnlyPlayer) { + pOnlyPlayer->notifyOnlyPlayingSyncable(); } } @@ -351,11 +352,14 @@ void EngineSync::notifyPlayingAudible(Syncable* pSyncable, bool playingAudible) if (newMaster != nullptr && newMaster != m_pMasterSyncable) { activateMaster(newMaster, SYNC_MASTER_SOFT); setMasterParams(newMaster); - } else if (auto onlyPlayer = getOnlyPlayingSyncable(); onlyPlayer != nullptr) { - // Even if we didn't change master, if there is only one player (us), then we should - // reinit the beat distance. - onlyPlayer->notifyOnlyPlayingSyncable(); - setMasterBeatDistance(onlyPlayer, onlyPlayer->getBeatDistance()); + } else { + Syncable* pOnlyPlayer = getUniqueSyncDeck(); + if (pOnlyPlayer) { + // Even if we didn't change master, if there is only one player (us), then we should + // reinit the beat distance. + pOnlyPlayer->notifyOnlyPlayingSyncable(); + setMasterBeatDistance(pOnlyPlayer, pOnlyPlayer->getBeatDistance()); + } } pSyncable->requestSync(); @@ -613,7 +617,7 @@ void EngineSync::setMasterParams(Syncable* pSource) { if (!pSource->isPlaying()) { // If the params source is not playing, but other syncables are, then we are a stopped // explicit Master and we should not initialize the beat distance. Take it from the - // internal clock instead. + // internal clock instead, because that will be up to date with the playing deck(s). bool playingSyncables = false; for (Syncable* pSyncable : qAsConst(m_syncables)) { if (pSyncable == pSource) { @@ -651,7 +655,7 @@ void EngineSync::setMasterParams(Syncable* pSource) { } } -Syncable* EngineSync::getOnlyPlayingSyncable() const { +Syncable* EngineSync::getUniqueSyncDeck() const { Syncable* onlyPlaying = nullptr; for (Syncable* pSyncable : m_syncables) { if (!pSyncable->isSynchronized()) { diff --git a/src/engine/sync/enginesync.h b/src/engine/sync/enginesync.h index 4988a14c422..016733aadcf 100644 --- a/src/engine/sync/enginesync.h +++ b/src/engine/sync/enginesync.h @@ -115,9 +115,9 @@ class EngineSync : public SyncableListener { void setMasterParams(Syncable* pSource); - /// Iff there is a single playing syncable, return it. This is used to initialize master - /// params. - Syncable* getOnlyPlayingSyncable() const; + /// Iff there is a single playing syncable in sync mode, return it. + /// This is used to initialize master params. + Syncable* getUniqueSyncDeck() const; /// Only for testing. Do not use. Syncable* getSyncableForGroup(const QString& group);