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
30 /// \defgroup PlaytreeIterReturn Playtree iterator return code
31 /// \ingroup PlaytreeIter
33 #define PLAY_TREE_ITER_ERROR 0
34 #define PLAY_TREE_ITER_ENTRY 1
35 #define PLAY_TREE_ITER_NODE 2
36 #define PLAY_TREE_ITER_END 3
39 /// \defgroup PlaytreeEntryTypes Playtree entry types
42 #define PLAY_TREE_ENTRY_NODE -1
43 #define PLAY_TREE_ENTRY_DVD 0
44 #define PLAY_TREE_ENTRY_VCD 1
45 #define PLAY_TREE_ENTRY_TV 2
46 #define PLAY_TREE_ENTRY_FILE 3
50 /// \defgroup PlaytreeEntryFlags Playtree flags
53 /// Play the item children in random order.
54 #define PLAY_TREE_RND (1<<0)
55 /// Playtree flags used by the iterator to mark items already "randomly" played.
56 #define PLAY_TREE_RND_PLAYED (1<<8)
59 /// \defgroup PlaytreeIterMode Playtree iterator mode
60 /// \ingroup PlaytreeIter
62 #define PLAY_TREE_ITER_NORMAL 0
63 #define PLAY_TREE_ITER_RND 1
66 /// \defgroup Playtree
69 typedef struct play_tree play_tree_t
;
70 /// \ingroup PlaytreeIter
71 typedef struct play_tree_iter play_tree_iter_t
;
72 typedef struct play_tree_param play_tree_param_t
;
76 typedef struct play_tree_info play_tree_info_t
;
77 // TODO : a attrib,val pair system and not something hardcoded
78 struct play_tree_info
{
87 struct play_tree_param
{
100 //play_tree_info_t info;
101 play_tree_param_t
* params
;
109 /// \defgroup PlaytreeIter Playtree iterator
110 /// \ingroup Playtree
113 /// Playtree iterator
114 struct play_tree_iter
{
115 /// Root of the iterated tree.
117 /// Current position in the tree.
119 /// \ref Config used.
120 struct m_config
* config
;
123 /// Selected file in the current item.
125 /// Number of files in the current item.
130 /// loop/valid stack to save/revert status when we go up/down.
132 /// status stack size
137 /// Create a new empty playtree item.
141 /// Free a playtree item.
142 /** \param pt Item to free.
143 * \param children If non-zero the item's children are recursively freed.
146 play_tree_free(play_tree_t
* pt
, int children
);
149 /// Free an item and its siblings.
150 /** \param pt Item to free.
151 * \param children If non-zero the items' children are recursively freed.
154 play_tree_free_list(play_tree_t
* pt
, int children
);
157 /// Set the children of a playtree item.
159 play_tree_set_child(play_tree_t
* pt
, play_tree_t
* child
);
161 /// Set the parent of a playtree item.
163 play_tree_set_parent(play_tree_t
* pt
, play_tree_t
* parent
);
166 /// Append an item after its siblings.
168 play_tree_append_entry(play_tree_t
* pt
, play_tree_t
* entry
);
170 /// Prepend an item before its siblings.
172 play_tree_prepend_entry(play_tree_t
* pt
, play_tree_t
* entry
);
174 /// Insert an item right after a siblings.
176 play_tree_insert_entry(play_tree_t
* pt
, play_tree_t
* entry
);
178 /// Detach an item from the tree.
180 play_tree_remove(play_tree_t
* pt
, int free_it
,int with_children
);
182 /// Add a file to an item.
184 play_tree_add_file(play_tree_t
* pt
,const char* file
);
186 /// Remove a file from an item.
188 play_tree_remove_file(play_tree_t
* pt
,const char* file
);
191 /// Add a config paramter to an item.
193 play_tree_set_param(play_tree_t
* pt
, struct bstr name
, struct bstr val
);
195 /// Remove a config parameter from an item.
197 play_tree_unset_param(play_tree_t
* pt
, const char* name
);
199 /// Copy the config parameters from one item to another.
201 play_tree_set_params_from(play_tree_t
* dest
,play_tree_t
* src
);
203 /// \addtogroup PlaytreeIter
206 /// Create a new iterator.
208 play_tree_iter_new(play_tree_t
* pt
, struct m_config
* config
);
210 /// Duplicate an iterator.
212 play_tree_iter_new_copy(play_tree_iter_t
* old
);
214 /// Free an iterator.
216 play_tree_iter_free(play_tree_iter_t
* iter
);
218 /// Step an iterator.
219 /** \param iter The iterator.
220 * \param d The direction: d > 0 == next , d < 0 == prev
221 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
222 * \return See \ref PlaytreeIterReturn.
225 play_tree_iter_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
227 /// Step up, useful to break a loop, etc.
228 /** \param iter The iterator.
229 * \param d The direction: d > 0 == next , d < 0 == prev
230 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
231 * \return See \ref PlaytreeIterReturn.
234 play_tree_iter_up_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
236 /// Enter a node child list, only useful when stopping on nodes.
238 play_tree_iter_down_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
240 /// Get a file from the current item.
242 play_tree_iter_get_file(play_tree_iter_t
* iter
, int d
);
245 // PlaytreeIter group
247 /// Create a playtree from a playlist file.
248 /** \ingroup PlaytreeParser
252 parse_playtree(struct stream
*stream
, struct m_config
*mconfig
, int forced
);
254 /// Clean a tree by destroying all empty elements.
256 play_tree_cleanup(play_tree_t
* pt
);
258 /// Create a playtree from a playlist file.
259 /** \ingroup PlaytreeParser
262 parse_playlist_file(struct m_config
*mconfig
, struct bstr file
);
264 /// \defgroup PtAPI Playtree highlevel API
265 /// \ingroup Playtree
266 /// Highlevel API with pt-suffix to different from low-level API
267 /// by Fabian Franz (mplayer@fabian-franz.de).
270 // Cleans up pt and creates a new iter.
271 play_tree_iter_t
* pt_iter_create(play_tree_t
** pt
, struct m_config
* config
);
274 void pt_iter_destroy(play_tree_iter_t
** iter
);
276 /// Gets the next available file in the direction (d=-1 || d=+1).
277 char* pt_iter_get_file(play_tree_iter_t
* iter
, int d
);
279 // Two Macros that implement forward and backward direction.
280 #define pt_iter_get_next_file(iter) pt_iter_get_file(iter, 1)
281 #define pt_iter_get_prev_file(iter) pt_iter_get_file(iter, -1)
283 /// Inserts entry into the playtree.
284 void pt_iter_insert_entry(play_tree_iter_t
* iter
, play_tree_t
* entry
);
286 /// Replaces current entry in playtree with entry by doing insert and remove.
287 void pt_iter_replace_entry(play_tree_iter_t
* iter
, play_tree_t
* entry
);
289 /// Adds a new file to the playtree, if it is not valid it is created.
290 void pt_add_file(play_tree_t
** ppt
, const char* filename
);
292 // A macro to use only the iter and not the other things.
293 #define pt_iter_add_file(iter, filename) pt_add_file(&iter->tree, filename)
295 /// Resets the iter and goes back to head.
296 void pt_iter_goto_head(play_tree_iter_t
* iter
);
302 #endif /* MPLAYER_PLAYTREE_H */