Clean up window movement
[cmus.git] / cmus / pl.h
blob546cd1fca414ad6e16745032d5bc4cb1ae0d3128
1 /*
2 * Copyright 2004-2005 Timo Hirvonen
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #ifndef _PL_H
21 #define _PL_H
23 #include <comment.h>
24 #include <list.h>
25 #include <window.h>
26 #include <search.h>
27 #include <track_info.h>
28 #include <expr.h>
29 #include <locking.h>
30 #include <debug.h>
32 #include <pthread.h>
33 #include <sys/time.h>
35 struct track {
36 /* next/prev track in artist/album/track tree */
37 struct list_head node;
39 /* next/prev track in shuffle list */
40 struct list_head shuffle_node;
42 /* next/prev track in sorted list */
43 struct list_head sorted_node;
45 struct album *album;
46 struct track_info *info;
48 char *name;
49 int disc;
50 int num;
51 unsigned int url : 1;
54 struct album {
55 /* next/prev album */
56 struct list_head node;
58 /* list of tracks */
59 struct list_head track_head;
61 struct artist *artist;
62 char *name;
63 /* date of the first track added to this album */
64 int date;
67 struct artist {
68 /* next/prev artist */
69 struct list_head node;
71 /* list of albums */
72 struct list_head album_head;
73 char *name;
75 /* albums visible for this artist in the tree_win? */
76 unsigned int expanded : 1;
78 /* if streams == 1 && name == NULL then display <Stream> */
79 //unsigned int streams : 1;
82 enum play_mode {
83 PLAY_MODE_TREE,
84 PLAY_MODE_SHUFFLE,
85 PLAY_MODE_SORTED
88 enum playlist_mode {
89 PLAYLIST_MODE_ALL,
90 PLAYLIST_MODE_ARTIST,
91 PLAYLIST_MODE_ALBUM
94 /* PLAY_QUEUE_VIEW and BROWSER_VIEW are defined in ui_curses.h */
95 #define TREE_VIEW 0
96 #define SHUFFLE_VIEW 1
97 #define SORTED_VIEW 2
99 struct playlist {
100 struct list_head artist_head;
101 struct list_head shuffle_head;
102 struct list_head sorted_head;
104 struct artist *cur_artist;
105 struct album *cur_album;
106 struct track *cur_track;
108 /* for sorted window */
109 char **sort_keys;
111 struct expr *filter;
113 struct window *tree_win;
114 struct window *track_win;
115 struct window *shuffle_win;
116 struct window *sorted_win;
118 /* one of the above windows */
119 struct window *cur_win;
121 enum play_mode play_mode;
122 enum playlist_mode playlist_mode;
124 unsigned int nr_tracks;
125 unsigned int total_time;
127 unsigned int status_changed : 1;
128 unsigned int repeat : 1;
130 pthread_mutex_t mutex;
133 extern struct playlist playlist;
134 extern struct searchable *tree_searchable;
135 extern struct searchable *shuffle_searchable;
136 extern struct searchable *sorted_searchable;
138 extern int pl_init(void);
139 extern int pl_exit(void);
141 /* set current track, these return track_info on success */
142 extern struct track_info *pl_set_next(void);
143 extern struct track_info *pl_set_prev(void);
144 extern struct track_info *pl_set_selected(void);
146 extern void pl_add_track(struct track_info *track_info);
148 extern void pl_set_sort_keys(char **keys);
149 extern void pl_clear(void);
150 extern void pl_set_filter(struct expr *expr);
151 extern void pl_remove(struct track_info *ti);
152 extern void pl_remove_sel(void);
153 extern void pl_toggle_expand_artist(void);
155 extern void pl_toggle_repeat(void);
156 extern void pl_toggle_playlist_mode(void);
157 extern void pl_toggle_play_mode(void);
158 extern void pl_set_repeat(int value);
159 extern void pl_set_playlist_mode(enum playlist_mode playlist_mode);
160 extern void pl_set_play_mode(enum play_mode play_mode);
161 extern void pl_get_status(int *repeat, enum playlist_mode *playlist_mode, enum play_mode *play_mode, int *total_time);
163 /* these are unlocked */
164 extern void __pl_set_view(int view);
166 extern void pl_toggle_active_window(void);
167 extern void pl_sel_current(void);
169 extern void pl_set_tree_win_nr_rows(int nr_rows);
170 extern void pl_set_track_win_nr_rows(int nr_rows);
171 extern void pl_set_shuffle_win_nr_rows(int nr_rows);
172 extern void pl_set_sorted_win_nr_rows(int nr_rows);
174 extern void pl_reshuffle(void);
177 * Run callback @cb for each selected track. Quit if @cb returns non-zero value.
179 * @cb: callback funtion
180 * @data: data argument for @cb
181 * @reverse: use reverse order?
183 * Returns: return value of last @cb call or 0 if @cb not called at all.
185 extern int __pl_for_each_selected(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);
186 extern int pl_for_each_selected(int (*cb)(void *data, struct track_info *ti), void *data, int reverse);
187 extern int pl_for_each(int (*cb)(void *data, struct track_info *ti), void *data);
189 #define pl_lock() cmus_mutex_lock(&playlist.mutex)
190 #define pl_unlock() cmus_mutex_unlock(&playlist.mutex)
192 static inline struct track *iter_to_shuffle_track(const struct iter *iter)
194 BUG_ON(iter->data0 != &playlist.shuffle_head);
195 return iter->data1;
198 static inline struct track *iter_to_sorted_track(const struct iter *iter)
200 BUG_ON(iter->data0 != &playlist.sorted_head);
201 return iter->data1;
204 static inline struct artist *iter_to_artist(const struct iter *iter)
206 BUG_ON(iter->data0 != &playlist.artist_head);
207 return iter->data1;
210 static inline struct album *iter_to_album(const struct iter *iter)
212 BUG_ON(iter->data0 != &playlist.artist_head);
213 return iter->data2;
216 static inline struct track *iter_to_track(const struct iter *iter)
218 return iter->data1;
221 #endif