Update temporary metadata when tags are changed

This commit is contained in:
Jonas Kvinge 2019-12-21 21:55:24 +01:00
parent 97bc980611
commit 882c94110e
3 changed files with 14 additions and 0 deletions

View File

@ -76,6 +76,18 @@ void PlaylistItem::SetTemporaryMetadata(const Song &metadata) {
temp_metadata_ = metadata;
}
void PlaylistItem::UpdateTemporaryMetadata(const Song &metadata) {
Song old_metadata = temp_metadata_;
temp_metadata_ = metadata;
// Keep samplerate, bitdepth and bitrate from the old metadata if it's not present in the new.
if (temp_metadata_.samplerate() <= 0 && old_metadata.samplerate() > 0) temp_metadata_.set_samplerate(old_metadata.samplerate());
if (temp_metadata_.bitdepth() <= 0 && old_metadata.bitdepth() > 0) temp_metadata_.set_bitdepth(old_metadata.bitdepth());
if (temp_metadata_.bitrate() <= 0 && old_metadata.bitrate() > 0) temp_metadata_.set_bitrate(old_metadata.bitrate());
}
void PlaylistItem::ClearTemporaryMetadata() {
temp_metadata_ = Song();
}

View File

@ -79,6 +79,7 @@ class PlaylistItem : public std::enable_shared_from_this<PlaylistItem> {
virtual QUrl Url() const = 0;
void SetTemporaryMetadata(const Song &metadata);
void UpdateTemporaryMetadata(const Song &metadata);
void ClearTemporaryMetadata();
bool HasTemporaryMetadata() const { return temp_metadata_.is_valid(); }

View File

@ -469,6 +469,7 @@ void PlaylistManager::SongsDiscovered(const SongList &songs) {
for (const PlaylistItemPtr item : items) {
if (item->Metadata().directory_id() != song.directory_id()) continue;
static_cast<CollectionPlaylistItem*>(item.get())->SetMetadata(song);
item->UpdateTemporaryMetadata(song);
data.p->ItemChanged(item);
}
}