Skip to content

Commit

Permalink
Merge pull request #4475 from uklotzde/track-by-url
Browse files Browse the repository at this point in the history
TrackDAO: Load a single track by URL
  • Loading branch information
Be-ing authored Oct 23, 2021
2 parents f2b1192 + 095de26 commit 55d2461
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/library/dao/trackdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC
/// access as a friend.
static bool getTrackHeaderParsedInternal(const mixxx::TrackRecord& trackRecord);

/// Lookup and load a track by URL.
///
/// Only local file URLs are supported.
///
/// Returns `nullptr` if no track matches the given URL.
TrackPointer getTrackByUrl(const QUrl& url) const {
return getTrackByRef(TrackRef::fromUrl(url));
}

signals:
// Forwarded from Track object
void trackDirty(TrackId trackId);
Expand Down
8 changes: 8 additions & 0 deletions src/track/trackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class TrackRef final {
std::move(id));
}

/// Convert a local file URL into a TrackRef.
static TrackRef fromUrl(
const QUrl& url,
TrackId id = TrackId()) {
const auto fileInfo = mixxx::FileInfo::fromQUrl(url);
return TrackRef::fromFileInfo(fileInfo, id);
}

// Default constructor
TrackRef() {
DEBUG_ASSERT(verifyConsistency());
Expand Down

0 comments on commit 55d2461

Please sign in to comment.