Skip to content

Commit

Permalink
Sync Lock: convert enums to enum classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ywwg committed Jul 10, 2021
1 parent 8559d2f commit e79703d
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 150 deletions.
2 changes: 1 addition & 1 deletion res/controllers/Hercules DJ Control MP3 e2-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1004,4 +1004,4 @@ HerculesMP3e2.filterMid = function(midino, control, value, status, group) {

HerculesMP3e2.filterLow = function(midino, control, value, status, group) {
HerculesMP3e2.filterKnob(group, "parameter1", value);
};
};
2 changes: 1 addition & 1 deletion src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void BpmControl::slotControlBeatSync(double value) {
}

bool BpmControl::syncTempo() {
if (getSyncMode() == SYNC_LEADER_EXPLICIT) {
if (getSyncMode() == SyncMode::LeaderExplicit) {
return false;
}
EngineBuffer* pOtherEngineBuffer = pickSyncTarget();
Expand Down
21 changes: 11 additions & 10 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ EngineBuffer::EngineBuffer(const QString& group,
m_bScalerOverride(false),
m_iSeekPhaseQueued(0),
m_iEnableSyncQueued(SYNC_REQUEST_NONE),
m_iSyncModeQueued(SYNC_INVALID),
m_iSyncModeQueued(static_cast<int>(SyncMode::Invalid)),
m_iTrackLoading(0),
m_bPlayAfterLoading(false),
m_pCrossfadeBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)),
Expand Down Expand Up @@ -404,9 +404,9 @@ void EngineBuffer::requestEnableSync(bool enabled) {
// If we're not playing, the queued event won't get processed so do it now.
if (m_playButton->get() == 0.0) {
if (enabled) {
m_pEngineSync->requestSyncMode(m_pSyncControl, SYNC_FOLLOWER);
m_pEngineSync->requestSyncMode(m_pSyncControl, SyncMode::Follower);
} else {
m_pEngineSync->requestSyncMode(m_pSyncControl, SYNC_NONE);
m_pEngineSync->requestSyncMode(m_pSyncControl, SyncMode::None);
}
return;
}
Expand Down Expand Up @@ -437,7 +437,7 @@ void EngineBuffer::requestSyncMode(SyncMode mode) {
if (m_playButton->get() == 0.0) {
m_pEngineSync->requestSyncMode(m_pSyncControl, mode);
} else {
m_iSyncModeQueued = mode;
m_iSyncModeQueued = static_cast<int>(mode);
}
}

Expand Down Expand Up @@ -1206,22 +1206,23 @@ void EngineBuffer::processSyncRequests() {
static_cast<SyncRequestQueued>(
m_iEnableSyncQueued.fetchAndStoreRelease(SYNC_REQUEST_NONE));
SyncMode mode_request =
static_cast<SyncMode>(m_iSyncModeQueued.fetchAndStoreRelease(SYNC_INVALID));
static_cast<SyncMode>(m_iSyncModeQueued.fetchAndStoreRelease(
static_cast<int>(SyncMode::Invalid)));
switch (enable_request) {
case SYNC_REQUEST_ENABLE:
m_pEngineSync->requestSyncMode(m_pSyncControl, SYNC_FOLLOWER);
m_pEngineSync->requestSyncMode(m_pSyncControl, SyncMode::Follower);
break;
case SYNC_REQUEST_DISABLE:
m_pEngineSync->requestSyncMode(m_pSyncControl, SYNC_NONE);
m_pEngineSync->requestSyncMode(m_pSyncControl, SyncMode::None);
break;
case SYNC_REQUEST_ENABLEDISABLE:
m_pEngineSync->requestSyncMode(m_pSyncControl, SYNC_FOLLOWER);
m_pEngineSync->requestSyncMode(m_pSyncControl, SYNC_NONE);
m_pEngineSync->requestSyncMode(m_pSyncControl, SyncMode::Follower);
m_pEngineSync->requestSyncMode(m_pSyncControl, SyncMode::None);
break;
case SYNC_REQUEST_NONE:
break;
}
if (mode_request != SYNC_INVALID) {
if (mode_request != SyncMode::Invalid) {
m_pEngineSync->requestSyncMode(m_pSyncControl,
static_cast<SyncMode>(mode_request));
}
Expand Down
32 changes: 17 additions & 15 deletions src/engine/sync/enginesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void EngineSync::requestSyncMode(Syncable* pSyncable, SyncMode mode) {
// decks that need to change as a result.
Syncable* oldLeader = m_pLeaderSyncable;
switch (mode) {
case SYNC_LEADER_EXPLICIT:
case SYNC_LEADER_SOFT: {
case SyncMode::LeaderExplicit:
case SyncMode::LeaderSoft: {
if (pSyncable->getBaseBpm() > 0) {
activateLeader(pSyncable, mode);
} else {
Expand All @@ -55,18 +55,18 @@ void EngineSync::requestSyncMode(Syncable* pSyncable, SyncMode mode) {
}
break;
}
case SYNC_FOLLOWER: {
case SyncMode::Follower: {
// A request for follower mode may be converted into an enabling of soft
// leader mode.
activateFollower(pSyncable);
Syncable* newLeader = pickLeader(pSyncable);
if (newLeader && newLeader != m_pLeaderSyncable) {
// if the leader has changed, activate it (this updates m_pLeaderSyncable)
activateLeader(newLeader, SYNC_LEADER_SOFT);
activateLeader(newLeader, SyncMode::LeaderSoft);
}
break;
}
case SYNC_NONE: {
case SyncMode::None: {
if (pSyncable != m_pInternalClock) {
deactivateSync(pSyncable);
}
Expand All @@ -86,7 +86,8 @@ void EngineSync::requestSyncMode(Syncable* pSyncable, SyncMode mode) {
// parameters, if any. Usually this is the new leader. (Note, that pointer might be null!)
Syncable* pParamsSyncable = m_pLeaderSyncable;
// But If we are newly soft leader, we need to match to some other deck.
if (pSyncable == m_pLeaderSyncable && pSyncable != oldLeader && mode != SYNC_LEADER_EXPLICIT) {
if (pSyncable == m_pLeaderSyncable && pSyncable != oldLeader &&
mode != SyncMode::LeaderExplicit) {
pParamsSyncable = findBpmMatchTarget(pSyncable);
if (!pParamsSyncable) {
// We weren't able to find anything to match to, so set ourselves as the
Expand Down Expand Up @@ -124,15 +125,16 @@ void EngineSync::activateFollower(Syncable* pSyncable) {
m_pLeaderSyncable = nullptr;
}

pSyncable->setSyncMode(SYNC_FOLLOWER);
pSyncable->setSyncMode(SyncMode::Follower);
}

void EngineSync::activateLeader(Syncable* pSyncable, SyncMode leaderType) {
VERIFY_OR_DEBUG_ASSERT(pSyncable) {
qWarning() << "WARNING: Logic Error: Called activateLeader on a nullptr Syncable.";
return;
}
VERIFY_OR_DEBUG_ASSERT(leaderType == SYNC_LEADER_SOFT || leaderType == SYNC_LEADER_EXPLICIT) {
VERIFY_OR_DEBUG_ASSERT(leaderType == SyncMode::LeaderSoft ||
leaderType == SyncMode::LeaderExplicit) {
qWarning() << "WARNING: Logic Error: Called activateLeader with non-leader mode";
}
if (kLogger.traceEnabled()) {
Expand All @@ -154,7 +156,7 @@ void EngineSync::activateLeader(Syncable* pSyncable, SyncMode leaderType) {
Syncable* pOldChannelLeader = m_pLeaderSyncable;
m_pLeaderSyncable = nullptr;
if (pOldChannelLeader) {
pOldChannelLeader->setSyncMode(SYNC_FOLLOWER);
pOldChannelLeader->setSyncMode(SyncMode::Follower);
}

m_pLeaderSyncable = pSyncable;
Expand All @@ -180,20 +182,20 @@ void EngineSync::deactivateSync(Syncable* pSyncable) {
}

// Notifications happen after-the-fact.
pSyncable->setSyncMode(SYNC_NONE);
pSyncable->setSyncMode(SyncMode::None);

bool bSyncDeckExists = syncDeckExists();
if (pSyncable != m_pInternalClock && !bSyncDeckExists) {
// Deactivate the internal clock if there are no more sync decks left.
m_pLeaderSyncable = nullptr;
m_pInternalClock->setSyncMode(SYNC_NONE);
m_pInternalClock->setSyncMode(SyncMode::None);
return;
}

if (wasLeader) {
Syncable* newLeader = pickLeader(nullptr);
if (newLeader != nullptr) {
activateLeader(newLeader, SYNC_LEADER_SOFT);
activateLeader(newLeader, SyncMode::LeaderSoft);
}
}
}
Expand All @@ -203,7 +205,7 @@ Syncable* EngineSync::pickLeader(Syncable* enabling_syncable) {
kLogger.trace() << "EngineSync::pickLeader";
}
if (m_pLeaderSyncable &&
m_pLeaderSyncable->getSyncMode() == SYNC_LEADER_EXPLICIT &&
m_pLeaderSyncable->getSyncMode() == SyncMode::LeaderExplicit &&
m_pLeaderSyncable->getBaseBpm() != 0.0) {
return m_pLeaderSyncable;
}
Expand Down Expand Up @@ -361,7 +363,7 @@ void EngineSync::notifyPlayingAudible(Syncable* pSyncable, bool playingAudible)
Syncable* newLeader = pickLeader(pSyncable);

if (newLeader != nullptr && newLeader != m_pLeaderSyncable) {
activateLeader(newLeader, SYNC_LEADER_SOFT);
activateLeader(newLeader, SyncMode::LeaderSoft);
reinitLeaderParams(newLeader);
} else {
Syncable* pOnlyPlayer = getUniquePlayingSyncedDeck();
Expand Down Expand Up @@ -473,7 +475,7 @@ Syncable* EngineSync::pickNonSyncSyncTarget(EngineChannel* pDontPick) const {
EngineBuffer* pBuffer = pChannel->getEngineBuffer();
if (pBuffer && pBuffer->getBpm().isValid()) {
if (pBuffer->getSpeed() != 0.0) {
if (pSyncable->getSyncMode() != SYNC_NONE) {
if (pSyncable->getSyncMode() != SyncMode::None) {
// Second choice: first playing sync deck
return pSyncable;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/sync/enginesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EngineSync : public SyncableListener {
/// 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 SyncMode::None.
bool syncDeckExists() const;

/// Return the current BPM of the Leader Syncable. If no Leader syncable is
Expand Down
18 changes: 9 additions & 9 deletions src/engine/sync/internalclock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const mixxx::Logger kLogger("InternalClock");
InternalClock::InternalClock(const QString& group, SyncableListener* pEngineSync)
: m_group(group),
m_pEngineSync(pEngineSync),
m_mode(SYNC_NONE),
m_mode(SyncMode::None),
m_iOldSampleRate(44100),
m_dOldBpm(124.0),
m_dBaseBpm(124.0),
Expand Down Expand Up @@ -59,7 +59,7 @@ void InternalClock::setSyncMode(SyncMode mode) {
// Syncable has absolutely no say in the matter. This is what EngineSync
// requires. Bypass confirmation by using setAndConfirm.
m_mode = mode;
m_pSyncLeaderEnabled->setAndConfirm(SyncModeToLeaderLight(mode));
m_pSyncLeaderEnabled->setAndConfirm(static_cast<double>(SyncModeToLeaderLight(mode)));
}

void InternalClock::notifyUniquePlaying() {
Expand All @@ -74,26 +74,26 @@ void InternalClock::slotSyncLeaderEnabledChangeRequest(double state) {
SyncMode mode = m_mode;
//Note: internal clock is always sync enabled
if (state > 0.0) {
if (mode == SYNC_LEADER_EXPLICIT) {
if (mode == SyncMode::LeaderExplicit) {
// Already leader.
return;
}
if (mode == SYNC_LEADER_SOFT) {
if (mode == SyncMode::LeaderSoft) {
// user request: make leader explicit
m_mode = SYNC_LEADER_EXPLICIT;
m_mode = SyncMode::LeaderExplicit;
return;
}
if (mode == SYNC_NONE) {
if (mode == SyncMode::None) {
m_dBaseBpm = m_dOldBpm;
}
m_pEngineSync->requestSyncMode(this, SYNC_LEADER_EXPLICIT);
m_pEngineSync->requestSyncMode(this, SyncMode::LeaderExplicit);
} else {
// Turning off leader goes back to follower mode.
if (mode == SYNC_FOLLOWER) {
if (mode == SyncMode::Follower) {
// Already not leader.
return;
}
m_pEngineSync->requestSyncMode(this, SYNC_FOLLOWER);
m_pEngineSync->requestSyncMode(this, SyncMode::Follower);
}
}

Expand Down
78 changes: 48 additions & 30 deletions src/engine/sync/syncable.h
Original file line number Diff line number Diff line change
@@ -1,66 +1,84 @@
#pragma once

#include <QDebug>
#include <QString>

class EngineChannel;

enum SyncMode {
SYNC_INVALID = -1,
SYNC_NONE = 0,
SYNC_FOLLOWER = 1,
// SYNC_LEADER_SOFT is a leader that Mixxx has chosen automatically.
enum class SyncMode {
Invalid = -1,
None = 0,
Follower = 1,
// LeaderSoft is a leader that Mixxx has chosen automatically.
// depending on how decks stop and start, it may reassign soft leader at will.
SYNC_LEADER_SOFT = 2,
// SYNC_LEADER_EXPLICIT represents an explicit request that the synacable be
// leader. Mixxx will only remove a SYNC_LEADER_SOFT if the track is stopped or
LeaderSoft = 2,
// LeaderExplicit represents an explicit request that the syncable be
// leader. Mixxx will only remove a LeaderSoft if the track is stopped or
// ejected.
SYNC_LEADER_EXPLICIT = 3,
SYNC_NUM_MODES
LeaderExplicit = 3,
NumModes
};

inline QDebug operator<<(QDebug debug, const SyncMode& mode) {
switch (mode) {
case SyncMode::Invalid:
return debug << "SyncMode::Invalid";
case SyncMode::None:
return debug << "SyncMode::None";
case SyncMode::Follower:
return debug << "SyncMode::Follower";
case SyncMode::LeaderSoft:
return debug << "SyncMode::LeaderSoft";
case SyncMode::LeaderExplicit:
return debug << "SyncMode::LeaderExplicit";
case SyncMode::NumModes:
return debug << "SyncMode::NumModes";
}
return debug << "SyncMode::Invalid (not in switch/case)";
}
inline SyncMode syncModeFromDouble(double value) {
// msvs does not allow to cast from double to an enum
SyncMode mode = static_cast<SyncMode>(int(value));
if (mode >= SYNC_NUM_MODES || mode < 0) {
return SYNC_NONE;
if (mode >= SyncMode::NumModes || mode == SyncMode::Invalid) {
return SyncMode::None;
}
return mode;
}

inline bool toSynchronized(SyncMode mode) {
return mode > SYNC_NONE;
return mode > SyncMode::None;
}

inline bool isFollower(SyncMode mode) {
return (mode == SYNC_FOLLOWER);
return (mode == SyncMode::Follower);
}

inline bool isLeader(SyncMode mode) {
return (mode == SYNC_LEADER_SOFT || mode == SYNC_LEADER_EXPLICIT);
return (mode == SyncMode::LeaderSoft || mode == SyncMode::LeaderExplicit);
}

enum SyncLeaderLight {
LEADER_INVALID = -1,
LEADER_OFF = 0,
LEADER_SOFT = 1,
LEADER_EXPLICIT = 2,
enum class SyncLeaderLight {
Invalid = -1,
Off = 0,
Soft = 1,
Explicit = 2,
};

inline SyncLeaderLight SyncModeToLeaderLight(SyncMode mode) {
switch (mode) {
case SYNC_INVALID:
case SYNC_NONE:
case SYNC_FOLLOWER:
return LEADER_OFF;
case SYNC_LEADER_SOFT:
return LEADER_SOFT;
case SYNC_LEADER_EXPLICIT:
return LEADER_EXPLICIT;
case SyncMode::Invalid:
case SyncMode::None:
case SyncMode::Follower:
return SyncLeaderLight::Off;
case SyncMode::LeaderSoft:
return SyncLeaderLight::Soft;
case SyncMode::LeaderExplicit:
return SyncLeaderLight::Explicit;
break;
case SYNC_NUM_MODES:
case SyncMode::NumModes:
break;
}
return LEADER_INVALID;
return SyncLeaderLight::Invalid;
}

/// Syncable is an abstract base class for any object that wants to participate
Expand Down
Loading

0 comments on commit e79703d

Please sign in to comment.