1 #ifndef MPLAYER_PLAYTREE_H
2 #define MPLAYER_PLAYTREE_H
10 /// \defgroup PlaytreeIterReturn Playtree iterator return code
11 /// \ingroup PlaytreeIter
13 #define PLAY_TREE_ITER_ERROR 0
14 #define PLAY_TREE_ITER_ENTRY 1
15 #define PLAY_TREE_ITER_NODE 2
16 #define PLAY_TREE_ITER_END 3
19 /// \defgroup PlaytreeEntryTypes Playtree entry types
22 #define PLAY_TREE_ENTRY_NODE -1
23 #define PLAY_TREE_ENTRY_DVD 0
24 #define PLAY_TREE_ENTRY_VCD 1
25 #define PLAY_TREE_ENTRY_TV 2
26 #define PLAY_TREE_ENTRY_FILE 3
30 /// \defgroup PlaytreeEntryFlags Playtree flags
33 /// Play the item children in random order.
34 #define PLAY_TREE_RND (1<<0)
35 /// Playtree flags used by the iterator to mark items already "randomly" played.
36 #define PLAY_TREE_RND_PLAYED (1<<8)
39 /// \defgroup PlaytreeIterMode Playtree iterator mode
40 /// \ingroup PlaytreeIter
42 #define PLAY_TREE_ITER_NORMAL 0
43 #define PLAY_TREE_ITER_RND 1
46 /// \defgroup Playtree
49 typedef struct play_tree play_tree_t
;
50 /// \ingroup PlaytreeIter
51 typedef struct play_tree_iter play_tree_iter_t
;
52 typedef struct play_tree_param play_tree_param_t
;
56 typedef struct play_tree_info play_tree_info_t
;
57 // TODO : a attrib,val pair system and not something hardcoded
58 struct play_tree_info
{
67 struct play_tree_param
{
80 //play_tree_info_t info;
81 play_tree_param_t
* params
;
89 /// \defgroup PlaytreeIter Playtree iterator
94 struct play_tree_iter
{
95 /// Root of the iterated tree.
97 /// Current position in the tree.
100 struct m_config
* config
;
103 /// Selected file in the current item.
105 /// Number of files in the current item.
110 /// loop/valid stack to save/revert status when we go up/down.
112 /// status stack size
117 /// Create a new empty playtree item.
121 /// Free a playtree item.
122 /** \param pt Item to free.
123 * \param children If non-zero the item's children are recursively freed.
126 play_tree_free(play_tree_t
* pt
, int children
);
129 /// Free an item and its siblings.
130 /** \param pt Item to free.
131 * \param children If non-zero the items' children are recursively freed.
134 play_tree_free_list(play_tree_t
* pt
, int children
);
137 /// Set the children of a playtree item.
139 play_tree_set_child(play_tree_t
* pt
, play_tree_t
* child
);
141 /// Set the parent of a playtree item.
143 play_tree_set_parent(play_tree_t
* pt
, play_tree_t
* parent
);
146 /// Append an item after its siblings.
148 play_tree_append_entry(play_tree_t
* pt
, play_tree_t
* entry
);
150 /// Prepend an item before its siblings.
152 play_tree_prepend_entry(play_tree_t
* pt
, play_tree_t
* entry
);
154 /// Insert an item right after a siblings.
156 play_tree_insert_entry(play_tree_t
* pt
, play_tree_t
* entry
);
158 /// Detach an item from the tree.
160 play_tree_remove(play_tree_t
* pt
, int free_it
,int with_children
);
162 /// Add a file to an item.
164 play_tree_add_file(play_tree_t
* pt
,char* file
);
166 /// Remove a file from an item.
168 play_tree_remove_file(play_tree_t
* pt
,char* file
);
171 /// Add a config paramter to an item.
173 play_tree_set_param(play_tree_t
* pt
, char* name
, char* val
);
175 /// Remove a config parameter from an item.
177 play_tree_unset_param(play_tree_t
* pt
, char* name
);
179 /// Copy the config parameters from one item to another.
181 play_tree_set_params_from(play_tree_t
* dest
,play_tree_t
* src
);
183 /// \addtogroup PlaytreeIter
186 /// Create a new iterator.
188 play_tree_iter_new(play_tree_t
* pt
, struct m_config
* config
);
190 /// Duplicate an iterator.
192 play_tree_iter_new_copy(play_tree_iter_t
* old
);
194 /// Free an iterator.
196 play_tree_iter_free(play_tree_iter_t
* iter
);
198 /// Step an iterator.
199 /** \param iter The iterator.
200 * \param d The direction: d > 0 == next , d < 0 == prev
201 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
202 * \return See \ref PlaytreeIterReturn.
205 play_tree_iter_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
207 /// Step up, useful to break a loop, etc.
208 /** \param iter The iterator.
209 * \param d The direction: d > 0 == next , d < 0 == prev
210 * \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
211 * \return See \ref PlaytreeIterReturn.
214 play_tree_iter_up_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
216 /// Enter a node child list, only useful when stopping on nodes.
218 play_tree_iter_down_step(play_tree_iter_t
* iter
, int d
,int with_nodes
);
220 /// Get a file from the current item.
222 play_tree_iter_get_file(play_tree_iter_t
* iter
, int d
);
225 // PlaytreeIter group
227 /// Create a playtree from a playlist file.
228 /** \ingroup PlaytreeParser
232 parse_playtree(struct stream
*stream
, struct m_config
*mconfig
, int forced
);
234 /// Clean a tree by destroying all empty elements.
236 play_tree_cleanup(play_tree_t
* pt
);
238 /// Create a playtree from a playlist file.
239 /** \ingroup PlaytreeParser
242 parse_playlist_file(struct m_config
*mconfig
, char* file
);
244 /// \defgroup PtAPI Playtree highlevel API
245 /// \ingroup Playtree
246 /// Highlevel API with pt-suffix to different from low-level API
247 /// by Fabian Franz (mplayer@fabian-franz.de).
250 // Cleans up pt and creates a new iter.
251 play_tree_iter_t
* pt_iter_create(play_tree_t
** pt
, struct m_config
* config
);
254 void pt_iter_destroy(play_tree_iter_t
** iter
);
256 /// Gets the next available file in the direction (d=-1 || d=+1).
257 char* pt_iter_get_file(play_tree_iter_t
* iter
, int d
);
259 // Two Macros that implement forward and backward direction.
260 #define pt_iter_get_next_file(iter) pt_iter_get_file(iter, 1)
261 #define pt_iter_get_prev_file(iter) pt_iter_get_file(iter, -1)
263 /// Inserts entry into the playtree.
264 void pt_iter_insert_entry(play_tree_iter_t
* iter
, play_tree_t
* entry
);
266 /// Replaces current entry in playtree with entry by doing insert and remove.
267 void pt_iter_replace_entry(play_tree_iter_t
* iter
, play_tree_t
* entry
);
269 /// Adds a new file to the playtree, if it is not valid it is created.
270 void pt_add_file(play_tree_t
** ppt
, char* filename
);
272 /// \brief Performs a convert to playtree-syntax, by concat path/file
273 /// and performs pt_add_file
274 void pt_add_gui_file(play_tree_t
** ppt
, char* path
, char* file
);
276 // Two macros to use only the iter and not the other things.
277 #define pt_iter_add_file(iter, filename) pt_add_file(&iter->tree, filename)
278 #define pt_iter_add_gui_file(iter, path, name) pt_add_gui_file(&iter->tree, path, name)
280 /// Resets the iter and goes back to head.
281 void pt_iter_goto_head(play_tree_iter_t
* iter
);
287 #endif /* MPLAYER_PLAYTREE_H */