diff --git a/src/library/dao/autodjcratesdao.cpp b/src/library/dao/autodjcratesdao.cpp index 7bb25346215..c4070b3d6ac 100644 --- a/src/library/dao/autodjcratesdao.cpp +++ b/src/library/dao/autodjcratesdao.cpp @@ -1072,24 +1072,25 @@ void AutoDJCratesDAO::slotPlaylistTrackRemoved(int playlistId, void AutoDJCratesDAO::slotPlayerInfoTrackChanged( const QString& group, TrackPointer pNewTrack, TrackPointer pOldTrack) { - playerInfoTrackUnloaded(group, pOldTrack); - playerInfoTrackLoaded(group, pNewTrack); + if (pOldTrack) { + playerInfoTrackUnloaded(group, pOldTrack->getId()); + } + if (pNewTrack) { + playerInfoTrackLoaded(group, pNewTrack->getId()); + } } // Signaled by the PlayerInfo singleton when a track is loaded to a deck. -void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& a_strGroup, - TrackPointer a_pTrack) { - // This gets called with a null track during an unload. Filter that out. - if (a_pTrack == nullptr) { +void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& group, + TrackId trackId) { + VERIFY_OR_DEBUG_ASSERT(trackId.isValid()) { return; } - // This counts as an auto-DJ reference. The idea is to prevent tracks that // are loaded into a deck from being randomly chosen. - TrackId trackId(a_pTrack->getId()); unsigned int numDecks = PlayerManager::numDecks(); for (unsigned int i = 0; i < numDecks; ++i) { - if (a_strGroup == PlayerManager::groupForDeck(i)) { + if (group == PlayerManager::groupForDeck(i)) { // Update the number of auto-DJ-playlist references to this track. QSqlQuery oQuery(m_database); // UPDATE temp_autodj_crates SET autodjrefs = autodjrefs + 1 @@ -1109,10 +1110,12 @@ void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& a_strGroup, // Signaled by the PlayerInfo singleton when a track is unloaded from a deck. void AutoDJCratesDAO::playerInfoTrackUnloaded(const QString& group, - TrackPointer pTrack) { + TrackId trackId) { + VERIFY_OR_DEBUG_ASSERT(trackId.isValid()) { + return; + } // This counts as an auto-DJ reference. The idea is to prevent tracks that // are loaded into a deck from being randomly chosen. - TrackId trackId(pTrack->getId()); unsigned int numDecks = PlayerManager::numDecks(); for (unsigned int i = 0; i < numDecks; ++i) { if (group == PlayerManager::groupForDeck(i)) { diff --git a/src/library/dao/autodjcratesdao.h b/src/library/dao/autodjcratesdao.h index 6e1be97411f..e82514340bd 100644 --- a/src/library/dao/autodjcratesdao.h +++ b/src/library/dao/autodjcratesdao.h @@ -97,8 +97,8 @@ class AutoDJCratesDAO : public QObject { TrackPointer pOldTrack); private: - void playerInfoTrackLoaded(const QString& group, TrackPointer pTrack); - void playerInfoTrackUnloaded(const QString& group, TrackPointer pTrack); + void playerInfoTrackLoaded(const QString& group, TrackId trackId); + void playerInfoTrackUnloaded(const QString& group, TrackId trackId); void updateAutoDjCrate(CrateId crateId); void deleteAutoDjCrate(CrateId crateId);