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 all commits
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->trackCollectionManager()->getTrackById(nextTrackId);
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->trackCollectionManager()->resolveTrackIdsFromUrls(
urls,
!pSource);
analyzeTracks(trackIds);
return trackIds.size() > 0;
}
Expand Down
20 changes: 11 additions & 9 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@ namespace {
} // anonymous namespace

AutoDJFeature::AutoDJFeature(Library* pLibrary,
UserSettingsPointer pConfig,
PlayerManagerInterface* pPlayerManager)
UserSettingsPointer pConfig,
PlayerManagerInterface* pPlayerManager)
: LibraryFeature(pLibrary, pConfig),
m_pTrackCollection(pLibrary->trackCollections()->internalCollection()),
m_pTrackCollection(pLibrary->trackCollectionManager()->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->trackCollectionManager(), 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);
m_pAutoDJProcessor = new AutoDJProcessor(this,
m_pConfig,
pPlayerManager,
pLibrary->trackCollectionManager(),
m_iAutoDJPlaylistId);
connect(m_pAutoDJProcessor,
&AutoDJProcessor::loadTrackToPlayer,
this,
Expand Down Expand Up @@ -169,7 +171,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->trackCollectionManager()->resolveTrackIdsFromUrls(urls,
!pSource);
if (trackIds.isEmpty()) {
return false;
Expand Down Expand Up @@ -250,7 +252,7 @@ void AutoDJFeature::slotAddRandomTrack() {
}

if (randomTrackId.isValid()) {
pRandomTrack = m_pTrackCollection->getTrackById(randomTrackId);
pRandomTrack = m_pLibrary->trackCollectionManager()->getTrackById(randomTrackId);
VERIFY_OR_DEBUG_ASSERT(pRandomTrack) {
qWarning() << "Track does not exist:"
<< randomTrackId;
Expand Down
8 changes: 6 additions & 2 deletions src/library/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ BansheeFeature::BansheeFeature(Library* pLibrary, UserSettingsPointer pConfig)
m_cancelImport(false),
m_icon(":/images/library/ic_library_banshee.svg") {
Q_UNUSED(pConfig);
m_pBansheePlaylistModel = new BansheePlaylistModel(this, m_pLibrary->trackCollections(), &m_connection);
m_pBansheePlaylistModel = new BansheePlaylistModel(
this, m_pLibrary->trackCollectionManager(), &m_connection);
m_isActivated = false;
m_title = tr("Banshee");
}
Expand Down Expand Up @@ -140,7 +141,10 @@ void BansheeFeature::appendTrackIdsFromRightClickIndex(QList<TrackId>* trackIds,
int playlistID = item->getData().toInt();
qDebug() << "BansheeFeature::appendTrackIdsFromRightClickIndex " << *pPlaylist << " " << playlistID;
if (playlistID > 0) {
BansheePlaylistModel* pPlaylistModelToAdd = new BansheePlaylistModel(this, m_pLibrary->trackCollections(), &m_connection);
BansheePlaylistModel* pPlaylistModelToAdd =
new BansheePlaylistModel(this,
m_pLibrary->trackCollectionManager(),
&m_connection);
pPlaylistModelToAdd->setTableModel(playlistID);
pPlaylistModelToAdd->select();

Expand Down
2 changes: 1 addition & 1 deletion src/library/baseexternallibraryfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ BaseExternalLibraryFeature::BaseExternalLibraryFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
: LibraryFeature(pLibrary, pConfig),
m_pTrackCollection(pLibrary->trackCollections()->internalCollection()) {
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()) {
m_pAddToAutoDJAction = make_parented<QAction>(tr("Add to Auto DJ Queue (bottom)"), this);
connect(m_pAddToAutoDJAction,
&QAction::triggered,
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
8 changes: 5 additions & 3 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ BrowseFeature::BrowseFeature(
UserSettingsPointer pConfig,
RecordingManager* pRecordingManager)
: LibraryFeature(pLibrary, pConfig),
m_pTrackCollection(pLibrary->trackCollections()->internalCollection()),
m_browseModel(this, pLibrary->trackCollections(), pRecordingManager),
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()),
m_browseModel(this, pLibrary->trackCollectionManager(), pRecordingManager),
m_proxyModel(&m_browseModel),
m_pLastRightClickedItem(nullptr),
m_icon(":/images/library/ic_library_computer.svg") {
Expand Down Expand Up @@ -485,7 +485,9 @@ QStringList BrowseFeature::getDefaultQuickLinks() const {
bool osDownloadsDirIncluded = false;
bool osDesktopDirIncluded = false;
bool osDocumentsDirIncluded = false;
const auto rootDirs = m_pLibrary->trackCollections()->internalCollection()->loadRootDirs();
const auto rootDirs = m_pLibrary->trackCollectionManager()
->internalCollection()
->loadRootDirs();
for (mixxx::FileInfo fileInfo : rootDirs) {
// Skip directories we don't have permission to.
if (!Sandbox::canAccess(&fileInfo)) {
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
3 changes: 2 additions & 1 deletion src/library/dlganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ DlgAnalysis::DlgAnalysis(WLibrary* parent,
box->insertWidget(1, m_pAnalysisLibraryTableView);
}

m_pAnalysisLibraryTableModel = new AnalysisLibraryTableModel(this, pLibrary->trackCollections());
m_pAnalysisLibraryTableModel = new AnalysisLibraryTableModel(
this, pLibrary->trackCollectionManager());
m_pAnalysisLibraryTableView->loadTrackModel(m_pAnalysisLibraryTableModel);

connect(radioButtonRecentlyAdded,
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlghidden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DlgHidden::DlgHidden(
box->insertWidget(1, m_pTrackTableView);
}

m_pHiddenTableModel = new HiddenTableModel(this, pLibrary->trackCollections());
m_pHiddenTableModel = new HiddenTableModel(this, pLibrary->trackCollectionManager());
m_pTrackTableView->loadTrackModel(m_pHiddenTableModel);

connect(btnUnhide,
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlgmissing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DlgMissing::DlgMissing(
box->insertWidget(1, m_pTrackTableView);
}

m_pMissingTableModel = new MissingTableModel(this, pLibrary->trackCollections());
m_pMissingTableModel = new MissingTableModel(this, pLibrary->trackCollectionManager());
m_pTrackTableView->loadTrackModel(m_pMissingTableModel);

connect(btnPurge, &QPushButton::clicked, m_pTrackTableView, &WTrackTableView::slotPurge);
Expand Down
Loading