playlist.h 5.68 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2010 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17
 *
 * 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.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20 21
#ifndef MPD_PLAYLIST_H
#define MPD_PLAYLIST_H
Warren Dukes's avatar
Warren Dukes committed
22

23
#include "queue.h"
Warren Dukes's avatar
Warren Dukes committed
24

25
#include <stdbool.h>
26

27 28
#define PLAYLIST_COMMENT	'#'

29 30 31
enum playlist_result {
	PLAYLIST_RESULT_SUCCESS,
	PLAYLIST_RESULT_ERRNO,
32
	PLAYLIST_RESULT_DENIED,
33 34 35 36 37 38
	PLAYLIST_RESULT_NO_SUCH_SONG,
	PLAYLIST_RESULT_NO_SUCH_LIST,
	PLAYLIST_RESULT_LIST_EXISTS,
	PLAYLIST_RESULT_BAD_NAME,
	PLAYLIST_RESULT_BAD_RANGE,
	PLAYLIST_RESULT_NOT_PLAYING,
39 40
	PLAYLIST_RESULT_TOO_LARGE,
	PLAYLIST_RESULT_DISABLED,
41 42
};

43
struct playlist {
44 45 46
	/**
	 * The song queue - it contains the "real" playlist.
	 */
47 48
	struct queue queue;

49 50 51 52 53 54
	/**
	 * This value is true if the player is currently playing (or
	 * should be playing).
	 */
	bool playing;

55 56 57 58 59 60 61 62 63 64 65 66 67 68
	/**
	 * 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;

	/**
	 * 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;

69 70 71 72 73
	/**
	 * The "current song pointer".  This is the song which is
	 * played when we get the "play" command.  It is also the song
	 * which is currently being played.
	 */
74
	int current;
75 76 77

	/**
	 * The "next" song to be played, when the current one
78 79 80 81
	 * finishes.  The decoder thread may start decoding and
	 * buffering it, while the "current" song is still playing.
	 *
	 * This variable is only valid if #playing is true.
82
	 */
83
	int queued;
84
};
85

86 87 88
/** the global playlist object */
extern struct playlist g_playlist;

Max Kellermann's avatar
Max Kellermann committed
89 90
void
playlist_global_init(void);
Warren Dukes's avatar
Warren Dukes committed
91

Max Kellermann's avatar
Max Kellermann committed
92 93
void
playlist_global_finish(void);
Warren Dukes's avatar
Warren Dukes committed
94

95 96 97 98 99 100 101 102 103
void
playlist_init(struct playlist *playlist);

void
playlist_finish(struct playlist *playlist);

void
playlist_tag_changed(struct playlist *playlist);

104 105 106
/**
 * Returns the "queue" object of the global playlist instance.
 */
107 108 109 110 111
static inline const struct queue *
playlist_get_queue(const struct playlist *playlist)
{
	return &playlist->queue;
}
112

113 114
void
playlist_clear(struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
115

116
#ifndef WIN32
117 118 119 120 121
/**
 * Appends a local file (outside the music database) to the playlist,
 * but only if the file's owner is equal to the specified uid.
 */
enum playlist_result
122 123
playlist_append_file(struct playlist *playlist, const char *path, int uid,
		     unsigned *added_id);
124
#endif
125

126
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
127 128
playlist_append_uri(struct playlist *playlist, const char *file,
		    unsigned *added_id);
Warren Dukes's avatar
Warren Dukes committed
129

130
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
131
playlist_append_song(struct playlist *playlist,
132
		  struct song *song, unsigned *added_id);
Warren Dukes's avatar
Warren Dukes committed
133

134
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
135
playlist_delete(struct playlist *playlist, unsigned song);
Warren Dukes's avatar
Warren Dukes committed
136

137 138 139 140 141 142 143 144 145
/**
 * 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
 */
enum playlist_result
playlist_delete_range(struct playlist *playlist, unsigned start, unsigned end);

146
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
147
playlist_delete_id(struct playlist *playlist, unsigned song);
148

149 150
void
playlist_stop(struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
151

152
enum playlist_result
153
playlist_play(struct playlist *playlist, int song);
Warren Dukes's avatar
Warren Dukes committed
154

155
enum playlist_result
156
playlist_play_id(struct playlist *playlist, int song);
157

158 159
void
playlist_next(struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
160

161 162
void
playlist_sync(struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
163

164 165
void
playlist_previous(struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
166

Max Kellermann's avatar
Max Kellermann committed
167 168
void
playlist_shuffle(struct playlist *playlist, unsigned start, unsigned end);
Warren Dukes's avatar
Warren Dukes committed
169

170
void
Max Kellermann's avatar
Max Kellermann committed
171
playlist_delete_song(struct playlist *playlist, const struct song *song);
Warren Dukes's avatar
Warren Dukes committed
172

173
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
174
playlist_move_range(struct playlist *playlist, unsigned start, unsigned end, int to);
Warren Dukes's avatar
Warren Dukes committed
175

176
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
177
playlist_move_id(struct playlist *playlist, unsigned id, int to);
178

179
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
180
playlist_swap_songs(struct playlist *playlist, unsigned song1, unsigned song2);
Warren Dukes's avatar
Warren Dukes committed
181

182
enum playlist_result
Max Kellermann's avatar
Max Kellermann committed
183
playlist_swap_songs_id(struct playlist *playlist, unsigned id1, unsigned id2);
184

185
bool
186
playlist_get_repeat(const struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
187

188 189
void
playlist_set_repeat(struct playlist *playlist, bool status);
Warren Dukes's avatar
Warren Dukes committed
190

191
bool
192
playlist_get_random(const struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
193

194 195
void
playlist_set_random(struct playlist *playlist, bool status);
Warren Dukes's avatar
Warren Dukes committed
196

197
bool
198
playlist_get_single(const struct playlist *playlist);
199

200 201
void
playlist_set_single(struct playlist *playlist, bool status);
202

203
bool
204
playlist_get_consume(const struct playlist *playlist);
205

206 207
void
playlist_set_consume(struct playlist *playlist, bool status);
208

209 210
int
playlist_get_current_song(const struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
211

212 213
int
playlist_get_next_song(const struct playlist *playlist);
214

215
unsigned
216
playlist_get_song_id(const struct playlist *playlist, unsigned song);
217

218 219
int
playlist_get_length(const struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
220

221
unsigned long
222
playlist_get_version(const struct playlist *playlist);
Warren Dukes's avatar
Warren Dukes committed
223

224
enum playlist_result
225
playlist_seek_song(struct playlist *playlist, unsigned song, float seek_time);
Warren Dukes's avatar
Warren Dukes committed
226

227
enum playlist_result
228
playlist_seek_song_id(struct playlist *playlist,
229
		       unsigned id, float seek_time);
230

231 232
void
playlist_increment_version_all(struct playlist *playlist);
233

Warren Dukes's avatar
Warren Dukes committed
234
#endif