From 62c66ea73c10aa3708c1a880419e8248e83d08ad Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sat, 20 Mar 2021 14:11:46 +0100 Subject: [PATCH 1/3] EngineSync: Remove BaseSyncableListener class --- CMakeLists.txt | 1 - src/engine/sync/basesyncablelistener.cpp | 161 ----------------------- src/engine/sync/basesyncablelistener.h | 71 ---------- src/engine/sync/enginesync.cpp | 148 ++++++++++++++++++++- src/engine/sync/enginesync.h | 57 +++++++- 5 files changed, 201 insertions(+), 237 deletions(-) delete mode 100644 src/engine/sync/basesyncablelistener.cpp delete mode 100644 src/engine/sync/basesyncablelistener.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a9411af452b..88700e9b18b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -599,7 +599,6 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL src/engine/sidechain/enginesidechain.cpp src/engine/sidechain/networkinputstreamworker.cpp src/engine/sidechain/networkoutputstreamworker.cpp - src/engine/sync/basesyncablelistener.cpp src/engine/sync/enginesync.cpp src/engine/sync/internalclock.cpp src/engine/sync/synccontrol.cpp diff --git a/src/engine/sync/basesyncablelistener.cpp b/src/engine/sync/basesyncablelistener.cpp deleted file mode 100644 index e36aefa1caf..00000000000 --- a/src/engine/sync/basesyncablelistener.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include "engine/sync/basesyncablelistener.h" - -#include - -#include "engine/sync/internalclock.h" - -namespace { - -const QString kInternalClockGroup = QStringLiteral("[InternalClock]"); - -} // anonymous namespace - -BaseSyncableListener::BaseSyncableListener(UserSettingsPointer pConfig) - : m_pConfig(pConfig), - m_pInternalClock(new InternalClock(kInternalClockGroup, this)), - m_pMasterSyncable(nullptr) { - qRegisterMetaType("SyncMode"); - m_pInternalClock->setMasterBpm(124.0); -} - -BaseSyncableListener::~BaseSyncableListener() { - // We use the slider value because that is never set to 0.0. - m_pConfig->set(ConfigKey("[InternalClock]", "bpm"), ConfigValue( - m_pInternalClock->getBpm())); - delete m_pInternalClock; -} - -void BaseSyncableListener::addSyncableDeck(Syncable* pSyncable) { - if (m_syncables.contains(pSyncable)) { - qDebug() << "BaseSyncableListener: already has" << pSyncable; - return; - } - m_syncables.append(pSyncable); -} - -void BaseSyncableListener::onCallbackStart(int sampleRate, int bufferSize) { - m_pInternalClock->onCallbackStart(sampleRate, bufferSize); -} - -void BaseSyncableListener::onCallbackEnd(int sampleRate, int bufferSize) { - m_pInternalClock->onCallbackEnd(sampleRate, bufferSize); -} - -EngineChannel* BaseSyncableListener::getMaster() const { - return m_pMasterSyncable ? m_pMasterSyncable->getChannel() : nullptr; -} - -Syncable* BaseSyncableListener::getSyncableForGroup(const QString& group) { - foreach (Syncable* pSyncable, m_syncables) { - if (pSyncable->getGroup() == group) { - return pSyncable; - } - } - return nullptr; -} - -bool BaseSyncableListener::syncDeckExists() const { - for (const auto& pSyncable : qAsConst(m_syncables)) { - if (pSyncable->isSynchronized() && pSyncable->getBaseBpm() > 0) { - return true; - } - } - return false; -} - -double BaseSyncableListener::masterBpm() const { - if (m_pMasterSyncable) { - return m_pMasterSyncable->getBpm(); - } - return m_pInternalClock->getBpm(); -} - -double BaseSyncableListener::masterBeatDistance() const { - if (m_pMasterSyncable) { - return m_pMasterSyncable->getBeatDistance(); - } - return m_pInternalClock->getBeatDistance(); -} - -double BaseSyncableListener::masterBaseBpm() const { - if (m_pMasterSyncable) { - return m_pMasterSyncable->getBaseBpm(); - } - return m_pInternalClock->getBaseBpm(); -} - -void BaseSyncableListener::setMasterBpm(Syncable* pSource, double bpm) { - //qDebug() << "BaseSyncableListener::setMasterBpm" << pSource << bpm; - if (pSource != m_pInternalClock) { - m_pInternalClock->setMasterBpm(bpm); - } - foreach (Syncable* pSyncable, m_syncables) { - if (pSyncable == pSource || - !pSyncable->isSynchronized()) { - continue; - } - pSyncable->setMasterBpm(bpm); - } -} - -void BaseSyncableListener::setMasterInstantaneousBpm(Syncable* pSource, double bpm) { - if (pSource != m_pInternalClock) { - m_pInternalClock->setInstantaneousBpm(bpm); - } - foreach (Syncable* pSyncable, m_syncables) { - if (pSyncable == pSource || - !pSyncable->isSynchronized()) { - continue; - } - pSyncable->setInstantaneousBpm(bpm); - } -} - -void BaseSyncableListener::setMasterBeatDistance(Syncable* pSource, double beatDistance) { - if (pSource != m_pInternalClock) { - m_pInternalClock->setMasterBeatDistance(beatDistance); - } - foreach (Syncable* pSyncable, m_syncables) { - if (pSyncable == pSource || - !pSyncable->isSynchronized()) { - continue; - } - pSyncable->setMasterBeatDistance(beatDistance); - } -} - -void BaseSyncableListener::setMasterParams( - Syncable* pSource, double beatDistance, double baseBpm, double bpm) { - //qDebug() << "BaseSyncableListener::setMasterParams, source is" << pSource->getGroup() << beatDistance << baseBpm << bpm; - if (pSource != m_pInternalClock) { - m_pInternalClock->setMasterParams(beatDistance, baseBpm, bpm); - } - foreach (Syncable* pSyncable, m_syncables) { - if (pSyncable == pSource || - !pSyncable->isSynchronized()) { - continue; - } - pSyncable->setMasterParams(beatDistance, baseBpm, bpm); - } -} - -void BaseSyncableListener::checkUniquePlayingSyncable() { - int playing_sync_decks = 0; - Syncable* unique_syncable = nullptr; - foreach (Syncable* pSyncable, m_syncables) { - if (!pSyncable->isSynchronized()) { - continue; - } - - if (pSyncable->isPlaying()) { - if (playing_sync_decks > 0) { - return; - } - unique_syncable = pSyncable; - ++playing_sync_decks; - } - } - if (playing_sync_decks == 1) { - unique_syncable->notifyOnlyPlayingSyncable(); - } -} diff --git a/src/engine/sync/basesyncablelistener.h b/src/engine/sync/basesyncablelistener.h deleted file mode 100644 index 2a875d4d77e..00000000000 --- a/src/engine/sync/basesyncablelistener.h +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - -#include "engine/sync/syncable.h" -#include "preferences/usersettings.h" - -class InternalClock; -class EngineChannel; - -/// BaseSyncableListener is a SyncableListener used by EngineSync. -/// It provides some foundational functionality for distributing -/// various sync updates. -// TODO(owilliams): This class is only inherited by EngineSync. It should -// be merged into that class. -class BaseSyncableListener : public SyncableListener { - public: - BaseSyncableListener(UserSettingsPointer pConfig); - ~BaseSyncableListener() override; - - void addSyncableDeck(Syncable* pSyncable); - EngineChannel* getMaster() const; - void onCallbackStart(int sampleRate, int bufferSize); - void onCallbackEnd(int sampleRate, int bufferSize); - - // Only for testing. Do not use. - Syncable* getSyncableForGroup(const QString& group); - Syncable* getMasterSyncable() override { - return m_pMasterSyncable; - } - - protected: - // This utility method returns true if it finds a deck not in SYNC_NONE mode. - bool syncDeckExists() const; - - // Return the current BPM of the master Syncable. If no master syncable is - // set then returns the BPM of the internal clock. - double masterBpm() const; - - // Returns the current beat distance of the master Syncable. If no master - // Syncable is set, then returns the beat distance of the internal clock. - double masterBeatDistance() const; - - // Returns the overall average BPM of the master Syncable if it were playing - // at 1.0 rate. This is used to calculate half/double multipliers and whether - // the master has a bpm at all. - double masterBaseBpm() const; - - // Set the BPM on every sync-enabled Syncable except pSource. - void setMasterBpm(Syncable* pSource, double bpm); - - // Set the master instantaneous BPM on every sync-enabled Syncable except - // pSource. - void setMasterInstantaneousBpm(Syncable* pSource, double bpm); - - // Set the master beat distance on every sync-enabled Syncable except - // pSource. - void setMasterBeatDistance(Syncable* pSource, double beatDistance); - - void setMasterParams(Syncable* pSource, double beatDistance, double baseBpm, double bpm); - - // Check if there is only one playing syncable deck, and notify it if so. - void checkUniquePlayingSyncable(); - - UserSettingsPointer m_pConfig; - // The InternalClock syncable. - InternalClock* m_pInternalClock; - // The current Syncable that is the master. - Syncable* m_pMasterSyncable; - // The list of all Syncables registered with BaseSyncableListener via - // addSyncableDeck. - QList m_syncables; -}; diff --git a/src/engine/sync/enginesync.cpp b/src/engine/sync/enginesync.cpp index f4508c4fb4e..ecaa18605d0 100644 --- a/src/engine/sync/enginesync.cpp +++ b/src/engine/sync/enginesync.cpp @@ -1,5 +1,6 @@ #include "engine/sync/enginesync.h" +#include #include #include "engine/channels/enginechannel.h" @@ -10,13 +11,21 @@ namespace { const mixxx::Logger kLogger("EngineSync"); -} // namespace +const QString kInternalClockGroup = QStringLiteral("[InternalClock]"); +} // anonymous namespace EngineSync::EngineSync(UserSettingsPointer pConfig) - : BaseSyncableListener(pConfig) { + : m_pConfig(pConfig), + m_pInternalClock(new InternalClock(kInternalClockGroup, this)), + m_pMasterSyncable(nullptr) { + qRegisterMetaType("SyncMode"); + m_pInternalClock->setMasterBpm(124.0); } EngineSync::~EngineSync() { + // We use the slider value because that is never set to 0.0. + m_pConfig->set(ConfigKey(kInternalClockGroup, "bpm"), ConfigValue(m_pInternalClock->getBpm())); + delete m_pInternalClock; } Syncable* EngineSync::pickMaster(Syncable* enabling_syncable) { @@ -478,3 +487,138 @@ bool EngineSync::otherSyncedPlaying(const QString& group) { } return othersInSync; } + +void EngineSync::addSyncableDeck(Syncable* pSyncable) { + if (m_syncables.contains(pSyncable)) { + qDebug() << "EngineSync: already has" << pSyncable; + return; + } + m_syncables.append(pSyncable); +} + +void EngineSync::onCallbackStart(int sampleRate, int bufferSize) { + m_pInternalClock->onCallbackStart(sampleRate, bufferSize); +} + +void EngineSync::onCallbackEnd(int sampleRate, int bufferSize) { + m_pInternalClock->onCallbackEnd(sampleRate, bufferSize); +} + +EngineChannel* EngineSync::getMaster() const { + return m_pMasterSyncable ? m_pMasterSyncable->getChannel() : nullptr; +} + +Syncable* EngineSync::getSyncableForGroup(const QString& group) { + foreach (Syncable* pSyncable, m_syncables) { + if (pSyncable->getGroup() == group) { + return pSyncable; + } + } + return nullptr; +} + +bool EngineSync::syncDeckExists() const { + for (const auto& pSyncable : qAsConst(m_syncables)) { + if (pSyncable->isSynchronized() && pSyncable->getBaseBpm() > 0) { + return true; + } + } + return false; +} + +double EngineSync::masterBpm() const { + if (m_pMasterSyncable) { + return m_pMasterSyncable->getBpm(); + } + return m_pInternalClock->getBpm(); +} + +double EngineSync::masterBeatDistance() const { + if (m_pMasterSyncable) { + return m_pMasterSyncable->getBeatDistance(); + } + return m_pInternalClock->getBeatDistance(); +} + +double EngineSync::masterBaseBpm() const { + if (m_pMasterSyncable) { + return m_pMasterSyncable->getBaseBpm(); + } + return m_pInternalClock->getBaseBpm(); +} + +void EngineSync::setMasterBpm(Syncable* pSource, double bpm) { + //qDebug() << "EngineSync::setMasterBpm" << pSource << bpm; + if (pSource != m_pInternalClock) { + m_pInternalClock->setMasterBpm(bpm); + } + foreach (Syncable* pSyncable, m_syncables) { + if (pSyncable == pSource || + !pSyncable->isSynchronized()) { + continue; + } + pSyncable->setMasterBpm(bpm); + } +} + +void EngineSync::setMasterInstantaneousBpm(Syncable* pSource, double bpm) { + if (pSource != m_pInternalClock) { + m_pInternalClock->setInstantaneousBpm(bpm); + } + foreach (Syncable* pSyncable, m_syncables) { + if (pSyncable == pSource || + !pSyncable->isSynchronized()) { + continue; + } + pSyncable->setInstantaneousBpm(bpm); + } +} + +void EngineSync::setMasterBeatDistance(Syncable* pSource, double beatDistance) { + if (pSource != m_pInternalClock) { + m_pInternalClock->setMasterBeatDistance(beatDistance); + } + foreach (Syncable* pSyncable, m_syncables) { + if (pSyncable == pSource || + !pSyncable->isSynchronized()) { + continue; + } + pSyncable->setMasterBeatDistance(beatDistance); + } +} + +void EngineSync::setMasterParams( + Syncable* pSource, double beatDistance, double baseBpm, double bpm) { + //qDebug() << "EngineSync::setMasterParams, source is" << pSource->getGroup() << beatDistance << baseBpm << bpm; + if (pSource != m_pInternalClock) { + m_pInternalClock->setMasterParams(beatDistance, baseBpm, bpm); + } + foreach (Syncable* pSyncable, m_syncables) { + if (pSyncable == pSource || + !pSyncable->isSynchronized()) { + continue; + } + pSyncable->setMasterParams(beatDistance, baseBpm, bpm); + } +} + +void EngineSync::checkUniquePlayingSyncable() { + int playing_sync_decks = 0; + Syncable* unique_syncable = nullptr; + foreach (Syncable* pSyncable, m_syncables) { + if (!pSyncable->isSynchronized()) { + continue; + } + + if (pSyncable->isPlaying()) { + if (playing_sync_decks > 0) { + return; + } + unique_syncable = pSyncable; + ++playing_sync_decks; + } + } + if (playing_sync_decks == 1) { + unique_syncable->notifyOnlyPlayingSyncable(); + } +} diff --git a/src/engine/sync/enginesync.h b/src/engine/sync/enginesync.h index db23b2b0e3f..0bafb40f00a 100644 --- a/src/engine/sync/enginesync.h +++ b/src/engine/sync/enginesync.h @@ -2,13 +2,15 @@ #include "preferences/usersettings.h" #include "engine/sync/syncable.h" -#include "engine/sync/basesyncablelistener.h" + +class InternalClock; +class EngineChannel; /// EngineSync is the heart of the Mixxx Master Sync engine. It knows which objects /// (Decks, Internal Clock, etc) are participating in Sync and what their statuses /// are. It also orchestrates sync handoffs between different decks as they play, /// stop, or request their status to change. -class EngineSync : public BaseSyncableListener { +class EngineSync : public SyncableListener { public: explicit EngineSync(UserSettingsPointer pConfig); ~EngineSync() override; @@ -53,6 +55,17 @@ class EngineSync : public BaseSyncableListener { // of other Syncables that are playing bool otherSyncedPlaying(const QString& group); + void addSyncableDeck(Syncable* pSyncable); + EngineChannel* getMaster() const; + void onCallbackStart(int sampleRate, int bufferSize); + void onCallbackEnd(int sampleRate, int bufferSize); + + // Only for testing. Do not use. + Syncable* getSyncableForGroup(const QString& group); + Syncable* getMasterSyncable() override { + return m_pMasterSyncable; + } + private: // Iterate over decks, and based on sync and play status, pick a new master. // if enabling_syncable is not null, we treat it as if it were enabled because we may @@ -75,4 +88,44 @@ class EngineSync : public BaseSyncableListener { // Unsets all sync state on a Syncable. void deactivateSync(Syncable* pSyncable); + + // This utility method returns true if it finds a deck not in SYNC_NONE mode. + bool syncDeckExists() const; + + // Return the current BPM of the master Syncable. If no master syncable is + // set then returns the BPM of the internal clock. + double masterBpm() const; + + // Returns the current beat distance of the master Syncable. If no master + // Syncable is set, then returns the beat distance of the internal clock. + double masterBeatDistance() const; + + // Returns the overall average BPM of the master Syncable if it were playing + // at 1.0 rate. This is used to calculate half/double multipliers and whether + // the master has a bpm at all. + double masterBaseBpm() const; + + // Set the BPM on every sync-enabled Syncable except pSource. + void setMasterBpm(Syncable* pSource, double bpm); + + // Set the master instantaneous BPM on every sync-enabled Syncable except + // pSource. + void setMasterInstantaneousBpm(Syncable* pSource, double bpm); + + // Set the master beat distance on every sync-enabled Syncable except + // pSource. + void setMasterBeatDistance(Syncable* pSource, double beatDistance); + + void setMasterParams(Syncable* pSource, double beatDistance, double baseBpm, double bpm); + + // Check if there is only one playing syncable deck, and notify it if so. + void checkUniquePlayingSyncable(); + + UserSettingsPointer m_pConfig; + // The InternalClock syncable. + InternalClock* m_pInternalClock; + // The current Syncable that is the master. + Syncable* m_pMasterSyncable; + // The list of all Syncables registered via addSyncableDeck. + QList m_syncables; }; From aff4cbd9ebf131401223f36157c7808961b0a087 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sat, 20 Mar 2021 14:54:59 +0100 Subject: [PATCH 2/3] EngineSync: Use /// for header file comments --- src/engine/sync/enginesync.h | 108 ++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/engine/sync/enginesync.h b/src/engine/sync/enginesync.h index 0bafb40f00a..70bb64cbece 100644 --- a/src/engine/sync/enginesync.h +++ b/src/engine/sync/enginesync.h @@ -6,7 +6,7 @@ class InternalClock; class EngineChannel; -/// EngineSync is the heart of the Mixxx Master Sync engine. It knows which objects +/// EngineSync is the heart of the Mixxx Sync Lock engine. It knows which objects /// (Decks, Internal Clock, etc) are participating in Sync and what their statuses /// are. It also orchestrates sync handoffs between different decks as they play, /// stop, or request their status to change. @@ -15,44 +15,44 @@ class EngineSync : public SyncableListener { explicit EngineSync(UserSettingsPointer pConfig); ~EngineSync() override; - // Used by Syncables to tell EngineSync it wants to be enabled in a - // specific mode. If the state change is accepted, EngineSync calls - // Syncable::notifySyncModeChanged. + /// Used by Syncables to tell EngineSync it wants to be enabled in a + /// specific mode. If the state change is accepted, EngineSync calls + /// Syncable::notifySyncModeChanged. void requestSyncMode(Syncable* pSyncable, SyncMode state) override; - // Used by Syncables to tell EngineSync it wants to be enabled in any mode - // (master/follower). + /// Used by Syncables to tell EngineSync it wants to be enabled in any mode + /// (master/follower). void requestEnableSync(Syncable* pSyncable, bool enabled) override; - // Syncables notify EngineSync directly about various events. EngineSync - // does not have a say in whether these succeed or not, they are simply - // notifications. + /// Syncables notify EngineSync directly about various events. EngineSync + /// does not have a say in whether these succeed or not, they are simply + /// notifications. void notifyBaseBpmChanged(Syncable* pSyncable, double bpm) override; void requestBpmUpdate(Syncable* pSyncable, double bpm) override; - // Instantaneous BPM refers to the actual, honest-to-god speed of playback - // at any moment, including any scratching that may be happening. + /// Instantaneous BPM refers to the actual, honest-to-god speed of playback + /// at any moment, including any scratching that may be happening. void notifyInstantaneousBpmChanged(Syncable* pSyncable, double bpm) override; - // the beat distance is updated on every callback. + /// the beat distance is updated on every callback. void notifyBeatDistanceChanged(Syncable* pSyncable, double beatDistance) override; - // Notify the engine that a syncable has started or stopped playing + /// Notify the engine that a syncable has started or stopped playing void notifyPlaying(Syncable* pSyncable, bool playing) override; void notifyScratching(Syncable* pSyncable, bool scratching) override; - // Used to pick a sync target for cases where master sync mode is not sufficient. - // Guaranteed to pick a Syncable that is a real deck and has an EngineBuffer, - // but can return nullptr if there are no choices. - // First choice is master sync, if it's a real deck, - // then it will fall back to the first playing syncable deck, - // then it will fall back to the first playing deck, - // then it will fall back to the first non-playing deck. - // If there is literally nothing loaded, returns nullptr. + /// Used to pick a sync target for cases where master sync mode is not sufficient. + /// Guaranteed to pick a Syncable that is a real deck and has an EngineBuffer, + /// but can return nullptr if there are no choices. + /// First choice is master sync, if it's a real deck, + /// then it will fall back to the first playing syncable deck, + /// then it will fall back to the first playing deck, + /// then it will fall back to the first non-playing deck. + /// If there is literally nothing loaded, returns nullptr. Syncable* pickNonSyncSyncTarget(EngineChannel* pDontPick) const; - // Used to test whether changing the rate of a Syncable would change the rate - // of other Syncables that are playing + /// Used to test whether changing the rate of a Syncable would change the rate + /// of other Syncables that are playing bool otherSyncedPlaying(const QString& group); void addSyncableDeck(Syncable* pSyncable); @@ -60,72 +60,74 @@ class EngineSync : public SyncableListener { void onCallbackStart(int sampleRate, int bufferSize); void onCallbackEnd(int sampleRate, int bufferSize); - // Only for testing. Do not use. + /// Only for testing. Do not use. Syncable* getSyncableForGroup(const QString& group); + + /// Only for testing. Do not use. Syncable* getMasterSyncable() override { return m_pMasterSyncable; } private: - // Iterate over decks, and based on sync and play status, pick a new master. - // if enabling_syncable is not null, we treat it as if it were enabled because we may - // be in the process of enabling it. + /// Iterate over decks, and based on sync and play status, pick a new master. + /// if enabling_syncable is not null, we treat it as if it were enabled because we may + /// be in the process of enabling it. Syncable* pickMaster(Syncable* enabling_syncable); - // Find a deck to match against, used in the case where there is no sync master. - // Looks first for a playing deck, and falls back to the first non-playing deck. - // If the requester is playing, don't match against a non-playing deck because - // that would be strange behavior for the user. - // Returns nullptr if none can be found. + /// Find a deck to match against, used in the case where there is no sync master. + /// Looks first for a playing deck, and falls back to the first non-playing deck. + /// If the requester is playing, don't match against a non-playing deck because + /// that would be strange behavior for the user. + /// Returns nullptr if none can be found. Syncable* findBpmMatchTarget(Syncable* requester); - // Activate a specific syncable as master. + /// Activate a specific syncable as master. void activateMaster(Syncable* pSyncable, bool explicitMaster); - // Activate a specific channel as Follower. Sets the syncable's bpm and - // beatDistance to match the master. + /// Activate a specific channel as Follower. Sets the syncable's bpm and + /// beatDistance to match the master. void activateFollower(Syncable* pSyncable); - // Unsets all sync state on a Syncable. + /// Unsets all sync state on a Syncable. void deactivateSync(Syncable* pSyncable); - // This utility method returns true if it finds a deck not in SYNC_NONE mode. + /// This utility method returns true if it finds a deck not in SYNC_NONE mode. bool syncDeckExists() const; - // Return the current BPM of the master Syncable. If no master syncable is - // set then returns the BPM of the internal clock. + /// Return the current BPM of the master Syncable. If no master syncable is + /// set then returns the BPM of the internal clock. double masterBpm() const; - // Returns the current beat distance of the master Syncable. If no master - // Syncable is set, then returns the beat distance of the internal clock. + /// Returns the current beat distance of the master Syncable. If no master + /// Syncable is set, then returns the beat distance of the internal clock. double masterBeatDistance() const; - // Returns the overall average BPM of the master Syncable if it were playing - // at 1.0 rate. This is used to calculate half/double multipliers and whether - // the master has a bpm at all. + /// Returns the overall average BPM of the master Syncable if it were playing + /// at 1.0 rate. This is used to calculate half/double multipliers and whether + /// the master has a bpm at all. double masterBaseBpm() const; - // Set the BPM on every sync-enabled Syncable except pSource. + /// Set the BPM on every sync-enabled Syncable except pSource. void setMasterBpm(Syncable* pSource, double bpm); - // Set the master instantaneous BPM on every sync-enabled Syncable except - // pSource. + /// Set the master instantaneous BPM on every sync-enabled Syncable except + /// pSource. void setMasterInstantaneousBpm(Syncable* pSource, double bpm); - // Set the master beat distance on every sync-enabled Syncable except - // pSource. + /// Set the master beat distance on every sync-enabled Syncable except + /// pSource. void setMasterBeatDistance(Syncable* pSource, double beatDistance); void setMasterParams(Syncable* pSource, double beatDistance, double baseBpm, double bpm); - // Check if there is only one playing syncable deck, and notify it if so. + /// Check if there is only one playing syncable deck, and notify it if so. void checkUniquePlayingSyncable(); UserSettingsPointer m_pConfig; - // The InternalClock syncable. + /// The InternalClock syncable. InternalClock* m_pInternalClock; - // The current Syncable that is the master. + /// The current Syncable that is the leader. Syncable* m_pMasterSyncable; - // The list of all Syncables registered via addSyncableDeck. + /// The list of all Syncables registered via addSyncableDeck. QList m_syncables; }; From 84a5e7f611a27edd32ba9a8dd0f474d867e82a5a Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sat, 20 Mar 2021 15:08:14 +0100 Subject: [PATCH 3/3] EngineSync: Make test functions private and use friend class/FRIEND_TEST --- src/engine/sync/enginesync.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/engine/sync/enginesync.h b/src/engine/sync/enginesync.h index 70bb64cbece..9e6e7d2abb9 100644 --- a/src/engine/sync/enginesync.h +++ b/src/engine/sync/enginesync.h @@ -1,7 +1,9 @@ #pragma once -#include "preferences/usersettings.h" +#include + #include "engine/sync/syncable.h" +#include "preferences/usersettings.h" class InternalClock; class EngineChannel; @@ -60,14 +62,6 @@ class EngineSync : public SyncableListener { void onCallbackStart(int sampleRate, int bufferSize); void onCallbackEnd(int sampleRate, int bufferSize); - /// Only for testing. Do not use. - Syncable* getSyncableForGroup(const QString& group); - - /// Only for testing. Do not use. - Syncable* getMasterSyncable() override { - return m_pMasterSyncable; - } - private: /// Iterate over decks, and based on sync and play status, pick a new master. /// if enabling_syncable is not null, we treat it as if it were enabled because we may @@ -123,6 +117,21 @@ class EngineSync : public SyncableListener { /// Check if there is only one playing syncable deck, and notify it if so. void checkUniquePlayingSyncable(); + /// Only for testing. Do not use. + Syncable* getSyncableForGroup(const QString& group); + + /// Only for testing. Do not use. + Syncable* getMasterSyncable() override { + return m_pMasterSyncable; + } + + FRIEND_TEST(EngineSyncTest, EnableOneDeckInitsMaster); + FRIEND_TEST(EngineSyncTest, EnableOneDeckInitializesMaster); + FRIEND_TEST(EngineSyncTest, SyncToNonSyncDeck); + FRIEND_TEST(EngineSyncTest, SetFileBpmUpdatesLocalBpm); + FRIEND_TEST(EngineSyncTest, BpmAdjustFactor); + friend class EngineSyncTest; + UserSettingsPointer m_pConfig; /// The InternalClock syncable. InternalClock* m_pInternalClock;