Makefile: Add a command to the binary build rule.
[mplayer.git] / playtree.h
blobc7bfaeb7f17ed3bb94884505d364fee3d13302aa
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_PLAYTREE_H
20 #define MPLAYER_PLAYTREE_H
22 /// \file
23 /// \ingroup Playtree
25 struct stream;
26 struct m_config;
28 /// \defgroup PlaytreeIterReturn Playtree iterator return code
29 /// \ingroup PlaytreeIter
30 ///@{
31 #define PLAY_TREE_ITER_ERROR 0
32 #define PLAY_TREE_ITER_ENTRY 1
33 #define PLAY_TREE_ITER_NODE 2
34 #define PLAY_TREE_ITER_END 3
35 ///@}
37 /// \defgroup PlaytreeEntryTypes Playtree entry types
38 /// \ingroup Playtree
39 ///@{
40 #define PLAY_TREE_ENTRY_NODE -1
41 #define PLAY_TREE_ENTRY_DVD 0
42 #define PLAY_TREE_ENTRY_VCD 1
43 #define PLAY_TREE_ENTRY_TV 2
44 #define PLAY_TREE_ENTRY_FILE 3
45 ///@}
48 /// \defgroup PlaytreeEntryFlags Playtree flags
49 /// \ingroup Playtree
50 ///@{
51 /// Play the item children in random order.
52 #define PLAY_TREE_RND (1<<0)
53 /// Playtree flags used by the iterator to mark items already "randomly" played.
54 #define PLAY_TREE_RND_PLAYED (1<<8)
55 ///@}
57 /// \defgroup PlaytreeIterMode Playtree iterator mode
58 /// \ingroup PlaytreeIter
59 ///@{
60 #define PLAY_TREE_ITER_NORMAL 0
61 #define PLAY_TREE_ITER_RND 1
62 ///@}
64 /// \defgroup Playtree
65 ///@{
67 typedef struct play_tree play_tree_t;
68 /// \ingroup PlaytreeIter
69 typedef struct play_tree_iter play_tree_iter_t;
70 typedef struct play_tree_param play_tree_param_t;
73 #if 0
74 typedef struct play_tree_info play_tree_info_t;
75 // TODO : a attrib,val pair system and not something hardcoded
76 struct play_tree_info {
77 char* title;
78 char* author;
79 char* copyright;
80 char* abstract;
81 // Some more ??
83 #endif
85 struct play_tree_param {
86 char* name;
87 char* value;
91 /// Playtree item
92 struct play_tree {
93 play_tree_t* parent;
94 play_tree_t* child;
95 play_tree_t* next;
96 play_tree_t* prev;
98 //play_tree_info_t info;
99 play_tree_param_t* params;
100 int loop;
101 char** files;
102 int entry_type;
103 int flags;
107 /// \defgroup PlaytreeIter Playtree iterator
108 /// \ingroup Playtree
109 ///@{
111 /// Playtree iterator
112 struct play_tree_iter {
113 /// Root of the iterated tree.
114 play_tree_t* root;
115 /// Current position in the tree.
116 play_tree_t* tree;
117 /// \ref Config used.
118 struct m_config* config;
119 /// Looping status
120 int loop;
121 /// Selected file in the current item.
122 int file;
123 /// Number of files in the current item.
124 int num_files;
125 int entry_pushed;
126 int mode;
128 /// loop/valid stack to save/revert status when we go up/down.
129 int* status_stack;
130 /// status stack size
131 int stack_size;
133 ///@}
135 /// Create a new empty playtree item.
136 play_tree_t*
137 play_tree_new(void);
139 /// Free a playtree item.
140 /** \param pt Item to free.
141 * \param children If non-zero the item's children are recursively freed.
143 void
144 play_tree_free(play_tree_t* pt, int children);
147 /// Free an item and its siblings.
148 /** \param pt Item to free.
149 * \param children If non-zero the items' children are recursively freed.
151 void
152 play_tree_free_list(play_tree_t* pt, int children);
155 /// Set the children of a playtree item.
156 void
157 play_tree_set_child(play_tree_t* pt, play_tree_t* child);
159 /// Set the parent of a playtree item.
160 void
161 play_tree_set_parent(play_tree_t* pt, play_tree_t* parent);
164 /// Append an item after its siblings.
165 void
166 play_tree_append_entry(play_tree_t* pt, play_tree_t* entry);
168 /// Prepend an item before its siblings.
169 void
170 play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry);
172 /// Insert an item right after a siblings.
173 void
174 play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry);
176 /// Detach an item from the tree.
177 void
178 play_tree_remove(play_tree_t* pt, int free_it,int with_children);
180 /// Add a file to an item.
181 void
182 play_tree_add_file(play_tree_t* pt,char* file);
184 /// Remove a file from an item.
186 play_tree_remove_file(play_tree_t* pt,char* file);
189 /// Add a config paramter to an item.
190 void
191 play_tree_set_param(play_tree_t* pt, char* name, char* val);
193 /// Remove a config parameter from an item.
195 play_tree_unset_param(play_tree_t* pt, char* name);
197 /// Copy the config parameters from one item to another.
198 void
199 play_tree_set_params_from(play_tree_t* dest,play_tree_t* src);
201 /// \addtogroup PlaytreeIter
202 ///@{
204 /// Create a new iterator.
205 play_tree_iter_t*
206 play_tree_iter_new(play_tree_t* pt, struct m_config* config);
208 /// Duplicate an iterator.
209 play_tree_iter_t*
210 play_tree_iter_new_copy(play_tree_iter_t* old);
212 /// Free an iterator.
213 void
214 play_tree_iter_free(play_tree_iter_t* iter);
216 /// Step an iterator.
217 /** \param iter The iterator.
218 * \param d The direction: d > 0 == next , d < 0 == prev
219 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
220 * \return See \ref PlaytreeIterReturn.
223 play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes);
225 /// Step up, useful to break a loop, etc.
226 /** \param iter The iterator.
227 * \param d The direction: d > 0 == next , d < 0 == prev
228 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
229 * \return See \ref PlaytreeIterReturn.
232 play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes);
234 /// Enter a node child list, only useful when stopping on nodes.
236 play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes);
238 /// Get a file from the current item.
239 char*
240 play_tree_iter_get_file(play_tree_iter_t* iter, int d);
242 ///@}
243 // PlaytreeIter group
245 /// Create a playtree from a playlist file.
246 /** \ingroup PlaytreeParser
248 struct m_config;
249 play_tree_t*
250 parse_playtree(struct stream *stream, struct m_config *mconfig, int forced);
252 /// Clean a tree by destroying all empty elements.
253 play_tree_t*
254 play_tree_cleanup(play_tree_t* pt);
256 /// Create a playtree from a playlist file.
257 /** \ingroup PlaytreeParser
259 play_tree_t*
260 parse_playlist_file(struct m_config *mconfig, char* file);
262 /// \defgroup PtAPI Playtree highlevel API
263 /// \ingroup Playtree
264 /// Highlevel API with pt-suffix to different from low-level API
265 /// by Fabian Franz (mplayer@fabian-franz.de).
266 ///@{
268 // Cleans up pt and creates a new iter.
269 play_tree_iter_t* pt_iter_create(play_tree_t** pt, struct m_config* config);
271 /// Frees the iter.
272 void pt_iter_destroy(play_tree_iter_t** iter);
274 /// Gets the next available file in the direction (d=-1 || d=+1).
275 char* pt_iter_get_file(play_tree_iter_t* iter, int d);
277 // Two Macros that implement forward and backward direction.
278 #define pt_iter_get_next_file(iter) pt_iter_get_file(iter, 1)
279 #define pt_iter_get_prev_file(iter) pt_iter_get_file(iter, -1)
281 /// Inserts entry into the playtree.
282 void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry);
284 /// Replaces current entry in playtree with entry by doing insert and remove.
285 void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry);
287 /// Adds a new file to the playtree, if it is not valid it is created.
288 void pt_add_file(play_tree_t** ppt, char* filename);
290 // A macro to use only the iter and not the other things.
291 #define pt_iter_add_file(iter, filename) pt_add_file(&iter->tree, filename)
293 /// Resets the iter and goes back to head.
294 void pt_iter_goto_head(play_tree_iter_t* iter);
296 ///@}
298 ///@}
300 #endif /* MPLAYER_PLAYTREE_H */