Skip to content

Commit

Permalink
Merge pull request #3871 from uklotzde/soundsourceproxy
Browse files Browse the repository at this point in the history
SoundSourceProxy: Code renaming/reordering
  • Loading branch information
Holzhaus committed May 17, 2021
2 parents 8051c05 + bd4c757 commit 02bc335
Showing 1 changed file with 27 additions and 22 deletions.
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

0 comments on commit 02bc335

Please sign in to comment.