diff --git a/src/mixer/playerinfo.cpp b/src/mixer/playerinfo.cpp index 91b2bfc42ce..93e43db93a9 100644 --- a/src/mixer/playerinfo.cpp +++ b/src/mixer/playerinfo.cpp @@ -67,6 +67,11 @@ void PlayerInfo::setTrackInfo(const QString& group, const TrackPointer& track) { emit trackUnloaded(group, pOld); } emit trackLoaded(group, track); + + if (m_currentlyPlayingDeck >= 0 && + group == PlayerManager::groupForDeck(m_currentlyPlayingDeck)) { + emit currentPlayingTrackChanged(track); + } } bool PlayerInfo::isTrackLoaded(const TrackPointer& pTrack) const { @@ -113,6 +118,17 @@ void PlayerInfo::updateCurrentPlayingDeck() { double maxVolume = 0; int maxDeck = -1; + CSAMPLE_GAIN xfl, xfr; + // TODO: supply correct parameters to the function. If the hamster style + // for the crossfader is enabled, the result is currently wrong. + EngineXfader::getXfadeGains(m_pCOxfader->get(), + 1.0, + 0.0, + MIXXX_XFADER_ADDITIVE, + false, + &xfl, + &xfr); + for (int i = 0; i < (int)PlayerManager::numDecks(); ++i) { DeckControls* pDc = getDeckControls(i); @@ -129,12 +145,6 @@ void PlayerInfo::updateCurrentPlayingDeck() { continue; } - CSAMPLE_GAIN xfl, xfr; - // TODO: supply correct parameters to the function. If the hamster style - // for the crossfader is enabled, the result is currently wrong. - EngineXfader::getXfadeGains(m_pCOxfader->get(), 1.0, 0.0, MIXXX_XFADER_ADDITIVE, false, - &xfl, &xfr); - const auto orient = static_cast(pDc->m_orientation.get()); double xfvol; if (orient == EngineChannel::LEFT) { @@ -151,16 +161,16 @@ void PlayerInfo::updateCurrentPlayingDeck() { maxVolume = dvol; } } - if (maxDeck != m_currentlyPlayingDeck) { - m_currentlyPlayingDeck = maxDeck; - locker.unlock(); + locker.unlock(); + + int oldDeck = m_currentlyPlayingDeck.fetchAndStoreRelease(maxDeck); + if (maxDeck != oldDeck) { emit currentPlayingDeckChanged(maxDeck); emit currentPlayingTrackChanged(getCurrentPlayingTrack()); } } int PlayerInfo::getCurrentPlayingDeck() { - QMutexLocker locker(&m_mutex); return m_currentlyPlayingDeck; } diff --git a/src/mixer/playerinfo.h b/src/mixer/playerinfo.h index 2b06412cb09..7fc1035fcc9 100644 --- a/src/mixer/playerinfo.h +++ b/src/mixer/playerinfo.h @@ -1,6 +1,7 @@ // Helper class to have easy access #pragma once +#include #include #include #include @@ -57,7 +58,7 @@ class PlayerInfo : public QObject { ControlProxy* m_pCOxfader; // QMap is faster than QHash for small count of elements < 50 QMap m_loadedTrackMap; - int m_currentlyPlayingDeck; + QAtomicInt m_currentlyPlayingDeck; QList m_deckControlList; static PlayerInfo* m_pPlayerinfo;