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_current = get_current_status_item( p_playlist ) == p_item;
67 bool b_autostart = var_CreateGetBool( p_playlist, "playlist-autostart" );
68 bool b_stop = 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, PLAYLIST_END, false );
103 if( !b_flat ) var_SetAddress( p_playlist, "leaf-to-parent", p_input );
107 if( b_stop || !b_autostart )
110 playlist_Stop( p_playlist );
115 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
116 pl_Locked, get_current_status_node( p_playlist ), p_item );
122 /*****************************************************************************
123 * An input item's meta or duration has changed (Event Callback)
124 *****************************************************************************/
125 static void input_item_changed( const vlc_event_t * p_event,
128 playlist_item_t *p_item = user_data;
129 VLC_UNUSED( p_event );
130 var_SetAddress( p_item->p_playlist, "item-change", p_item->p_input );
133 /*****************************************************************************
134 * Listen to vlc_InputItemAddSubItem event
135 *****************************************************************************/
136 static void install_input_item_observer( playlist_item_t * p_item )
138 vlc_event_manager_t * p_em = &p_item->p_input->event_manager;
139 vlc_event_attach( p_em, vlc_InputItemSubItemTreeAdded,
140 input_item_add_subitem_tree, p_item );
141 vlc_event_attach( p_em, vlc_InputItemDurationChanged,
142 input_item_changed, p_item );
143 vlc_event_attach( p_em, vlc_InputItemMetaChanged,
144 input_item_changed, p_item );
145 vlc_event_attach( p_em, vlc_InputItemNameChanged,
146 input_item_changed, p_item );
147 vlc_event_attach( p_em, vlc_InputItemInfoChanged,
148 input_item_changed, p_item );
149 vlc_event_attach( p_em, vlc_InputItemErrorWhenReadingChanged,
150 input_item_changed, p_item );
153 static void uninstall_input_item_observer( playlist_item_t * p_item )
155 vlc_event_manager_t * p_em = &p_item->p_input->event_manager;
156 vlc_event_detach( p_em, vlc_InputItemSubItemTreeAdded,
157 input_item_add_subitem_tree, p_item );
158 vlc_event_detach( p_em, vlc_InputItemMetaChanged,
159 input_item_changed, p_item );
160 vlc_event_detach( p_em, vlc_InputItemDurationChanged,
161 input_item_changed, p_item );
162 vlc_event_detach( p_em, vlc_InputItemNameChanged,
163 input_item_changed, p_item );
164 vlc_event_detach( p_em, vlc_InputItemInfoChanged,
165 input_item_changed, p_item );
166 vlc_event_detach( p_em, vlc_InputItemErrorWhenReadingChanged,
167 input_item_changed, p_item );
170 /*****************************************************************************
171 * Playlist item creation
172 *****************************************************************************/
173 playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist,
174 input_item_t *p_input )
176 playlist_item_t* p_item = malloc( sizeof( playlist_item_t ) );
182 p_item->p_input = p_input;
183 vlc_gc_incref( p_item->p_input );
185 p_item->i_id = ++pl_priv(p_playlist)->i_last_playlist_id;
187 p_item->p_parent = NULL;
188 p_item->i_children = -1;
189 p_item->pp_children = NULL;
191 p_item->p_playlist = p_playlist;
193 install_input_item_observer( p_item );
198 /***************************************************************************
199 * Playlist item destruction
200 ***************************************************************************/
205 * \param p_item item to delete
206 * \return VLC_SUCCESS
208 int playlist_ItemRelease( playlist_item_t *p_item )
211 playlist_t *p_playlist = p_item->p_playlist;
214 /* Surprise, we can't actually do more because we
215 * don't do refcounting, or eauivalent.
216 * Because item are not only accessed by their id
217 * using playlist_item outside the PL_LOCK isn't safe.
218 * Most of the modules does that.
220 * Who wants to add proper memory management? */
221 uninstall_input_item_observer( p_item );
222 ARRAY_APPEND( pl_priv(p_playlist)->items_to_delete, p_item);
229 * Remove an input item when it appears from a root playlist item
230 * \param p_playlist playlist object
231 * \param p_input the input to delete
232 * \param p_root root playlist item
233 * \param b_do_stop must stop or not the playlist
234 * \return VLC_SUCCESS or VLC_EGENERIC
236 static int DeleteFromInput( playlist_t *p_playlist, input_item_t *p_input,
237 playlist_item_t *p_root, bool b_do_stop )
240 playlist_item_t *p_item = playlist_ItemFindFromInputAndRoot(
241 p_playlist, p_input, p_root, false );
242 if( !p_item ) return VLC_EGENERIC;
243 return playlist_DeleteItem( p_playlist, p_item, b_do_stop );
249 * Remove an input item when it appears from a root playlist item
250 * \param p_playlist playlist object
251 * \param p_input the input to delete
252 * \param p_root root playlist item
253 * \param b_locked TRUE if the playlist is locked
254 * \return VLC_SUCCESS or VLC_EGENERIC
256 int playlist_DeleteFromInputInParent( playlist_t *p_playlist,
257 input_item_t *p_item,
258 playlist_item_t *p_root, bool b_locked )
261 PL_LOCK_IF( !b_locked );
262 i_ret = DeleteFromInput( p_playlist, p_item, p_root, true );
263 PL_UNLOCK_IF( !b_locked );
270 * Search anywhere in playlist for an an input item and delete it
271 * \param p_playlist playlist object
272 * \param p_input the input to delete
273 * \param b_locked TRUE if the playlist is locked
274 * \return VLC_SUCCESS or VLC_ENOITEM
276 int playlist_DeleteFromInput( playlist_t *p_playlist, input_item_t *p_input,
280 PL_LOCK_IF( !b_locked );
281 i_ret = DeleteFromInput( p_playlist, p_input,
282 p_playlist->p_root, true );
283 PL_UNLOCK_IF( !b_locked );
284 return ( i_ret == VLC_SUCCESS ? VLC_SUCCESS : VLC_ENOITEM );
290 * \param p_playlist playlist object
291 * \param b_locked TRUE if the playlist is locked
294 void playlist_Clear( playlist_t * p_playlist, bool b_locked )
296 PL_LOCK_IF( !b_locked );
297 playlist_NodeEmpty( p_playlist, p_playlist->p_playing, true );
298 PL_UNLOCK_IF( !b_locked );
302 * Delete playlist item
304 * Remove a playlist item from the playlist, given its id
305 * This function is to be used only by the playlist
306 * \param p_playlist playlist object
307 * \param i_id id of the item do delete
308 * \return VLC_SUCCESS or an error
310 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
313 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
314 if( !p_item ) return VLC_EGENERIC;
315 return playlist_DeleteItem( p_playlist, p_item, true );
318 /***************************************************************************
319 * Playlist item addition
320 ***************************************************************************/
324 * Add an item to the playlist or the media library
325 * \param p_playlist the playlist to add into
326 * \param psz_uri the mrl to add to the playlist
327 * \param psz_name a text giving a name or description of this item
328 * \param i_mode the mode used when adding
329 * \param i_pos the position in the playlist where to add. If this is
330 * PLAYLIST_END the item will be added at the end of the playlist
331 * regardless of its size
332 * \param b_playlist TRUE for playlist, FALSE for media library
333 * \param b_locked TRUE if the playlist is locked
334 * \return VLC_SUCCESS or a VLC error code
336 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
337 const char *psz_name, int i_mode, int i_pos,
338 bool b_playlist, bool b_locked )
340 return playlist_AddExt( p_playlist, psz_uri, psz_name,
341 i_mode, i_pos, -1, 0, NULL, 0, b_playlist, b_locked );
345 * Add a MRL into the playlist or the media library, duration and options given
347 * \param p_playlist the playlist to add into
348 * \param psz_uri the mrl to add to the playlist
349 * \param psz_name a text giving a name or description of this item
350 * \param i_mode the mode used when adding
351 * \param i_pos the position in the playlist where to add. If this is
352 * PLAYLIST_END the item will be added at the end of the playlist
353 * regardless of its size
354 * \param i_duration length of the item in milliseconds.
355 * \param i_options the number of options
356 * \param ppsz_options an array of options
357 * \param i_option_flags options flags
358 * \param b_playlist TRUE for playlist, FALSE for media library
359 * \param b_locked TRUE if the playlist is locked
360 * \return VLC_SUCCESS or a VLC error code
362 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
363 const char *psz_name, int i_mode, int i_pos,
365 int i_options, const char *const *ppsz_options,
366 unsigned i_option_flags,
367 bool b_playlist, bool b_locked )
370 input_item_t *p_input;
372 p_input = input_item_NewExt( p_playlist, psz_uri, psz_name,
373 i_options, ppsz_options, i_option_flags,
375 if( p_input == NULL )
377 i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
379 vlc_gc_decref( p_input );
384 * Add an input item to the playlist node
386 * \param p_playlist the playlist to add into
387 * \param p_input the input item to add
388 * \param i_mode the mode used when adding
389 * \param i_pos the position in the playlist where to add. If this is
390 * PLAYLIST_END the item will be added at the end of the playlist
391 * regardless of its size
392 * \param b_playlist TRUE for playlist, FALSE for media library
393 * \param b_locked TRUE if the playlist is locked
394 * \return VLC_SUCCESS or VLC_ENOMEM or VLC_EGENERIC
396 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
397 int i_mode, int i_pos, bool b_playlist,
400 playlist_item_t *p_item;
401 if( p_playlist->b_die ) return VLC_EGENERIC;
402 if( !pl_priv(p_playlist)->b_doing_ml )
403 PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
406 PL_LOCK_IF( !b_locked );
408 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
409 if( p_item == NULL ) return VLC_ENOMEM;
410 AddItem( p_playlist, p_item,
411 b_playlist ? p_playlist->p_playing :
412 p_playlist->p_media_library , i_mode, i_pos );
414 GoAndPreparse( p_playlist, i_mode, p_item );
416 PL_UNLOCK_IF( !b_locked );
421 * Add an input item to a given node
423 * \param p_playlist the playlist to add into
424 * \param p_input the input item to add
425 * \param p_parent the parent item to add into
426 * \param i_mode the mode used when addin
427 * \param i_pos the position in the playlist where to add. If this is
428 * PLAYLIST_END the item will be added at the end of the playlist
429 * regardless of its size
430 * \param b_locked TRUE if the playlist is locked
431 * \return the new playlist item
433 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
434 input_item_t *p_input,
435 playlist_item_t *p_parent,
436 int i_mode, int i_pos,
439 playlist_item_t *p_item;
441 assert( p_parent && p_parent->i_children != -1 );
443 if( p_playlist->b_die )
445 PL_LOCK_IF( !b_locked );
447 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
448 if( p_item == NULL ) return NULL;
449 AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
451 GoAndPreparse( p_playlist, i_mode, p_item );
453 PL_UNLOCK_IF( !b_locked );
459 * Insert a tree of input items into a given playlist node
461 * \param p_playlist the playlist to insert into
462 * \param p_parent the receiving playlist node (can be an item)
463 * \param p_node the root of input item tree,
464 only it's contents will be inserted
465 * \param i_pos the position in the playlist where to insert. If this is
466 * PLAYLIST_END the items will be added at the end of the playlist
467 * regardless of its size
468 * \param b_flat TRUE if the new tree contents should be flattened into a list
469 * \return the first new leaf inserted (in playing order)
471 playlist_item_t *playlist_InsertInputItemTree (
472 playlist_t *p_playlist, playlist_item_t *p_parent,
473 input_item_node_t *p_node, int i_pos, bool b_flat )
475 playlist_item_t *p_first_leaf = NULL;
476 RecursiveAddIntoParent ( p_playlist, p_parent, p_node, i_pos, b_flat, &p_first_leaf );
480 /*****************************************************************************
481 * Playlist item misc operations
482 *****************************************************************************/
487 * Transform an item to a node. Return the node in the category tree, or NULL
489 * This function must be entered without the playlist lock
490 * \param p_playlist the playlist object
491 * \param p_item the item to transform
492 * \param b_locked TRUE if the playlist is locked
493 * \return the item transform in a node
495 static playlist_item_t *ItemToNode( playlist_t *p_playlist,
496 playlist_item_t *p_item,
499 PL_LOCK_IF( !b_locked );
501 assert( p_item->p_parent );
504 playlist_item_t *p_up = p_item;
505 while( p_up->p_parent )
507 if( p_up->p_parent == p_playlist->p_playing ||
508 p_up->p_parent == p_playlist->p_media_library )
510 if( !pl_priv(p_playlist)->b_tree ) b_flat = true;
513 p_up = p_up->p_parent;
518 ChangeToNode( p_playlist, p_item );
519 if( p_up == p_playlist->p_root )
520 var_SetAddress( p_playlist, "item-change", p_item->p_input );
521 PL_UNLOCK_IF( !b_locked );
526 playlist_item_t *p_status_item = get_current_status_item( p_playlist );
527 playlist_item_t *p_status_node = get_current_status_node( p_playlist );
528 if( p_item == p_status_item )
530 /* We're deleting the current playlist item. Update
531 * the playlist object to point at the previous item
532 * so the playlist won't be restarted */
533 playlist_item_t *p_prev_status_item = NULL;
535 while( i < p_status_node->i_children &&
536 p_status_node->pp_children[i] != p_status_item )
538 p_prev_status_item = p_status_node->pp_children[i];
541 if( i == p_status_node->i_children )
542 p_prev_status_item = NULL;
543 if( p_prev_status_item )
544 set_current_status_item( p_playlist, p_prev_status_item );
547 DeleteFromInput( p_playlist, p_item->p_input,
548 p_playlist->p_root, false );
550 pl_priv(p_playlist)->b_reset_currently_playing = true;
551 vlc_cond_signal( &pl_priv(p_playlist)->signal );
553 PL_UNLOCK_IF( !b_locked );
554 return p_item->p_parent;
559 * Find an item within a root, given its input id.
561 * \param p_playlist the playlist object
562 * \param p_item the input item
563 * \param p_root root playlist item
564 * \param b_items_only TRUE if we want the item himself
565 * \return the first found item, or NULL if not found
567 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
568 input_item_t *p_item,
569 playlist_item_t *p_root,
573 for( i = 0 ; i< p_root->i_children ; i++ )
575 if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) &&
576 p_root->pp_children[i]->p_input == p_item )
578 return p_root->pp_children[i];
580 else if( p_root->pp_children[i]->i_children >= 0 )
582 playlist_item_t *p_search =
583 playlist_ItemFindFromInputAndRoot( p_playlist, p_item,
584 p_root->pp_children[i],
586 if( p_search ) return p_search;
593 static int ItemIndex ( playlist_item_t *p_item )
595 for( int i = 0; i < p_item->p_parent->i_children; i++ )
596 if( p_item->p_parent->pp_children[i] == p_item ) return i;
603 * This function must be entered with the playlist lock
605 * \param p_playlist the playlist
606 * \param p_item the item to move
607 * \param p_node the new parent of the item
608 * \param i_newpos the new position under this new parent
609 * \return VLC_SUCCESS or an error
611 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
612 playlist_item_t *p_node, int i_newpos )
616 if( p_node->i_children == -1 ) return VLC_EGENERIC;
618 playlist_item_t *p_detach = p_item->p_parent;
619 int i_index = ItemIndex( p_item );
621 REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, i_index );
623 if( p_detach == p_node && i_index < i_newpos )
626 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
627 p_item->p_parent = p_node;
629 pl_priv( p_playlist )->b_reset_currently_playing = true;
630 vlc_cond_signal( &pl_priv( p_playlist )->signal );
635 * Moves an array of items
637 * This function must be entered with the playlist lock
639 * \param p_playlist the playlist
640 * \param i_items the number of indexes to move
641 * \param pp_items the array of indexes to move
642 * \param p_node the target node
643 * \param i_newpos the target position under this node
644 * \return VLC_SUCCESS or an error
646 int playlist_TreeMoveMany( playlist_t *p_playlist,
647 int i_items, playlist_item_t **pp_items,
648 playlist_item_t *p_node, int i_newpos )
652 if ( p_node->i_children == -1 ) return VLC_EGENERIC;
655 for( i = 0; i < i_items; i++ )
657 playlist_item_t *p_item = pp_items[i];
658 int i_index = ItemIndex( p_item );
659 playlist_item_t *p_parent = p_item->p_parent;
660 REMOVE_ELEM( p_parent->pp_children, p_parent->i_children, i_index );
661 if ( p_parent == p_node && i_index < i_newpos ) i_newpos--;
663 for( i = i_items - 1; i >= 0; i-- )
665 playlist_item_t *p_item = pp_items[i];
666 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
667 p_item->p_parent = p_node;
670 pl_priv( p_playlist )->b_reset_currently_playing = true;
671 vlc_cond_signal( &pl_priv( p_playlist )->signal );
676 * Send a notification that an item has been added to a node
678 * \param p_playlist the playlist object
679 * \param i_item_id id of the item added
680 * \param i_node_id id of the node in wich the item was added
681 * \param b_signal TRUE if the function must send a signal
684 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
685 int i_node_id, bool b_signal )
687 playlist_private_t *p_sys = pl_priv(p_playlist);
690 p_sys->b_reset_currently_playing = true;
692 vlc_cond_signal( &p_sys->signal );
695 add.i_item = i_item_id;
696 add.i_node = i_node_id;
699 val.p_address = &add;
701 var_Set( p_playlist, "playlist-item-append", val );
704 /***************************************************************************
705 * The following functions are local
706 ***************************************************************************/
708 /* Enqueue an item for preparsing, and play it, if needed */
709 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
710 playlist_item_t *p_item )
713 if( (i_mode & PLAYLIST_GO ) )
715 pl_priv(p_playlist)->request.b_request = true;
716 pl_priv(p_playlist)->request.i_skip = 0;
717 pl_priv(p_playlist)->request.p_item = p_item;
718 if( pl_priv(p_playlist)->p_input )
719 input_Stop( pl_priv(p_playlist)->p_input, true );
720 pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
721 vlc_cond_signal( &pl_priv(p_playlist)->signal );
723 /* Preparse if no artist/album info, and hasn't been preparsed allready
724 and if user has some preparsing option (auto-preparse variable)
726 char *psz_artist = input_item_GetArtist( p_item->p_input );
727 char *psz_album = input_item_GetAlbum( p_item->p_input );
728 if( pl_priv(p_playlist)->b_auto_preparse &&
729 input_item_IsPreparsed( p_item->p_input ) == false &&
730 ( EMPTY_STR( psz_artist ) || ( EMPTY_STR( psz_album ) ) )
732 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
737 /* Add the playlist item to the requested node and fire a notification */
738 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
739 playlist_item_t *p_node, int i_mode, int i_pos )
742 ARRAY_APPEND(p_playlist->items, p_item);
743 ARRAY_APPEND(p_playlist->all_items, p_item);
745 if( i_pos == PLAYLIST_END )
746 playlist_NodeAppend( p_playlist, p_item, p_node );
748 playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
750 if( !pl_priv(p_playlist)->b_doing_ml )
751 playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id,
752 !( i_mode & PLAYLIST_NO_REBUILD ) );
755 /* Actually convert an item to a node */
756 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
759 if( p_item->i_children == -1 )
760 p_item->i_children = 0;
762 /* Remove it from the array of available items */
763 ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
765 ARRAY_REMOVE( p_playlist->items, i );
768 /* Do the actual removal */
769 int playlist_DeleteItem( playlist_t * p_playlist, playlist_item_t *p_item,
773 int i_id = p_item->i_id;
776 if( p_item->i_children > -1 )
778 return playlist_NodeDelete( p_playlist, p_item, true, false );
781 pl_priv(p_playlist)->b_reset_currently_playing = true;
782 var_SetInteger( p_playlist, "playlist-item-deleted", i_id );
784 /* Remove the item from the bank */
785 ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
787 ARRAY_REMOVE( p_playlist->all_items, i );
789 ARRAY_BSEARCH( p_playlist->items,->i_id, int, i_id, i );
791 ARRAY_REMOVE( p_playlist->items, i );
793 /* Check if it is the current item */
794 if( get_current_status_item( p_playlist ) == p_item )
796 /* Stop it if we have to */
799 playlist_Control( p_playlist, PLAYLIST_STOP, pl_Locked );
800 msg_Info( p_playlist, "stopping playback" );
802 /* In any case, this item can't be the next one to be played ! */
803 set_current_status_item( p_playlist, NULL );
806 ARRAY_BSEARCH( p_playlist->current,->i_id, int, i_id, i );
808 ARRAY_REMOVE( p_playlist->current, i );
810 PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
812 /* Remove the item from its parent */
813 playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
815 playlist_ItemRelease( p_item );
820 static int RecursiveAddIntoParent (
821 playlist_t *p_playlist, playlist_item_t *p_parent,
822 input_item_node_t *p_node, int i_pos, bool b_flat,
823 playlist_item_t **pp_first_leaf )
825 if( p_parent->i_children == -1 ) ChangeToNode( p_playlist, p_parent );
827 if( i_pos == PLAYLIST_END ) i_pos = p_parent->i_children;
829 for( int i = 0; i < p_node->i_children; i++ )
831 playlist_item_t *p_child = NULL;
832 if( b_flat ? p_node->pp_children[i]->i_children == 0 : 1 )
834 p_child = playlist_NodeAddInput( p_playlist,
835 p_node->pp_children[i]->p_item,
837 PLAYLIST_INSERT, i_pos,
841 if( p_node->pp_children[i]->i_children > 0 )
845 i_pos = RecursiveAddIntoParent(
846 p_playlist, p_parent,
847 p_node->pp_children[i], i_pos, true,
852 RecursiveAddIntoParent( p_playlist, p_child,
853 p_node->pp_children[i], 0, false,
857 assert( p_child != NULL );
858 if( i == 0 ) *pp_first_leaf = p_child;