From 26951695144b1a65b413cc817257cfd6fe9cd15a Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 13 Mar 2021 03:14:30 +0100 Subject: [PATCH] Add type to metadata bundle to avoid updating previous song when it shouldn't --- src/core/player.cpp | 34 +++++++++++++++++--------------- src/engine/enginebase.h | 13 ++++++++---- src/engine/gstengine.cpp | 2 ++ src/engine/gstenginepipeline.cpp | 1 + 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/core/player.cpp b/src/core/player.cpp index d97e5a41..cc889d46 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -666,24 +666,26 @@ void Player::SeekBackward() { void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle &bundle) { - PlaylistItemPtr item = app_->playlist_manager()->active()->current_item(); - if (!item) return; - - if (bundle.url == item->Url()) { - Song song = item->Metadata(); - bool minor = song.MergeFromSimpleMetaBundle(bundle); - app_->playlist_manager()->active()->SetStreamMetadata(item->Url(), song, minor); - return; + if (bundle.type == Engine::SimpleMetaBundle::Type_Any || bundle.type == Engine::SimpleMetaBundle::Type_Current) { + PlaylistItemPtr item = app_->playlist_manager()->active()->current_item(); + if (item && bundle.url == item->Url()) { + Song song = item->Metadata(); + bool minor = song.MergeFromSimpleMetaBundle(bundle); + app_->playlist_manager()->active()->SetStreamMetadata(item->Url(), song, minor); + return; + } } - int next_row = app_->playlist_manager()->active()->next_row(); - if (next_row != -1) { - PlaylistItemPtr next_item = app_->playlist_manager()->active()->item_at(next_row); - if (bundle.url == next_item->Url()) { - Song song = next_item->Metadata(); - song.MergeFromSimpleMetaBundle(bundle); - next_item->SetTemporaryMetadata(song); - app_->playlist_manager()->active()->ItemChanged(next_row); + if (bundle.type == Engine::SimpleMetaBundle::Type_Any || bundle.type == Engine::SimpleMetaBundle::Type_Next) { + int next_row = app_->playlist_manager()->active()->next_row(); + if (next_row != -1) { + PlaylistItemPtr next_item = app_->playlist_manager()->active()->item_at(next_row); + if (bundle.url == next_item->Url()) { + Song song = next_item->Metadata(); + song.MergeFromSimpleMetaBundle(bundle); + next_item->SetTemporaryMetadata(song); + app_->playlist_manager()->active()->ItemChanged(next_row); + } } } diff --git a/src/engine/enginebase.h b/src/engine/enginebase.h index eb9d834a..9802702d 100644 --- a/src/engine/enginebase.h +++ b/src/engine/enginebase.h @@ -52,11 +52,10 @@ typedef std::vector Scope; class Base : public QObject { Q_OBJECT -protected: + protected: Base(); -public: - + public: ~Base() override; struct OutputDetails { @@ -213,7 +212,13 @@ public: }; struct SimpleMetaBundle { - SimpleMetaBundle() : length(-1), year(-1), track(-1), filetype(Song::FileType_Unknown), samplerate(-1), bitdepth(-1), bitrate(-1) {} + SimpleMetaBundle() : type(Type_Any), length(-1), year(-1), track(-1), filetype(Song::FileType_Unknown), samplerate(-1), bitdepth(-1), bitrate(-1) {} + enum Type { + Type_Any, + Type_Current, + Type_Next, + }; + Type type; QUrl url; QUrl stream_url; QString title; diff --git a/src/engine/gstengine.cpp b/src/engine/gstengine.cpp index b62fa8ff..4b441e09 100644 --- a/src/engine/gstengine.cpp +++ b/src/engine/gstengine.cpp @@ -930,9 +930,11 @@ void GstEngine::StreamDiscovered(GstDiscoverer*, GstDiscovererInfo *info, GError Engine::SimpleMetaBundle bundle; if (discovered_url == instance->current_pipeline_->stream_url()) { + bundle.type = Engine::SimpleMetaBundle::Type_Current; bundle.url = instance->current_pipeline_->original_url(); } else if (discovered_url == instance->current_pipeline_->next_stream_url()) { + bundle.type = Engine::SimpleMetaBundle::Type_Next; bundle.url = instance->current_pipeline_->next_original_url(); } bundle.stream_url = QUrl(discovered_url); diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 2fdca04d..4bf0229e 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -926,6 +926,7 @@ void GstEnginePipeline::TagMessageReceived(GstMessage *msg) { gst_message_parse_tag(msg, &taglist); Engine::SimpleMetaBundle bundle; + bundle.type = Engine::SimpleMetaBundle::Type_Current; bundle.url = original_url_; bundle.title = ParseStrTag(taglist, GST_TAG_TITLE); bundle.artist = ParseStrTag(taglist, GST_TAG_ARTIST);