@@ -12,7 +12,10 @@ PlayerImpl::PlayerImpl()
1212 addOption (&stopAfterCurrentAlbumOption_);
1313}
1414
15- PlayerImpl::~PlayerImpl () = default ;
15+ ColumnsQueryPtr PlayerImpl::createColumnsQuery (const std::vector<std::string>& columns)
16+ {
17+ return std::make_unique<ColumnsQueryImpl>(columns);
18+ }
1619
1720std::unique_ptr<WorkQueue> PlayerImpl::createWorkQueue ()
1821{
@@ -46,6 +49,88 @@ void PlayerImpl::disconnect()
4649 artworkFetcher_.reset ();
4750}
4851
52+ std::vector<PlayQueueItemInfo> PlayerImpl::getPlayQueue (ColumnsQuery* query)
53+ {
54+ auto queryImpl = dynamic_cast <ColumnsQueryImpl*>(query);
55+
56+ PlaylistLockGuard lock (playlistMutex_);
57+
58+ std::vector<PlayQueueItemInfo> items;
59+ auto size = ddbApi->playqueue_get_count ();
60+
61+ if (!size)
62+ {
63+ return items;
64+ }
65+
66+ items.reserve (size);
67+
68+ for (auto i = 0 ; i < size; i++)
69+ {
70+ PlaylistItemPtr item (ddbApi->playqueue_get_item (i));
71+ PlaylistPtr playlist (ddbApi->pl_get_playlist (item.get ()));
72+ auto playlistId = playlists_.getId (playlist.get ());
73+ auto playlistIndex = ddbApi->plt_get_idx (playlist.get ());
74+ auto itemIndex = ddbApi->plt_get_item_idx (playlist.get (), item.get (), PL_MAIN);
75+
76+ if (queryImpl)
77+ {
78+ auto columns = queryImpl->evaluate (playlist.get (), item.get ());
79+ items.emplace_back (playlistId, playlistIndex, itemIndex, std::move (columns));
80+ }
81+ else
82+ {
83+ items.emplace_back (playlistId, playlistIndex, itemIndex);
84+ }
85+ }
86+
87+ return items;
88+ }
89+
90+ void PlayerImpl::addToPlayQueue (const PlaylistRef& plref, int32_t itemIndex, int32_t queueIndex)
91+ {
92+ PlaylistLockGuard lock (playlistMutex_);
93+
94+ auto playlist = playlists_.resolve (plref);
95+ auto item = resolvePlaylistItem (playlist.get (), itemIndex);
96+
97+ if (!item)
98+ throw InvalidRequestException (" itemIndex is out of range" );
99+
100+ if (queueIndex < 0 || queueIndex >= ddbApi->playqueue_get_count ())
101+ ddbApi->playqueue_push (item.get ());
102+ else
103+ ddbApi->playqueue_insert_at (queueIndex, item.get ());
104+ }
105+
106+ void PlayerImpl::removeFromPlayQueue (int32_t queueIndex)
107+ {
108+ PlaylistLockGuard lock (playlistMutex_);
109+
110+ if (queueIndex < 0 || queueIndex >= ddbApi->playqueue_get_count ())
111+ throw InvalidRequestException (" queueIndex is out of range" );
112+
113+ ddbApi->playqueue_remove_nth (queueIndex);
114+ }
115+
116+ void PlayerImpl::removeFromPlayQueue (const PlaylistRef& plref, int32_t itemIndex)
117+ {
118+ PlaylistLockGuard lock (playlistMutex_);
119+
120+ auto playlist = playlists_.resolve (plref);
121+ auto item = resolvePlaylistItem (playlist.get (), itemIndex);
122+
123+ if (!item)
124+ throw InvalidRequestException (" itemIndex is out of range" );
125+
126+ ddbApi->playqueue_remove (item.get ());
127+ }
128+
129+ void PlayerImpl::clearPlayQueue ()
130+ {
131+ ddbApi->playqueue_clear ();
132+ }
133+
49134boost::unique_future<ArtworkResult> PlayerImpl::fetchCurrentArtwork ()
50135{
51136 if (!artworkFetcher_)
@@ -99,12 +184,24 @@ void PlayerImpl::handleMessage(uint32_t id, uintptr_t, uint32_t p1, uint32_t)
99184 emitEvents (PlayerEvents::PLAYER_CHANGED);
100185 break ;
101186
187+ case DB_EV_TRACKINFOCHANGED:
188+ switch (p1)
189+ {
190+ case DDB_PLAYLIST_CHANGE_PLAYQUEUE:
191+ emitEvents (PlayerEvents::PLAY_QUEUE_CHANGED);
192+ break ;
193+ }
194+ break ;
195+
102196 case DB_EV_PLAYLISTCHANGED:
103197 switch (p1)
104198 {
105199 case DDB_PLAYLIST_CHANGE_CONTENT:
106- // Notify player change for the case when currently played item is reordered or removed
107- emitEvents (PlayerEvents::PLAYER_CHANGED | PlayerEvents::PLAYLIST_ITEMS_CHANGED);
200+ // Notify player/queue change for the case when currently played/queued item is reordered or removed
201+ emitEvents (
202+ PlayerEvents::PLAYER_CHANGED |
203+ PlayerEvents::PLAYLIST_ITEMS_CHANGED |
204+ PlayerEvents::PLAY_QUEUE_CHANGED);
108205 break ;
109206
110207 case DDB_PLAYLIST_CHANGE_CREATED:
@@ -114,8 +211,15 @@ void PlayerImpl::handleMessage(uint32_t id, uintptr_t, uint32_t p1, uint32_t)
114211
115212 case DDB_PLAYLIST_CHANGE_DELETED:
116213 case DDB_PLAYLIST_CHANGE_POSITION:
117- // Reordering or removing playlists might change index of currently playing playlist
118- emitEvents (PlayerEvents::PLAYER_CHANGED | PlayerEvents::PLAYLIST_SET_CHANGED);
214+ // Reordering or removing playlists might change playlist index of currently playing/queued item
215+ emitEvents (
216+ PlayerEvents::PLAYER_CHANGED |
217+ PlayerEvents::PLAYLIST_SET_CHANGED |
218+ PlayerEvents::PLAY_QUEUE_CHANGED);
219+ break ;
220+
221+ case DDB_PLAYLIST_CHANGE_PLAYQUEUE:
222+ emitEvents (PlayerEvents::PLAY_QUEUE_CHANGED);
119223 break ;
120224 }
121225
0 commit comments