void EngineSync::requestSyncMode(Syncable* pSyncable, SyncMode mode) { //qDebug() << "EngineSync::requestSyncMode" << pSyncable->getGroup() << mode; // Based on the call hierarchy I don't think this is possible. (Famous last words.) Q_ASSERT(pSyncable); const bool channelIsMaster = m_pMasterSyncable == pSyncable; if (mode == SYNC_MASTER) { activateMaster(pSyncable); setMasterBpm(pSyncable, pSyncable->getBpm()); setMasterBeatDistance(pSyncable, pSyncable->getBeatDistance()); } else if (mode == SYNC_FOLLOWER) { if (pSyncable == m_pInternalClock && channelIsMaster) { if (syncDeckExists()) { // Internal clock cannot be set to follower if there are other decks // with sync on. Notify them that their mode has not changed. pSyncable->notifySyncModeChanged(SYNC_MASTER); } else { // No sync deck exists. Allow the clock to go inactive. This // case does not happen in practice since the logic in // deactivateSync also deactivates the internal clock when the // last sync deck deactivates but leave this in for good // measure. pSyncable->notifySyncModeChanged(SYNC_FOLLOWER); } } else if (channelIsMaster) { // Was this deck master before? If so do a handoff. m_pMasterSyncable = NULL; activateFollower(pSyncable); // Hand off to the internal clock and keep the current BPM and beat // distance. activateMaster(m_pInternalClock); activateFollower(pSyncable); } else if (m_pMasterSyncable == NULL) { // If no master active, activate the internal clock. activateMaster(m_pInternalClock); setMasterBpm(pSyncable, pSyncable->getBpm()); setMasterBeatDistance(pSyncable, pSyncable->getBeatDistance()); activateFollower(pSyncable); } else { activateFollower(pSyncable); } } else { if (pSyncable == m_pInternalClock && channelIsMaster && syncDeckExists()) { // Internal clock cannot be disabled if there are other decks with // sync on. Notify them that their mode has not changed. pSyncable->notifySyncModeChanged(SYNC_MASTER); } else { deactivateSync(pSyncable); } } }
void EngineSync::requestEnableSync(Syncable* pSyncable, bool bEnabled) { qDebug() << "EngineSync::requestEnableSync" << pSyncable->getGroup() << bEnabled; if (bEnabled) { int playingSyncDecks = playingSyncDeckCount(); bool foundPlayingDeck = false; if (m_pMasterSyncable == NULL) { // There is no master. If any other deck is playing we will match // the first available bpm -- sync won't be enabled on these decks, // otherwise there would have been a master. bool foundTargetBpm = false; double targetBpm = 0.0; double targetBeatDistance = 0.0; foreach (const Syncable* other_deck, m_syncables) { if (other_deck == pSyncable) { // skip this deck continue; } double otherDeckBpm = other_deck->getBpm(); if (otherDeckBpm > 0.0) { foundTargetBpm = true; targetBpm = otherDeckBpm; targetBeatDistance = other_deck->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()) { foundPlayingDeck = true; break; } } } activateMaster(m_pInternalClock); if (foundTargetBpm) { setMasterBpm(NULL, targetBpm); setMasterBeatDistance(NULL, targetBeatDistance); } else { setMasterBpm(pSyncable, pSyncable->getBpm()); setMasterBeatDistance(pSyncable, pSyncable->getBeatDistance()); } } else if (m_pMasterSyncable == m_pInternalClock && playingSyncDecks == 0) {
void SyncControl::setMasterParams(double beatDistance, double baseBpm, double bpm) { m_unmultipliedTargetBeatDistance = beatDistance; m_masterBpmAdjustFactor = determineBpmMultiplier(m_pFileBpm->get(), baseBpm); setMasterBpm(bpm); updateTargetBeatDistance(); }