From 2f119b7c067ea9ccafeacab36d0e1987b973ccb4 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 1 Oct 2017 20:31:35 -0700 Subject: [PATCH] TrackList no longer implements ITrackListEditor. Instead, we have a new TrackListEditor implementation that may be constructed with a TrackList instance. --- src/core/audio/PlaybackService.cpp | 19 +++++----- src/core/audio/PlaybackService.h | 8 ++--- src/core/library/track/TrackList.cpp | 47 +++++++++++++++++++++++++ src/core/library/track/TrackList.h | 52 ++++++++++++++++------------ 4 files changed, 92 insertions(+), 34 deletions(-) diff --git a/src/core/audio/PlaybackService.cpp b/src/core/audio/PlaybackService.cpp index 7aedc1079..1b091d9c1 100755 --- a/src/core/audio/PlaybackService.cpp +++ b/src/core/audio/PlaybackService.cpp @@ -764,12 +764,15 @@ ITrackListEditor* PlaybackService::EditPlaylist() { public: SdkTrackListEditor( PlaybackService& playback, - TrackListEditor& tracks, + TrackList& tracks, Queue& queue, Mutex& mutex) : PlaybackService::Editor(playback, tracks, queue, mutex) { } + virtual ~SdkTrackListEditor() { + } + virtual void Release() { delete this; } @@ -813,14 +816,14 @@ have finished all operations. */ PlaybackService::Editor::Editor( PlaybackService& playback, - TrackListEditor& tracks, + TrackList& tracks, Queue& queue, Mutex& mutex) : playback(playback) -, tracks(tracks) , queue(queue) , lock(mutex) , edited(false) { + this->tracks = IEditor(new musik::core::TrackListEditor(tracks)); this->playIndex = playback.GetIndex(); this->nextTrackInvalidated = false; } @@ -863,7 +866,7 @@ PlaybackService::Editor::~Editor() { } bool PlaybackService::Editor::Insert(int64_t id, size_t index) { - if ((this->edited = this->tracks.Insert(id, index))) { + if ((this->edited = this->tracks->Insert(id, index))) { if (index == this->playIndex) { ++this->playIndex; } @@ -878,7 +881,7 @@ bool PlaybackService::Editor::Insert(int64_t id, size_t index) { } bool PlaybackService::Editor::Swap(size_t index1, size_t index2) { - if ((this->edited = this->tracks.Swap(index1, index2))) { + if ((this->edited = this->tracks->Swap(index1, index2))) { if (index1 == this->playIndex) { this->playIndex = index2; this->nextTrackInvalidated = true; @@ -894,7 +897,7 @@ bool PlaybackService::Editor::Swap(size_t index1, size_t index2) { } bool PlaybackService::Editor::Move(size_t from, size_t to) { - if ((this->edited = this->tracks.Move(from, to))) { + if ((this->edited = this->tracks->Move(from, to))) { if (from == this->playIndex) { this->playIndex = to; } @@ -912,7 +915,7 @@ bool PlaybackService::Editor::Move(size_t from, size_t to) { } bool PlaybackService::Editor::Delete(size_t index) { - if ((this->edited = this->tracks.Delete(index))) { + if ((this->edited = this->tracks->Delete(index))) { if (this->playback.Count() == 0) { this->playIndex = NO_POSITION; } @@ -931,7 +934,7 @@ bool PlaybackService::Editor::Delete(size_t index) { } void PlaybackService::Editor::Add(const int64_t id) { - this->tracks.Add(id); + this->tracks->Add(id); if (this->playback.Count() - 1 == this->playIndex + 1) { this->nextTrackInvalidated = true; diff --git a/src/core/audio/PlaybackService.h b/src/core/audio/PlaybackService.h index 9c75cbf57..887a8a7eb 100755 --- a/src/core/audio/PlaybackService.h +++ b/src/core/audio/PlaybackService.h @@ -128,10 +128,10 @@ namespace musik { namespace core { namespace audio { that lock when it's destructed. */ class Editor : public musik::core::sdk::ITrackListEditor { public: - using TrackListEditor = musik::core::sdk::ITrackListEditor; + using IEditor = std::shared_ptr; Editor(Editor&& other); - ~Editor(); + virtual ~Editor(); /* ITrackListEditor */ virtual bool Insert(int64_t id, size_t index); @@ -151,12 +151,12 @@ namespace musik { namespace core { namespace audio { Editor( PlaybackService& playback, - TrackListEditor& tracks, + TrackList& tracks, Queue& queue, Mutex& mutex); PlaybackService& playback; - TrackListEditor& tracks; + IEditor tracks; Queue& queue; Lock lock; size_t playIndex; diff --git a/src/core/library/track/TrackList.cpp b/src/core/library/track/TrackList.cpp index 04693865f..c0c3d85b5 100755 --- a/src/core/library/track/TrackList.cpp +++ b/src/core/library/track/TrackList.cpp @@ -223,3 +223,50 @@ void TrackList::AddToCache(int64_t key, TrackPtr value) const { cacheList.erase(last); } } + +/* * * * * TrackListEditor * * * * */ + +template +struct NoDeleter { + void operator()(T* t) { + } +}; + +TrackListEditor::TrackListEditor(std::shared_ptr trackList) { + this->trackList = trackList; +} + +TrackListEditor::TrackListEditor(TrackList& trackList) { + this->trackList = std::shared_ptr(&trackList, NoDeleter()); +} + +TrackListEditor::~TrackListEditor() { +} + +void TrackListEditor::Add(const int64_t id) { + this->trackList->Add(id); +} + +bool TrackListEditor::Insert(int64_t id, size_t index) { + return this->trackList->Insert(id, index); +} + +bool TrackListEditor::Swap(size_t index1, size_t index2) { + return this->trackList->Swap(index1, index2); +} + +bool TrackListEditor::Move(size_t from, size_t to) { + return this->trackList->Move(from, to); +} + +bool TrackListEditor::Delete(size_t index) { + return this->trackList->Delete(index); +} + +void TrackListEditor::Clear() { + this->trackList->Clear(); +} + +void TrackListEditor::Shuffle() { + this->trackList->Shuffle(); +} \ No newline at end of file diff --git a/src/core/library/track/TrackList.h b/src/core/library/track/TrackList.h index 4fe6e7b90..de2695c4d 100755 --- a/src/core/library/track/TrackList.h +++ b/src/core/library/track/TrackList.h @@ -45,20 +45,7 @@ namespace musik { namespace core { - /* */ - class TrackList_ITrackList : public musik::core::sdk::ITrackList { - public: virtual void Release() { /* not used by the SDK */ } - }; - - class TrackList_ITrackListEditor : public musik::core::sdk::ITrackListEditor { - public: virtual void Release() { /* not used by the SDK */ } - }; - /* */ - - class TrackList : - public TrackList_ITrackList, - public TrackList_ITrackListEditor - { + class TrackList : public musik::core::sdk::ITrackList { public: TrackList(ILibraryPtr library); TrackList(TrackList* other); @@ -72,15 +59,16 @@ namespace musik { namespace core { virtual int64_t GetId(size_t index) const; virtual int IndexOf(int64_t id) const; virtual musik::core::sdk::ITrack* GetTrack(size_t index) const; + virtual void Release() { /* not used now */ } - /* ITrackListEditor */ - virtual void Add(const int64_t id); - virtual bool Insert(int64_t id, size_t index); - virtual bool Swap(size_t index1, size_t index2); - virtual bool Move(size_t from, size_t to); - virtual bool Delete(size_t index); - virtual void Clear(); - virtual void Shuffle(); + /* TrackListEditor passes through to us */ + void Add(const int64_t id); + bool Insert(int64_t id, size_t index); + bool Swap(size_t index1, size_t index2); + bool Move(size_t from, size_t to); + bool Delete(size_t index); + void Clear(); + void Shuffle(); /* implementation specific */ TrackPtr Get(size_t index) const; @@ -103,4 +91,24 @@ namespace musik { namespace core { std::vector ids; ILibraryPtr library; }; + + class TrackListEditor : public musik::core::sdk::ITrackListEditor { + public: + TrackListEditor(std::shared_ptr trackList); + TrackListEditor(TrackList& trackList); + + virtual ~TrackListEditor(); + + virtual void Add(const int64_t id); + virtual bool Insert(int64_t id, size_t index); + virtual bool Swap(size_t index1, size_t index2); + virtual bool Move(size_t from, size_t to); + virtual bool Delete(size_t index); + virtual void Clear(); + virtual void Shuffle(); + virtual void Release() { /* nothing yet */ } + + private: + std::shared_ptr trackList; + }; } }