3 * \brief playlist service class
5 * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
6 * \author Charles Yates <charles.yates@pandora.be>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "mlt_playlist.h"
24 #include "mlt_tractor.h"
25 #include "mlt_multitrack.h"
26 #include "mlt_field.h"
27 #include "mlt_frame.h"
28 #include "mlt_transition.h"
34 /** \brief virtual playlist entry
37 struct playlist_entry_s
39 mlt_producer producer
;
40 mlt_position frame_in
;
41 mlt_position frame_out
;
42 mlt_position frame_count
;
44 mlt_position producer_length
;
46 int preservation_hack
;
49 /** Forward declarations
52 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
);
53 static int mlt_playlist_unmix( mlt_playlist
this, int clip
);
54 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
);
59 mlt_playlist
mlt_playlist_init( )
61 mlt_playlist
this = calloc( sizeof( struct mlt_playlist_s
), 1 );
64 mlt_producer producer
= &this->parent
;
66 // Construct the producer
67 mlt_producer_init( producer
, this );
69 // Override the producer get_frame
70 producer
->get_frame
= producer_get_frame
;
72 // Define the destructor
73 producer
->close
= ( mlt_destructor
)mlt_playlist_close
;
74 producer
->close_object
= this;
77 mlt_producer_init( &this->blank
, NULL
);
78 mlt_properties_set( MLT_PRODUCER_PROPERTIES( &this->blank
), "mlt_service", "blank" );
79 mlt_properties_set( MLT_PRODUCER_PROPERTIES( &this->blank
), "resource", "blank" );
81 // Indicate that this producer is a playlist
82 mlt_properties_set_data( MLT_PLAYLIST_PROPERTIES( this ), "playlist", this, 0, NULL
, NULL
);
84 // Specify the eof condition
85 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "eof", "pause" );
86 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "resource", "<playlist>" );
87 mlt_properties_set( MLT_PLAYLIST_PROPERTIES( this ), "mlt_type", "mlt_producer" );
88 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "in", 0 );
89 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "out", -1 );
90 mlt_properties_set_position( MLT_PLAYLIST_PROPERTIES( this ), "length", 0 );
93 this->list
= malloc( this->size
* sizeof( playlist_entry
* ) );
99 /** Get the producer associated to this playlist.
102 mlt_producer
mlt_playlist_producer( mlt_playlist
this )
104 return this != NULL ?
&this->parent
: NULL
;
107 /** Get the service associated to this playlist.
110 mlt_service
mlt_playlist_service( mlt_playlist
this )
112 return MLT_PRODUCER_SERVICE( &this->parent
);
115 /** Get the propertues associated to this playlist.
118 mlt_properties
mlt_playlist_properties( mlt_playlist
this )
120 return MLT_PRODUCER_PROPERTIES( &this->parent
);
123 /** Refresh the playlist after a clip has been changed.
126 static int mlt_playlist_virtual_refresh( mlt_playlist
this )
128 // Obtain the properties
129 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
131 mlt_position frame_count
= 0;
133 for ( i
= 0; i
< this->count
; i
++ )
136 mlt_producer producer
= this->list
[ i
]->producer
;
139 int current_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
141 // Check if the length of the producer has changed
142 if ( this->list
[ i
]->frame_in
!= mlt_producer_get_in( producer
) ||
143 this->list
[ i
]->frame_out
!= mlt_producer_get_out( producer
) )
145 // This clip should be removed...
146 if ( current_length
< 1 )
148 this->list
[ i
]->frame_in
= 0;
149 this->list
[ i
]->frame_out
= -1;
150 this->list
[ i
]->frame_count
= 0;
154 this->list
[ i
]->frame_in
= mlt_producer_get_in( producer
);
155 this->list
[ i
]->frame_out
= mlt_producer_get_out( producer
);
156 this->list
[ i
]->frame_count
= current_length
;
159 // Update the producer_length
160 this->list
[ i
]->producer_length
= current_length
;
164 // Calculate the frame_count
165 this->list
[ i
]->frame_count
= ( this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1 ) * this->list
[ i
]->repeat
;
167 // Update the frame_count for this clip
168 frame_count
+= this->list
[ i
]->frame_count
;
171 // Refresh all properties
172 mlt_events_block( properties
, properties
);
173 mlt_properties_set_position( properties
, "length", frame_count
);
174 mlt_events_unblock( properties
, properties
);
175 mlt_properties_set_position( properties
, "out", frame_count
- 1 );
180 /** Listener for producers on the playlist.
183 static void mlt_playlist_listener( mlt_producer producer
, mlt_playlist
this )
185 mlt_playlist_virtual_refresh( this );
188 /** Append to the virtual playlist.
191 static int mlt_playlist_virtual_append( mlt_playlist
this, mlt_producer source
, mlt_position in
, mlt_position out
)
193 mlt_producer producer
= NULL
;
194 mlt_properties properties
= NULL
;
195 mlt_properties parent
= NULL
;
197 // If we have a cut, then use the in/out points from the cut
198 if ( mlt_producer_is_blank( source
) )
200 // Make sure the blank is long enough to accomodate the length specified
201 if ( out
- in
+ 1 > mlt_producer_get_length( &this->blank
) )
203 mlt_properties blank_props
= MLT_PRODUCER_PROPERTIES( &this->blank
);
204 mlt_events_block( blank_props
, blank_props
);
205 mlt_producer_set_in_and_out( &this->blank
, in
, out
);
206 mlt_events_unblock( blank_props
, blank_props
);
209 // Now make sure the cut comes from this this->blank
210 if ( source
== NULL
)
212 producer
= mlt_producer_cut( &this->blank
, in
, out
);
214 else if ( !mlt_producer_is_cut( source
) || mlt_producer_cut_parent( source
) != &this->blank
)
216 producer
= mlt_producer_cut( &this->blank
, in
, out
);
221 mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer
) );
224 properties
= MLT_PRODUCER_PROPERTIES( producer
);
226 else if ( mlt_producer_is_cut( source
) )
230 in
= mlt_producer_get_in( producer
);
231 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
232 out
= mlt_producer_get_out( producer
);
233 properties
= MLT_PRODUCER_PROPERTIES( producer
);
234 mlt_properties_inc_ref( properties
);
238 producer
= mlt_producer_cut( source
, in
, out
);
239 if ( in
== -1 || in
< mlt_producer_get_in( producer
) )
240 in
= mlt_producer_get_in( producer
);
241 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
242 out
= mlt_producer_get_out( producer
);
243 properties
= MLT_PRODUCER_PROPERTIES( producer
);
246 // Fetch the cuts parent properties
247 parent
= MLT_PRODUCER_PROPERTIES( mlt_producer_cut_parent( producer
) );
249 // Remove fezzik normalisers for fx cuts
250 if ( mlt_properties_get_int( parent
, "meta.fx_cut" ) )
252 mlt_service service
= MLT_PRODUCER_SERVICE( mlt_producer_cut_parent( producer
) );
253 mlt_filter filter
= mlt_service_filter( service
, 0 );
254 while ( filter
!= NULL
&& mlt_properties_get_int( MLT_FILTER_PROPERTIES( filter
), "_fezzik" ) )
256 mlt_service_detach( service
, filter
);
257 filter
= mlt_service_filter( service
, 0 );
259 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer
), "meta.fx_cut", 1 );
262 // Check that we have room
263 if ( this->count
>= this->size
)
266 this->list
= realloc( this->list
, ( this->size
+ 10 ) * sizeof( playlist_entry
* ) );
267 for ( i
= this->size
; i
< this->size
+ 10; i
++ ) this->list
[ i
] = NULL
;
272 this->list
[ this->count
] = calloc( sizeof( playlist_entry
), 1 );
273 if ( this->list
[ this->count
] != NULL
)
275 this->list
[ this->count
]->producer
= producer
;
276 this->list
[ this->count
]->frame_in
= in
;
277 this->list
[ this->count
]->frame_out
= out
;
278 this->list
[ this->count
]->frame_count
= out
- in
+ 1;
279 this->list
[ this->count
]->repeat
= 1;
280 this->list
[ this->count
]->producer_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
281 this->list
[ this->count
]->event
= mlt_events_listen( parent
, this, "producer-changed", ( mlt_listener
)mlt_playlist_listener
);
282 mlt_event_inc_ref( this->list
[ this->count
]->event
);
283 mlt_properties_set( properties
, "eof", "pause" );
284 mlt_producer_set_speed( producer
, 0 );
288 return mlt_playlist_virtual_refresh( this );
291 static mlt_producer
mlt_playlist_locate( mlt_playlist
this, mlt_position
*position
, int *clip
, int *total
)
293 // Default producer to NULL
294 mlt_producer producer
= NULL
;
296 // Loop for each producer until found
297 for ( *clip
= 0; *clip
< this->count
; *clip
+= 1 )
299 // Increment the total
300 *total
+= this->list
[ *clip
]->frame_count
;
302 // Check if the position indicates that we have found the clip
303 // Note that 0 length clips get skipped automatically
304 if ( *position
< this->list
[ *clip
]->frame_count
)
306 // Found it, now break
307 producer
= this->list
[ *clip
]->producer
;
312 // Decrement position by length of this entry
313 *position
-= this->list
[ *clip
]->frame_count
;
320 /** Seek in the virtual playlist.
323 static mlt_service
mlt_playlist_virtual_seek( mlt_playlist
this, int *progressive
)
325 // Map playlist position to real producer in virtual playlist
326 mlt_position position
= mlt_producer_frame( &this->parent
);
328 // Keep the original position since we change it while iterating through the list
329 mlt_position original
= position
;
331 // Clip index and total
335 // Locate the producer for the position
336 mlt_producer producer
= mlt_playlist_locate( this, &position
, &i
, &total
);
338 // Get the properties
339 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
341 // Automatically close previous producers if requested
342 if ( i
> 1 // keep immediate previous in case app wants to get info about what just finished
343 && position
< 2 // tolerate off-by-one error on going to next clip
344 && mlt_properties_get_int( properties
, "autoclose" ) )
347 // They might have jumped ahead!
348 for ( j
= 0; j
< i
- 1; j
++ )
350 mlt_service_lock( MLT_PRODUCER_SERVICE( this->list
[ j
]->producer
) );
351 mlt_producer p
= this->list
[ j
]->producer
;
354 this->list
[ j
]->producer
= NULL
;
355 mlt_service_unlock( MLT_PRODUCER_SERVICE( p
) );
356 mlt_producer_close( p
);
358 // If p is null, the lock will not have been "taken"
362 // Get the eof handling
363 char *eof
= mlt_properties_get( properties
, "eof" );
365 // Seek in real producer to relative position
366 if ( producer
!= NULL
)
368 int count
= this->list
[ i
]->frame_count
/ this->list
[ i
]->repeat
;
369 *progressive
= count
== 1;
370 mlt_producer_seek( producer
, (int)position
% count
);
372 else if ( !strcmp( eof
, "pause" ) && total
> 0 )
374 playlist_entry
*entry
= this->list
[ this->count
- 1 ];
375 int count
= entry
->frame_count
/ entry
->repeat
;
376 mlt_producer this_producer
= MLT_PLAYLIST_PRODUCER( this );
377 mlt_producer_seek( this_producer
, original
- 1 );
378 producer
= entry
->producer
;
379 mlt_producer_seek( producer
, (int)entry
->frame_out
% count
);
380 mlt_producer_set_speed( this_producer
, 0 );
381 mlt_producer_set_speed( producer
, 0 );
382 *progressive
= count
== 1;
384 else if ( !strcmp( eof
, "loop" ) && total
> 0 )
386 playlist_entry
*entry
= this->list
[ 0 ];
387 mlt_producer this_producer
= MLT_PLAYLIST_PRODUCER( this );
388 mlt_producer_seek( this_producer
, 0 );
389 producer
= entry
->producer
;
390 mlt_producer_seek( producer
, 0 );
394 producer
= &this->blank
;
397 return MLT_PRODUCER_SERVICE( producer
);
400 /** Invoked when a producer indicates that it has prematurely reached its end.
403 static mlt_producer
mlt_playlist_virtual_set_out( mlt_playlist
this )
405 // Default producer to blank
406 mlt_producer producer
= &this->blank
;
408 // Map playlist position to real producer in virtual playlist
409 mlt_position position
= mlt_producer_frame( &this->parent
);
411 // Loop through the virtual playlist
414 for ( i
= 0; i
< this->count
; i
++ )
416 if ( position
< this->list
[ i
]->frame_count
)
418 // Found it, now break
419 producer
= this->list
[ i
]->producer
;
424 // Decrement position by length of this entry
425 position
-= this->list
[ i
]->frame_count
;
429 // Seek in real producer to relative position
430 if ( i
< this->count
&& this->list
[ i
]->frame_out
!= position
)
432 // Update the frame_count for the changed clip (hmmm)
433 this->list
[ i
]->frame_out
= position
;
434 this->list
[ i
]->frame_count
= this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1;
436 // Refresh the playlist
437 mlt_playlist_virtual_refresh( this );
443 /** Obtain the current clips index.
446 int mlt_playlist_current_clip( mlt_playlist
this )
448 // Map playlist position to real producer in virtual playlist
449 mlt_position position
= mlt_producer_frame( &this->parent
);
451 // Loop through the virtual playlist
454 for ( i
= 0; i
< this->count
; i
++ )
456 if ( position
< this->list
[ i
]->frame_count
)
458 // Found it, now break
463 // Decrement position by length of this entry
464 position
-= this->list
[ i
]->frame_count
;
471 /** Obtain the current clips producer.
474 mlt_producer
mlt_playlist_current( mlt_playlist
this )
476 int i
= mlt_playlist_current_clip( this );
477 if ( i
< this->count
)
478 return this->list
[ i
]->producer
;
483 /** Get the position which corresponds to the start of the next clip.
486 mlt_position
mlt_playlist_clip( mlt_playlist
this, mlt_whence whence
, int index
)
488 mlt_position position
= 0;
489 int absolute_clip
= index
;
492 // Determine the absolute clip
495 case mlt_whence_relative_start
:
496 absolute_clip
= index
;
499 case mlt_whence_relative_current
:
500 absolute_clip
= mlt_playlist_current_clip( this ) + index
;
503 case mlt_whence_relative_end
:
504 absolute_clip
= this->count
- index
;
508 // Check that we're in a valid range
509 if ( absolute_clip
< 0 )
511 else if ( absolute_clip
> this->count
)
512 absolute_clip
= this->count
;
514 // Now determine the position
515 for ( i
= 0; i
< absolute_clip
; i
++ )
516 position
+= this->list
[ i
]->frame_count
;
521 /** Get all the info about the clip specified.
524 int mlt_playlist_get_clip_info( mlt_playlist
this, mlt_playlist_clip_info
*info
, int index
)
526 int error
= index
< 0 || index
>= this->count
|| this->list
[ index
]->producer
== NULL
;
527 memset( info
, 0, sizeof( mlt_playlist_clip_info
) );
530 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ index
]->producer
);
531 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
533 info
->producer
= producer
;
534 info
->cut
= this->list
[ index
]->producer
;
535 info
->start
= mlt_playlist_clip( this, mlt_whence_relative_start
, index
);
536 info
->resource
= mlt_properties_get( properties
, "resource" );
537 info
->frame_in
= this->list
[ index
]->frame_in
;
538 info
->frame_out
= this->list
[ index
]->frame_out
;
539 info
->frame_count
= this->list
[ index
]->frame_count
;
540 info
->repeat
= this->list
[ index
]->repeat
;
541 info
->length
= mlt_producer_get_length( producer
);
542 info
->fps
= mlt_producer_get_fps( producer
);
548 /** Get number of clips in the playlist.
551 int mlt_playlist_count( mlt_playlist
this )
556 /** Clear the playlist.
559 int mlt_playlist_clear( mlt_playlist
this )
562 for ( i
= 0; i
< this->count
; i
++ )
564 mlt_event_close( this->list
[ i
]->event
);
565 mlt_producer_close( this->list
[ i
]->producer
);
568 return mlt_playlist_virtual_refresh( this );
571 /** Append a producer to the playlist.
574 int mlt_playlist_append( mlt_playlist
this, mlt_producer producer
)
576 // Append to virtual list
577 return mlt_playlist_virtual_append( this, producer
, 0, mlt_producer_get_playtime( producer
) - 1 );
580 /** Append a producer to the playlist with in/out points.
583 int mlt_playlist_append_io( mlt_playlist
this, mlt_producer producer
, mlt_position in
, mlt_position out
)
585 // Append to virtual list
586 if ( in
!= -1 && out
!= -1 )
587 return mlt_playlist_virtual_append( this, producer
, in
, out
);
589 return mlt_playlist_append( this, producer
);
592 /** Append a blank to the playlist of a given length.
595 int mlt_playlist_blank( mlt_playlist
this, mlt_position length
)
597 // Append to the virtual list
599 return mlt_playlist_virtual_append( this, &this->blank
, 0, length
);
604 /** Insert a producer into the playlist.
607 int mlt_playlist_insert( mlt_playlist
this, mlt_producer producer
, int where
, mlt_position in
, mlt_position out
)
610 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
611 mlt_playlist_append_io( this, producer
, in
, out
);
613 // Move to the position specified
614 mlt_playlist_move( this, this->count
- 1, where
);
615 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
617 return mlt_playlist_virtual_refresh( this );
620 /** Remove an entry in the playlist.
623 int mlt_playlist_remove( mlt_playlist
this, int where
)
625 int error
= where
< 0 || where
>= this->count
;
626 if ( error
== 0 && mlt_playlist_unmix( this, where
) != 0 )
628 // We need to know the current clip and the position within the playlist
629 int current
= mlt_playlist_current_clip( this );
630 mlt_position position
= mlt_producer_position( MLT_PLAYLIST_PRODUCER( this ) );
632 // We need all the details about the clip we're removing
633 mlt_playlist_clip_info where_info
;
634 playlist_entry
*entry
= this->list
[ where
];
635 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( entry
->producer
);
641 mlt_playlist_get_clip_info( this, &where_info
, where
);
643 // Make sure the clip to be removed is valid and correct if necessary
646 if ( where
>= this->count
)
647 where
= this->count
- 1;
649 // Reorganise the list
650 for ( i
= where
+ 1; i
< this->count
; i
++ )
651 this->list
[ i
- 1 ] = this->list
[ i
];
654 if ( entry
->preservation_hack
== 0 )
656 // Decouple from mix_in/out if necessary
657 if ( mlt_properties_get_data( properties
, "mix_in", NULL
) != NULL
)
659 mlt_properties mix
= mlt_properties_get_data( properties
, "mix_in", NULL
);
660 mlt_properties_set_data( mix
, "mix_out", NULL
, 0, NULL
, NULL
);
662 if ( mlt_properties_get_data( properties
, "mix_out", NULL
) != NULL
)
664 mlt_properties mix
= mlt_properties_get_data( properties
, "mix_out", NULL
);
665 mlt_properties_set_data( mix
, "mix_in", NULL
, 0, NULL
, NULL
);
668 if ( mlt_properties_ref_count( MLT_PRODUCER_PROPERTIES( entry
->producer
) ) == 1 )
669 mlt_producer_clear( entry
->producer
);
672 // Close the producer associated to the clip info
673 mlt_event_close( entry
->event
);
674 mlt_producer_close( entry
->producer
);
677 if ( where
== current
)
678 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), where_info
.start
);
679 else if ( where
< current
&& this->count
> 0 )
680 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), position
- where_info
.frame_count
);
681 else if ( this->count
== 0 )
682 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), 0 );
687 // Refresh the playlist
688 mlt_playlist_virtual_refresh( this );
694 /** Move an entry in the playlist.
697 int mlt_playlist_move( mlt_playlist
this, int src
, int dest
)
701 /* We need to ensure that the requested indexes are valid and correct it as necessary */
704 if ( src
>= this->count
)
705 src
= this->count
- 1;
709 if ( dest
>= this->count
)
710 dest
= this->count
- 1;
712 if ( src
!= dest
&& this->count
> 1 )
714 int current
= mlt_playlist_current_clip( this );
715 mlt_position position
= mlt_producer_position( MLT_PLAYLIST_PRODUCER( this ) );
716 playlist_entry
*src_entry
= NULL
;
718 // We need all the details about the current clip
719 mlt_playlist_clip_info current_info
;
721 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
722 position
-= current_info
.start
;
724 if ( current
== src
)
726 else if ( current
> src
&& current
< dest
)
728 else if ( current
== dest
)
731 src_entry
= this->list
[ src
];
734 for ( i
= src
; i
> dest
; i
-- )
735 this->list
[ i
] = this->list
[ i
- 1 ];
739 for ( i
= src
; i
< dest
; i
++ )
740 this->list
[ i
] = this->list
[ i
+ 1 ];
742 this->list
[ dest
] = src_entry
;
744 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
745 mlt_producer_seek( MLT_PLAYLIST_PRODUCER( this ), current_info
.start
+ position
);
746 mlt_playlist_virtual_refresh( this );
752 /** Repeat the specified clip n times.
755 int mlt_playlist_repeat_clip( mlt_playlist
this, int clip
, int repeat
)
757 int error
= repeat
< 1 || clip
< 0 || clip
>= this->count
;
760 playlist_entry
*entry
= this->list
[ clip
];
761 entry
->repeat
= repeat
;
762 mlt_playlist_virtual_refresh( this );
767 /** Resize the specified clip.
770 int mlt_playlist_resize_clip( mlt_playlist
this, int clip
, mlt_position in
, mlt_position out
)
772 int error
= clip
< 0 || clip
>= this->count
;
773 if ( error
== 0 && mlt_playlist_resize_mix( this, clip
, in
, out
) != 0 )
775 playlist_entry
*entry
= this->list
[ clip
];
776 mlt_producer producer
= entry
->producer
;
777 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
779 mlt_events_block( properties
, properties
);
781 if ( mlt_producer_is_blank( producer
) )
783 // Make sure the blank is long enough to accomodate the length specified
784 if ( out
- in
+ 1 > mlt_producer_get_length( &this->blank
) )
786 mlt_properties blank_props
= MLT_PRODUCER_PROPERTIES( &this->blank
);
787 mlt_properties_set_int( blank_props
, "length", out
- in
+ 1 );
788 mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( producer
), "length", out
- in
+ 1 );
789 mlt_producer_set_in_and_out( &this->blank
, 0, out
- in
);
795 if ( out
<= -1 || out
>= mlt_producer_get_length( producer
) )
796 out
= mlt_producer_get_length( producer
) - 1;
805 mlt_producer_set_in_and_out( producer
, in
, out
);
806 mlt_events_unblock( properties
, properties
);
807 mlt_playlist_virtual_refresh( this );
812 /** Split a clip on the playlist at the given position.
815 int mlt_playlist_split( mlt_playlist
this, int clip
, mlt_position position
)
817 int error
= clip
< 0 || clip
>= this->count
;
820 playlist_entry
*entry
= this->list
[ clip
];
821 position
= position
< 0 ? entry
->frame_count
+ position
- 1 : position
;
822 if ( position
>= 0 && position
< entry
->frame_count
- 1 )
824 int in
= entry
->frame_in
;
825 int out
= entry
->frame_out
;
826 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
827 mlt_playlist_resize_clip( this, clip
, in
, in
+ position
);
828 if ( !mlt_producer_is_blank( entry
->producer
) )
831 mlt_properties entry_properties
= MLT_PRODUCER_PROPERTIES( entry
->producer
);
832 mlt_producer split
= mlt_producer_cut( entry
->producer
, in
+ position
+ 1, out
);
833 mlt_properties split_properties
= MLT_PRODUCER_PROPERTIES( split
);
834 mlt_playlist_insert( this, split
, clip
+ 1, 0, -1 );
835 for ( i
= 0; i
< mlt_properties_count( entry_properties
); i
++ )
837 char *name
= mlt_properties_get_name( entry_properties
, i
);
838 if ( name
!= NULL
&& !strncmp( name
, "meta.", 5 ) )
839 mlt_properties_set( split_properties
, name
, mlt_properties_get_value( entry_properties
, i
) );
841 mlt_producer_close( split
);
845 mlt_playlist_insert( this, &this->blank
, clip
+ 1, 0, out
- position
- 1 );
847 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
848 mlt_playlist_virtual_refresh( this );
858 /** Split the playlist at the absolute position.
861 int mlt_playlist_split_at( mlt_playlist
this, mlt_position position
, int left
)
863 int result
= this == NULL ?
-1 : 0;
866 if ( position
>= 0 && position
< mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) ) )
868 int clip
= mlt_playlist_get_clip_index_at( this, position
);
869 mlt_playlist_clip_info info
;
870 mlt_playlist_get_clip_info( this, &info
, clip
);
871 if ( left
&& position
!= info
.start
)
872 mlt_playlist_split( this, clip
, position
- info
.start
- 1 );
874 mlt_playlist_split( this, clip
, position
- info
.start
);
877 else if ( position
<= 0 )
883 result
= mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
889 /** Join 1 or more consecutive clips.
892 int mlt_playlist_join( mlt_playlist
this, int clip
, int count
, int merge
)
894 int error
= clip
< 0 || clip
>= this->count
;
898 mlt_playlist new_clip
= mlt_playlist_init( );
899 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
900 if ( clip
+ count
>= this->count
)
901 count
= this->count
- clip
- 1;
902 for ( i
= 0; i
<= count
; i
++ )
904 playlist_entry
*entry
= this->list
[ clip
];
905 mlt_playlist_append( new_clip
, entry
->producer
);
906 mlt_playlist_repeat_clip( new_clip
, i
, entry
->repeat
);
907 entry
->preservation_hack
= 1;
908 mlt_playlist_remove( this, clip
);
910 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
911 mlt_playlist_insert( this, MLT_PLAYLIST_PRODUCER( new_clip
), clip
, 0, -1 );
912 mlt_playlist_close( new_clip
);
917 /** Mix consecutive clips for a specified length and apply transition if specified.
920 int mlt_playlist_mix( mlt_playlist
this, int clip
, int length
, mlt_transition transition
)
922 int error
= ( clip
< 0 || clip
+ 1 >= this->count
);
925 playlist_entry
*clip_a
= this->list
[ clip
];
926 playlist_entry
*clip_b
= this->list
[ clip
+ 1 ];
927 mlt_producer track_a
= NULL
;
928 mlt_producer track_b
= NULL
;
929 mlt_tractor tractor
= mlt_tractor_new( );
930 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
932 // Check length is valid for both clips and resize if necessary.
933 int max_size
= clip_a
->frame_count
> clip_b
->frame_count ? clip_a
->frame_count
: clip_b
->frame_count
;
934 length
= length
> max_size ? max_size
: length
;
936 // Create the a and b tracks/cuts if necessary - note that no cuts are required if the length matches
937 if ( length
!= clip_a
->frame_count
)
938 track_a
= mlt_producer_cut( clip_a
->producer
, clip_a
->frame_out
- length
+ 1, clip_a
->frame_out
);
940 track_a
= clip_a
->producer
;
942 if ( length
!= clip_b
->frame_count
)
943 track_b
= mlt_producer_cut( clip_b
->producer
, clip_b
->frame_in
, clip_b
->frame_in
+ length
- 1 );
945 track_b
= clip_b
->producer
;
947 // Set the tracks on the tractor
948 mlt_tractor_set_track( tractor
, track_a
, 0 );
949 mlt_tractor_set_track( tractor
, track_b
, 1 );
951 // Insert the mix object into the playlist
952 mlt_playlist_insert( this, MLT_TRACTOR_PRODUCER( tractor
), clip
+ 1, -1, -1 );
953 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor
), "mlt_mix", tractor
, 0, NULL
, NULL
);
955 // Attach the transition
956 if ( transition
!= NULL
)
958 mlt_field field
= mlt_tractor_field( tractor
);
959 mlt_field_plant_transition( field
, transition
, 0, 1 );
960 mlt_transition_set_in_and_out( transition
, 0, length
- 1 );
963 // Close our references to the tracks if we created new cuts above (the tracks can still be used here)
964 if ( track_a
!= clip_a
->producer
)
965 mlt_producer_close( track_a
);
966 if ( track_b
!= clip_b
->producer
)
967 mlt_producer_close( track_b
);
969 // Check if we have anything left on the right hand clip
970 if ( track_b
== clip_b
->producer
)
972 clip_b
->preservation_hack
= 1;
973 mlt_playlist_remove( this, clip
+ 2 );
975 else if ( clip_b
->frame_out
- clip_b
->frame_in
> length
)
977 mlt_playlist_resize_clip( this, clip
+ 2, clip_b
->frame_in
+ length
, clip_b
->frame_out
);
978 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( clip_b
->producer
), "mix_in", tractor
, 0, NULL
, NULL
);
979 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor
), "mix_out", clip_b
->producer
, 0, NULL
, NULL
);
983 mlt_producer_clear( clip_b
->producer
);
984 mlt_playlist_remove( this, clip
+ 2 );
987 // Check if we have anything left on the left hand clip
988 if ( track_a
== clip_a
->producer
)
990 clip_a
->preservation_hack
= 1;
991 mlt_playlist_remove( this, clip
);
993 else if ( clip_a
->frame_out
- clip_a
->frame_in
> length
)
995 mlt_playlist_resize_clip( this, clip
, clip_a
->frame_in
, clip_a
->frame_out
- length
);
996 mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( clip_a
->producer
), "mix_out", tractor
, 0, NULL
, NULL
);
997 mlt_properties_set_data( MLT_TRACTOR_PROPERTIES( tractor
), "mix_in", clip_a
->producer
, 0, NULL
, NULL
);
1001 mlt_producer_clear( clip_a
->producer
);
1002 mlt_playlist_remove( this, clip
);
1005 // Unblock and force a fire off of change events to listeners
1006 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1007 mlt_playlist_virtual_refresh( this );
1008 mlt_tractor_close( tractor
);
1013 /** Add a transition to an existing mix.
1016 int mlt_playlist_mix_add( mlt_playlist
this, int clip
, mlt_transition transition
)
1018 mlt_producer producer
= mlt_producer_cut_parent( mlt_playlist_get_clip( this, clip
) );
1019 mlt_properties properties
= producer
!= NULL ?
MLT_PRODUCER_PROPERTIES( producer
) : NULL
;
1020 mlt_tractor tractor
= properties
!= NULL ?
mlt_properties_get_data( properties
, "mlt_mix", NULL
) : NULL
;
1021 int error
= transition
== NULL
|| tractor
== NULL
;
1024 mlt_field field
= mlt_tractor_field( tractor
);
1025 mlt_field_plant_transition( field
, transition
, 0, 1 );
1026 mlt_transition_set_in_and_out( transition
, 0, this->list
[ clip
]->frame_count
- 1 );
1031 /** Return the clip at the clip index.
1034 mlt_producer
mlt_playlist_get_clip( mlt_playlist
this, int clip
)
1036 if ( clip
>= 0 && clip
< this->count
)
1037 return this->list
[ clip
]->producer
;
1041 /** Return the clip at the specified position.
1044 mlt_producer
mlt_playlist_get_clip_at( mlt_playlist
this, mlt_position position
)
1046 int index
= 0, total
= 0;
1047 return mlt_playlist_locate( this, &position
, &index
, &total
);
1050 /** Return the clip index of the specified position.
1053 int mlt_playlist_get_clip_index_at( mlt_playlist
this, mlt_position position
)
1055 int index
= 0, total
= 0;
1056 mlt_playlist_locate( this, &position
, &index
, &total
);
1060 /** Determine if the clip is a mix.
1063 int mlt_playlist_clip_is_mix( mlt_playlist
this, int clip
)
1065 mlt_producer producer
= mlt_producer_cut_parent( mlt_playlist_get_clip( this, clip
) );
1066 mlt_properties properties
= producer
!= NULL ?
MLT_PRODUCER_PROPERTIES( producer
) : NULL
;
1067 mlt_tractor tractor
= properties
!= NULL ?
mlt_properties_get_data( properties
, "mlt_mix", NULL
) : NULL
;
1068 return tractor
!= NULL
;
1071 /** Remove a mixed clip - ensure that the cuts included in the mix find their way
1072 back correctly on to the playlist.
1075 static int mlt_playlist_unmix( mlt_playlist
this, int clip
)
1077 int error
= ( clip
< 0 || clip
>= this->count
);
1079 // Ensure that the clip request is actually a mix
1082 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ clip
]->producer
);
1083 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
1084 error
= mlt_properties_get_data( properties
, "mlt_mix", NULL
) == NULL
||
1085 this->list
[ clip
]->preservation_hack
;
1090 playlist_entry
*mix
= this->list
[ clip
];
1091 mlt_tractor tractor
= ( mlt_tractor
)mlt_producer_cut_parent( mix
->producer
);
1092 mlt_properties properties
= MLT_TRACTOR_PROPERTIES( tractor
);
1093 mlt_producer clip_a
= mlt_properties_get_data( properties
, "mix_in", NULL
);
1094 mlt_producer clip_b
= mlt_properties_get_data( properties
, "mix_out", NULL
);
1095 int length
= mlt_producer_get_playtime( MLT_TRACTOR_PRODUCER( tractor
) );
1096 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
1098 if ( clip_a
!= NULL
)
1100 mlt_producer_set_in_and_out( clip_a
, mlt_producer_get_in( clip_a
), mlt_producer_get_out( clip_a
) + length
);
1104 mlt_producer cut
= mlt_tractor_get_track( tractor
, 0 );
1105 mlt_playlist_insert( this, cut
, clip
, -1, -1 );
1109 if ( clip_b
!= NULL
)
1111 mlt_producer_set_in_and_out( clip_b
, mlt_producer_get_in( clip_b
) - length
, mlt_producer_get_out( clip_b
) );
1115 mlt_producer cut
= mlt_tractor_get_track( tractor
, 1 );
1116 mlt_playlist_insert( this, cut
, clip
+ 1, -1, -1 );
1119 mlt_properties_set_data( properties
, "mlt_mix", NULL
, 0, NULL
, NULL
);
1120 mlt_playlist_remove( this, clip
);
1121 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1122 mlt_playlist_virtual_refresh( this );
1127 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
)
1129 int error
= ( clip
< 0 || clip
>= this->count
);
1131 // Ensure that the clip request is actually a mix
1134 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ clip
]->producer
);
1135 mlt_properties properties
= MLT_PRODUCER_PROPERTIES( producer
);
1136 error
= mlt_properties_get_data( properties
, "mlt_mix", NULL
) == NULL
;
1141 playlist_entry
*mix
= this->list
[ clip
];
1142 mlt_tractor tractor
= ( mlt_tractor
)mlt_producer_cut_parent( mix
->producer
);
1143 mlt_properties properties
= MLT_TRACTOR_PROPERTIES( tractor
);
1144 mlt_producer clip_a
= mlt_properties_get_data( properties
, "mix_in", NULL
);
1145 mlt_producer clip_b
= mlt_properties_get_data( properties
, "mix_out", NULL
);
1146 mlt_producer track_a
= mlt_tractor_get_track( tractor
, 0 );
1147 mlt_producer track_b
= mlt_tractor_get_track( tractor
, 1 );
1148 int length
= out
- in
+ 1;
1149 int length_diff
= length
- mlt_producer_get_playtime( MLT_TRACTOR_PRODUCER( tractor
) );
1150 mlt_events_block( MLT_PLAYLIST_PROPERTIES( this ), this );
1152 if ( clip_a
!= NULL
)
1153 mlt_producer_set_in_and_out( clip_a
, mlt_producer_get_in( clip_a
), mlt_producer_get_out( clip_a
) - length_diff
);
1155 if ( clip_b
!= NULL
)
1156 mlt_producer_set_in_and_out( clip_b
, mlt_producer_get_in( clip_b
) + length_diff
, mlt_producer_get_out( clip_b
) );
1158 mlt_producer_set_in_and_out( track_a
, mlt_producer_get_in( track_a
) - length_diff
, mlt_producer_get_out( track_a
) );
1159 mlt_producer_set_in_and_out( track_b
, mlt_producer_get_in( track_b
), mlt_producer_get_out( track_b
) + length_diff
);
1160 mlt_producer_set_in_and_out( MLT_MULTITRACK_PRODUCER( mlt_tractor_multitrack( tractor
) ), in
, out
);
1161 mlt_producer_set_in_and_out( MLT_TRACTOR_PRODUCER( tractor
), in
, out
);
1162 mlt_properties_set_position( MLT_PRODUCER_PROPERTIES( mix
->producer
), "length", out
- in
+ 1 );
1163 mlt_producer_set_in_and_out( mix
->producer
, in
, out
);
1165 mlt_events_unblock( MLT_PLAYLIST_PROPERTIES( this ), this );
1166 mlt_playlist_virtual_refresh( this );
1171 /** Consolodate adjacent blank producers.
1174 void mlt_playlist_consolidate_blanks( mlt_playlist
this, int keep_length
)
1179 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1181 mlt_events_block( properties
, properties
);
1182 for ( i
= 1; i
< this->count
; i
++ )
1184 playlist_entry
*left
= this->list
[ i
- 1 ];
1185 playlist_entry
*right
= this->list
[ i
];
1187 if ( mlt_producer_is_blank( left
->producer
) && mlt_producer_is_blank( right
->producer
) )
1189 mlt_playlist_resize_clip( this, i
- 1, 0, left
->frame_count
+ right
->frame_count
- 1 );
1190 mlt_playlist_remove( this, i
-- );
1194 if ( !keep_length
&& this->count
> 0 )
1196 playlist_entry
*last
= this->list
[ this->count
- 1 ];
1197 if ( mlt_producer_is_blank( last
->producer
) )
1198 mlt_playlist_remove( this, this->count
- 1 );
1201 mlt_events_unblock( properties
, properties
);
1202 mlt_playlist_virtual_refresh( this );
1206 /** Determine if the specified clip index is a blank.
1209 int mlt_playlist_is_blank( mlt_playlist
this, int clip
)
1211 return this == NULL
|| mlt_producer_is_blank( mlt_playlist_get_clip( this, clip
) );
1214 /** Determine if the specified position is a blank.
1217 int mlt_playlist_is_blank_at( mlt_playlist
this, mlt_position position
)
1219 return this == NULL
|| mlt_producer_is_blank( mlt_playlist_get_clip_at( this, position
) );
1222 /** Replace the specified clip with a blank and return the clip.
1225 mlt_producer
mlt_playlist_replace_with_blank( mlt_playlist
this, int clip
)
1227 mlt_producer producer
= NULL
;
1228 if ( !mlt_playlist_is_blank( this, clip
) )
1230 playlist_entry
*entry
= this->list
[ clip
];
1231 int in
= entry
->frame_in
;
1232 int out
= entry
->frame_out
;
1233 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1234 producer
= entry
->producer
;
1235 mlt_properties_inc_ref( MLT_PRODUCER_PROPERTIES( producer
) );
1236 mlt_events_block( properties
, properties
);
1237 mlt_playlist_remove( this, clip
);
1238 mlt_playlist_blank( this, out
- in
);
1239 mlt_playlist_move( this, this->count
- 1, clip
);
1240 mlt_events_unblock( properties
, properties
);
1241 mlt_playlist_virtual_refresh( this );
1242 mlt_producer_set_in_and_out( producer
, in
, out
);
1247 void mlt_playlist_insert_blank( mlt_playlist
this, int clip
, int length
)
1249 if ( this != NULL
&& length
>= 0 )
1251 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1252 mlt_events_block( properties
, properties
);
1253 mlt_playlist_blank( this, length
);
1254 mlt_playlist_move( this, this->count
- 1, clip
);
1255 mlt_events_unblock( properties
, properties
);
1256 mlt_playlist_virtual_refresh( this );
1260 void mlt_playlist_pad_blanks( mlt_playlist
this, mlt_position position
, int length
, int find
)
1262 if ( this != NULL
&& length
!= 0 )
1264 int clip
= mlt_playlist_get_clip_index_at( this, position
);
1265 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1266 mlt_events_block( properties
, properties
);
1267 if ( find
&& clip
< this->count
&& !mlt_playlist_is_blank( this, clip
) )
1269 if ( clip
< this->count
&& mlt_playlist_is_blank( this, clip
) )
1271 mlt_playlist_clip_info info
;
1272 mlt_playlist_get_clip_info( this, &info
, clip
);
1273 if ( info
.frame_out
+ length
> info
.frame_in
)
1274 mlt_playlist_resize_clip( this, clip
, info
.frame_in
, info
.frame_out
+ length
);
1276 mlt_playlist_remove( this, clip
);
1278 else if ( find
&& clip
< this->count
&& length
> 0 )
1280 mlt_playlist_insert_blank( this, clip
, length
);
1282 mlt_events_unblock( properties
, properties
);
1283 mlt_playlist_virtual_refresh( this );
1287 int mlt_playlist_insert_at( mlt_playlist
this, mlt_position position
, mlt_producer producer
, int mode
)
1289 int ret
= this == NULL
|| position
< 0 || producer
== NULL
;
1292 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1293 int length
= mlt_producer_get_playtime( producer
);
1294 int clip
= mlt_playlist_get_clip_index_at( this, position
);
1295 mlt_playlist_clip_info info
;
1296 mlt_playlist_get_clip_info( this, &info
, clip
);
1297 mlt_events_block( properties
, this );
1298 if ( clip
< this->count
&& mlt_playlist_is_blank( this, clip
) )
1300 // Split and move to new clip if need be
1301 if ( position
!= info
.start
&& mlt_playlist_split( this, clip
, position
- info
.start
- 1 ) == 0 )
1302 mlt_playlist_get_clip_info( this, &info
, ++ clip
);
1304 // Split again if need be
1305 if ( length
< info
.frame_count
)
1306 mlt_playlist_split( this, clip
, length
- 1 );
1309 mlt_playlist_remove( this, clip
);
1312 mlt_playlist_insert( this, producer
, clip
, -1, -1 );
1315 else if ( clip
< this->count
)
1317 if ( position
> info
.start
+ info
.frame_count
/ 2 )
1319 if ( mode
== 1 && clip
< this->count
&& mlt_playlist_is_blank( this, clip
) )
1321 mlt_playlist_get_clip_info( this, &info
, clip
);
1322 if ( length
< info
.frame_count
)
1323 mlt_playlist_split( this, clip
, length
);
1324 mlt_playlist_remove( this, clip
);
1326 mlt_playlist_insert( this, producer
, clip
, -1, -1 );
1332 if ( position
== info
.start
)
1333 mlt_playlist_remove( this, clip
);
1335 mlt_playlist_blank( this, position
- mlt_properties_get_int( properties
, "length" ) - 1 );
1337 mlt_playlist_append( this, producer
);
1338 ret
= this->count
- 1;
1340 mlt_events_unblock( properties
, this );
1341 mlt_playlist_virtual_refresh( this );
1350 int mlt_playlist_clip_start( mlt_playlist
this, int clip
)
1352 mlt_playlist_clip_info info
;
1353 if ( mlt_playlist_get_clip_info( this, &info
, clip
) == 0 )
1355 return clip
< 0 ?
0 : mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
1358 int mlt_playlist_clip_length( mlt_playlist
this, int clip
)
1360 mlt_playlist_clip_info info
;
1361 if ( mlt_playlist_get_clip_info( this, &info
, clip
) == 0 )
1362 return info
.frame_count
;
1366 int mlt_playlist_blanks_from( mlt_playlist
this, int clip
, int bounded
)
1369 mlt_playlist_clip_info info
;
1370 if ( this != NULL
&& clip
< this->count
)
1372 mlt_playlist_get_clip_info( this, &info
, clip
);
1373 if ( mlt_playlist_is_blank( this, clip
) )
1374 count
+= info
.frame_count
;
1376 bounded
= this->count
;
1377 for ( clip
++; clip
< this->count
&& bounded
>= 0; clip
++ )
1379 mlt_playlist_get_clip_info( this, &info
, clip
);
1380 if ( mlt_playlist_is_blank( this, clip
) )
1381 count
+= info
.frame_count
;
1389 int mlt_playlist_remove_region( mlt_playlist
this, mlt_position position
, int length
)
1391 int index
= mlt_playlist_get_clip_index_at( this, position
);
1392 if ( index
>= 0 && index
< this->count
)
1394 mlt_properties properties
= MLT_PLAYLIST_PROPERTIES( this );
1395 int clip_start
= mlt_playlist_clip_start( this, index
);
1396 int clip_length
= mlt_playlist_clip_length( this, index
);
1397 int list_length
= mlt_producer_get_playtime( MLT_PLAYLIST_PRODUCER( this ) );
1398 mlt_events_block( properties
, this );
1400 if ( position
+ length
> list_length
)
1401 length
-= ( position
+ length
- list_length
);
1403 if ( clip_start
< position
)
1405 mlt_playlist_split( this, index
++, position
- clip_start
);
1406 clip_length
-= position
- clip_start
;
1411 if ( mlt_playlist_clip_length( this, index
) > length
)
1412 mlt_playlist_split( this, index
, length
);
1413 length
-= mlt_playlist_clip_length( this, index
);
1414 mlt_playlist_remove( this, index
);
1417 mlt_playlist_consolidate_blanks( this, 0 );
1418 mlt_events_unblock( properties
, this );
1419 mlt_playlist_virtual_refresh( this );
1421 // Just to be sure, we'll get the clip index again...
1422 index
= mlt_playlist_get_clip_index_at( this, position
);
1427 int mlt_playlist_move_region( mlt_playlist
this, mlt_position position
, int length
, int new_position
)
1435 /** Get the current frame.
1438 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
)
1440 // Check that we have a producer
1441 if ( producer
== NULL
)
1447 // Get this mlt_playlist
1448 mlt_playlist
this = producer
->child
;
1450 // Need to ensure the frame is deinterlaced when repeating 1 frame
1451 int progressive
= 0;
1453 // Get the real producer
1454 mlt_service real
= mlt_playlist_virtual_seek( this, &progressive
);
1456 // Check that we have a producer
1459 *frame
= mlt_frame_init( MLT_PRODUCER_SERVICE( producer
) );
1464 if ( !mlt_properties_get_int( MLT_SERVICE_PROPERTIES( real
), "meta.fx_cut" ) )
1466 mlt_service_get_frame( real
, frame
, index
);
1470 mlt_producer parent
= mlt_producer_cut_parent( ( mlt_producer
)real
);
1471 *frame
= mlt_frame_init( MLT_PRODUCER_SERVICE( parent
) );
1472 mlt_properties_set_int( MLT_FRAME_PROPERTIES( *frame
), "fx_cut", 1 );
1473 mlt_frame_push_service( *frame
, NULL
);
1474 mlt_frame_push_audio( *frame
, NULL
);
1475 mlt_service_apply_filters( MLT_PRODUCER_SERVICE( parent
), *frame
, 0 );
1476 mlt_service_apply_filters( real
, *frame
, 0 );
1477 mlt_deque_pop_front( MLT_FRAME_IMAGE_STACK( *frame
) );
1478 mlt_deque_pop_front( MLT_FRAME_AUDIO_STACK( *frame
) );
1481 // Check if we're at the end of the clip
1482 mlt_properties properties
= MLT_FRAME_PROPERTIES( *frame
);
1483 if ( mlt_properties_get_int( properties
, "end_of_clip" ) )
1484 mlt_playlist_virtual_set_out( this );
1486 // Set the consumer progressive property
1489 mlt_properties_set_int( properties
, "consumer_deinterlace", progressive
);
1490 mlt_properties_set_int( properties
, "test_audio", 1 );
1493 // Check for notifier and call with appropriate argument
1494 mlt_properties playlist_properties
= MLT_PRODUCER_PROPERTIES( producer
);
1495 void ( *notifier
)( void * ) = mlt_properties_get_data( playlist_properties
, "notifier", NULL
);
1496 if ( notifier
!= NULL
)
1498 void *argument
= mlt_properties_get_data( playlist_properties
, "notifier_arg", NULL
);
1499 notifier( argument
);
1502 // Update position on the frame we're creating
1503 mlt_frame_set_position( *frame
, mlt_producer_frame( producer
) );
1505 // Position ourselves on the next frame
1506 mlt_producer_prepare_next( producer
);
1511 /** Close the playlist.
1514 void mlt_playlist_close( mlt_playlist
this )
1516 if ( this != NULL
&& mlt_properties_dec_ref( MLT_PLAYLIST_PROPERTIES( this ) ) <= 0 )
1519 this->parent
.close
= NULL
;
1520 for ( i
= 0; i
< this->count
; i
++ )
1522 mlt_event_close( this->list
[ i
]->event
);
1523 mlt_producer_close( this->list
[ i
]->producer
);
1524 free( this->list
[ i
] );
1526 mlt_producer_close( &this->blank
);
1527 mlt_producer_close( &this->parent
);