1 /*****************************************************************************
2 * item.c : Playlist item creation/deletion/add/removal functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 #include <vlc_common.h>
30 #include <vlc_playlist.h>
31 #include "playlist_internal.h"
33 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
34 playlist_item_t *p_node, int i_mode, int i_pos );
35 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
37 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item );
39 static playlist_item_t *ItemToNode( playlist_t *, playlist_item_t *, bool );
41 static int RecursiveAddIntoParent (
42 playlist_t *p_playlist, playlist_item_t *p_parent,
43 input_item_node_t *p_node, int i_pos, bool b_flat,
44 playlist_item_t **pp_first_leaf );
46 /*****************************************************************************
47 * An input item has gained subitems (Event Callback)
48 *****************************************************************************/
50 static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
53 input_item_t *p_input = p_event->p_obj;
54 playlist_t *p_playlist = (( playlist_item_t* ) user_data)->p_playlist;
55 input_item_node_t *p_new_root = p_event->u.input_item_subitem_tree_added.p_root;
59 playlist_item_t *p_item =
60 playlist_ItemGetByInput( p_playlist, p_input );
62 assert( p_item != NULL );
63 playlist_item_t *p_parent = p_item->p_parent;
64 assert( p_parent != NULL );
66 bool b_play = var_CreateGetBool( p_playlist, "playlist-autostart" ) &&
67 get_current_status_item( p_playlist ) == p_item;
68 bool b_stop = b_play && p_item->i_flags & PLAYLIST_SUBITEM_STOP_FLAG;
69 p_item->i_flags &= ~PLAYLIST_SUBITEM_STOP_FLAG;
72 for( int i = 0; i < p_parent->i_children; i++ )
74 if( p_parent->pp_children[i] == p_item )
82 playlist_item_t *p_up = p_item;
83 while( p_up->p_parent )
85 if( p_up->p_parent == p_playlist->p_playing ||
86 p_up->p_parent == p_playlist->p_media_library )
88 if( !pl_priv(p_playlist)->b_tree ) b_flat = true;
91 p_up = p_up->p_parent;
95 playlist_DeleteItem( p_playlist, p_item, true );
96 p_item = playlist_InsertInputItemTree( p_playlist, p_parent,
97 p_new_root, pos, true );
100 p_item = playlist_InsertInputItemTree( p_playlist, p_item,
101 p_new_root, 0, false );
107 playlist_Stop( p_playlist );
112 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
113 pl_Locked, get_current_status_node( p_playlist ), p_item );
118 /*****************************************************************************
119 * An input item's meta or duration has changed (Event Callback)
120 *****************************************************************************/
121 static void input_item_changed( const vlc_event_t * p_event,
124 playlist_item_t *p_item = user_data;
125 VLC_UNUSED( p_event );
126 var_SetAddress( p_item->p_playlist, "item-change", p_item->p_input );
129 /*****************************************************************************
130 * Listen to vlc_InputItemAddSubItem event
131 *****************************************************************************/
132 static void install_input_item_observer( playlist_item_t * p_item )
134 vlc_event_manager_t * p_em = &p_item->p_input->event_manager;
135 vlc_event_attach( p_em, vlc_InputItemSubItemTreeAdded,
136 input_item_add_subitem_tree, p_item );
137 vlc_event_attach( p_em, vlc_InputItemDurationChanged,
138 input_item_changed, p_item );
139 vlc_event_attach( p_em, vlc_InputItemMetaChanged,
140 input_item_changed, p_item );
141 vlc_event_attach( p_em, vlc_InputItemNameChanged,
142 input_item_changed, p_item );
143 vlc_event_attach( p_em, vlc_InputItemInfoChanged,
144 input_item_changed, p_item );
145 vlc_event_attach( p_em, vlc_InputItemErrorWhenReadingChanged,
146 input_item_changed, p_item );
149 static void uninstall_input_item_observer( playlist_item_t * p_item )
151 vlc_event_manager_t * p_em = &p_item->p_input->event_manager;
152 vlc_event_detach( p_em, vlc_InputItemSubItemTreeAdded,
153 input_item_add_subitem_tree, p_item );
154 vlc_event_detach( p_em, vlc_InputItemMetaChanged,
155 input_item_changed, p_item );
156 vlc_event_detach( p_em, vlc_InputItemDurationChanged,
157 input_item_changed, p_item );
158 vlc_event_detach( p_em, vlc_InputItemNameChanged,
159 input_item_changed, p_item );
160 vlc_event_detach( p_em, vlc_InputItemInfoChanged,
161 input_item_changed, p_item );
162 vlc_event_detach( p_em, vlc_InputItemErrorWhenReadingChanged,
163 input_item_changed, p_item );
166 /*****************************************************************************
167 * Playlist item creation
168 *****************************************************************************/
169 playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist,
170 input_item_t *p_input )
172 playlist_item_t* p_item = malloc( sizeof( playlist_item_t ) );
178 p_item->p_input = p_input;
179 vlc_gc_incref( p_item->p_input );
181 p_item->i_id = ++pl_priv(p_playlist)->i_last_playlist_id;
183 p_item->p_parent = NULL;
184 p_item->i_children = -1;
185 p_item->pp_children = NULL;
187 p_item->p_playlist = p_playlist;
189 install_input_item_observer( p_item );
194 /***************************************************************************
195 * Playlist item destruction
196 ***************************************************************************/
201 * \param p_item item to delete
202 * \return VLC_SUCCESS
204 int playlist_ItemRelease( playlist_item_t *p_item )
207 playlist_t *p_playlist = p_item->p_playlist;
210 /* Surprise, we can't actually do more because we
211 * don't do refcounting, or eauivalent.
212 * Because item are not only accessed by their id
213 * using playlist_item outside the PL_LOCK isn't safe.
214 * Most of the modules does that.
216 * Who wants to add proper memory management? */
217 uninstall_input_item_observer( p_item );
218 ARRAY_APPEND( pl_priv(p_playlist)->items_to_delete, p_item);
225 * Remove an input item when it appears from a root playlist item
226 * \param p_playlist playlist object
227 * \param p_input the input to delete
228 * \param p_root root playlist item
229 * \param b_do_stop must stop or not the playlist
230 * \return VLC_SUCCESS or VLC_EGENERIC
232 static int DeleteFromInput( playlist_t *p_playlist, input_item_t *p_input,
233 playlist_item_t *p_root, bool b_do_stop )
236 playlist_item_t *p_item = playlist_ItemFindFromInputAndRoot(
237 p_playlist, p_input, p_root, false );
238 if( !p_item ) return VLC_EGENERIC;
239 return playlist_DeleteItem( p_playlist, p_item, b_do_stop );
245 * Remove an input item when it appears from a root playlist item
246 * \param p_playlist playlist object
247 * \param p_input the input to delete
248 * \param p_root root playlist item
249 * \param b_locked TRUE if the playlist is locked
250 * \return VLC_SUCCESS or VLC_EGENERIC
252 int playlist_DeleteFromInputInParent( playlist_t *p_playlist,
253 input_item_t *p_item,
254 playlist_item_t *p_root, bool b_locked )
257 PL_LOCK_IF( !b_locked );
258 i_ret = DeleteFromInput( p_playlist, p_item, p_root, true );
259 PL_UNLOCK_IF( !b_locked );
266 * Search anywhere in playlist for an an input item and delete it
267 * \param p_playlist playlist object
268 * \param p_input the input to delete
269 * \param b_locked TRUE if the playlist is locked
270 * \return VLC_SUCCESS or VLC_ENOITEM
272 int playlist_DeleteFromInput( playlist_t *p_playlist, input_item_t *p_input,
276 PL_LOCK_IF( !b_locked );
277 i_ret = DeleteFromInput( p_playlist, p_input,
278 p_playlist->p_root, true );
279 PL_UNLOCK_IF( !b_locked );
280 return ( i_ret == VLC_SUCCESS ? VLC_SUCCESS : VLC_ENOITEM );
286 * \param p_playlist playlist object
287 * \param b_locked TRUE if the playlist is locked
290 void playlist_Clear( playlist_t * p_playlist, bool b_locked )
292 PL_LOCK_IF( !b_locked );
293 playlist_NodeEmpty( p_playlist, p_playlist->p_playing, true );
294 PL_UNLOCK_IF( !b_locked );
298 * Delete playlist item
300 * Remove a playlist item from the playlist, given its id
301 * This function is to be used only by the playlist
302 * \param p_playlist playlist object
303 * \param i_id id of the item do delete
304 * \return VLC_SUCCESS or an error
306 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
309 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
310 if( !p_item ) return VLC_EGENERIC;
311 return playlist_DeleteItem( p_playlist, p_item, true );
314 /***************************************************************************
315 * Playlist item addition
316 ***************************************************************************/
320 * Add an item to the playlist or the media library
321 * \param p_playlist the playlist to add into
322 * \param psz_uri the mrl to add to the playlist
323 * \param psz_name a text giving a name or description of this item
324 * \param i_mode the mode used when adding
325 * \param i_pos the position in the playlist where to add. If this is
326 * PLAYLIST_END the item will be added at the end of the playlist
327 * regardless of its size
328 * \param b_playlist TRUE for playlist, FALSE for media library
329 * \param b_locked TRUE if the playlist is locked
330 * \return VLC_SUCCESS or a VLC error code
332 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
333 const char *psz_name, int i_mode, int i_pos,
334 bool b_playlist, bool b_locked )
336 return playlist_AddExt( p_playlist, psz_uri, psz_name,
337 i_mode, i_pos, -1, 0, NULL, 0, b_playlist, b_locked );
341 * Add a MRL into the playlist or the media library, duration and options given
343 * \param p_playlist the playlist to add into
344 * \param psz_uri the mrl to add to the playlist
345 * \param psz_name a text giving a name or description of this item
346 * \param i_mode the mode used when adding
347 * \param i_pos the position in the playlist where to add. If this is
348 * PLAYLIST_END the item will be added at the end of the playlist
349 * regardless of its size
350 * \param i_duration length of the item in milliseconds.
351 * \param i_options the number of options
352 * \param ppsz_options an array of options
353 * \param i_option_flags options flags
354 * \param b_playlist TRUE for playlist, FALSE for media library
355 * \param b_locked TRUE if the playlist is locked
356 * \return VLC_SUCCESS or a VLC error code
358 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
359 const char *psz_name, int i_mode, int i_pos,
361 int i_options, const char *const *ppsz_options,
362 unsigned i_option_flags,
363 bool b_playlist, bool b_locked )
366 input_item_t *p_input;
368 p_input = input_item_NewExt( p_playlist, psz_uri, psz_name,
369 i_options, ppsz_options, i_option_flags,
371 if( p_input == NULL )
373 i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
375 vlc_gc_decref( p_input );
380 * Add an input item to the playlist node
382 * \param p_playlist the playlist to add into
383 * \param p_input the input item to add
384 * \param i_mode the mode used when adding
385 * \param i_pos the position in the playlist where to add. If this is
386 * PLAYLIST_END the item will be added at the end of the playlist
387 * regardless of its size
388 * \param b_playlist TRUE for playlist, FALSE for media library
389 * \param b_locked TRUE if the playlist is locked
390 * \return VLC_SUCCESS or VLC_ENOMEM or VLC_EGENERIC
392 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
393 int i_mode, int i_pos, bool b_playlist,
396 playlist_item_t *p_item;
397 if( p_playlist->b_die ) return VLC_EGENERIC;
398 if( !pl_priv(p_playlist)->b_doing_ml )
399 PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
402 PL_LOCK_IF( !b_locked );
404 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
405 if( p_item == NULL ) return VLC_ENOMEM;
406 AddItem( p_playlist, p_item,
407 b_playlist ? p_playlist->p_playing :
408 p_playlist->p_media_library , i_mode, i_pos );
410 GoAndPreparse( p_playlist, i_mode, p_item );
412 PL_UNLOCK_IF( !b_locked );
417 * Add an input item to a given node
419 * \param p_playlist the playlist to add into
420 * \param p_input the input item to add
421 * \param p_parent the parent item to add into
422 * \param i_mode the mode used when addin
423 * \param i_pos the position in the playlist where to add. If this is
424 * PLAYLIST_END the item will be added at the end of the playlist
425 * regardless of its size
426 * \param b_locked TRUE if the playlist is locked
427 * \return the new playlist item
429 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
430 input_item_t *p_input,
431 playlist_item_t *p_parent,
432 int i_mode, int i_pos,
435 playlist_item_t *p_item;
437 assert( p_parent && p_parent->i_children != -1 );
439 if( p_playlist->b_die )
441 PL_LOCK_IF( !b_locked );
443 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
444 if( p_item == NULL ) return NULL;
445 AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
447 PL_UNLOCK_IF( !b_locked );
453 * Insert a tree of input items into a given playlist node
455 * \param p_playlist the playlist to insert into
456 * \param p_parent the receiving playlist node (can be an item)
457 * \param p_node the root of input item tree,
458 only it's contents will be inserted
459 * \param i_pos the position in the playlist where to insert. If this is
460 * PLAYLIST_END the items will be added at the end of the playlist
461 * regardless of its size
462 * \param b_flat TRUE if the new tree contents should be flattened into a list
463 * \return the first new leaf inserted (in playing order)
465 playlist_item_t *playlist_InsertInputItemTree (
466 playlist_t *p_playlist, playlist_item_t *p_parent,
467 input_item_node_t *p_node, int i_pos, bool b_flat )
469 playlist_item_t *p_first_leaf = NULL;
470 RecursiveAddIntoParent ( p_playlist, p_parent, p_node, i_pos, b_flat, &p_first_leaf );
474 /*****************************************************************************
475 * Playlist item misc operations
476 *****************************************************************************/
481 * Transform an item to a node. Return the node in the category tree, or NULL
483 * This function must be entered without the playlist lock
484 * \param p_playlist the playlist object
485 * \param p_item the item to transform
486 * \param b_locked TRUE if the playlist is locked
487 * \return the item transform in a node
489 static playlist_item_t *ItemToNode( playlist_t *p_playlist,
490 playlist_item_t *p_item,
493 PL_LOCK_IF( !b_locked );
495 assert( p_item->p_parent );
498 playlist_item_t *p_up = p_item;
499 while( p_up->p_parent )
501 if( p_up->p_parent == p_playlist->p_playing ||
502 p_up->p_parent == p_playlist->p_media_library )
504 if( !pl_priv(p_playlist)->b_tree ) b_flat = true;
507 p_up = p_up->p_parent;
512 ChangeToNode( p_playlist, p_item );
513 if( p_up == p_playlist->p_root )
514 var_SetAddress( p_playlist, "item-change", p_item->p_input );
515 PL_UNLOCK_IF( !b_locked );
520 playlist_item_t *p_status_item = get_current_status_item( p_playlist );
521 playlist_item_t *p_status_node = get_current_status_node( p_playlist );
522 if( p_item == p_status_item )
524 /* We're deleting the current playlist item. Update
525 * the playlist object to point at the previous item
526 * so the playlist won't be restarted */
527 playlist_item_t *p_prev_status_item = NULL;
529 while( i < p_status_node->i_children &&
530 p_status_node->pp_children[i] != p_status_item )
532 p_prev_status_item = p_status_node->pp_children[i];
535 if( i == p_status_node->i_children )
536 p_prev_status_item = NULL;
537 if( p_prev_status_item )
538 set_current_status_item( p_playlist, p_prev_status_item );
541 DeleteFromInput( p_playlist, p_item->p_input,
542 p_playlist->p_root, false );
544 pl_priv(p_playlist)->b_reset_currently_playing = true;
545 vlc_cond_signal( &pl_priv(p_playlist)->signal );
547 PL_UNLOCK_IF( !b_locked );
548 return p_item->p_parent;
553 * Find an item within a root, given its input id.
555 * \param p_playlist the playlist object
556 * \param p_item the input item
557 * \param p_root root playlist item
558 * \param b_items_only TRUE if we want the item himself
559 * \return the first found item, or NULL if not found
561 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
562 input_item_t *p_item,
563 playlist_item_t *p_root,
567 for( i = 0 ; i< p_root->i_children ; i++ )
569 if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) &&
570 p_root->pp_children[i]->p_input == p_item )
572 return p_root->pp_children[i];
574 else if( p_root->pp_children[i]->i_children >= 0 )
576 playlist_item_t *p_search =
577 playlist_ItemFindFromInputAndRoot( p_playlist, p_item,
578 p_root->pp_children[i],
580 if( p_search ) return p_search;
587 static int ItemIndex ( playlist_item_t *p_item )
589 for( int i = 0; i < p_item->p_parent->i_children; i++ )
590 if( p_item->p_parent->pp_children[i] == p_item ) return i;
597 * This function must be entered with the playlist lock
599 * \param p_playlist the playlist
600 * \param p_item the item to move
601 * \param p_node the new parent of the item
602 * \param i_newpos the new position under this new parent
603 * \return VLC_SUCCESS or an error
605 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
606 playlist_item_t *p_node, int i_newpos )
610 if( p_node->i_children == -1 ) return VLC_EGENERIC;
612 playlist_item_t *p_detach = p_item->p_parent;
613 int i_index = ItemIndex( p_item );
615 REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, i_index );
617 if( p_detach == p_node && i_index < i_newpos )
620 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
621 p_item->p_parent = p_node;
623 pl_priv( p_playlist )->b_reset_currently_playing = true;
624 vlc_cond_signal( &pl_priv( p_playlist )->signal );
629 * Moves an array of items
631 * This function must be entered with the playlist lock
633 * \param p_playlist the playlist
634 * \param i_items the number of indexes to move
635 * \param pp_items the array of indexes to move
636 * \param p_node the target node
637 * \param i_newpos the target position under this node
638 * \return VLC_SUCCESS or an error
640 int playlist_TreeMoveMany( playlist_t *p_playlist,
641 int i_items, playlist_item_t **pp_items,
642 playlist_item_t *p_node, int i_newpos )
646 if ( p_node->i_children == -1 ) return VLC_EGENERIC;
649 for( i = 0; i < i_items; i++ )
651 playlist_item_t *p_item = pp_items[i];
652 int i_index = ItemIndex( p_item );
653 playlist_item_t *p_parent = p_item->p_parent;
654 REMOVE_ELEM( p_parent->pp_children, p_parent->i_children, i_index );
655 if ( p_parent == p_node && i_index < i_newpos ) i_newpos--;
657 for( i = i_items - 1; i >= 0; i-- )
659 playlist_item_t *p_item = pp_items[i];
660 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
661 p_item->p_parent = p_node;
664 pl_priv( p_playlist )->b_reset_currently_playing = true;
665 vlc_cond_signal( &pl_priv( p_playlist )->signal );
670 * Send a notification that an item has been added to a node
672 * \param p_playlist the playlist object
673 * \param i_item_id id of the item added
674 * \param i_node_id id of the node in wich the item was added
675 * \param b_signal TRUE if the function must send a signal
678 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
679 int i_node_id, bool b_signal )
681 playlist_private_t *p_sys = pl_priv(p_playlist);
684 p_sys->b_reset_currently_playing = true;
686 vlc_cond_signal( &p_sys->signal );
689 add.i_item = i_item_id;
690 add.i_node = i_node_id;
693 val.p_address = &add;
695 var_Set( p_playlist, "playlist-item-append", val );
698 /***************************************************************************
699 * The following functions are local
700 ***************************************************************************/
702 /* Enqueue an item for preparsing, and play it, if needed */
703 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
704 playlist_item_t *p_item )
707 if( (i_mode & PLAYLIST_GO ) )
709 pl_priv(p_playlist)->request.b_request = true;
710 pl_priv(p_playlist)->request.i_skip = 0;
711 pl_priv(p_playlist)->request.p_item = p_item;
712 if( pl_priv(p_playlist)->p_input )
713 input_Stop( pl_priv(p_playlist)->p_input, true );
714 pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
715 vlc_cond_signal( &pl_priv(p_playlist)->signal );
717 /* Preparse if PREPARSE or SPREPARSE & not enough meta */
718 char *psz_artist = input_item_GetArtist( p_item->p_input );
719 char *psz_album = input_item_GetAlbum( p_item->p_input );
720 if( pl_priv(p_playlist)->b_auto_preparse &&
721 (i_mode & PLAYLIST_PREPARSE ||
722 ( i_mode & PLAYLIST_SPREPARSE &&
723 ( EMPTY_STR( psz_artist ) || ( EMPTY_STR( psz_album ) ) )
725 playlist_PreparseEnqueue( p_playlist, p_item->p_input, pl_Locked );
726 /* If we already have it, signal it */
727 else if( !EMPTY_STR( psz_artist ) && !EMPTY_STR( psz_album ) )
728 input_item_SetPreparsed( p_item->p_input, true );
733 /* Add the playlist item to the requested node and fire a notification */
734 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
735 playlist_item_t *p_node, int i_mode, int i_pos )
738 ARRAY_APPEND(p_playlist->items, p_item);
739 ARRAY_APPEND(p_playlist->all_items, p_item);
741 if( i_pos == PLAYLIST_END )
742 playlist_NodeAppend( p_playlist, p_item, p_node );
744 playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
746 if( !pl_priv(p_playlist)->b_doing_ml )
747 playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id,
748 !( i_mode & PLAYLIST_NO_REBUILD ) );
751 /* Actually convert an item to a node */
752 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
755 if( p_item->i_children == -1 )
756 p_item->i_children = 0;
758 /* Remove it from the array of available items */
759 ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
761 ARRAY_REMOVE( p_playlist->items, i );
764 /* Do the actual removal */
765 int playlist_DeleteItem( playlist_t * p_playlist, playlist_item_t *p_item,
769 int i_id = p_item->i_id;
772 if( p_item->i_children > -1 )
774 return playlist_NodeDelete( p_playlist, p_item, true, false );
777 pl_priv(p_playlist)->b_reset_currently_playing = true;
778 var_SetInteger( p_playlist, "playlist-item-deleted", i_id );
780 /* Remove the item from the bank */
781 ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
783 ARRAY_REMOVE( p_playlist->all_items, i );
785 ARRAY_BSEARCH( p_playlist->items,->i_id, int, i_id, i );
787 ARRAY_REMOVE( p_playlist->items, i );
789 /* Check if it is the current item */
790 if( get_current_status_item( p_playlist ) == p_item )
792 /* Stop it if we have to */
795 playlist_Control( p_playlist, PLAYLIST_STOP, pl_Locked );
796 msg_Info( p_playlist, "stopping playback" );
798 /* In any case, this item can't be the next one to be played ! */
799 set_current_status_item( p_playlist, NULL );
802 ARRAY_BSEARCH( p_playlist->current,->i_id, int, i_id, i );
804 ARRAY_REMOVE( p_playlist->current, i );
806 PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
808 /* Remove the item from its parent */
809 playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
811 playlist_ItemRelease( p_item );
816 static int RecursiveAddIntoParent (
817 playlist_t *p_playlist, playlist_item_t *p_parent,
818 input_item_node_t *p_node, int i_pos, bool b_flat,
819 playlist_item_t **pp_first_leaf )
821 if( p_parent->i_children == -1 ) ChangeToNode( p_playlist, p_parent );
823 if( i_pos == PLAYLIST_END ) i_pos = p_parent->i_children;
825 for( int i = 0; i < p_node->i_children; i++ )
827 playlist_item_t *p_child = NULL;
828 if( b_flat ? p_node->pp_children[i]->i_children == 0 : 1 )
830 p_child = playlist_NodeAddInput( p_playlist,
831 p_node->pp_children[i]->p_item,
833 PLAYLIST_INSERT, i_pos,
837 if( p_node->pp_children[i]->i_children > 0 )
841 i_pos = RecursiveAddIntoParent(
842 p_playlist, p_parent,
843 p_node->pp_children[i], i_pos, true,
848 RecursiveAddIntoParent( p_playlist, p_child,
849 p_node->pp_children[i], 0, false,
853 assert( p_child != NULL );
854 if( i == 0 ) *pp_first_leaf = p_child;