2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2016-02-26 17:54:05 +01:00
|
|
|
* Copyright 2003-2016 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2013-01-04 20:50:00 +01:00
|
|
|
#ifndef MPD_PLAYLIST_HXX
|
|
|
|
#define MPD_PLAYLIST_HXX
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2014-01-24 00:17:50 +01:00
|
|
|
#include "queue/Queue.hxx"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-12-02 12:00:32 +01:00
|
|
|
enum TagType : uint8_t;
|
2013-10-28 10:12:21 +01:00
|
|
|
struct PlayerControl;
|
2014-01-07 21:39:47 +01:00
|
|
|
class DetachedSong;
|
2014-02-01 00:45:58 +01:00
|
|
|
class Database;
|
2013-12-02 12:00:32 +01:00
|
|
|
class Error;
|
2014-02-02 14:37:52 +01:00
|
|
|
class SongLoader;
|
2014-08-27 19:11:55 +02:00
|
|
|
class SongTime;
|
|
|
|
class SignedSongTime;
|
2016-03-10 20:10:14 +01:00
|
|
|
class QueueListener;
|
2009-11-03 21:08:48 +01:00
|
|
|
|
2009-01-24 13:34:53 +01:00
|
|
|
struct playlist {
|
2009-01-23 00:06:53 +01:00
|
|
|
/**
|
|
|
|
* The song queue - it contains the "real" playlist.
|
|
|
|
*/
|
2016-03-10 20:03:45 +01:00
|
|
|
Queue queue;
|
2009-01-22 23:40:11 +01:00
|
|
|
|
2016-03-10 20:10:14 +01:00
|
|
|
QueueListener &listener;
|
|
|
|
|
2009-01-23 00:09:26 +01:00
|
|
|
/**
|
|
|
|
* This value is true if the player is currently playing (or
|
|
|
|
* should be playing).
|
|
|
|
*/
|
|
|
|
bool playing;
|
|
|
|
|
2009-01-24 13:20:07 +01:00
|
|
|
/**
|
|
|
|
* If true, then any error is fatal; if false, MPD will
|
|
|
|
* attempt to play the next song on non-fatal errors. During
|
|
|
|
* seeking, this flag is set.
|
|
|
|
*/
|
|
|
|
bool stop_on_error;
|
|
|
|
|
2014-07-11 20:01:53 +02:00
|
|
|
/**
|
|
|
|
* If true, then a bulk edit has been initiated by
|
|
|
|
* BeginBulk(), and UpdateQueuedSong() and OnModified() will
|
|
|
|
* be postponed until CommitBulk()
|
|
|
|
*/
|
|
|
|
bool bulk_edit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Has the queue been modified during bulk edit mode?
|
|
|
|
*/
|
|
|
|
bool bulk_modified;
|
|
|
|
|
2009-01-24 13:20:07 +01:00
|
|
|
/**
|
|
|
|
* Number of errors since playback was started. If this
|
|
|
|
* number exceeds the length of the playlist, MPD gives up,
|
|
|
|
* because all songs have been tried.
|
|
|
|
*/
|
|
|
|
unsigned error_count;
|
|
|
|
|
2009-01-23 00:06:53 +01:00
|
|
|
/**
|
2016-03-18 17:35:29 +01:00
|
|
|
* The "current song pointer" (the order number). This is the
|
|
|
|
* song which is played when we get the "play" command. It is
|
|
|
|
* also the song which is currently being played.
|
2009-01-23 00:06:53 +01:00
|
|
|
*/
|
2007-05-16 14:02:10 +02:00
|
|
|
int current;
|
2009-01-23 00:06:53 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-18 17:35:29 +01:00
|
|
|
* The "next" song to be played (the order number), when the
|
|
|
|
* current one finishes. The decoder thread may start
|
|
|
|
* decoding and buffering it, while the "current" song is
|
|
|
|
* still playing.
|
2009-01-23 07:33:15 +01:00
|
|
|
*
|
|
|
|
* This variable is only valid if #playing is true.
|
2009-01-23 00:06:53 +01:00
|
|
|
*/
|
2007-05-16 14:02:10 +02:00
|
|
|
int queued;
|
|
|
|
|
2016-03-10 20:10:14 +01:00
|
|
|
playlist(unsigned max_length,
|
|
|
|
QueueListener &_listener)
|
|
|
|
:queue(max_length),
|
|
|
|
listener(_listener),
|
|
|
|
playing(false),
|
2014-07-11 20:01:53 +02:00
|
|
|
bulk_edit(false),
|
|
|
|
current(-1), queued(-1) {
|
2013-01-06 14:55:35 +01:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-06 14:55:35 +01:00
|
|
|
~playlist() {
|
|
|
|
}
|
2009-02-04 18:56:41 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
uint32_t GetVersion() const {
|
|
|
|
return queue.version;
|
|
|
|
}
|
2009-02-04 18:56:41 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
unsigned GetLength() const {
|
|
|
|
return queue.GetLength();
|
|
|
|
}
|
2009-02-04 18:56:41 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
unsigned PositionToId(unsigned position) const {
|
|
|
|
return queue.PositionToId(position);
|
|
|
|
}
|
2009-01-24 14:51:35 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
gcc_pure
|
|
|
|
int GetCurrentPosition() const;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
gcc_pure
|
|
|
|
int GetNextPosition() const;
|
2008-10-15 22:35:13 +02:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
/**
|
|
|
|
* Returns the song object which is currently queued. Returns
|
|
|
|
* none if there is none (yet?) or if MPD isn't playing.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2014-01-07 21:39:47 +01:00
|
|
|
const DetachedSong *GetQueuedSong() const;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
/**
|
|
|
|
* This is the "PLAYLIST" event handler. It is invoked by the
|
|
|
|
* player thread whenever it requests a new queued song, or
|
|
|
|
* when it exits.
|
|
|
|
*/
|
2013-10-28 10:12:21 +01:00
|
|
|
void SyncWithPlayer(PlayerControl &pc);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Called by all editing methods after a modification.
|
2016-03-10 20:10:14 +01:00
|
|
|
* Updates the queue version and invokes
|
|
|
|
* QueueListener::OnQueueModified().
|
2013-01-07 10:55:05 +01:00
|
|
|
*/
|
|
|
|
void OnModified();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2014-11-26 08:49:19 +01:00
|
|
|
/**
|
|
|
|
* Called when playback of a new song starts. Unlike
|
|
|
|
* QueuedSongStarted(), this also gets called when the user
|
|
|
|
* manually switches to another song. It may be used for
|
|
|
|
* playlist fixups.
|
|
|
|
*
|
|
|
|
* The song being started is specified by the #current
|
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
void SongStarted();
|
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
/**
|
|
|
|
* Updates the "queued song". Calculates the next song
|
|
|
|
* according to the current one (if MPD isn't playing, it
|
|
|
|
* takes the first song), and queues this song. Clears the
|
|
|
|
* old queued song if there was one.
|
|
|
|
*
|
|
|
|
* @param prev the song which was previously queued, as
|
|
|
|
* determined by playlist_get_queued_song()
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
void UpdateQueuedSong(PlayerControl &pc, const DetachedSong *prev);
|
2009-09-30 23:13:13 +02:00
|
|
|
|
2014-11-26 08:34:51 +01:00
|
|
|
/**
|
|
|
|
* Queue a song, addressed by its order number.
|
|
|
|
*/
|
|
|
|
void QueueSongOrder(PlayerControl &pc, unsigned order);
|
|
|
|
|
2014-11-25 19:21:22 +01:00
|
|
|
/**
|
|
|
|
* Called when the player thread has started playing the
|
2014-11-26 08:49:19 +01:00
|
|
|
* "queued" song, i.e. it has switched from one song to the
|
|
|
|
* next automatically.
|
2014-11-25 19:21:22 +01:00
|
|
|
*/
|
|
|
|
void QueuedSongStarted(PlayerControl &pc);
|
|
|
|
|
2014-11-26 08:34:51 +01:00
|
|
|
/**
|
|
|
|
* The player has stopped for some reason. Check the error,
|
|
|
|
* and decide whether to re-start playback.
|
|
|
|
*/
|
|
|
|
void ResumePlayback(PlayerControl &pc);
|
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
public:
|
2014-07-11 20:01:53 +02:00
|
|
|
void BeginBulk();
|
|
|
|
void CommitBulk(PlayerControl &pc);
|
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
void Clear(PlayerControl &pc);
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2013-10-21 23:22:16 +02:00
|
|
|
/**
|
|
|
|
* A tag in the play queue has been modified by the player
|
|
|
|
* thread. Apply the given song's tag to the current song if
|
|
|
|
* the song matches.
|
|
|
|
*/
|
2014-01-07 21:39:47 +01:00
|
|
|
void TagModified(DetachedSong &&song);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2014-02-01 00:44:41 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
2013-10-22 00:36:48 +02:00
|
|
|
/**
|
|
|
|
* The database has been modified. Pull all updates.
|
|
|
|
*/
|
2014-02-01 00:45:58 +01:00
|
|
|
void DatabaseModified(const Database &db);
|
2014-02-01 00:44:41 +01:00
|
|
|
#endif
|
2013-01-09 22:21:16 +01:00
|
|
|
|
2014-02-27 17:27:23 +01:00
|
|
|
/**
|
2016-02-28 10:51:07 +01:00
|
|
|
* Throws PlaylistError if the queue would be too large.
|
|
|
|
*
|
|
|
|
* @return the new song id
|
2014-02-27 17:27:23 +01:00
|
|
|
*/
|
2016-02-28 10:51:07 +01:00
|
|
|
unsigned AppendSong(PlayerControl &pc, DetachedSong &&song);
|
2014-02-27 17:27:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the new song id or 0 on error
|
|
|
|
*/
|
|
|
|
unsigned AppendURI(PlayerControl &pc,
|
|
|
|
const SongLoader &loader,
|
|
|
|
const char *uri_utf8,
|
|
|
|
Error &error);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
protected:
|
2013-10-28 10:12:21 +01:00
|
|
|
void DeleteInternal(PlayerControl &pc,
|
2014-01-07 21:39:47 +01:00
|
|
|
unsigned song, const DetachedSong **queued_p);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
public:
|
2015-12-18 09:21:11 +01:00
|
|
|
void DeletePosition(PlayerControl &pc, unsigned position);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void DeleteOrder(PlayerControl &pc, unsigned order) {
|
|
|
|
DeletePosition(pc, queue.OrderToPosition(order));
|
2013-01-07 10:55:05 +01:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void DeleteId(PlayerControl &pc, unsigned id);
|
2013-01-07 10:55:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a range of songs from the playlist.
|
|
|
|
*
|
|
|
|
* @param start the position of the first song to delete
|
|
|
|
* @param end the position after the last song to delete
|
|
|
|
*/
|
2015-12-18 09:21:11 +01:00
|
|
|
void DeleteRange(PlayerControl &pc, unsigned start, unsigned end);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2016-03-18 18:01:01 +01:00
|
|
|
/**
|
|
|
|
* Mark the given song as "stale", i.e. as not being available
|
|
|
|
* anymore. This gets called when a song is removed from the
|
|
|
|
* database. The method attempts to remove all instances of
|
|
|
|
* this song from the queue.
|
|
|
|
*/
|
|
|
|
void StaleSong(PlayerControl &pc, const char *uri);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
void Shuffle(PlayerControl &pc, unsigned start, unsigned end);
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void MoveRange(PlayerControl &pc, unsigned start,
|
|
|
|
unsigned end, int to);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void MoveId(PlayerControl &pc, unsigned id, int to);
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void SwapIds(PlayerControl &pc, unsigned id1, unsigned id2);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void SetPriorityRange(PlayerControl &pc,
|
|
|
|
unsigned start_position, unsigned end_position,
|
|
|
|
uint8_t priority);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2015-12-18 09:21:11 +01:00
|
|
|
void SetPriorityId(PlayerControl &pc,
|
|
|
|
unsigned song_id, uint8_t priority);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2014-07-12 03:00:01 +02:00
|
|
|
/**
|
2014-08-28 12:53:48 +02:00
|
|
|
* Sets the start_time and end_time attributes on the song
|
2014-07-12 03:00:01 +02:00
|
|
|
* with the specified id.
|
|
|
|
*/
|
2016-02-28 10:51:07 +01:00
|
|
|
void SetSongIdRange(PlayerControl &pc, unsigned id,
|
|
|
|
SongTime start, SongTime end);
|
2014-07-12 03:00:01 +02:00
|
|
|
|
2016-02-28 10:40:31 +01:00
|
|
|
void AddSongIdTag(unsigned id, TagType tag_type, const char *value);
|
|
|
|
void ClearSongIdTag(unsigned id, TagType tag_type);
|
2013-12-02 12:00:32 +01:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
void Stop(PlayerControl &pc);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2015-11-11 19:57:37 +01:00
|
|
|
bool PlayPosition(PlayerControl &pc, int position, Error &error);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2016-03-18 17:49:29 +01:00
|
|
|
bool PlayOrder(PlayerControl &pc, unsigned order, Error &error);
|
2009-03-27 14:42:55 +01:00
|
|
|
|
2015-11-11 19:57:37 +01:00
|
|
|
bool PlayId(PlayerControl &pc, int id, Error &error);
|
2009-03-27 14:42:55 +01:00
|
|
|
|
2015-11-11 19:57:37 +01:00
|
|
|
bool PlayNext(PlayerControl &pc, Error &error);
|
2009-03-30 00:01:02 +02:00
|
|
|
|
2015-11-11 19:57:37 +01:00
|
|
|
bool PlayPrevious(PlayerControl &pc, Error &error);
|
2013-01-07 10:55:05 +01:00
|
|
|
|
2015-11-11 19:32:32 +01:00
|
|
|
bool SeekSongOrder(PlayerControl &pc,
|
|
|
|
unsigned song_order,
|
|
|
|
SongTime seek_time,
|
|
|
|
Error &error);
|
2014-08-31 14:23:06 +02:00
|
|
|
|
2015-11-11 19:32:32 +01:00
|
|
|
bool SeekSongPosition(PlayerControl &pc,
|
|
|
|
unsigned sonag_position,
|
|
|
|
SongTime seek_time,
|
|
|
|
Error &error);
|
2013-01-07 10:55:05 +01:00
|
|
|
|
2015-11-11 19:32:32 +01:00
|
|
|
bool SeekSongId(PlayerControl &pc,
|
|
|
|
unsigned song_id, SongTime seek_time,
|
|
|
|
Error &error);
|
2009-03-30 00:01:02 +02:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
/**
|
|
|
|
* Seek within the current song. Fails if MPD is not currently
|
|
|
|
* playing.
|
|
|
|
*
|
2015-03-17 11:21:29 +01:00
|
|
|
* @param seek_time the time
|
2013-01-07 10:55:05 +01:00
|
|
|
* @param relative if true, then the specified time is relative to the
|
|
|
|
* current position
|
|
|
|
*/
|
2015-11-11 19:32:32 +01:00
|
|
|
bool SeekCurrent(PlayerControl &pc,
|
|
|
|
SignedSongTime seek_time, bool relative,
|
|
|
|
Error &error);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
bool GetRepeat() const {
|
|
|
|
return queue.repeat;
|
|
|
|
}
|
2009-02-08 06:21:00 +01:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
void SetRepeat(PlayerControl &pc, bool new_value);
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
bool GetRandom() const {
|
|
|
|
return queue.random;
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
void SetRandom(PlayerControl &pc, bool new_value);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
bool GetSingle() const {
|
|
|
|
return queue.single;
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2013-10-28 10:12:21 +01:00
|
|
|
void SetSingle(PlayerControl &pc, bool new_value);
|
2004-06-09 04:50:44 +02:00
|
|
|
|
2013-01-07 10:55:05 +01:00
|
|
|
bool GetConsume() const {
|
|
|
|
return queue.consume;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetConsume(bool new_value);
|
|
|
|
};
|
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#endif
|