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 {
39 
41 
46  bool playing;
47 
54 
60  bool bulk_edit;
61 
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 
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 
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) {
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 
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 
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
void UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev)
Updates the "queued song".
void DeleteInternal(PlayerControl &pc, unsigned song, const DetachedSong **queued_p)
void ClearSongIdTag(unsigned id, TagType tag_type)
void SongStarted()
Called when playback of a new song starts.
int current
The "current song pointer" (the order number).
Definition: Playlist.hxx:79
uint32_t version
the current version number
Definition: Queue.hxx:79
void StaleSong(PlayerControl &pc, const char *uri)
Mark the given song as "stale", i.e.
int queued
The "next" song to be played (the order number), when the current one finishes.
Definition: Playlist.hxx:89
void AddSongIdTag(unsigned id, TagType tag_type, const char *value)
bool GetRepeat() const
Definition: Playlist.hxx:336
int PositionToId(unsigned position) const
Definition: Queue.hxx:157
void Clear(PlayerControl &pc)
void PlayNext(PlayerControl &pc)
Throws std::runtime_error or #Error on error.
void SetConsume(bool new_value)
A time stamp within a song.
Definition: Chrono.hxx:31
bool GetConsume() const
Definition: Playlist.hxx:354
bool consume
remove each played files.
Definition: Queue.hxx:98
bool GetSingle() const
Definition: Playlist.hxx:348
bool repeat
repeat playback when the end of the queue has been reached?
Definition: Queue.hxx:92
void QueueSongOrder(PlayerControl &pc, unsigned order)
Queue a song, addressed by its order number.
uint32_t GetVersion() const
Definition: Playlist.hxx:103
void SwapIds(PlayerControl &pc, unsigned id1, unsigned id2)
playlist(unsigned max_length, QueueListener &_listener)
Definition: Playlist.hxx:91
void DeleteRange(PlayerControl &pc, unsigned start, unsigned end)
Deletes a range of songs from the playlist.
void PlayPrevious(PlayerControl &pc)
Throws std::runtime_error or #Error on error.
void SetPriorityId(PlayerControl &pc, unsigned song_id, uint8_t priority)
void OnModified()
Called by all editing methods after a modification.
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.
void DeleteId(PlayerControl &pc, unsigned id)
void DeleteOrder(PlayerControl &pc, unsigned order)
Definition: Playlist.hxx:226
void SetRandom(PlayerControl &pc, bool new_value)
A queue of songs.
Definition: Queue.hxx:44
void QueuedSongStarted(PlayerControl &pc)
Called when the player thread has started playing the "queued" song, i.e.
unsigned error_count
Number of errors since playback was started.
Definition: Playlist.hxx:72
void MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
gcc_pure unsigned OrderToPosition(unsigned _order) const noexcept
Definition: Queue.hxx:165
gcc_pure const DetachedSong * GetQueuedSong() const noexcept
Returns the song object which is currently queued.
void BeginBulk()
TagType
Codes for the type of a tag item.
Definition: TagType.h:30
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
void SeekSongOrder(PlayerControl &pc, unsigned song_order, SongTime seek_time)
Throws std::runtime_error or #Error on error.
unsigned PositionToId(unsigned position) const
Definition: Playlist.hxx:111
void SyncWithPlayer(PlayerControl &pc)
This is the "PLAYLIST" event handler.
void PlayId(PlayerControl &pc, int id)
Throws std::runtime_error or #Error on error.
bool bulk_modified
Has the queue been modified during bulk edit mode?
Definition: Playlist.hxx:65
unsigned GetLength() const
Definition: Playlist.hxx:107
bool bulk_edit
If true, then a bulk edit has been initiated by BeginBulk(), and UpdateQueuedSong() and OnModified() ...
Definition: Playlist.hxx:60
bool random
play back songs in random order?
Definition: Queue.hxx:101
unsigned GetLength() const
Definition: Queue.hxx:117
bool single
play only current song.
Definition: Queue.hxx:95
Queue queue
The song queue - it contains the "real" playlist.
Definition: Playlist.hxx:38
void SetRepeat(PlayerControl &pc, bool new_value)
gcc_pure int GetCurrentPosition() const noexcept
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
gcc_pure int GetNextPosition() const noexcept
void MoveId(PlayerControl &pc, unsigned id, int to)
void PlayPosition(PlayerControl &pc, int position)
Throws std::runtime_error or #Error on error.
void SeekCurrent(PlayerControl &pc, SignedSongTime seek_time, bool relative)
Seek within the current song.
void DeletePosition(PlayerControl &pc, unsigned position)
A utility class that loads a DetachedSong object by its URI.
Definition: SongLoader.hxx:41
QueueListener & listener
Definition: Playlist.hxx:40
bool GetRandom() const
Definition: Playlist.hxx:342
void Stop(PlayerControl &pc)
void SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2)
#define gcc_pure
Definition: Compiler.h:116
void PlayOrder(PlayerControl &pc, unsigned order)
Throws std::runtime_error or #Error on error.
void Shuffle(PlayerControl &pc, unsigned start, unsigned end)
void SeekSongPosition(PlayerControl &pc, unsigned sonag_position, SongTime seek_time)
Throws std::runtime_error or #Error on error.
unsigned AppendURI(PlayerControl &pc, const SongLoader &loader, const char *uri_utf8)
Throws #std::runtime_error on error.
void SetPriorityRange(PlayerControl &pc, unsigned start_position, unsigned end_position, uint8_t priority)
const Storage const char * uri
void ResumePlayback(PlayerControl &pc)
The player has stopped for some reason.
void SeekSongId(PlayerControl &pc, unsigned song_id, SongTime seek_time)
Throws std::runtime_error or #Error on error.
bool playing
This value is true if the player is currently playing (or should be playing).
Definition: Playlist.hxx:46
void SetSingle(PlayerControl &pc, bool new_value)
void TagModified(DetachedSong &&song)
A tag in the play queue has been modified by the player thread.
void CommitBulk(PlayerControl &pc)
unsigned AppendSong(PlayerControl &pc, DetachedSong &&song)
Throws PlaylistError if the queue would be too large.