Updated IPlaybackService (and impl) to allow the ability to set the play

queue from plugins.
This commit is contained in:
casey langen 2017-02-05 21:19:41 -08:00
parent d91f05627a
commit aa64784128
4 changed files with 66 additions and 4 deletions

View File

@ -433,6 +433,29 @@ void PlaybackService::Play(TrackList& tracks, size_t index) {
} }
} }
void PlaybackService::Play(musik::core::sdk::ITrackList* source, size_t index) {
if (source) {
/* see if we have a TrackList -- if we do we can optimize the copy */
TrackList* sourceTrackList = dynamic_cast<TrackList*>(source);
if (sourceTrackList) {
this->Play(*sourceTrackList, index);
return;
}
/* otherwise use slower impl to be compatible with SDK */
{
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
this->CopyFrom(source);
this->unshuffled.Clear();
}
if (index <= source->Count()) {
this->Play(index);
}
}
}
void PlaybackService::CopyTo(TrackList& target) { void PlaybackService::CopyTo(TrackList& target) {
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex); std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
target.CopyFrom(this->playlist); target.CopyFrom(this->playlist);
@ -451,6 +474,34 @@ void PlaybackService::CopyFrom(TrackList& source) {
} }
} }
void PlaybackService::CopyFrom(musik::core::sdk::ITrackList* source) {
if (source) {
/* see if we have a TrackList -- if we do we can optimize the copy */
TrackList* sourceTrackList = dynamic_cast<TrackList*>(source);
if (sourceTrackList) {
this->CopyFrom(*sourceTrackList);
return;
}
/* otherwise we gotta do it one at a time */
std::unique_lock<std::recursive_mutex> lock(this->playlistMutex);
this->playlist.Clear();
for (size_t i = 0; i < source->Count(); i++) {
this->playlist.Add(source->GetId(i));
}
this->index = NO_POSITION;
this->nextIndex = NO_POSITION;
if (this->playingTrack) {
this->index = playlist.IndexOf(this->playingTrack->GetId());
POST(this, MESSAGE_PREPARE_NEXT_TRACK, NO_POSITION, 0);
}
}
}
void PlaybackService::Play(size_t index) { void PlaybackService::Play(size_t index) {
std::string uri = this->UriAtIndex(index); std::string uri = this->UriAtIndex(index);

View File

@ -99,8 +99,11 @@ namespace musik { namespace core { namespace audio {
virtual double GetDuration(); virtual double GetDuration();
virtual musik::core::sdk::IRetainedTrack* GetTrack(size_t index); virtual musik::core::sdk::IRetainedTrack* GetTrack(size_t index);
virtual musik::core::sdk::IRetainedTrack* GetPlayingTrack(); virtual musik::core::sdk::IRetainedTrack* GetPlayingTrack();
virtual void CopyFrom(musik::core::sdk::ITrackList* source);
virtual void Play(musik::core::sdk::ITrackList* source, size_t index);
/* app-specific implementation */ /* app-specific implementation. similar to some SDK methods, but use
concrete data types with known optimizations */
musik::core::audio::ITransport& GetTransport() { return this->transport; } musik::core::audio::ITransport& GetTransport() { return this->transport; }
void Play(musik::core::TrackList& tracks, size_t index); void Play(musik::core::TrackList& tracks, size_t index);
void CopyTo(musik::core::TrackList& target); void CopyTo(musik::core::TrackList& target);

View File

@ -36,11 +36,13 @@
#include "constants.h" #include "constants.h"
#include "IRetainedTrack.h" #include "IRetainedTrack.h"
#include "ITrackList.h"
namespace musik { namespace core { namespace sdk { namespace musik { namespace core { namespace sdk {
class IPlaybackService { class IPlaybackService {
public: public:
/* sdk v1 */
virtual void Play(size_t index) = 0; virtual void Play(size_t index) = 0;
virtual bool Next() = 0; virtual bool Next() = 0;
virtual bool Previous() = 0; virtual bool Previous() = 0;
@ -70,7 +72,13 @@ namespace musik { namespace core { namespace sdk {
virtual size_t Count() = 0; virtual size_t Count() = 0;
virtual IRetainedTrack* GetTrack(size_t index) = 0; virtual IRetainedTrack* GetTrack(size_t index) = 0;
virtual IRetainedTrack* GetPlayingTrack() = 0; /* sdk v2 */
/* sdk v2 */
virtual IRetainedTrack* GetPlayingTrack() = 0;
/* sdk v3*/
virtual void CopyFrom(ITrackList* trackList) = 0;
virtual void Play(ITrackList* source, size_t index) = 0;
}; };
} } } } } }

View File

@ -61,9 +61,9 @@ using namespace cursespp;
using namespace std::chrono; using namespace std::chrono;
/* if the user hasn't changed the selected index in 30 seconds /* if the user hasn't changed the selected index in 60 seconds
we assume he's not paying attention, and will automatically scroll we assume he's not paying attention, and will automatically scroll
the view to the next track if it's invisible. */ the view to the playing track if it's invisible. */
static const milliseconds AUTO_SCROLL_COOLDOWN = milliseconds(60000LL); static const milliseconds AUTO_SCROLL_COOLDOWN = milliseconds(60000LL);
static inline milliseconds now() { static inline milliseconds now() {