From a864efb1bc5b304212c1886c932a46cbc4118815 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 1 Oct 2017 20:45:53 -0700 Subject: [PATCH] Track abstract class now only directly implements ITrack. TagStore has been extracted, and implements ITagStore and delegates to Track implementation. --- src/core/library/Indexer.cpp | 10 ++++++---- src/core/library/track/Track.cpp | 30 ++++++++++++++++++++++++++++++ src/core/library/track/Track.h | 28 ++++++++++++++++++++-------- src/core/sdk/ITagStore.h | 4 ++-- 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/core/library/Indexer.cpp b/src/core/library/Indexer.cpp index ee0249b8d..bb784147e 100644 --- a/src/core/library/Indexer.cpp +++ b/src/core/library/Indexer.cpp @@ -364,6 +364,7 @@ void Indexer::ReadMetadataFromFile( bool saveToDb = false; /* read the tag from the plugin */ + TagStore store(track); typedef TagReaderList::iterator Iterator; Iterator it = this->tagReaders.begin(); while (it != this->tagReaders.end()) { @@ -373,7 +374,7 @@ void Indexer::ReadMetadataFromFile( fprintf(logFile, " - %s\n", file.string().c_str()); } - if ((*it)->Read(file.string().c_str(), &track)) { + if ((*it)->Read(file.string().c_str(), &store)) { saveToDb = true; break; } @@ -795,9 +796,10 @@ void Indexer::RunAnalyzers() { if (LibraryTrack::Load(&track, this->dbConnection)) { PluginVector runningAnalyzers; + TagStore store(track); PluginVector::iterator plugin = analyzers.begin(); for ( ; plugin != analyzers.end(); ++plugin) { - if ((*plugin)->Start(&track)) { + if ((*plugin)->Start(&store)) { runningAnalyzers.push_back(*plugin); } } @@ -815,7 +817,7 @@ void Indexer::RunAnalyzers() { while ((buffer = stream->GetNextProcessedOutputBuffer()) && !runningAnalyzers.empty()) { PluginVector::iterator plugin = runningAnalyzers.begin(); while(plugin != runningAnalyzers.end()) { - if ((*plugin)->Analyze(&track, buffer)) { + if ((*plugin)->Analyze(&store, buffer)) { ++plugin; } else { @@ -830,7 +832,7 @@ void Indexer::RunAnalyzers() { PluginVector::iterator plugin = analyzers.begin(); for ( ; plugin != analyzers.end(); ++plugin) { - if ((*plugin)->End(&track)) { + if ((*plugin)->End(&store)) { successPlugins++; } } diff --git a/src/core/library/track/Track.cpp b/src/core/library/track/Track.cpp index 54ff21fdf..0fb1e32c8 100644 --- a/src/core/library/track/Track.cpp +++ b/src/core/library/track/Track.cpp @@ -39,6 +39,8 @@ using namespace musik::core; +/* * * * Track * * * */ + Track::~Track() { } @@ -54,3 +56,31 @@ ILibraryPtr Track::Library() { int Track::LibraryId() { return 0; } + +/* * * * TagStore * * * */ + +template +struct NoDeleter { + void operator()(T* t) { + } +}; + +TagStore::TagStore(TrackPtr track) { + this->track = track; +} + +TagStore::TagStore(Track& track) { + this->track = TrackPtr(&track, NoDeleter()); +} + +void TagStore::SetValue(const char* key, const char* value) { + this->track->SetValue(key, value); +} + +void TagStore::ClearValue(const char* key) { + this->track->ClearValue(key); +} + +void TagStore::SetThumbnail(const char *data, long size) { + this->track->SetThumbnail(data, size); +} \ No newline at end of file diff --git a/src/core/library/track/Track.h b/src/core/library/track/Track.h index 48de03867..d07151290 100644 --- a/src/core/library/track/Track.h +++ b/src/core/library/track/Track.h @@ -45,12 +45,8 @@ namespace musik { namespace core { class Track; typedef std::shared_ptr TrackPtr; - typedef std::vector TrackVector; - class Track : - public musik::core::sdk::ITagStore, - public musik::core::sdk::ITrack - { + class Track : public musik::core::sdk::ITrack { public: typedef std::multimap MetadataMap; typedef std::pair MetadataIteratorRange; @@ -66,9 +62,11 @@ namespace musik { namespace core { virtual std::string GetString(const char* metakey) = 0; virtual std::string Uri() = 0; - /* ITagStore */ - virtual void SetValue(const char* metakey, const char* value) = 0; - virtual void ClearValue(const char* metakey) = 0; + /* ITrack is a ready only interface; we use the ITagStore interface + for writing. we replicate the interface here, and have TagStore pass + through to us */ + virtual void SetValue(const char* key, const char* value) = 0; + virtual void ClearValue(const char* key) = 0; virtual void SetThumbnail(const char *data, long size) = 0; /* ITrack */ @@ -78,9 +76,23 @@ namespace musik { namespace core { virtual double GetDouble(const char* key, double defaultValue = 0.0f) = 0; virtual int Uri(char* dst, int size) = 0; + /* implementation specific */ virtual MetadataIteratorRange GetValues(const char* metakey) = 0; virtual MetadataIteratorRange GetAllValues() = 0; virtual TrackPtr Copy() = 0; }; + class TagStore : public musik::core::sdk::ITagStore { + public: + TagStore(TrackPtr track); + TagStore(Track& track); + + virtual void SetValue(const char* key, const char* value) override; + virtual void ClearValue(const char* key) override; + virtual void SetThumbnail(const char *data, long size) override; + + private: + TrackPtr track; + }; + } } diff --git a/src/core/sdk/ITagStore.h b/src/core/sdk/ITagStore.h index 1aad8a2c6..50e51e735 100644 --- a/src/core/sdk/ITagStore.h +++ b/src/core/sdk/ITagStore.h @@ -38,8 +38,8 @@ namespace musik { namespace core { namespace sdk { class ITagStore { public: - virtual void SetValue(const char* metakey, const char* value) = 0; - virtual void ClearValue(const char* metakey) = 0; + virtual void SetValue(const char* key, const char* value) = 0; + virtual void ClearValue(const char* value) = 0; virtual void SetThumbnail(const char *data, long size) = 0; /* should be SetBlob with a key */ };