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

SoundSourceProxy: Code renaming/reordering #3871

Merged
merged 2 commits into from
May 17, 2021
Merged
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
49 changes: 27 additions & 22 deletions src/sources/soundsourceproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,6 @@ bool SoundSourceProxy::updateTrackFromSource(
bool metadataSynchronized = false;
mixxx::TrackMetadata trackMetadata =
m_pTrack->getMetadata(&metadataSynchronized);
// If the file tags have already been parsed at least once, the
// existing track metadata should not be updated implicitly, i.e.
// if the user did not explicitly choose to (re-)import metadata
// explicitly from this file.
bool mergeExtraMetadataFromSource = false;
if (metadataSynchronized && mode == UpdateTrackFromSourceMode::Once) {
// No (re-)import needed or desired, only merge missing properties
mergeExtraMetadataFromSource = true;
}

// Save for later to replace the unreliable and imprecise audio
// properties imported from file tags (see below).
Expand All @@ -562,7 +553,17 @@ bool SoundSourceProxy::updateTrackFromSource(
QImage coverImg;
DEBUG_ASSERT(coverImg.isNull());
QImage* pCoverImg = nullptr; // pointer also serves as a flag
if (!mergeExtraMetadataFromSource) {

// If the file tags have already been parsed at least once, the
// existing track metadata should not be updated implicitly, i.e.
// if the user did not explicitly choose to (re-)import metadata
// explicitly from this file.
bool mergeExtraMetadataFromSource = false;
if (metadataSynchronized && mode == UpdateTrackFromSourceMode::Once) {
// No (re-)import needed or desired, only merge missing properties
mergeExtraMetadataFromSource = true;
} else {
// Import the cover initially or when a reimport has been requested
const auto coverInfo = m_pTrack->getCoverInfo();
if (coverInfo.source == CoverInfo::USER_SELECTED &&
coverInfo.type == CoverInfo::FILE) {
Expand All @@ -579,10 +580,12 @@ bool SoundSourceProxy::updateTrackFromSource(
}

// Parse the tags stored in the audio file
auto metadataImported =
m_pSoundSource->importTrackMetadataAndCoverImage(
&trackMetadata, pCoverImg);
if (metadataImported.first == mixxx::MetadataSource::ImportResult::Failed) {
auto metadataImportedFromSource =
importTrackMetadataAndCoverImage(
&trackMetadata,
pCoverImg);
if (metadataImportedFromSource.first ==
mixxx::MetadataSource::ImportResult::Failed) {
kLogger.warning()
<< "Failed to import track metadata"
<< (pCoverImg ? "and embedded cover art" : "")
Expand All @@ -596,7 +599,7 @@ bool SoundSourceProxy::updateTrackFromSource(
if (mergeExtraMetadataFromSource) {
// No reimport of embedded cover image desired in this case
DEBUG_ASSERT(!pCoverImg);
if (metadataImported.first == mixxx::MetadataSource::ImportResult::Succeeded) {
if (metadataImportedFromSource.first == mixxx::MetadataSource::ImportResult::Succeeded) {
// Partial import of properties that are not (yet) stored
// in the database
return m_pTrack->mergeExtraMetadataFromSource(trackMetadata);
Expand Down Expand Up @@ -669,26 +672,28 @@ bool SoundSourceProxy::updateTrackFromSource(
if (trackMetadata.refTrackInfo().parseArtistTitleFromFileName(
fileInfo.fileName(), splitArtistTitle)) {
// Pretend that metadata import succeeded
metadataImported.first = mixxx::MetadataSource::ImportResult::Succeeded;
if (metadataImported.second.isNull()) {
metadataImportedFromSource.first = mixxx::MetadataSource::ImportResult::Succeeded;
if (metadataImportedFromSource.second.isNull()) {
// Since this is also some kind of metadata import, we mark the
// track's metadata as synchronized with the time stamp of the file.
metadataImported.second = fileInfo.lastModified();
metadataImportedFromSource.second = fileInfo.lastModified();
}
}
}

// Do not continue with unknown and maybe invalid metadata!
if (metadataImported.first != mixxx::MetadataSource::ImportResult::Succeeded) {
if (metadataImportedFromSource.first != mixxx::MetadataSource::ImportResult::Succeeded) {
return false;
}

m_pTrack->replaceMetadataFromSource(
std::move(trackMetadata),
metadataImported.second);
metadataImportedFromSource.second);

bool pendingBeatsImport = m_pTrack->getBeatsImportStatus() == Track::ImportStatus::Pending;
bool pendingCueImport = m_pTrack->getCueImportStatus() == Track::ImportStatus::Pending;
const bool pendingBeatsImport =
m_pTrack->getBeatsImportStatus() == Track::ImportStatus::Pending;
const bool pendingCueImport =
m_pTrack->getCueImportStatus() == Track::ImportStatus::Pending;
if (pendingBeatsImport || pendingCueImport) {
// Try to open the audio source once to determine the actual
// stream properties for finishing the pending import.
Expand Down