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
31 /// \defgroup PlaytreeIterReturn Playtree iterator return code
32 /// \ingroup PlaytreeIter
34 #define PLAY_TREE_ITER_ERROR 0
35 #define PLAY_TREE_ITER_ENTRY 1
36 #define PLAY_TREE_ITER_NODE 2
37 #define PLAY_TREE_ITER_END 3
40 /// \defgroup PlaytreeEntryTypes Playtree entry types
43 #define PLAY_TREE_ENTRY_NODE -1
44 #define PLAY_TREE_ENTRY_DVD 0
45 #define PLAY_TREE_ENTRY_VCD 1
46 #define PLAY_TREE_ENTRY_TV 2
47 #define PLAY_TREE_ENTRY_FILE 3
51 /// \defgroup PlaytreeEntryFlags Playtree flags
54 /// Play the item children in random order.
55 #define PLAY_TREE_RND (1<<0)
56 /// Playtree flags used by the iterator to mark items already "randomly" played.
57 #define PLAY_TREE_RND_PLAYED (1<<8)
60 /// \defgroup PlaytreeIterMode Playtree iterator mode
61 /// \ingroup PlaytreeIter
63 #define PLAY_TREE_ITER_NORMAL 0
64 #define PLAY_TREE_ITER_RND 1
67 /// \defgroup Playtree
70 typedef struct play_tree play_tree_t
;
71 /// \ingroup PlaytreeIter
72 typedef struct play_tree_iter play_tree_iter_t
;
73 typedef struct play_tree_param play_tree_param_t
;
77 typedef struct play_tree_info play_tree_info_t
;
78 // TODO : a attrib,val pair system and not something hardcoded
79 struct play_tree_info
{
88 struct play_tree_param
{
101 //play_tree_info_t info;
102 play_tree_param_t
* params
;
110 /// \defgroup PlaytreeIter Playtree iterator
111 /// \ingroup Playtree
114 /// Playtree iterator
115 struct play_tree_iter
{
116 /// Root of the iterated tree.
118 /// Current position in the tree.
120 /// \ref Config used.
121 struct m_config
* config
;
124 /// Selected file in the current item.
126 /// Number of files in the current item.
131 /// loop/valid stack to save/revert status when we go up/down.
133 /// status stack size
138 /// Create a new empty playtree item.
142 /// Free a playtree item.
143 /** \param pt Item to free.
144 * \param children If non-zero the item's children are recursively freed.
147 play_tree_free(play_tree_t
* pt
, int children
);
150 /// Free an item and its siblings.
151 /** \param pt Item to free.
152 * \param children If non-zero the items' children are recursively freed.
155 play_tree_free_list(play_tree_t
* pt
, int children
);
158 /// Set the children of a playtree item.
160 play_tree_set_child(play_tree_t
* pt
, play_tree_t
* child
);
162 /// Set the parent of a playtree item.
164 play_tree_set_parent(play_tree_t
* pt
, play_tree_t
* parent
);
167 /// Append an item after its siblings.
169 play_tree_append_entry(play_tree_t
* pt
, play_tree_t
* entry
);
171 /// Prepend an item before its siblings.
173 play_tree_prepend_entry(play_tree_t
* pt
, play_tree_t
* entry
);
175 /// Insert an item right after a siblings.
177 play_tree_insert_entry(play_tree_t
* pt
, play_tree_t
* entry
);
179 /// Detach an item from the tree.
181 play_tree_remove(play_tree_t
* pt
, int free_it
,int with_children
);
183 /// Add a file to an item.
185 play_tree_add_file(play_tree_t
* pt
,const char* file
);
187 /// Remove a file from an item.
189 play_tree_remove_file(play_tree_t
* pt
,const char* file
);
192 /// Add a config paramter to an item.
194 play_tree_set_param(play_tree_t
* pt
, struct bstr name
, struct bstr val
);
196 /// Remove a config parameter from an item.
198 play_tree_unset_param(play_tree_t
* pt
, const char* name
);
200 /// Copy the config parameters from one item to another.
202 play_tree_set_params_from(play_tree_t
* dest
,play_tree_t
* src
);
204 /// \addtogroup PlaytreeIter
207 /// Create a new iterator.
209 play_tree_iter_new(play_tree_t
* pt
, struct m_config
* config
);
211 /// Duplicate an iterator.
213 play_tree_iter_new_copy(play_tree_iter_t
* old
);
215 /// Free an iterator.
217 play_tree_iter_free(play_tree_iter_t
* iter
);
219 /// Step an iterator.
220 /** \param iter The iterator.
221 * \param d The direction: d > 0 == next , d < 0 == prev
222 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
223 * \return See \ref PlaytreeIterReturn.
226 play_tree_iter_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
228 /// Step up, useful to break a loop, etc.
229 /** \param iter The iterator.
230 * \param d The direction: d > 0 == next , d < 0 == prev
231 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
232 * \return See \ref PlaytreeIterReturn.
235 play_tree_iter_up_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
237 /// Enter a node child list, only useful when stopping on nodes.
239 play_tree_iter_down_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
241 /// Get a file from the current item.
243 play_tree_iter_get_file(play_tree_iter_t
* iter
, int d
);
246 // PlaytreeIter group
248 /// Create a playtree from a playlist file.
249 /** \ingroup PlaytreeParser
253 parse_playtree(struct stream
*stream
, struct MPOpts
*opts
, int forced
);
255 /// Clean a tree by destroying all empty elements.
257 play_tree_cleanup(play_tree_t
* pt
);
259 /// Create a playtree from a playlist file.
260 /** \ingroup PlaytreeParser
263 parse_playlist_file(struct MPOpts
*opts
, struct bstr file
);
265 /// \defgroup PtAPI Playtree highlevel API
266 /// \ingroup Playtree
267 /// Highlevel API with pt-suffix to different from low-level API
268 /// by Fabian Franz (mplayer@fabian-franz.de).
271 // Cleans up pt and creates a new iter.
272 play_tree_iter_t
* pt_iter_create(play_tree_t
** pt
, struct m_config
* config
);
275 void pt_iter_destroy(play_tree_iter_t
** iter
);
277 /// Gets the next available file in the direction (d=-1 || d=+1).
278 char* pt_iter_get_file(play_tree_iter_t
* iter
, int d
);
280 // Two Macros that implement forward and backward direction.
281 #define pt_iter_get_next_file(iter) pt_iter_get_file(iter, 1)
282 #define pt_iter_get_prev_file(iter) pt_iter_get_file(iter, -1)
284 /// Inserts entry into the playtree.
285 void pt_iter_insert_entry(play_tree_iter_t
* iter
, play_tree_t
* entry
);
287 /// Replaces current entry in playtree with entry by doing insert and remove.
288 void pt_iter_replace_entry(play_tree_iter_t
* iter
, play_tree_t
* entry
);
290 /// Adds a new file to the playtree, if it is not valid it is created.
291 void pt_add_file(play_tree_t
** ppt
, const char* filename
);
293 // A macro to use only the iter and not the other things.
294 #define pt_iter_add_file(iter, filename) pt_add_file(&iter->tree, filename)
296 /// Resets the iter and goes back to head.
297 void pt_iter_goto_head(play_tree_iter_t
* iter
);
303 #endif /* MPLAYER_PLAYTREE_H */