| 1 |
/* |
| 2 |
* Copyright 2008-2011 Various Authors |
| 3 |
* Copyright 2004-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 LIB_H |
| 20 |
#define LIB_H |
| 21 |
|
| 22 |
#include "editable.h" |
| 23 |
#include "search.h" |
| 24 |
#include "track_info.h" |
| 25 |
#include "expr.h" |
| 26 |
#include "rbtree.h" |
| 27 |
|
| 28 |
struct tree_track { |
| 29 |
struct shuffle_track shuffle_track; |
| 30 |
|
| 31 |
/* position in track search tree */ |
| 32 |
struct rb_node tree_node; |
| 33 |
|
| 34 |
struct album *album; |
| 35 |
}; |
| 36 |
|
| 37 |
static inline struct track_info *tree_track_info(const struct tree_track *track) |
| 38 |
{ |
| 39 |
return ((struct simple_track *)track)->info; |
| 40 |
} |
| 41 |
|
| 42 |
static inline struct tree_track *to_tree_track(const struct rb_node *node) |
| 43 |
{ |
| 44 |
return container_of(node, struct tree_track, tree_node); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
struct album { |
| 49 |
/* position in album search tree */ |
| 50 |
struct rb_node tree_node; |
| 51 |
|
| 52 |
/* root of track tree */ |
| 53 |
struct rb_root track_root; |
| 54 |
|
| 55 |
struct artist *artist; |
| 56 |
char *name; |
| 57 |
char *sort_name; |
| 58 |
char *collkey_name; |
| 59 |
char *collkey_sort_name; |
| 60 |
/* date of the first track added to this album */ |
| 61 |
int date; |
| 62 |
}; |
| 63 |
|
| 64 |
struct artist { |
| 65 |
/* position in artist search tree */ |
| 66 |
struct rb_node tree_node; |
| 67 |
|
| 68 |
/* root of album tree */ |
| 69 |
struct rb_root album_root; |
| 70 |
|
| 71 |
char *name; |
| 72 |
char *sort_name; |
| 73 |
char *auto_sort_name; |
| 74 |
char *collkey_name; |
| 75 |
char *collkey_sort_name; |
| 76 |
char *collkey_auto_sort_name; |
| 77 |
|
| 78 |
/* albums visible for this artist in the tree_win? */ |
| 79 |
unsigned int expanded : 1; |
| 80 |
unsigned int is_compilation : 1; |
| 81 |
}; |
| 82 |
|
| 83 |
const char *artist_sort_name(const struct artist *); |
| 84 |
|
| 85 |
enum aaa_mode { |
| 86 |
AAA_MODE_ALL, |
| 87 |
AAA_MODE_ARTIST, |
| 88 |
AAA_MODE_ALBUM |
| 89 |
}; |
| 90 |
|
| 91 |
extern struct editable lib_editable; |
| 92 |
extern struct tree_track *lib_cur_track; |
| 93 |
extern enum aaa_mode aaa_mode; |
| 94 |
extern unsigned int play_sorted; |
| 95 |
extern char *lib_live_filter; |
| 96 |
|
| 97 |
extern struct searchable *tree_searchable; |
| 98 |
extern struct window *lib_tree_win; |
| 99 |
extern struct window *lib_track_win; |
| 100 |
extern struct window *lib_cur_win; |
| 101 |
extern struct rb_root lib_artist_root; |
| 102 |
|
| 103 |
#define CUR_ALBUM (lib_cur_track->album) |
| 104 |
#define CUR_ARTIST (lib_cur_track->album->artist) |
| 105 |
|
| 106 |
void lib_init(void); |
| 107 |
void tree_init(void); |
| 108 |
struct track_info *lib_set_next(void); |
| 109 |
struct track_info *lib_set_prev(void); |
| 110 |
void lib_add_track(struct track_info *track_info); |
| 111 |
void lib_set_filter(struct expr *expr); |
| 112 |
void lib_set_live_filter(const char *str); |
| 113 |
int lib_remove(struct track_info *ti); |
| 114 |
void lib_clear_store(void); |
| 115 |
void lib_reshuffle(void); |
| 116 |
void lib_set_view(int view); |
| 117 |
int lib_for_each(int (*cb)(void *data, struct track_info *ti), void *data); |
| 118 |
int lib_for_each_filtered(int (*cb)(void *data, struct track_info *ti), void *data); |
| 119 |
|
| 120 |
struct tree_track *lib_find_track(struct track_info *ti); |
| 121 |
struct track_info *lib_set_track(struct tree_track *track); |
| 122 |
void lib_store_cur_track(struct track_info *ti); |
| 123 |
struct track_info *lib_get_cur_stored_track(void); |
| 124 |
|
| 125 |
struct tree_track *tree_get_selected(void); |
| 126 |
struct track_info *tree_set_selected(void); |
| 127 |
void tree_sort_artists(void); |
| 128 |
void tree_add_track(struct tree_track *track); |
| 129 |
void tree_remove(struct tree_track *track); |
| 130 |
void tree_remove_sel(void); |
| 131 |
void tree_toggle_active_window(void); |
| 132 |
void tree_toggle_expand_artist(void); |
| 133 |
void tree_expand_matching(const char *text); |
| 134 |
void tree_expand_all(void); |
| 135 |
void tree_sel_current(void); |
| 136 |
void tree_sel_first(void); |
| 137 |
void tree_sel_track(struct tree_track *t); |
| 138 |
int tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse); |
| 139 |
int __tree_for_each_sel(int (*cb)(void *data, struct track_info *ti), void *data, int reverse); |
| 140 |
|
| 141 |
struct track_info *sorted_set_selected(void); |
| 142 |
void sorted_sel_current(void); |
| 143 |
|
| 144 |
static inline struct tree_track *iter_to_sorted_track(const struct iter *iter) |
| 145 |
{ |
| 146 |
return iter->data1; |
| 147 |
} |
| 148 |
|
| 149 |
static inline struct artist *iter_to_artist(const struct iter *iter) |
| 150 |
{ |
| 151 |
return iter->data1; |
| 152 |
} |
| 153 |
|
| 154 |
static inline struct album *iter_to_album(const struct iter *iter) |
| 155 |
{ |
| 156 |
return iter->data2; |
| 157 |
} |
| 158 |
|
| 159 |
static inline struct tree_track *iter_to_tree_track(const struct iter *iter) |
| 160 |
{ |
| 161 |
return iter->data1; |
| 162 |
} |
| 163 |
|
| 164 |
static inline struct artist *to_artist(const struct rb_node *node) |
| 165 |
{ |
| 166 |
return container_of(node, struct artist, tree_node); |
| 167 |
} |
| 168 |
|
| 169 |
static inline struct album *to_album(const struct rb_node *node) |
| 170 |
{ |
| 171 |
return container_of(node, struct album, tree_node); |
| 172 |
} |
| 173 |
|
| 174 |
#endif |