Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load tracks via TrackCollectionManager #3842

Merged
merged 2 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/analyzer/trackanalysisscheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "analyzer/trackanalysisscheduler.h"

#include "library/library.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "moc_trackanalysisscheduler.cpp"
#include "util/logger.h"

Expand Down Expand Up @@ -275,7 +275,7 @@ bool TrackAnalysisScheduler::submitNextTrack(Worker* worker) {
DEBUG_ASSERT(nextTrackId.isValid());
if (nextTrackId.isValid()) {
TrackPointer nextTrack =
m_library->trackCollection().getTrackById(nextTrackId);
m_library->trackCollections()->getTrackById(nextTrackId);
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
if (nextTrack) {
if (m_pendingTrackIds.insert(nextTrackId).second) {
if (worker->submitNextTrack(std::move(nextTrack))) {
Expand Down
8 changes: 5 additions & 3 deletions src/library/analysisfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "library/dlganalysis.h"
#include "library/library.h"
#include "library/librarytablemodel.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "moc_analysisfeature.cpp"
#include "sources/soundsourceproxy.h"
#include "util/debug.h"
Expand Down Expand Up @@ -226,8 +226,10 @@ void AnalysisFeature::onTrackAnalysisSchedulerFinished() {
}

bool AnalysisFeature::dropAccept(const QList<QUrl>& urls, QObject* pSource) {
QList<TrackId> trackIds = m_pLibrary->trackCollection().resolveTrackIdsFromUrls(urls,
!pSource);
const QList<TrackId> trackIds =
m_pLibrary->trackCollections()->resolveTrackIdsFromUrls(
urls,
!pSource);
analyzeTracks(trackIds);
return trackIds.size() > 0;
}
Expand Down
11 changes: 5 additions & 6 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ namespace {
} // anonymous namespace

AutoDJFeature::AutoDJFeature(Library* pLibrary,
UserSettingsPointer pConfig,
PlayerManagerInterface* pPlayerManager)
UserSettingsPointer pConfig,
PlayerManagerInterface* pPlayerManager)
: LibraryFeature(pLibrary, pConfig),
m_pTrackCollection(pLibrary->trackCollections()->internalCollection()),
m_playlistDao(m_pTrackCollection->getPlaylistDAO()),
m_iAutoDJPlaylistId(findOrCrateAutoDjPlaylistId(m_playlistDao)),
m_pAutoDJProcessor(nullptr),
m_pAutoDJView(nullptr),
m_autoDjCratesDao(m_iAutoDJPlaylistId, m_pTrackCollection, m_pConfig),
m_autoDjCratesDao(m_iAutoDJPlaylistId, pLibrary->trackCollections(), m_pConfig),
m_icon(":/images/library/ic_library_autodj.svg") {

qRegisterMetaType<AutoDJProcessor::AutoDJState>("AutoDJState");
m_pAutoDJProcessor = new AutoDJProcessor(
this, m_pConfig, pPlayerManager, pLibrary->trackCollections(), m_iAutoDJPlaylistId);
Expand Down Expand Up @@ -169,7 +168,7 @@ bool AutoDJFeature::dropAccept(const QList<QUrl>& urls, QObject* pSource) {
// Auto DJ playlist.
// pSource != nullptr it is a drop from inside Mixxx and indicates all
// tracks already in the DB
QList<TrackId> trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(urls,
QList<TrackId> trackIds = m_pLibrary->trackCollections()->resolveTrackIdsFromUrls(urls,
!pSource);
if (trackIds.isEmpty()) {
return false;
Expand Down Expand Up @@ -250,7 +249,7 @@ void AutoDJFeature::slotAddRandomTrack() {
}

if (randomTrackId.isValid()) {
pRandomTrack = m_pTrackCollection->getTrackById(randomTrackId);
pRandomTrack = m_pLibrary->trackCollections()->getTrackById(randomTrackId);
VERIFY_OR_DEBUG_ASSERT(pRandomTrack) {
qWarning() << "Track does not exist:"
<< randomTrackId;
Expand Down
2 changes: 1 addition & 1 deletion src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ bool BaseSqlTableModel::setTrackValueForColumn(
}

TrackPointer BaseSqlTableModel::getTrack(const QModelIndex& index) const {
return m_pTrackCollectionManager->internalCollection()->getTrackById(getTrackId(index));
return m_pTrackCollectionManager->getTrackById(getTrackId(index));
}

TrackId BaseSqlTableModel::getTrackId(const QModelIndex& index) const {
Expand Down
2 changes: 1 addition & 1 deletion src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ void BaseTrackTableModel::emitDataChangedForMultipleRowsInColumn(

TrackPointer BaseTrackTableModel::getTrackByRef(
const TrackRef& trackRef) const {
return m_pTrackCollectionManager->internalCollection()->getTrackByRef(trackRef);
return m_pTrackCollectionManager->getTrackByRef(trackRef);
}

TrackId BaseTrackTableModel::doGetTrackId(
Expand Down
45 changes: 24 additions & 21 deletions src/library/dao/autodjcratesdao.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "library/dao/autodjcratesdao.h"

#include "moc_autodjcratesdao.cpp"

#include <QRandomGenerator>
#include <QtDebug>
#include <QtSql>
Expand All @@ -11,9 +9,11 @@
#include "library/dao/trackschema.h"
#include "library/queryutil.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "library/trackset/crate/crateschema.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "moc_autodjcratesdao.cpp"
#include "track/track.h"

#if !defined(VERBOSE_DEBUG_LOG)
Expand Down Expand Up @@ -58,11 +58,11 @@ int bounded_rand(int highest) {

AutoDJCratesDAO::AutoDJCratesDAO(
int iAutoDjPlaylistId,
TrackCollection* pTrackCollection,
TrackCollectionManager* pTrackCollectionManager,
UserSettingsPointer pConfig)
: m_iAutoDjPlaylistId(iAutoDjPlaylistId),
m_pTrackCollection(pTrackCollection),
m_database(pTrackCollection->database()),
m_pTrackCollectionManager(pTrackCollectionManager),
m_database(pTrackCollectionManager->internalCollection()->database()),
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
m_pConfig(pConfig),
// The database has not been created yet.
m_bAutoDjCratesDbCreated(false),
Expand Down Expand Up @@ -216,47 +216,47 @@ void AutoDJCratesDAO::createAndConnectAutoDjCratesDatabase() {

// Be notified when a track is modified.
// We only care when the number of times it's been played changes.
connect(m_pTrackCollection,
connect(m_pTrackCollectionManager->internalCollection(),
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
&TrackCollection::trackDirty,
this,
&AutoDJCratesDAO::slotTrackDirty);

// Be notified when the status of crates changes.
connect(m_pTrackCollection,
connect(m_pTrackCollectionManager->internalCollection(),
&TrackCollection::crateInserted,
this,
&AutoDJCratesDAO::slotCrateInserted);
connect(m_pTrackCollection,
connect(m_pTrackCollectionManager->internalCollection(),
&TrackCollection::crateDeleted,
this,
&AutoDJCratesDAO::slotCrateDeleted);
connect(m_pTrackCollection,
connect(m_pTrackCollectionManager->internalCollection(),
&TrackCollection::crateUpdated,
this,
&AutoDJCratesDAO::slotCrateUpdated);
connect(m_pTrackCollection,
connect(m_pTrackCollectionManager->internalCollection(),
&TrackCollection::crateTracksChanged,
this,
&AutoDJCratesDAO::slotCrateTracksChanged);

// Be notified when playlists are added/removed.
// We only care about set-log playlists.
connect(&m_pTrackCollection->getPlaylistDAO(),
connect(&m_pTrackCollectionManager->internalCollection()->getPlaylistDAO(),
&PlaylistDAO::added,
this,
&AutoDJCratesDAO::slotPlaylistAdded);
connect(&m_pTrackCollection->getPlaylistDAO(),
connect(&m_pTrackCollectionManager->internalCollection()->getPlaylistDAO(),
&PlaylistDAO::deleted,
this,
&AutoDJCratesDAO::slotPlaylistDeleted);

// Be notified when tracks are added/removed from playlists.
// We only care about the auto-DJ playlist and the set-log playlists.
connect(&m_pTrackCollection->getPlaylistDAO(),
connect(&m_pTrackCollectionManager->internalCollection()->getPlaylistDAO(),
&PlaylistDAO::trackAdded,
this,
&AutoDJCratesDAO::slotPlaylistTrackAdded);
connect(&m_pTrackCollection->getPlaylistDAO(),
connect(&m_pTrackCollectionManager->internalCollection()->getPlaylistDAO(),
&PlaylistDAO::trackRemoved,
this,
&AutoDJCratesDAO::slotPlaylistTrackRemoved);
Expand Down Expand Up @@ -732,7 +732,7 @@ TrackId AutoDJCratesDAO::getRandomTrackIdFromAutoDj(int percentActive) {
// Signaled by the track DAO when a track's information is updated.
void AutoDJCratesDAO::slotTrackDirty(TrackId trackId) {
// Update our record of the number of times played, if that changed.
TrackPointer pTrack = m_pTrackCollection->getTrackById(trackId);
TrackPointer pTrack = m_pTrackCollectionManager->getTrackById(trackId);
if (!pTrack) {
return;
}
Expand Down Expand Up @@ -763,7 +763,7 @@ void AutoDJCratesDAO::slotTrackDirty(TrackId trackId) {
void AutoDJCratesDAO::slotCrateInserted(CrateId crateId) {
// If this newly-added crate is in the auto-DJ queue, add it to the list.
Crate crate;
if (m_pTrackCollection->crates().readCrateById(crateId, &crate)) {
if (m_pTrackCollectionManager->internalCollection()->crates().readCrateById(crateId, &crate)) {
if (crate.isAutoDjSource()) {
updateAutoDjCrate(crateId);
}
Expand All @@ -772,7 +772,7 @@ void AutoDJCratesDAO::slotCrateInserted(CrateId crateId) {

void AutoDJCratesDAO::slotCrateUpdated(CrateId crateId) {
Crate crate;
if (m_pTrackCollection->crates().readCrateById(crateId, &crate)) {
if (m_pTrackCollectionManager->internalCollection()->crates().readCrateById(crateId, &crate)) {
if (crate.isAutoDjSource()) {
updateAutoDjCrate(crateId);
} else {
Expand Down Expand Up @@ -918,8 +918,10 @@ void AutoDJCratesDAO::slotCrateTracksChanged(
const QList<TrackId>& removedTrackIds) {
// Skip this if it's not an auto-DJ crate.
Crate crate;
if (!m_pTrackCollection->crates().readCrateById(crateId, &crate)
|| !crate.isAutoDjSource()) {
if (!m_pTrackCollectionManager->internalCollection()
->crates()
.readCrateById(crateId, &crate) ||
!crate.isAutoDjSource()) {
return;
}

Expand Down Expand Up @@ -1009,8 +1011,9 @@ void AutoDJCratesDAO::slotCrateTracksChanged(
// Signaled by the playlistDAO when a playlist is added.
void AutoDJCratesDAO::slotPlaylistAdded(int playlistId) {
// We only care about changes to set-log playlists.
if (m_pTrackCollection->getPlaylistDAO().getHiddenType(playlistId)
== PlaylistDAO::PLHT_SET_LOG) {
if (m_pTrackCollectionManager->internalCollection()
->getPlaylistDAO()
.getHiddenType(playlistId) == PlaylistDAO::PLHT_SET_LOG) {
m_lstSetLogPlaylistIds.append(playlistId);
updateLastPlayedDateTime();
}
Expand Down
6 changes: 3 additions & 3 deletions src/library/dao/autodjcratesdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "track/trackid.h"
#include "util/class.h"

class TrackCollection;
class TrackCollectionManager;

class AutoDJCratesDAO : public QObject {
Q_OBJECT
public:
AutoDJCratesDAO(
int iAutoDjPlaylistId,
TrackCollection* pTrackCollection,
TrackCollectionManager* pTrackCollectionManager,
UserSettingsPointer a_pConfig);
~AutoDJCratesDAO() override;

Expand Down Expand Up @@ -99,7 +99,7 @@ class AutoDJCratesDAO : public QObject {
// The auto-DJ playlist's ID.
const int m_iAutoDjPlaylistId;

TrackCollection* m_pTrackCollection;
TrackCollectionManager* m_pTrackCollectionManager;

// The SQL database we interact with.
QSqlDatabase m_database;
Expand Down
6 changes: 0 additions & 6 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,6 @@ void Library::setEditMedatataSelectedClick(bool enabled) {
emit setSelectedClick(enabled);
}

TrackCollection& Library::trackCollection() {
DEBUG_ASSERT(m_pTrackCollectionManager);
DEBUG_ASSERT(m_pTrackCollectionManager->internalCollection());
return *m_pTrackCollectionManager->internalCollection();
}

void Library::searchTracksInCollection(const QString& query) {
VERIFY_OR_DEBUG_ASSERT(m_pMixxxLibraryFeature) {
return;
Expand Down
3 changes: 0 additions & 3 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class Library: public QObject {

TrackCollectionManager* trackCollections() const;

// Deprecated: Obtain directly from TrackCollectionManager
TrackCollection& trackCollection();

void bindSearchboxWidget(WSearchLineEdit* pSearchboxWidget);
void bindSidebarWidget(WLibrarySidebar* sidebarWidget);
void bindLibraryWidget(WLibrary* libraryWidget,
Expand Down
2 changes: 1 addition & 1 deletion src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void LibraryTableModel::setTableModel() {
int LibraryTableModel::addTracks(const QModelIndex& index,
const QList<QString>& locations) {
Q_UNUSED(index);
QList<TrackId> trackIds = m_pTrackCollectionManager->internalCollection()->resolveTrackIdsFromLocations(
QList<TrackId> trackIds = m_pTrackCollectionManager->resolveTrackIdsFromLocations(
locations);
select();
return trackIds.size();
Expand Down
2 changes: 1 addition & 1 deletion src/library/mixxxlibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool MixxxLibraryFeature::dropAccept(const QList<QUrl>& urls, QObject* pSource)
if (pSource) {
return false;
} else {
QList<TrackId> trackIds = m_pTrackCollection->resolveTrackIdsFromUrls(
QList<TrackId> trackIds = m_pLibrary->trackCollections()->resolveTrackIdsFromUrls(
urls, true);
return trackIds.size() > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int PlaylistTableModel::addTracks(const QModelIndex& index,
return 0;
}

QList<TrackId> trackIds = m_pTrackCollectionManager->internalCollection()->resolveTrackIdsFromLocations(
QList<TrackId> trackIds = m_pTrackCollectionManager->resolveTrackIdsFromLocations(
locations);

const int positionColumn = fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION);
Expand Down
39 changes: 23 additions & 16 deletions src/library/trackcollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ class TrackCollection : public QObject,
return m_pTrackSource;
}

// This function returns a track ID of all file in the list not already visible,
// it adds and unhides the tracks as well.
QList<TrackId> resolveTrackIds(
const QList<mixxx::FileInfo>& trackFiles,
TrackDAO::ResolveTrackIdFlags flags);
QList<TrackId> resolveTrackIdsFromUrls(
const QList<QUrl>& urls,
bool addMissing);
QList<TrackId> resolveTrackIdsFromLocations(
const QList<QString>& locations);

bool insertCrate(const Crate& crate, CrateId* pCrateId = nullptr);
bool updateCrate(const Crate& crate);
bool deleteCrate(CrateId crateId);
Expand All @@ -95,11 +84,6 @@ class TrackCollection : public QObject,

bool updateAutoDjCrate(CrateId crateId, bool isAutoDjSource);

TrackPointer getTrackById(
TrackId trackId) const;

TrackPointer getTrackByRef(
const TrackRef& trackRef) const;
TrackId getTrackIdByRef(
const TrackRef& trackRef) const;

Expand Down Expand Up @@ -135,6 +119,29 @@ class TrackCollection : public QObject,
: TrackCollection(nullptr, pConfig) {
}

// TODO: All functions that load tracks or that may add tracks
// will soon require additional context data that is provided
// by TrackCollectionManager as an additional parameter. These
// functions must only be invoked by TrackCollectionManager and
// therefore don't appear in the public interface of this class.
// See also: https://github.com/mixxxdj/mixxx/pull/2656

// This function returns a track ID of all file in the list not already visible,
// it adds and unhides the tracks as well.
QList<TrackId> resolveTrackIds(
const QList<mixxx::FileInfo>& trackFiles,
TrackDAO::ResolveTrackIdFlags flags);
QList<TrackId> resolveTrackIdsFromUrls(
const QList<QUrl>& urls,
bool addMissing);
QList<TrackId> resolveTrackIdsFromLocations(
const QList<QString>& locations);

TrackPointer getTrackById(
TrackId trackId) const;
TrackPointer getTrackByRef(
const TrackRef& trackRef) const;

TrackPointer getOrAddTrack(
const TrackRef& trackRef,
bool* pAlreadyInLibrary = nullptr);
Expand Down
4 changes: 2 additions & 2 deletions src/library/trackcollectioniterator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "library/trackcollectioniterator.h"

#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"

namespace mixxx {

Expand All @@ -11,7 +11,7 @@ std::optional<TrackPointer> TrackByIdCollectionIterator::nextItem() {
return std::nullopt;
}
const auto trackPtr =
m_pTrackCollection->getTrackById(*nextTrackId);
m_pTrackCollectionManager->getTrackById(*nextTrackId);
if (!trackPtr) {
return std::nullopt;
}
Expand Down
Loading