From b81488400ebc7df1a6deca9f0311be21f1f13af6 Mon Sep 17 00:00:00 2001 From: casey langen Date: Thu, 9 Feb 2017 20:20:41 -0800 Subject: [PATCH] - Updated IPlaybackRemote interface to get a callback when the play queue changes - Updated ISimpleDataProvider to accept limit and offset input paramters when querying tracklists --- .../win32globalhotkeys_plugin.cpp | 4 ++++ src/core/audio/PlaybackService.cpp | 13 ++++++++++- src/core/library/LocalSimpleDataProvider.cpp | 12 ++++++++-- src/core/library/LocalSimpleDataProvider.h | 9 ++++++-- .../query/local/CategoryTrackListQuery.cpp | 2 +- .../query/local/SearchTrackListQuery.cpp | 6 +++-- .../library/query/local/TrackListQueryBase.h | 22 +++++++++++++++++++ src/core/sdk/IPlaybackRemote.h | 1 + src/core/sdk/ISimpleDataProvider.h | 8 +++++-- 9 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp b/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp index c3cffe0fb..ebfaf3d17 100644 --- a/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp +++ b/src/contrib/win32globalhotkeys/win32globalhotkeys_plugin.cpp @@ -173,6 +173,10 @@ class MMShellHook: virtual void OnModeChanged(musik::core::sdk::RepeatMode repeatMode, bool shuffled) { } + + virtual void OnPlayQueueChanged() { + + } }; static MMShellHook plugin; diff --git a/src/core/audio/PlaybackService.cpp b/src/core/audio/PlaybackService.cpp index cd6da8973..a9206f8c0 100755 --- a/src/core/audio/PlaybackService.cpp +++ b/src/core/audio/PlaybackService.cpp @@ -71,6 +71,7 @@ using Editor = PlaybackService::Editor; #define MESSAGE_MODE_CHANGED 1005 #define MESSAGE_SHUFFLED 1006 #define MESSAGE_NOTIFY_EDITED 1007 +#define MESSAGE_NOTIFY_RESET 1008 class StreamMessage : public Message { public: @@ -336,7 +337,13 @@ void PlaybackService::ProcessMessage(IMessage &message) { else if (type == MESSAGE_TIME_CHANGED) { this->TimeChanged(transport.Position()); } - else if (type == MESSAGE_NOTIFY_EDITED) { + else if (type == MESSAGE_NOTIFY_EDITED || + type == MESSAGE_NOTIFY_RESET) + { + for (auto it = remotes.begin(); it != remotes.end(); it++) { + (*it)->OnPlayQueueChanged(); + } + this->QueueEdited(); } } @@ -446,6 +453,8 @@ void PlaybackService::Play(const TrackList& tracks, size_t index) { if (index <= tracks.Count()) { this->Play(index); } + + POST(this, MESSAGE_NOTIFY_RESET, 0, 0); } void PlaybackService::Play(const musik::core::sdk::ITrackList* source, size_t index) { @@ -468,6 +477,8 @@ void PlaybackService::Play(const musik::core::sdk::ITrackList* source, size_t in if (index <= source->Count()) { this->Play(index); } + + POST(this, MESSAGE_NOTIFY_RESET, 0, 0); } } diff --git a/src/core/library/LocalSimpleDataProvider.cpp b/src/core/library/LocalSimpleDataProvider.cpp index 1e7ff8338..d9ca78802 100644 --- a/src/core/library/LocalSimpleDataProvider.cpp +++ b/src/core/library/LocalSimpleDataProvider.cpp @@ -58,11 +58,15 @@ LocalSimpleDataProvider::~LocalSimpleDataProvider() { } -ITrackList* LocalSimpleDataProvider::QueryTracks(const char* query) { +ITrackList* LocalSimpleDataProvider::QueryTracks(const char* query, int limit, int offset) { try { std::shared_ptr search( new SearchTrackListQuery(this->library, std::string(query ? query : ""))); + if (limit >= 0) { + search->SetLimitAndOffset(limit, offset); + } + this->library->Enqueue(search, ILibrary::QuerySynchronous); if (search->GetStatus() == IQuery::Finished) { @@ -77,12 +81,16 @@ ITrackList* LocalSimpleDataProvider::QueryTracks(const char* query) { } ITrackList* LocalSimpleDataProvider::QueryTracksByCategory( - const char* categoryType, unsigned long long selectedId) + const char* categoryType, unsigned long long selectedId, int limit, int offset) { try { std::shared_ptr search( new CategoryTrackListQuery(this->library, categoryType, selectedId)); + if (limit >= 0) { + search->SetLimitAndOffset(limit, offset); + } + this->library->Enqueue(search, ILibrary::QuerySynchronous); if (search->GetStatus() == IQuery::Finished) { diff --git a/src/core/library/LocalSimpleDataProvider.h b/src/core/library/LocalSimpleDataProvider.h index 49bda097d..eac852eee 100644 --- a/src/core/library/LocalSimpleDataProvider.h +++ b/src/core/library/LocalSimpleDataProvider.h @@ -46,12 +46,17 @@ namespace musik { namespace core { namespace db { namespace local { virtual ~LocalSimpleDataProvider(); virtual musik::core::sdk::ITrackList* - QueryTracks(const char* query = ""); + QueryTracks( + const char* query = "", + int limit = -1, + int offset = 0); virtual musik::core::sdk::ITrackList* QueryTracksByCategory( const char* categoryType, - unsigned long long selectedId); + unsigned long long selectedId, + int limit = -1, + int offset = 0); virtual musik::core::sdk::IMetadataValueList* QueryCategory( diff --git a/src/core/library/query/local/CategoryTrackListQuery.cpp b/src/core/library/query/local/CategoryTrackListQuery.cpp index 35e4b4079..6d5d2372c 100755 --- a/src/core/library/query/local/CategoryTrackListQuery.cpp +++ b/src/core/library/query/local/CategoryTrackListQuery.cpp @@ -109,7 +109,7 @@ bool CategoryTrackListQuery::OnRun(Connection& db) { "SELECT DISTINCT t.id, al.name " \ "FROM tracks t, albums al, artists ar, genres gn " \ "WHERE t.%s=? AND t.album_id=al.id AND t.visual_genre_id=gn.id AND t.visual_artist_id=ar.id " - "ORDER BY al.name, disc, track, ar.name") % this->column); + "ORDER BY al.name, disc, track, ar.name %s") % this->column % this->GetLimitAndOffset()); Statement trackQuery(query.c_str(), db); trackQuery.BindInt(0, this->id); diff --git a/src/core/library/query/local/SearchTrackListQuery.cpp b/src/core/library/query/local/SearchTrackListQuery.cpp index 41c5cd62d..fd05361f6 100755 --- a/src/core/library/query/local/SearchTrackListQuery.cpp +++ b/src/core/library/query/local/SearchTrackListQuery.cpp @@ -101,16 +101,18 @@ bool SearchTrackListQuery::OnRun(Connection& db) { "WHERE " "(t.title LIKE ? OR al.name LIKE ? OR ar.name LIKE ? OR gn.name LIKE ?) " " AND t.album_id=al.id AND t.visual_genre_id=gn.id AND t.visual_artist_id=ar.id " - "ORDER BY al.name, disc, track, ar.name"; + "ORDER BY al.name, disc, track, ar.name "; } else { query = "SELECT DISTINCT t.id, al.name " "FROM tracks t, albums al, artists ar, genres gn " "WHERE t.album_id=al.id AND t.visual_genre_id=gn.id AND t.visual_artist_id=ar.id " - "ORDER BY al.name, disc, track, ar.name"; + "ORDER BY al.name, disc, track, ar.name "; } + query += this->GetLimitAndOffset(); + Statement trackQuery(query.c_str(), db); if (hasFilter) { diff --git a/src/core/library/query/local/TrackListQueryBase.h b/src/core/library/query/local/TrackListQueryBase.h index bbe398bfc..59d92d1c4 100755 --- a/src/core/library/query/local/TrackListQueryBase.h +++ b/src/core/library/query/local/TrackListQueryBase.h @@ -38,6 +38,7 @@ #include #include #include +#include namespace musik { namespace core { namespace db { namespace local { @@ -46,17 +47,38 @@ namespace musik { namespace core { namespace db { namespace local { typedef std::shared_ptr Result; typedef std::shared_ptr > Headers; + TrackListQueryBase() { + this->limit = -1; + this->offset = 0; + } + virtual ~TrackListQueryBase() { }; virtual std::string Name() = 0; virtual Result GetResult() = 0; virtual Headers GetHeaders() = 0; virtual size_t GetQueryHash() = 0; + virtual void SetLimitAndOffset(int limit, int offset = 0) { + this->limit = limit; + this->offset = offset; + } + virtual musik::core::sdk::ITrackList* GetSdkResult() { return new WrappedTrackList(GetResult()); } + protected: + std::string GetLimitAndOffset() { + if (this->limit > 0 && this->offset >= 0) { + return boost::str(boost::format("LIMIT %d OFFSET %d") + % this->limit % this->offset); + } + return ""; + } + private: + int limit, offset; + class WrappedTrackList : public musik::core::sdk::ITrackList { public: WrappedTrackList(Result wrapped) { diff --git a/src/core/sdk/IPlaybackRemote.h b/src/core/sdk/IPlaybackRemote.h index 0fe15846e..ff8b6fa05 100644 --- a/src/core/sdk/IPlaybackRemote.h +++ b/src/core/sdk/IPlaybackRemote.h @@ -47,6 +47,7 @@ namespace musik { namespace core { namespace sdk { virtual void OnPlaybackStateChanged(PlaybackState state) = 0; virtual void OnVolumeChanged(double volume) = 0; virtual void OnModeChanged(RepeatMode repeatMode, bool shuffled) = 0; + virtual void OnPlayQueueChanged() = 0; }; } } } diff --git a/src/core/sdk/ISimpleDataProvider.h b/src/core/sdk/ISimpleDataProvider.h index 53142aa4b..f3cfa1f23 100644 --- a/src/core/sdk/ISimpleDataProvider.h +++ b/src/core/sdk/ISimpleDataProvider.h @@ -43,11 +43,15 @@ namespace musik { namespace core { namespace sdk { class ISimpleDataProvider { public: virtual ITrackList* QueryTracks( - const char* query = nullptr) = 0; + const char* query = nullptr, + int limit = -1, + int offset = 0) = 0; virtual ITrackList* QueryTracksByCategory( const char* categoryType, - unsigned long long selectedId) = 0; + unsigned long long selectedId, + int limit = -1, + int offset = 0) = 0; virtual IMetadataValueList* QueryCategory( const char* type,