TrackList no longer implements ITrackListEditor. Instead, we have a new

TrackListEditor implementation that may be constructed with a TrackList
instance.
This commit is contained in:
casey langen 2017-10-01 20:31:35 -07:00
parent b8069098af
commit 2f119b7c06
4 changed files with 92 additions and 34 deletions

View File

@ -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;

View File

@ -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<musik::core::sdk::ITrackListEditor>;
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;

View File

@ -223,3 +223,50 @@ void TrackList::AddToCache(int64_t key, TrackPtr value) const {
cacheList.erase(last);
}
}
/* * * * * TrackListEditor * * * * */
template <typename T>
struct NoDeleter {
void operator()(T* t) {
}
};
TrackListEditor::TrackListEditor(std::shared_ptr<TrackList> trackList) {
this->trackList = trackList;
}
TrackListEditor::TrackListEditor(TrackList& trackList) {
this->trackList = std::shared_ptr<TrackList>(&trackList, NoDeleter<TrackList>());
}
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();
}

View File

@ -45,20 +45,7 @@
namespace musik { namespace core {
/* <ugh> */
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 */ }
};
/* </ugh> */
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<int64_t> ids;
ILibraryPtr library;
};
class TrackListEditor : public musik::core::sdk::ITrackListEditor {
public:
TrackListEditor(std::shared_ptr<TrackList> 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> trackList;
};
} }