Skip to content

Commit

Permalink
Merge pull request #2024 from iamcodemaker/seeing-double
Browse files Browse the repository at this point in the history
trigger double load clone from PlayerManager instead of BaseTrackPlayer
  • Loading branch information
Be-ing authored Feb 10, 2019
2 parents 46916ba + 7ef5e98 commit 21713cd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
26 changes: 8 additions & 18 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ BaseTrackPlayerImpl::BaseTrackPlayerImpl(QObject* pParent,
m_pPlay->connectValueChanged(this, &BaseTrackPlayerImpl::slotPlayToggled);

pVisualsManager->addDeck(group);

m_cloneTimer.start();
}

BaseTrackPlayerImpl::~BaseTrackPlayerImpl() {
Expand Down Expand Up @@ -265,18 +263,6 @@ void BaseTrackPlayerImpl::disconnectLoadedTrack() {
}

void BaseTrackPlayerImpl::slotLoadTrack(TrackPointer pNewTrack, bool bPlay) {
mixxx::Duration elapsed = m_cloneTimer.restart();
if (elapsed < mixxx::Duration::fromSeconds(0.5)) {
// load pressed twice quickly, clone instead of loading
EngineChannel* pChannel = m_pEngineMaster->getEngineSync()->pickNonSyncSyncTarget(m_pChannel);
slotCloneChannel(pChannel);
}
else {
slotLoadTrackInternal(pNewTrack, bPlay);
}
}

void BaseTrackPlayerImpl::slotLoadTrackInternal(TrackPointer pNewTrack, bool bPlay) {
qDebug() << "BaseTrackPlayerImpl::slotLoadTrack" << getGroup();
// Before loading the track, ensure we have access. This uses lazy
// evaluation to make sure track isn't NULL before we dereference it.
Expand Down Expand Up @@ -439,7 +425,11 @@ TrackPointer BaseTrackPlayerImpl::getLoadedTrack() const {
return m_pLoadedTrack;
}

void BaseTrackPlayerImpl::slotCloneDeck(const QString& group) {
void BaseTrackPlayerImpl::slotCloneDeck() {
slotCloneChannel(m_pEngineMaster->getEngineSync()->pickNonSyncSyncTarget(m_pChannel));
}

void BaseTrackPlayerImpl::slotCloneFromGroup(const QString& group) {
EngineChannel* pChannel = m_pEngineMaster->getChannel(group);
if (!pChannel) {
return;
Expand All @@ -451,9 +441,9 @@ void BaseTrackPlayerImpl::slotCloneDeck(const QString& group) {
void BaseTrackPlayerImpl::slotCloneFromDeck(double d) {
int deck = std::lround(d);
if (deck < 1) {
slotCloneChannel(m_pEngineMaster->getEngineSync()->pickNonSyncSyncTarget(m_pChannel));
slotCloneDeck();
} else {
slotCloneDeck(PlayerManager::groupForDeck(deck-1));
slotCloneFromGroup(PlayerManager::groupForDeck(deck-1));
}
}

Expand All @@ -474,7 +464,7 @@ void BaseTrackPlayerImpl::slotCloneChannel(EngineChannel* pChannel) {
return;
}

slotLoadTrackInternal(pTrack, false);
slotLoadTrack(pTrack, false);
}

void BaseTrackPlayerImpl::slotSetReplayGain(mixxx::ReplayGain replayGain) {
Expand Down
12 changes: 5 additions & 7 deletions src/mixer/basetrackplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "mixer/baseplayer.h"
#include "track/track.h"
#include "util/memory.h"
#include "util/performancetimer.h"

class EngineMaster;
class ControlObject;
Expand Down Expand Up @@ -39,8 +38,8 @@ class BaseTrackPlayer : public BasePlayer {

public slots:
virtual void slotLoadTrack(TrackPointer pTrack, bool bPlay = false) = 0;
virtual void slotCloneChannel(EngineChannel* pChannel) = 0;
virtual void slotCloneDeck(const QString& group) = 0;
virtual void slotCloneFromGroup(const QString& group) = 0;
virtual void slotCloneDeck() = 0;

signals:
void newTrackLoaded(TrackPointer pLoadedTrack);
Expand Down Expand Up @@ -77,15 +76,15 @@ class BaseTrackPlayerImpl : public BaseTrackPlayer {

public slots:
void slotLoadTrack(TrackPointer track, bool bPlay) final;
void slotCloneChannel(EngineChannel* pChannel) final;
void slotCloneDeck(const QString& group) final;
void slotCloneFromGroup(const QString& group) final;
void slotCloneDeck() final;
void slotTrackLoaded(TrackPointer pNewTrack, TrackPointer pOldTrack);
void slotLoadFailed(TrackPointer pTrack, QString reason);
void slotSetReplayGain(mixxx::ReplayGain replayGain);
void slotPlayToggled(double);

private slots:
void slotLoadTrackInternal(TrackPointer pNewTrack, bool bPlay);
void slotCloneChannel(EngineChannel* pChannel);
void slotCloneFromDeck(double deck);
void slotPassthroughEnabled(double v);
void slotVinylControlEnabled(double v);
Expand All @@ -109,7 +108,6 @@ class BaseTrackPlayerImpl : public BaseTrackPlayer {
EngineDeck* m_pChannel;
bool m_replaygainPending;
EngineChannel* m_pChannelToCloneFrom;
PerformanceTimer m_cloneTimer;

// Deck clone control
std::unique_ptr<ControlObject> m_pCloneFromDeck;
Expand Down
14 changes: 12 additions & 2 deletions src/mixer/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ PlayerManager::PlayerManager(UserSettingsPointer pConfig,

// This is parented to the PlayerManager so does not need to be deleted
m_pSamplerBank = new SamplerBank(this);

m_cloneTimer.start();
}

PlayerManager::~PlayerManager() {
Expand Down Expand Up @@ -564,7 +566,7 @@ void PlayerManager::slotCloneDeck(QString source_group, QString target_group) {
return;
}

pPlayer->slotCloneDeck(source_group);
pPlayer->slotCloneFromGroup(source_group);
}

void PlayerManager::slotLoadTrackToPlayer(TrackPointer pTrack, QString group, bool play) {
Expand All @@ -577,7 +579,15 @@ void PlayerManager::slotLoadTrackToPlayer(TrackPointer pTrack, QString group, bo
return;
}

pPlayer->slotLoadTrack(pTrack, play);
mixxx::Duration elapsed = m_cloneTimer.restart();
if (m_lastLoadedPlayer == group && elapsed < mixxx::Duration::fromSeconds(0.5)) {
// load pressed twice quickly, clone instead of loading
pPlayer->slotCloneDeck();
} else {
pPlayer->slotLoadTrack(pTrack, play);
}

m_lastLoadedPlayer = group;
}

void PlayerManager::slotLoadToPlayer(QString location, QString group) {
Expand Down
4 changes: 4 additions & 0 deletions src/mixer/playermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "analyzer/trackanalysisscheduler.h"
#include "preferences/usersettings.h"
#include "track/track.h"
#include "util/performancetimer.h"

class Auxiliary;
class BaseTrackPlayer;
Expand Down Expand Up @@ -250,6 +251,9 @@ class PlayerManager : public QObject, public PlayerManagerInterface {
// Used to protect access to PlayerManager state across threads.
mutable QMutex m_mutex;

PerformanceTimer m_cloneTimer;
QString m_lastLoadedPlayer;

UserSettingsPointer m_pConfig;
SoundManager* m_pSoundManager;
EffectsManager* m_pEffectsManager;
Expand Down
4 changes: 2 additions & 2 deletions src/test/autodjprocessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class FakeDeck : public BaseTrackPlayer {
play.set(bPlay);
}

MOCK_METHOD1(slotCloneChannel, void(EngineChannel* pChannel));
MOCK_METHOD1(slotCloneDeck, void(const QString& group));
MOCK_METHOD1(slotCloneFromGroup, void(const QString& group));
MOCK_METHOD0(slotCloneDeck, void());

TrackPointer loadedTrack;
ControlLinPotmeter playposition;
Expand Down

0 comments on commit 21713cd

Please sign in to comment.