Skip to content

Commit

Permalink
Add an option to resolve a temporary track for the case when metadata…
Browse files Browse the repository at this point in the history
… shall not be stored in library and track file.
  • Loading branch information
daschuer committed Nov 26, 2024
1 parent cdb91bb commit 4ebda38
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ BaseTrackPlayerImpl::~BaseTrackPlayerImpl() {
}

TrackPointer BaseTrackPlayerImpl::loadFakeTrack(bool bPlay, double filebpm) {
TrackPointer pTrack(Track::newTemporary());
TrackPointer pTrack = Track::newTemporary();
pTrack->setAudioProperties(
mixxx::kEngineChannelCount,
mixxx::audio::SampleRate(44100),
Expand Down
54 changes: 52 additions & 2 deletions src/track/globaltrackcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ QSet<TrackId> GlobalTrackCacheLocker::getCachedTrackIds() const {
}

GlobalTrackCacheResolver::GlobalTrackCacheResolver(
mixxx::FileAccess fileAccess)
mixxx::FileAccess fileAccess,
bool temporary)
: m_lookupResult(GlobalTrackCacheLookupResult::None) {
DEBUG_ASSERT(m_pInstance);
m_pInstance->resolve(this, std::move(fileAccess), TrackId());
if (temporary) {
m_pInstance->resolveTemporary(this, std::move(fileAccess));
} else {
m_pInstance->resolve(this, std::move(fileAccess), TrackId());
}
m_pInstance->m_mutex.unlock();
}

Expand Down Expand Up @@ -685,6 +690,51 @@ void GlobalTrackCache::resolve(
std::move(trackRef));
}

void GlobalTrackCache::resolveTemporary(
GlobalTrackCacheResolver* /*in/out*/ pCacheResolver,
mixxx::FileAccess /*in*/ fileAccess) {
DEBUG_ASSERT(pCacheResolver);

TrackPointer pTrack;

auto trackRef = TrackRef::fromFileInfo(fileAccess.info());
if (trackRef.hasCanonicalLocation()) {
pTrack = lookupByCanonicalLocation(trackRef.getCanonicalLocation());
if (pTrack) {
// Multiple tracks may reference the same physical file on disk
auto cachedTrackRef = createTrackRef(*pTrack);
if (trackRef.getLocation() != cachedTrackRef.getLocation()) {
kLogger.warning()
<< "Found a different track for the same canonical location:"
<< "requested =" << trackRef
<< "cached =" << cachedTrackRef;
pCacheResolver->initLookupResult(
GlobalTrackCacheLookupResult::ConflictCanonicalLocation,
TrackPointer(),
std::move(cachedTrackRef));
} else {
pCacheResolver->initLookupResult(
GlobalTrackCacheLookupResult::Hit,
std::move(pTrack),
std::move(cachedTrackRef));
}
return;
}
}

pTrack = Track::newTemporary(std::move(fileAccess));
while (m_incompletTrack) {
// Wait for completion.
m_isTrackCompleted.wait(&m_mutex);
// now the track should be empty
}
m_incompletTrack = pTrack;
pCacheResolver->initLookupResult(
GlobalTrackCacheLookupResult::Miss,
std::move(pTrack),
std::move(trackRef));
}

TrackRef GlobalTrackCache::initTrackId(
const TrackPointer& strongPtr,
const TrackRef& trackRef,
Expand Down
11 changes: 8 additions & 3 deletions src/track/globaltrackcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class GlobalTrackCacheLocker {
class GlobalTrackCacheResolver final: public GlobalTrackCacheLocker {
public:
GlobalTrackCacheResolver(
mixxx::FileAccess fileAccess);
mixxx::FileAccess fileAccess,
bool temporary = false);
GlobalTrackCacheResolver(
mixxx::FileAccess fileAccess,
TrackId trackId);
Expand Down Expand Up @@ -252,8 +253,12 @@ class GlobalTrackCache : public QObject {

void resolve(
GlobalTrackCacheResolver* /*in/out*/ pCacheResolver,
mixxx::FileAccess /*in*/ fileAccess,
TrackId /*in*/ trackId);
mixxx::FileAccess fileAccess,
TrackId trackId);

void resolveTemporary(
GlobalTrackCacheResolver* /*in/out*/ pCacheResolver,
mixxx::FileAccess fileAccess);

TrackRef initTrackId(
const TrackPointer& strongPtr,
Expand Down

0 comments on commit 4ebda38

Please sign in to comment.