Skip to content

Commit

Permalink
Merge pull request #4668 from ywwg/eject-undo
Browse files Browse the repository at this point in the history
Implement Un-eject
  • Loading branch information
daschuer authored Feb 18, 2022
2 parents 19560e2 + 777d32f commit 879dcca
Show file tree
Hide file tree
Showing 24 changed files with 317 additions and 59 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ add_executable(mixxx-test
src/test/nativeeffects_test.cpp
src/test/performancetimer_test.cpp
src/test/playcountertest.cpp
src/test/playermanagertest.cpp
src/test/playlisttest.cpp
src/test/portmidicontroller_test.cpp
src/test/portmidienumeratortest.cpp
Expand Down
17 changes: 0 additions & 17 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ EngineBuffer::EngineBuffer(const QString& group,
m_pKeylock = new ControlPushButton(ConfigKey(m_group, "keylock"), true);
m_pKeylock->setButtonMode(ControlPushButton::TOGGLE);

m_pEject = new ControlPushButton(ConfigKey(m_group, "eject"));
connect(m_pEject, &ControlObject::valueChanged,
this, &EngineBuffer::slotEjectTrack,
Qt::DirectConnection);

m_pTrackLoaded = new ControlObject(ConfigKey(m_group, "track_loaded"), false);
m_pTrackLoaded->setReadOnly();

Expand Down Expand Up @@ -325,7 +320,6 @@ EngineBuffer::~EngineBuffer() {
delete m_pScaleRB;

delete m_pKeylock;
delete m_pEject;

SampleUtil::free(m_pCrossfadeBuffer);

Expand Down Expand Up @@ -1442,17 +1436,6 @@ TrackPointer EngineBuffer::getLoadedTrack() const {
return m_pCurrentTrack;
}

void EngineBuffer::slotEjectTrack(double v) {
if (v > 0) {
// Don't allow rejections while playing a track. We don't need to lock to
// call ControlObject::get() so this is fine.
if (m_playButton->get() > 0) {
return;
}
ejectTrack();
}
}

mixxx::audio::FramePos EngineBuffer::getExactPlayPos() const {
if (!m_visualPlayPos->isValid()) {
return mixxx::audio::kStartFramePos;
Expand Down
6 changes: 1 addition & 5 deletions src/engine/enginebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class EngineBuffer : public EngineObject {

bool isTrackLoaded() const;
TrackPointer getLoadedTrack() const;
void ejectTrack();

mixxx::audio::FramePos getExactPlayPos() const;
double getVisualPlayPos() const;
Expand Down Expand Up @@ -174,8 +175,6 @@ class EngineBuffer : public EngineObject {
void slotControlSeek(double);
void slotKeylockEngineChanged(double);

void slotEjectTrack(double);

signals:
void trackLoaded(TrackPointer pNewTrack, TrackPointer pOldTrack);
void trackLoadFailed(TrackPointer pTrack, const QString& reason);
Expand Down Expand Up @@ -207,8 +206,6 @@ class EngineBuffer : public EngineObject {

void hintReader(const double rate);

void ejectTrack();

double fractionalPlayposFromAbsolute(mixxx::audio::FramePos position);

void doSeekFractional(double fractionalPos, enum SeekRequest seekType);
Expand Down Expand Up @@ -351,7 +348,6 @@ class EngineBuffer : public EngineObject {
// thread, which is required to avoid segfaults.
ControlProxy* m_pPassthroughEnabled;

ControlPushButton* m_pEject;
ControlObject* m_pTrackLoaded;

// Whether or not to repeat the track when at the end
Expand Down
9 changes: 6 additions & 3 deletions src/mixer/auxiliary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#include "soundio/soundmanager.h"
#include "soundio/soundmanagerutil.h"

Auxiliary::Auxiliary(QObject* pParent, const QString& group, int index,
SoundManager* pSoundManager, EngineMaster* pEngine,
EffectsManager* pEffectsManager)
Auxiliary::Auxiliary(PlayerManager* pParent,
const QString& group,
int index,
SoundManager* pSoundManager,
EngineMaster* pEngine,
EffectsManager* pEffectsManager)
: BasePlayer(pParent, group) {
ChannelHandleAndGroup channelGroup = pEngine->registerChannelGroup(group);
EngineAux* pAuxiliary = new EngineAux(channelGroup, pEffectsManager);
Expand Down
12 changes: 6 additions & 6 deletions src/mixer/auxiliary.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class SoundManager;
class Auxiliary : public BasePlayer {
Q_OBJECT
public:
Auxiliary(QObject* pParent,
const QString& group,
int index,
SoundManager* pSoundManager,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager);
Auxiliary(PlayerManager* pParent,
const QString& group,
int index,
SoundManager* pSoundManager,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager);
~Auxiliary() override;

signals:
Expand Down
3 changes: 2 additions & 1 deletion src/mixer/baseplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include "moc_baseplayer.cpp"

BasePlayer::BasePlayer(QObject* pParent, const QString& group)
BasePlayer::BasePlayer(PlayerManager* pParent, const QString& group)
: QObject(pParent),
m_pPlayerManager(pParent),
m_group(group) {
}
7 changes: 6 additions & 1 deletion src/mixer/baseplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
#include <QObject>
#include <QString>

#include "mixer/playermanager.h"

class BasePlayer : public QObject {
Q_OBJECT
public:
BasePlayer(QObject* pParent, const QString& group);
BasePlayer(PlayerManager* pParent, const QString& group);
~BasePlayer() override = default;

inline const QString& getGroup() const {
return m_group;
}

protected:
PlayerManager* m_pPlayerManager;

private:
const QString m_group;
};
32 changes: 30 additions & 2 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ inline double trackColorToDouble(mixxx::RgbColor::optional_t color) {
}
} // namespace

BaseTrackPlayer::BaseTrackPlayer(QObject* pParent, const QString& group)
BaseTrackPlayer::BaseTrackPlayer(PlayerManager* pParent, const QString& group)
: BasePlayer(pParent, group) {
}

BaseTrackPlayerImpl::BaseTrackPlayerImpl(
QObject* pParent,
PlayerManager* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
Expand Down Expand Up @@ -83,6 +83,13 @@ BaseTrackPlayerImpl::BaseTrackPlayerImpl(
this,
&BaseTrackPlayerImpl::slotLoadFailed);

m_pEject = std::make_unique<ControlPushButton>(ConfigKey(getGroup(), "eject"));
connect(m_pEject.get(),
&ControlObject::valueChanged,
this,
&BaseTrackPlayerImpl::slotEjectTrack,
Qt::DirectConnection);

// Get loop point control objects
m_pLoopInPoint = make_parented<ControlProxy>(
getGroup(), "loop_start_position", this);
Expand Down Expand Up @@ -297,6 +304,26 @@ void BaseTrackPlayerImpl::loadTrack(TrackPointer pTrack) {
connectLoadedTrack();
}

void BaseTrackPlayerImpl::slotEjectTrack(double v) {
if (v <= 0) {
return;
}
if (!m_pLoadedTrack) {
TrackPointer lastEjected = m_pPlayerManager->getLastEjectedTrack();
if (lastEjected) {
slotLoadTrack(lastEjected, false);
}
return;
}

// Don't allow rejections while playing a track. We don't need to lock to
// call ControlObject::get() so this is fine.
if (m_pPlay->toBool()) {
return;
}
m_pChannel->getEngineBuffer()->ejectTrack();
}

TrackPointer BaseTrackPlayerImpl::unloadTrack() {
if (!m_pLoadedTrack) {
// nothing to do
Expand Down Expand Up @@ -344,6 +371,7 @@ TrackPointer BaseTrackPlayerImpl::unloadTrack() {

TrackPointer pUnloadedTrack(std::move(m_pLoadedTrack));
DEBUG_ASSERT(!m_pLoadedTrack);
emit trackUnloaded(pUnloadedTrack);
return pUnloadedTrack;
}

Expand Down
9 changes: 7 additions & 2 deletions src/mixer/basetrackplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BaseTrackPlayer : public BasePlayer {
RESET_SPEED
};

BaseTrackPlayer(QObject* pParent, const QString& group);
BaseTrackPlayer(PlayerManager* pParent, const QString& group);
~BaseTrackPlayer() override = default;

virtual TrackPointer getLoadedTrack() const = 0;
Expand All @@ -41,9 +41,11 @@ class BaseTrackPlayer : public BasePlayer {
virtual void slotLoadTrack(TrackPointer pTrack, bool bPlay = false) = 0;
virtual void slotCloneFromGroup(const QString& group) = 0;
virtual void slotCloneDeck() = 0;
virtual void slotEjectTrack(double) = 0;

signals:
void newTrackLoaded(TrackPointer pLoadedTrack);
void trackUnloaded(TrackPointer pUnloadedTrack);
void loadingTrack(TrackPointer pNewTrack, TrackPointer pOldTrack);
void playerEmpty();
void noVinylControlInputConfigured();
Expand All @@ -52,7 +54,7 @@ class BaseTrackPlayer : public BasePlayer {
class BaseTrackPlayerImpl : public BaseTrackPlayer {
Q_OBJECT
public:
BaseTrackPlayerImpl(QObject* pParent,
BaseTrackPlayerImpl(PlayerManager* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
Expand All @@ -76,6 +78,7 @@ class BaseTrackPlayerImpl : public BaseTrackPlayer {

public slots:
void slotLoadTrack(TrackPointer track, bool bPlay) final;
void slotEjectTrack(double) final;
void slotCloneFromGroup(const QString& group) final;
void slotCloneDeck() final;
void slotTrackLoaded(TrackPointer pNewTrack, TrackPointer pOldTrack);
Expand Down Expand Up @@ -117,6 +120,8 @@ class BaseTrackPlayerImpl : public BaseTrackPlayer {
bool m_replaygainPending;
EngineChannel* m_pChannelToCloneFrom;

std::unique_ptr<ControlPushButton> m_pEject;

// Deck clone control
std::unique_ptr<ControlObject> m_pCloneFromDeck;
std::unique_ptr<ControlObject> m_pCloneFromSampler;
Expand Down
2 changes: 1 addition & 1 deletion src/mixer/deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "moc_deck.cpp"

Deck::Deck(QObject* pParent,
Deck::Deck(PlayerManager* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
Expand Down
2 changes: 1 addition & 1 deletion src/mixer/deck.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Deck : public BaseTrackPlayerImpl {
Q_OBJECT
public:
Deck(QObject* pParent,
Deck(PlayerManager* pParent,
UserSettingsPointer pConfig,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager,
Expand Down
9 changes: 6 additions & 3 deletions src/mixer/microphone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#include "soundio/soundmanager.h"
#include "soundio/soundmanagerutil.h"

Microphone::Microphone(QObject* pParent, const QString& group, int index,
SoundManager* pSoundManager, EngineMaster* pEngine,
EffectsManager* pEffectsManager)
Microphone::Microphone(PlayerManager* pParent,
const QString& group,
int index,
SoundManager* pSoundManager,
EngineMaster* pEngine,
EffectsManager* pEffectsManager)
: BasePlayer(pParent, group) {
ChannelHandleAndGroup channelGroup = pEngine->registerChannelGroup(group);
EngineMicrophone* pMicrophone =
Expand Down
12 changes: 6 additions & 6 deletions src/mixer/microphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class SoundManager;
class Microphone : public BasePlayer {
Q_OBJECT
public:
Microphone(QObject* pParent,
const QString& group,
int index,
SoundManager* pSoundManager,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager);
Microphone(PlayerManager* pParent,
const QString& group,
int index,
SoundManager* pSoundManager,
EngineMaster* pMixingEngine,
EffectsManager* pEffectsManager);
~Microphone() override;

signals:
Expand Down
24 changes: 23 additions & 1 deletion src/mixer/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "effects/effectsmanager.h"
#include "engine/channels/enginedeck.h"
#include "engine/enginemaster.h"
#include "library/library.h"
#include "mixer/auxiliary.h"
#include "mixer/deck.h"
#include "mixer/microphone.h"
Expand Down Expand Up @@ -163,6 +162,7 @@ PlayerManager::~PlayerManager() {
}

void PlayerManager::bindToLibrary(Library* pLibrary) {
m_pLibrary = pLibrary;
const auto locker = lockMutex(&m_mutex);
connect(pLibrary, &Library::loadTrackToPlayer, this, &PlayerManager::slotLoadTrackToPlayer);
connect(pLibrary,
Expand Down Expand Up @@ -411,6 +411,10 @@ void PlayerManager::addDeckInner() {
&BaseTrackPlayer::noVinylControlInputConfigured,
this,
&PlayerManager::noVinylControlInputConfigured);
connect(pDeck,
&BaseTrackPlayer::trackUnloaded,
this,
&PlayerManager::slotSaveEjectedTrack);

if (m_pTrackAnalysisScheduler) {
connect(pDeck,
Expand Down Expand Up @@ -469,6 +473,10 @@ void PlayerManager::addSamplerInner() {
this,
&PlayerManager::slotAnalyzeTrack);
}
connect(pSampler,
&BaseTrackPlayer::trackUnloaded,
this,
&PlayerManager::slotSaveEjectedTrack);

m_players[handleGroup.handle()] = pSampler;
m_samplers.append(pSampler);
Expand Down Expand Up @@ -590,6 +598,13 @@ Sampler* PlayerManager::getSampler(unsigned int sampler) const {
return m_samplers[sampler - 1];
}

TrackPointer PlayerManager::getLastEjectedTrack() const {
if (m_pLibrary) {
return m_pLibrary->trackCollectionManager()->getTrackById(m_lastEjectedTrackId);
}
return nullptr;
}

Microphone* PlayerManager::getMicrophone(unsigned int microphone) const {
const auto locker = lockMutex(&m_mutex);
if (microphone < 1 || microphone >= static_cast<unsigned int>(m_microphones.size())) {
Expand Down Expand Up @@ -729,6 +744,13 @@ void PlayerManager::slotAnalyzeTrack(TrackPointer track) {
}
}

void PlayerManager::slotSaveEjectedTrack(TrackPointer track) {
VERIFY_OR_DEBUG_ASSERT(track) {
return;
}
m_lastEjectedTrackId = track->getId();
}

void PlayerManager::onTrackAnalysisProgress(TrackId trackId, AnalyzerProgress analyzerProgress) {
emit trackAnalyzerProgress(trackId, analyzerProgress);
}
Expand Down
Loading

0 comments on commit 879dcca

Please sign in to comment.