| 1 |
/* |
| 2 |
* Copyright 2008-2011 Various Authors |
| 3 |
* Copyright 2006 Timo Hirvonen |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License as |
| 7 |
* published by the Free Software Foundation; either version 2 of the |
| 8 |
* License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef TRACK_H |
| 20 |
#define TRACK_H |
| 21 |
|
| 22 |
#include "list.h" |
| 23 |
#include "rbtree.h" |
| 24 |
#include "iter.h" |
| 25 |
#include "track_info.h" |
| 26 |
|
| 27 |
struct simple_track { |
| 28 |
struct list_head node; |
| 29 |
struct rb_node tree_node; |
| 30 |
struct track_info *info; |
| 31 |
unsigned int marked : 1; |
| 32 |
}; |
| 33 |
|
| 34 |
struct shuffle_track { |
| 35 |
struct simple_track simple_track; |
| 36 |
struct rb_node tree_node; |
| 37 |
double rand; |
| 38 |
}; |
| 39 |
|
| 40 |
static inline struct track_info *shuffle_track_info(const struct shuffle_track *track) |
| 41 |
{ |
| 42 |
return ((struct simple_track *)track)->info; |
| 43 |
} |
| 44 |
|
| 45 |
static inline struct simple_track *to_simple_track(const struct list_head *item) |
| 46 |
{ |
| 47 |
return container_of(item, struct simple_track, node); |
| 48 |
} |
| 49 |
|
| 50 |
static inline struct simple_track *iter_to_simple_track(const struct iter *iter) |
| 51 |
{ |
| 52 |
return iter->data1; |
| 53 |
} |
| 54 |
|
| 55 |
static inline struct simple_track *tree_node_to_simple_track(const struct rb_node *node) |
| 56 |
{ |
| 57 |
return container_of(node, struct simple_track, tree_node); |
| 58 |
} |
| 59 |
|
| 60 |
static inline struct shuffle_track *tree_node_to_shuffle_track(const struct rb_node *node) |
| 61 |
{ |
| 62 |
return container_of(node, struct shuffle_track, tree_node); |
| 63 |
} |
| 64 |
|
| 65 |
/* NOTE: does not ref ti */ |
| 66 |
void simple_track_init(struct simple_track *track, struct track_info *ti); |
| 67 |
|
| 68 |
/* refs ti */ |
| 69 |
struct simple_track *simple_track_new(struct track_info *ti); |
| 70 |
|
| 71 |
int simple_track_get_prev(struct iter *); |
| 72 |
int simple_track_get_next(struct iter *); |
| 73 |
|
| 74 |
/* data is window */ |
| 75 |
int simple_track_search_get_current(void *data, struct iter *iter); |
| 76 |
int simple_track_search_matches(void *data, struct iter *iter, const char *text); |
| 77 |
|
| 78 |
struct shuffle_track *shuffle_list_get_next(struct rb_root *root, struct shuffle_track *cur, |
| 79 |
int (*filter)(const struct simple_track *)); |
| 80 |
|
| 81 |
struct shuffle_track *shuffle_list_get_prev(struct rb_root *root, struct shuffle_track *cur, |
| 82 |
int (*filter)(const struct simple_track *)); |
| 83 |
|
| 84 |
struct simple_track *simple_list_get_next(struct list_head *head, struct simple_track *cur, |
| 85 |
int (*filter)(const struct simple_track *)); |
| 86 |
|
| 87 |
struct simple_track *simple_list_get_prev(struct list_head *head, struct simple_track *cur, |
| 88 |
int (*filter)(const struct simple_track *)); |
| 89 |
|
| 90 |
void sorted_list_add_track(struct list_head *head, struct rb_root *tree_root, struct simple_track *track, |
| 91 |
const sort_key_t *keys, int tiebreak); |
| 92 |
void sorted_list_remove_track(struct list_head *head, struct rb_root *tree_root, struct simple_track *track); |
| 93 |
void sorted_list_rebuild(struct list_head *head, struct rb_root *tree_root, const sort_key_t *keys); |
| 94 |
|
| 95 |
void list_add_rand(struct list_head *head, struct list_head *node, int nr); |
| 96 |
|
| 97 |
int simple_list_for_each_marked(struct list_head *head, |
| 98 |
int (*cb)(void *data, struct track_info *ti), void *data, int reverse); |
| 99 |
|
| 100 |
void shuffle_list_add(struct shuffle_track *track, struct rb_root *tree_root); |
| 101 |
void shuffle_list_reshuffle(struct rb_root *tree_root); |
| 102 |
|
| 103 |
#endif |