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
28 /// \defgroup PlaytreeIterReturn Playtree iterator return code
29 /// \ingroup PlaytreeIter
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
37 /// \defgroup PlaytreeEntryTypes Playtree entry types
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
48 /// \defgroup PlaytreeEntryFlags Playtree flags
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)
57 /// \defgroup PlaytreeIterMode Playtree iterator mode
58 /// \ingroup PlaytreeIter
60 #define PLAY_TREE_ITER_NORMAL 0
61 #define PLAY_TREE_ITER_RND 1
64 /// \defgroup Playtree
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
;
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
{
85 struct play_tree_param
{
98 //play_tree_info_t info;
99 play_tree_param_t
* params
;
107 /// \defgroup PlaytreeIter Playtree iterator
108 /// \ingroup Playtree
111 /// Playtree iterator
112 struct play_tree_iter
{
113 /// Root of the iterated tree.
115 /// Current position in the tree.
117 /// \ref Config used.
118 struct m_config
* config
;
121 /// Selected file in the current item.
123 /// Number of files in the current item.
128 /// loop/valid stack to save/revert status when we go up/down.
130 /// status stack size
135 /// Create a new empty playtree item.
139 /// Free a playtree item.
140 /** \param pt Item to free.
141 * \param children If non-zero the item's children are recursively freed.
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.
152 play_tree_free_list(play_tree_t
* pt
, int children
);
155 /// Set the children of a playtree item.
157 play_tree_set_child(play_tree_t
* pt
, play_tree_t
* child
);
159 /// Set the parent of a playtree item.
161 play_tree_set_parent(play_tree_t
* pt
, play_tree_t
* parent
);
164 /// Append an item after its siblings.
166 play_tree_append_entry(play_tree_t
* pt
, play_tree_t
* entry
);
168 /// Prepend an item before its siblings.
170 play_tree_prepend_entry(play_tree_t
* pt
, play_tree_t
* entry
);
172 /// Insert an item right after a siblings.
174 play_tree_insert_entry(play_tree_t
* pt
, play_tree_t
* entry
);
176 /// Detach an item from the tree.
178 play_tree_remove(play_tree_t
* pt
, int free_it
,int with_children
);
180 /// Add a file to an item.
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.
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.
199 play_tree_set_params_from(play_tree_t
* dest
,play_tree_t
* src
);
201 /// \addtogroup PlaytreeIter
204 /// Create a new iterator.
206 play_tree_iter_new(play_tree_t
* pt
, struct m_config
* config
);
208 /// Duplicate an iterator.
210 play_tree_iter_new_copy(play_tree_iter_t
* old
);
212 /// Free an iterator.
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.
240 play_tree_iter_get_file(play_tree_iter_t
* iter
, int d
);
243 // PlaytreeIter group
245 /// Create a playtree from a playlist file.
246 /** \ingroup PlaytreeParser
250 parse_playtree(struct stream
*stream
, struct m_config
*mconfig
, int forced
);
252 /// Clean a tree by destroying all empty elements.
254 play_tree_cleanup(play_tree_t
* pt
);
256 /// Create a playtree from a playlist file.
257 /** \ingroup PlaytreeParser
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).
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
);
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
);
300 #endif /* MPLAYER_PLAYTREE_H */