1 /* 2 This file is part of Deadbeef Player source code 3 http://deadbeef.sourceforge.net 4 5 playlist management 6 7 Copyright (C) 2009-2013 Alexey Yakovenko 8 9 This software is provided 'as-is', without any express or implied 10 warranty. In no event will the authors be held liable for any damages 11 arising from the use of this software. 12 13 Permission is granted to anyone to use this software for any purpose, 14 including commercial applications, and to alter it and redistribute it 15 freely, subject to the following restrictions: 16 17 1. The origin of this software must not be misrepresented; you must not 18 claim that you wrote the original software. If you use this software 19 in a product, an acknowledgment in the product documentation would be 20 appreciated but is not required. 21 2. Altered source versions must be plainly marked as such, and must not be 22 misrepresented as being the original software. 23 3. This notice may not be removed or altered from any source distribution. 24 25 Alexey Yakovenko waker@users.sourceforge.net 26 */ 27 28 #ifndef __PLAYLIST_H 29 #define __PLAYLIST_H 30 31 #include <stdint.h> 32 #include <time.h> 33 #include "deadbeef.h" 34 35 #define PL_MAX_ITERATORS 2 36 37 // predefined properties stored in metadata for storage unification: 38 // :URI - full pathname 39 // :DECODER - decoder id 40 // :TRACKNUM - subsong index (sid, nsf, cue, etc) 41 // :DURATION - length in seconds 42 43 typedef struct playItem_s { 44 int startsample; 45 int endsample; 46 int shufflerating; // sort order for shuffle mode 47 // private area, must not be visible to plugins 48 float _duration; 49 uint32_t _flags; 50 int _refc; 51 struct playItem_s *next[PL_MAX_ITERATORS]; // next item in linked list 52 struct playItem_s *prev[PL_MAX_ITERATORS]; // prev item in linked list 53 struct DB_metaInfo_s *meta; // linked list storing metainfo 54 unsigned selected : 1; 55 unsigned played : 1; // mark as played in shuffle mode 56 unsigned in_playlist : 1; // 1 if item is in playlist 57 } playItem_t; 58 59 typedef struct playlist_s { 60 char *title; 61 struct playlist_s *next; 62 int count[2]; 63 float totaltime; 64 int modification_idx; 65 int last_save_modification_idx; 66 playItem_t *head[PL_MAX_ITERATORS]; // head of linked list 67 playItem_t *tail[PL_MAX_ITERATORS]; // tail of linked list 68 int current_row[PL_MAX_ITERATORS]; // current row (cursor) 69 int scroll; 70 struct DB_metaInfo_s *meta; // linked list storing metainfo 71 int refc; 72 int files_add_visibility; 73 unsigned fast_mode : 1; 74 unsigned files_adding : 1; 75 } playlist_t; 76 77 // global playlist control functions 78 int 79 pl_init (void); 80 81 void 82 pl_free (void); 83 84 void 85 pl_lock (void); 86 87 void 88 pl_unlock (void); 89 90 //void 91 //plt_lock (void); 92 // 93 //void 94 //plt_unlock (void); 95 96 // playlist management functions 97 98 // it is highly recommended to access that from inside plt_lock/unlock block 99 playlist_t * 100 plt_get_curr_ptr (void); 101 102 playlist_t * 103 plt_get_for_idx (int idx); 104 105 void 106 plt_ref (playlist_t *plt); 107 108 void 109 plt_unref (playlist_t *plt); 110 111 playlist_t * 112 plt_alloc (const char *title); 113 114 void 115 plt_free (playlist_t *plt); 116 117 int 118 plt_get_count (void); 119 120 playlist_t * 121 plt_get_list (void); 122 123 playItem_t * 124 plt_get_head (int plt); 125 126 int 127 plt_get_sel_count (int plt); 128 129 int 130 plt_add (int before, const char *title); 131 132 void 133 plt_remove (int plt); 134 135 int 136 plt_find (const char *name); 137 138 void 139 plt_set_curr_idx (int plt); 140 141 int 142 plt_get_curr_idx (void); 143 144 void 145 plt_set_curr (playlist_t *plt); 146 147 playlist_t * 148 plt_get_curr (void); 149 150 int 151 plt_get_idx_of (playlist_t *plt); 152 153 int 154 plt_get_title (playlist_t *plt, char *buffer, int bufsize); 155 156 int 157 plt_set_title (playlist_t *plt, const char *title); 158 159 void 160 plt_modified (playlist_t *plt); 161 162 int 163 plt_get_modification_idx (playlist_t *plt); 164 165 // moves playlist #from to position #to 166 void 167 plt_move (int from, int to); 168 169 // playlist access functions 170 void 171 pl_clear (void); 172 173 void 174 plt_clear (playlist_t *plt); 175 176 int 177 plt_add_dir (playlist_t *plt, const char *dirname, int (*cb)(playItem_t *it, void *data), void *user_data); 178 179 int 180 plt_add_file (playlist_t *plt, const char *fname, int (*cb)(playItem_t *it, void *data), void *user_data); 181 182 int 183 pl_add_files_begin (playlist_t *plt); 184 185 void 186 pl_add_files_end (void); 187 188 playItem_t * 189 plt_insert_dir (playlist_t *plt, playItem_t *after, const char *dirname, int *pabort, int (*cb)(playItem_t *it, void *data), void *user_data); 190 191 playItem_t * 192 plt_insert_file (playlist_t *playlist, playItem_t *after, const char *fname, int *pabort, int (*cb)(playItem_t *it, void *data), void *user_data); 193 194 playItem_t * 195 pl_insert_item (playItem_t *after, playItem_t *it); 196 197 playItem_t * 198 plt_insert_item (playlist_t *playlist, playItem_t *after, playItem_t *it); 199 200 int 201 plt_remove_item (playlist_t *playlist, playItem_t *it); 202 203 playItem_t * 204 pl_item_alloc (void); 205 206 playItem_t * 207 pl_item_alloc_init (const char *fname, const char *decoder_id); 208 209 void 210 pl_item_ref (playItem_t *it); 211 212 void 213 pl_item_unref (playItem_t *it); 214 215 void 216 pl_item_copy (playItem_t *out, playItem_t *it); 217 218 int 219 pl_getcount (int iter); 220 221 int 222 plt_get_item_count (playlist_t *plt, int iter); 223 224 int 225 pl_getselcount (void); 226 227 int 228 plt_getselcount (playlist_t *playlist); 229 230 playItem_t * 231 pl_get_for_idx (int idx); 232 233 playItem_t * 234 plt_get_item_for_idx (playlist_t *playlist, int idx, int iter); 235 236 playItem_t * 237 pl_get_for_idx_and_iter (int idx, int iter); 238 239 int 240 plt_get_item_idx (playlist_t *playlist, playItem_t *it, int iter); 241 242 int 243 pl_get_idx_of (playItem_t *it); 244 245 int 246 pl_get_idx_of_iter (playItem_t *it, int iter); 247 248 playItem_t * 249 plt_insert_cue_from_buffer (playlist_t *plt, playItem_t *after, playItem_t *origin, const uint8_t *buffer, int buffersize, int numsamples, int samplerate); 250 251 playItem_t * 252 plt_insert_cue (playlist_t *plt, playItem_t *after, playItem_t *origin, int numsamples, int samplerate); 253 254 void 255 pl_add_meta (playItem_t *it, const char *key, const char *value); 256 257 void 258 pl_append_meta (playItem_t *it, const char *key, const char *value); 259 260 // must be used in explicit pl_lock/unlock block 261 // that makes it possible to avoid copying metadata on every access 262 // pl_find_meta may return overriden value (where the key is prefixed with '!') 263 const char * 264 pl_find_meta (playItem_t *it, const char *key); 265 266 const char * 267 pl_find_meta_raw (playItem_t *it, const char *key); 268 269 int 270 pl_find_meta_int (playItem_t *it, const char *key, int def); 271 272 float 273 pl_find_meta_float (playItem_t *it, const char *key, float def); 274 275 void 276 pl_replace_meta (playItem_t *it, const char *key, const char *value); 277 278 void 279 pl_set_meta_int (playItem_t *it, const char *key, int value); 280 281 void 282 pl_set_meta_float (playItem_t *it, const char *key, float value); 283 284 void 285 pl_delete_meta (playItem_t *it, const char *key); 286 287 void 288 pl_delete_all_meta (playItem_t *it); 289 290 // returns index of 1st deleted item 291 int 292 plt_delete_selected (playlist_t *plt); 293 294 int 295 pl_delete_selected (void); 296 297 void 298 plt_crop_selected (playlist_t *playlist); 299 300 void 301 pl_crop_selected (void); 302 303 int 304 plt_save (playlist_t *plt, playItem_t *first, playItem_t *last, const char *fname, int *pabort, int (*cb)(playItem_t *it, void *data), void *user_data); 305 306 int 307 plt_save_n (int n); 308 309 int 310 pl_save_current (void); 311 312 int 313 pl_save_all (void); 314 315 playItem_t * 316 plt_load (playlist_t *plt, playItem_t *after, const char *fname, int *pabort, int (*cb)(playItem_t *it, void *data), void *user_data); 317 318 int 319 pl_load_all (void); 320 321 void 322 plt_select_all (playlist_t *plt); 323 324 void 325 pl_select_all (void); 326 327 void 328 plt_reshuffle (playlist_t *playlist, playItem_t **ppmin, playItem_t **ppmax); 329 330 // required to calculate total playtime 331 void 332 plt_set_item_duration (playlist_t *playlist, playItem_t *it, float duration); 333 334 float 335 pl_get_item_duration (playItem_t *it); 336 337 void 338 pl_set_item_replaygain (playItem_t *it, int idx, float value); 339 340 float 341 pl_get_item_replaygain (playItem_t *it, int idx); 342 343 uint32_t 344 pl_get_item_flags (playItem_t *it); 345 346 void 347 pl_set_item_flags (playItem_t *it, uint32_t flags); 348 349 // returns number of characters printed, not including trailing 0 350 // [a]rtist, [t]itle, al[b]um, [l]ength, track[n]umber 351 int 352 pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char *fmt); 353 354 int 355 pl_format_title_escaped (playItem_t *it, int idx, char *s, int size, int id, const char *fmt); 356 357 void 358 pl_format_time (float t, char *dur, int size); 359 360 void 361 plt_reset_cursor (playlist_t *plt); 362 363 float 364 plt_get_totaltime (playlist_t *plt); 365 366 float 367 pl_get_totaltime (void); 368 369 void 370 pl_set_selected (playItem_t *it, int sel); 371 372 int 373 pl_is_selected (playItem_t *it); 374 375 playItem_t * 376 plt_get_first (playlist_t *playlist, int iter); 377 378 playItem_t * 379 pl_get_first (int iter); 380 381 playItem_t * 382 plt_get_last (playlist_t *playlist, int iter); 383 384 playItem_t * 385 pl_get_last (int iter); 386 387 playItem_t * 388 pl_get_next (playItem_t *it, int iter); 389 390 playItem_t * 391 pl_get_prev (playItem_t *it, int iter); 392 393 int 394 plt_get_cursor (playlist_t *plt, int iter); 395 396 int 397 pl_get_cursor (int iter); 398 399 void 400 plt_set_cursor (playlist_t *plt, int iter, int cursor); 401 402 void 403 pl_set_cursor (int iter, int cursor); 404 405 void 406 plt_move_items (playlist_t *to, int iter, playlist_t *from, playItem_t *drop_before, uint32_t *indexes, int count); 407 408 void 409 plt_copy_items (playlist_t *to, int iter, playlist_t *from, playItem_t *before, uint32_t *indices, int cnt); 410 411 void 412 plt_search_reset (playlist_t *plt); 413 414 void 415 plt_search_process (playlist_t *plt, const char *text); 416 417 void 418 plt_sort (playlist_t *plt, int iter, int id, const char *format, int order); 419 420 void 421 plt_sort_random (playlist_t *plt, int iter); 422 423 void 424 pl_items_copy_junk (struct playItem_s *from, struct playItem_s *first, struct playItem_s *last); 425 426 struct DB_metaInfo_s * 427 pl_get_metadata_head (playItem_t *it); 428 429 void 430 pl_delete_metadata (playItem_t *it, struct DB_metaInfo_s *meta); 431 432 void 433 pl_set_order (int order); 434 435 int 436 pl_get_order (void); 437 438 playlist_t * 439 pl_get_playlist (playItem_t *it); 440 441 void 442 plt_init_shuffle_albums (playlist_t *plt, int r); 443 444 void 445 plt_set_fast_mode (playlist_t *plt, int fast); 446 447 int 448 plt_is_fast_mode (playlist_t *plt); 449 450 void 451 pl_ensure_lock (void); 452 453 int 454 pl_get_meta (playItem_t *it, const char *key, char *val, int size); 455 456 int 457 pl_get_meta_raw (playItem_t *it, const char *key, char *val, int size); 458 459 int 460 pl_meta_exists (playItem_t *it, const char *key); 461 462 int 463 plt_get_meta (playlist_t *handle, const char *key, char *val, int size); 464 465 int 466 plt_get_idx (playlist_t *plt); 467 468 int 469 plt_save_config (playlist_t *plt); 470 471 int 472 listen_file_added (int (*callback)(ddb_fileadd_data_t *data, void *user_data), void *user_data); 473 474 void 475 unlisten_file_added (int id); 476 477 int 478 listen_file_add_beginend (void (*callback_begin) (ddb_fileadd_data_t *data, void *user_data), void (*callback_end)(ddb_fileadd_data_t *data, void *user_data), void *user_data); 479 480 void 481 unlisten_file_add_beginend (int id); 482 483 playItem_t * 484 plt_load2 (int visibility, playlist_t *plt, playItem_t *after, const char *fname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data); 485 486 int 487 plt_add_file2 (int visibility, playlist_t *plt, const char *fname, int (*callback)(playItem_t *it, void *user_data), void *user_data); 488 489 int 490 plt_add_dir2 (int visibility, playlist_t *plt, const char *dirname, int (*callback)(playItem_t *it, void *user_data), void *user_data); 491 492 playItem_t * 493 plt_insert_file2 (int visibility, playlist_t *playlist, playItem_t *after, const char *fname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data); 494 495 playItem_t * 496 plt_insert_dir2 (int visibility, playlist_t *plt, playItem_t *after, const char *dirname, int *pabort, int (*callback)(playItem_t *it, void *user_data), void *user_data); 497 498 int 499 plt_add_files_begin (playlist_t *plt, int visibility); 500 501 void 502 plt_add_files_end (playlist_t *plt, int visibility); 503 504 void 505 plt_deselect_all (playlist_t *plt); 506 507 void 508 plt_set_scroll (playlist_t *plt, int scroll); 509 510 int 511 plt_get_scroll (playlist_t *plt); 512 513 const char * 514 pl_format_duration (playItem_t *it, const char *ret, char *dur, int size); 515 516 int 517 pl_format_item_queue (playItem_t *it, char *s, int size); 518 519 void 520 send_trackinfochanged (playItem_t *track); 521 522 #endif // __PLAYLIST_H 523