MPD: queue/Playlist.hxx Source File

MPD 0.20.18

Playlist.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_PLAYLIST_HXX
21 #define MPD_PLAYLIST_HXX
22
23 #include "queue/Queue.hxx"
24
25 enum TagType : uint8_t;
26 struct PlayerControl;
27 class DetachedSong;
28 class Database;
29 class SongLoader;
30 class SongTime;
31 class SignedSongTime;
32 class QueueListener;
33
34 struct playlist {
38 Queue queue;
39
40 QueueListener &listener;
41
46 bool playing;
47
53 bool stop_on_error;
54
60 bool bulk_edit;
61
65 bool bulk_modified;
66
72 unsigned error_count;
73
79 int current;
80
89 int queued;
90
91 playlist(unsigned max_length,
92 QueueListener &_listener)
93 :queue(max_length),
94 listener(_listener),
95 playing(false),
96 bulk_edit(false),
97 current(-1), queued(-1) {
98 }
99
100 ~playlist() {
101 }
102
103 uint32_t GetVersion() const {
104 return queue.version;
105 }
106
107 unsigned GetLength() const {
108 return queue.GetLength();
109 }
110
111 unsigned PositionToId(unsigned position) const {
112 return queue.PositionToId(position);
113 }
114
115 gcc_pure
116 int GetCurrentPosition() const noexcept;
117
118 gcc_pure
119 int GetNextPosition() const noexcept;
120
125 gcc_pure
126 const DetachedSong *GetQueuedSong() const noexcept;
127
133 void SyncWithPlayer(PlayerControl &pc);
134
135 protected:
141 void OnModified();
142
152 void SongStarted();
153
163 void UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev);
164
168 void QueueSongOrder(PlayerControl &pc, unsigned order);
169
175 void QueuedSongStarted(PlayerControl &pc);
176
181 void ResumePlayback(PlayerControl &pc);
182
183 public:
184 void BeginBulk();
185 void CommitBulk(PlayerControl &pc);
186
187 void Clear(PlayerControl &pc);
188
194 void TagModified(DetachedSong &&song);
195
196 #ifdef ENABLE_DATABASE
197
200 void DatabaseModified(const Database &db);
201 #endif
202
208 unsigned AppendSong(PlayerControl &pc, DetachedSong &&song);
209
215 unsigned AppendURI(PlayerControl &pc,
216 const SongLoader &loader,
217 const char *uri_utf8);
218
219 protected:
220 void DeleteInternal(PlayerControl &pc,
221 unsigned song, const DetachedSong **queued_p);
222
223 public:
224 void DeletePosition(PlayerControl &pc, unsigned position);
225
226 void DeleteOrder(PlayerControl &pc, unsigned order) {
227 DeletePosition(pc, queue.OrderToPosition(order));
228 }
229
230 void DeleteId(PlayerControl &pc, unsigned id);
231
238 void DeleteRange(PlayerControl &pc, unsigned start, unsigned end);
239
246 void StaleSong(PlayerControl &pc, const char *uri);
247
248 void Shuffle(PlayerControl &pc, unsigned start, unsigned end);
249
250 void MoveRange(PlayerControl &pc, unsigned start,
251 unsigned end, int to);
252
253 void MoveId(PlayerControl &pc, unsigned id, int to);
254
255 void SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2);
256
257 void SwapIds(PlayerControl &pc, unsigned id1, unsigned id2);
258
259 void SetPriorityRange(PlayerControl &pc,
260 unsigned start_position, unsigned end_position,
261 uint8_t priority);
262
263 void SetPriorityId(PlayerControl &pc,
264 unsigned song_id, uint8_t priority);
265
270 void SetSongIdRange(PlayerControl &pc, unsigned id,
271 SongTime start, SongTime end);
272
273 void AddSongIdTag(unsigned id, TagType tag_type, const char *value);
274 void ClearSongIdTag(unsigned id, TagType tag_type);
275
276 void Stop(PlayerControl &pc);
277
281 void PlayPosition(PlayerControl &pc, int position);
282
286 void PlayOrder(PlayerControl &pc, unsigned order);
287
291 void PlayId(PlayerControl &pc, int id);
292
296 void PlayNext(PlayerControl &pc);
297
301 void PlayPrevious(PlayerControl &pc);
302
306 void SeekSongOrder(PlayerControl &pc,
307 unsigned song_order,
308 SongTime seek_time);
309
313 void SeekSongPosition(PlayerControl &pc,
314 unsigned sonag_position,
315 SongTime seek_time);
316
320 void SeekSongId(PlayerControl &pc,
321 unsigned song_id, SongTime seek_time);
322
333 void SeekCurrent(PlayerControl &pc,
334 SignedSongTime seek_time, bool relative);
335
336 bool GetRepeat() const {
337 return queue.repeat;
338 }
339
340 void SetRepeat(PlayerControl &pc, bool new_value);
341
342 bool GetRandom() const {
343 return queue.random;
344 }
345
346 void SetRandom(PlayerControl &pc, bool new_value);
347
348 bool GetSingle() const {
349 return queue.single;
350 }
351
352 void SetSingle(PlayerControl &pc, bool new_value);
353
354 bool GetConsume() const {
355 return queue.consume;
356 }
357
358 void SetConsume(bool new_value);
359
360 private:
370 unsigned MoveOrderToCurrent(unsigned old_order);
371 };
372
373 #endif
playlist::UpdateQueuedSong
void UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev)
Updates the "queued song".
playlist::DeleteInternal
void DeleteInternal(PlayerControl &pc, unsigned song, const DetachedSong **queued_p)
playlist::ClearSongIdTag
void ClearSongIdTag(unsigned id, TagType tag_type)
playlist
Definition: Playlist.hxx:34
playlist::SongStarted
void SongStarted()
Called when playback of a new song starts.
playlist::current
int current
The "current song pointer" (the order number).
Definition: Playlist.hxx:79
Queue::version
uint32_t version
the current version number
Definition: Queue.hxx:79
playlist::StaleSong
void StaleSong(PlayerControl &pc, const char *uri)
Mark the given song as "stale", i.e.
playlist::queued
int queued
The "next" song to be played (the order number), when the current one finishes.
Definition: Playlist.hxx:89
playlist::AddSongIdTag
void AddSongIdTag(unsigned id, TagType tag_type, const char *value)
playlist::GetRepeat
bool GetRepeat() const
Definition: Playlist.hxx:336
Queue::PositionToId
int PositionToId(unsigned position) const
Definition: Queue.hxx:157
playlist::Clear
void Clear(PlayerControl &pc)
playlist::PlayNext
void PlayNext(PlayerControl &pc)
Throws std::runtime_error or #Error on error.
playlist::SetConsume
void SetConsume(bool new_value)
SongTime
A time stamp within a song.
Definition: Chrono.hxx:31
playlist::GetConsume
bool GetConsume() const
Definition: Playlist.hxx:354
Queue::consume
bool consume
remove each played files.
Definition: Queue.hxx:98
Database
Definition: Interface.hxx:35
playlist::GetSingle
bool GetSingle() const
Definition: Playlist.hxx:348
Queue::repeat
bool repeat
repeat playback when the end of the queue has been reached?
Definition: Queue.hxx:92
playlist::QueueSongOrder
void QueueSongOrder(PlayerControl &pc, unsigned order)
Queue a song, addressed by its order number.
playlist::GetVersion
uint32_t GetVersion() const
Definition: Playlist.hxx:103
playlist::SwapIds
void SwapIds(PlayerControl &pc, unsigned id1, unsigned id2)
playlist::playlist
playlist(unsigned max_length, QueueListener &_listener)
Definition: Playlist.hxx:91
playlist::DeleteRange
void DeleteRange(PlayerControl &pc, unsigned start, unsigned end)
Deletes a range of songs from the playlist.
playlist::PlayPrevious
void PlayPrevious(PlayerControl &pc)
Throws std::runtime_error or #Error on error.
playlist::SetPriorityId
void SetPriorityId(PlayerControl &pc, unsigned song_id, uint8_t priority)
playlist::OnModified
void OnModified()
Called by all editing methods after a modification.
Queue.hxx
playlist::SetSongIdRange
void SetSongIdRange(PlayerControl &pc, unsigned id, SongTime start, SongTime end)
Sets the start_time and end_time attributes on the song with the specified id.
playlist::DeleteId
void DeleteId(PlayerControl &pc, unsigned id)
playlist::DeleteOrder
void DeleteOrder(PlayerControl &pc, unsigned order)
Definition: Playlist.hxx:226
playlist::SetRandom
void SetRandom(PlayerControl &pc, bool new_value)
Queue
A queue of songs.
Definition: Queue.hxx:44
playlist::QueuedSongStarted
void QueuedSongStarted(PlayerControl &pc)
Called when the player thread has started playing the "queued" song, i.e.
playlist::error_count
unsigned error_count
Number of errors since playback was started.
Definition: Playlist.hxx:72
playlist::MoveRange
void MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
Queue::OrderToPosition
gcc_pure unsigned OrderToPosition(unsigned _order) const noexcept
Definition: Queue.hxx:165
playlist::GetQueuedSong
gcc_pure const DetachedSong * GetQueuedSong() const noexcept
Returns the song object which is currently queued.
playlist::BeginBulk
void BeginBulk()
TagType
TagType
Codes for the type of a tag item.
Definition: TagType.h:30
playlist::stop_on_error
bool stop_on_error
If true, then any error is fatal; if false, MPD will attempt to play the next song on non-fatal error...
Definition: Playlist.hxx:53
playlist::SeekSongOrder
void SeekSongOrder(PlayerControl &pc, unsigned song_order, SongTime seek_time)
Throws std::runtime_error or #Error on error.
playlist::PositionToId
unsigned PositionToId(unsigned position) const
Definition: Playlist.hxx:111
playlist::SyncWithPlayer
void SyncWithPlayer(PlayerControl &pc)
This is the "PLAYLIST" event handler.
playlist::PlayId
void PlayId(PlayerControl &pc, int id)
Throws std::runtime_error or #Error on error.
playlist::bulk_modified
bool bulk_modified
Has the queue been modified during bulk edit mode?
Definition: Playlist.hxx:65
playlist::GetLength
unsigned GetLength() const
Definition: Playlist.hxx:107
playlist::bulk_edit
bool bulk_edit
If true, then a bulk edit has been initiated by BeginBulk(), and UpdateQueuedSong() and OnModified() ...
Definition: Playlist.hxx:60
Queue::random
bool random
play back songs in random order?
Definition: Queue.hxx:101
PlayerControl
Definition: Control.hxx:100
Queue::GetLength
unsigned GetLength() const
Definition: Queue.hxx:117
Queue::single
bool single
play only current song.
Definition: Queue.hxx:95
playlist::queue
Queue queue
The song queue - it contains the "real" playlist.
Definition: Playlist.hxx:38
playlist::SetRepeat
void SetRepeat(PlayerControl &pc, bool new_value)
playlist::GetCurrentPosition
gcc_pure int GetCurrentPosition() const noexcept
SignedSongTime
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
playlist::GetNextPosition
gcc_pure int GetNextPosition() const noexcept
playlist::MoveId
void MoveId(PlayerControl &pc, unsigned id, int to)
playlist::PlayPosition
void PlayPosition(PlayerControl &pc, int position)
Throws std::runtime_error or #Error on error.
playlist::SeekCurrent
void SeekCurrent(PlayerControl &pc, SignedSongTime seek_time, bool relative)
Seek within the current song.
playlist::DeletePosition
void DeletePosition(PlayerControl &pc, unsigned position)
SongLoader
A utility class that loads a DetachedSong object by its URI.
Definition: SongLoader.hxx:41
playlist::listener
QueueListener & listener
Definition: Playlist.hxx:40
playlist::GetRandom
bool GetRandom() const
Definition: Playlist.hxx:342
playlist::Stop
void Stop(PlayerControl &pc)
playlist::SwapPositions
void SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2)
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
playlist::PlayOrder
void PlayOrder(PlayerControl &pc, unsigned order)
Throws std::runtime_error or #Error on error.
playlist::Shuffle
void Shuffle(PlayerControl &pc, unsigned start, unsigned end)
playlist::SeekSongPosition
void SeekSongPosition(PlayerControl &pc, unsigned sonag_position, SongTime seek_time)
Throws std::runtime_error or #Error on error.
DetachedSong
Definition: DetachedSong.hxx:37
playlist::AppendURI
unsigned AppendURI(PlayerControl &pc, const SongLoader &loader, const char *uri_utf8)
Throws #std::runtime_error on error.
playlist::SetPriorityRange
void SetPriorityRange(PlayerControl &pc, unsigned start_position, unsigned end_position, uint8_t priority)
uri
const Storage const char * uri
Definition: DatabasePlaylist.hxx:31
playlist::ResumePlayback
void ResumePlayback(PlayerControl &pc)
The player has stopped for some reason.
playlist::SeekSongId
void SeekSongId(PlayerControl &pc, unsigned song_id, SongTime seek_time)
Throws std::runtime_error or #Error on error.
playlist::playing
bool playing
This value is true if the player is currently playing (or should be playing).
Definition: Playlist.hxx:46
QueueListener
Definition: Listener.hxx:23
playlist::SetSingle
void SetSingle(PlayerControl &pc, bool new_value)
playlist::~playlist
~playlist()
Definition: Playlist.hxx:100
playlist::TagModified
void TagModified(DetachedSong &&song)
A tag in the play queue has been modified by the player thread.
playlist::CommitBulk
void CommitBulk(PlayerControl &pc)
playlist::AppendSong
unsigned AppendSong(PlayerControl &pc, DetachedSong &&song)
Throws PlaylistError if the queue would be too large.