2 * mlt_playlist.c -- playlist service class
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "mlt_playlist.h"
24 #include "mlt_tractor.h"
25 #include "mlt_field.h"
26 #include "mlt_frame.h"
27 #include "mlt_transition.h"
33 /** Virtual playlist entry.
36 typedef struct playlist_entry_s
38 mlt_producer producer
;
39 mlt_position frame_in
;
40 mlt_position frame_out
;
41 mlt_position frame_count
;
43 mlt_position producer_length
;
47 struct playlist_entry_s
*mix_in
;
48 struct playlist_entry_s
*mix_out
;
52 /** Private definition.
57 struct mlt_producer_s parent
;
58 struct mlt_producer_s blank
;
62 playlist_entry
**list
;
65 /** Forward declarations
68 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
);
69 static int mlt_playlist_unmix( mlt_playlist
this, int clip
);
70 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
);
75 mlt_playlist
mlt_playlist_init( )
77 mlt_playlist
this = calloc( sizeof( struct mlt_playlist_s
), 1 );
80 mlt_producer producer
= &this->parent
;
82 // Construct the producer
83 mlt_producer_init( producer
, this );
85 // Override the producer get_frame
86 producer
->get_frame
= producer_get_frame
;
88 // Define the destructor
89 producer
->close
= ( mlt_destructor
)mlt_playlist_close
;
90 producer
->close_object
= this;
93 mlt_producer_init( &this->blank
, NULL
);
94 mlt_properties_set( mlt_producer_properties( &this->blank
), "mlt_service", "blank" );
95 mlt_properties_set( mlt_producer_properties( &this->blank
), "resource", "blank" );
97 // Indicate that this producer is a playlist
98 mlt_properties_set_data( mlt_playlist_properties( this ), "playlist", this, 0, NULL
, NULL
);
100 // Specify the eof condition
101 mlt_properties_set( mlt_playlist_properties( this ), "eof", "pause" );
102 mlt_properties_set( mlt_playlist_properties( this ), "resource", "<playlist>" );
103 mlt_properties_set( mlt_playlist_properties( this ), "mlt_type", "mlt_producer" );
104 mlt_properties_set_position( mlt_playlist_properties( this ), "in", 0 );
105 mlt_properties_set_position( mlt_playlist_properties( this ), "out", 0 );
106 mlt_properties_set_position( mlt_playlist_properties( this ), "length", 0 );
109 this->list
= malloc( this->size
* sizeof( playlist_entry
* ) );
115 /** Get the producer associated to this playlist.
118 mlt_producer
mlt_playlist_producer( mlt_playlist
this )
120 return this != NULL ?
&this->parent
: NULL
;
123 /** Get the service associated to this playlist.
126 mlt_service
mlt_playlist_service( mlt_playlist
this )
128 return mlt_producer_service( &this->parent
);
131 /** Get the propertues associated to this playlist.
134 mlt_properties
mlt_playlist_properties( mlt_playlist
this )
136 return mlt_producer_properties( &this->parent
);
139 /** Refresh the playlist after a clip has been changed.
142 static int mlt_playlist_virtual_refresh( mlt_playlist
this )
144 // Obtain the properties
145 mlt_properties properties
= mlt_playlist_properties( this );
147 // Get the fps of the first producer
148 double fps
= mlt_properties_get_double( properties
, "first_fps" );
150 mlt_position frame_count
= 0;
152 for ( i
= 0; i
< this->count
; i
++ )
155 mlt_producer producer
= this->list
[ i
]->producer
;
156 int current_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
161 // Inherit it from the producer
162 fps
= mlt_producer_get_fps( producer
);
164 else if ( fps
!= mlt_properties_get_double( mlt_producer_properties( producer
), "fps" ) )
166 // Generate a warning for now - the following attempt to fix may fail
167 fprintf( stderr
, "Warning: fps mismatch on playlist producer %d\n", this->count
);
169 // It should be safe to impose fps on an image producer, but not necessarily safe for video
170 mlt_properties_set_double( mlt_producer_properties( producer
), "fps", fps
);
173 // Check if the length of the producer has changed
174 if ( this->list
[ i
]->producer
!= &this->blank
&&
175 ( this->list
[ i
]->frame_in
!= mlt_producer_get_in( producer
) ||
176 this->list
[ i
]->frame_out
!= mlt_producer_get_out( producer
) ) )
178 // This clip should be removed...
179 if ( current_length
< 1 )
181 this->list
[ i
]->frame_in
= 0;
182 this->list
[ i
]->frame_out
= -1;
183 this->list
[ i
]->frame_count
= 0;
187 this->list
[ i
]->frame_in
= mlt_producer_get_in( producer
);
188 this->list
[ i
]->frame_out
= mlt_producer_get_out( producer
);
189 this->list
[ i
]->frame_count
= current_length
;
192 // Update the producer_length
193 this->list
[ i
]->producer_length
= current_length
;
196 // Calculate the frame_count
197 this->list
[ i
]->frame_count
= ( this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1 ) * this->list
[ i
]->repeat
;
199 // Update the frame_count for this clip
200 frame_count
+= this->list
[ i
]->frame_count
;
203 // Refresh all properties
204 mlt_properties_set_double( properties
, "first_fps", fps
);
205 mlt_properties_set_double( properties
, "fps", fps
== 0 ?
25 : fps
);
206 mlt_events_block( properties
, properties
);
207 mlt_properties_set_position( properties
, "length", frame_count
);
208 mlt_events_unblock( properties
, properties
);
209 mlt_properties_set_position( properties
, "out", frame_count
- 1 );
214 /** Listener for producers on the playlist.
217 static void mlt_playlist_listener( mlt_producer producer
, mlt_playlist
this )
219 mlt_playlist_virtual_refresh( this );
222 /** Append to the virtual playlist.
225 static int mlt_playlist_virtual_append( mlt_playlist
this, mlt_producer source
, mlt_position in
, mlt_position out
)
227 char *resource
= source
!= NULL ?
mlt_properties_get( mlt_producer_properties( source
), "resource" ) : NULL
;
228 mlt_producer producer
= NULL
;
229 mlt_properties properties
= NULL
;
231 // If we have a cut, then use the in/out points from the cut
232 if ( resource
== NULL
|| !strcmp( resource
, "blank" ) )
234 producer
= &this->blank
;
235 properties
= mlt_producer_properties( producer
);
236 mlt_properties_inc_ref( properties
);
238 else if ( mlt_producer_is_cut( source
) )
242 in
= mlt_producer_get_in( producer
);
243 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
244 out
= mlt_producer_get_out( producer
);
245 properties
= mlt_producer_properties( producer
);
246 mlt_properties_inc_ref( properties
);
250 producer
= mlt_producer_cut( source
, in
, out
);
251 if ( in
== -1 || in
< mlt_producer_get_in( producer
) )
252 in
= mlt_producer_get_in( producer
);
253 if ( out
== -1 || out
> mlt_producer_get_out( producer
) )
254 out
= mlt_producer_get_out( producer
);
255 properties
= mlt_producer_properties( producer
);
258 // Check that we have room
259 if ( this->count
>= this->size
)
262 this->list
= realloc( this->list
, ( this->size
+ 10 ) * sizeof( playlist_entry
* ) );
263 for ( i
= this->size
; i
< this->size
+ 10; i
++ ) this->list
[ i
] = NULL
;
267 this->list
[ this->count
] = calloc( sizeof( playlist_entry
), 1 );
268 this->list
[ this->count
]->producer
= producer
;
269 this->list
[ this->count
]->frame_in
= in
;
270 this->list
[ this->count
]->frame_out
= out
;
271 this->list
[ this->count
]->frame_count
= out
- in
+ 1;
272 this->list
[ this->count
]->repeat
= 1;
273 this->list
[ this->count
]->producer_length
= mlt_producer_get_out( producer
) - mlt_producer_get_in( producer
) + 1;
274 this->list
[ this->count
]->event
= mlt_events_listen( properties
, this, "producer-changed", ( mlt_listener
)mlt_playlist_listener
);
275 mlt_event_inc_ref( this->list
[ this->count
]->event
);
277 mlt_properties_set( properties
, "eof", "pause" );
278 mlt_producer_set_speed( producer
, 0 );
282 return mlt_playlist_virtual_refresh( this );
285 /** Seek in the virtual playlist.
288 static mlt_service
mlt_playlist_virtual_seek( mlt_playlist
this )
290 // Default producer to blank
291 mlt_producer producer
= NULL
;
293 // Map playlist position to real producer in virtual playlist
294 mlt_position position
= mlt_producer_frame( &this->parent
);
296 mlt_position original
= position
;
298 // Total number of frames
301 // Get the properties
302 mlt_properties properties
= mlt_playlist_properties( this );
304 // Get the eof handling
305 char *eof
= mlt_properties_get( properties
, "eof" );
307 // Index for the main loop
310 // Loop for each producer until found
311 for ( i
= 0; i
< this->count
; i
++ )
313 // Increment the total
314 total
+= this->list
[ i
]->frame_count
;
316 // Check if the position indicates that we have found the clip
317 // Note that 0 length clips get skipped automatically
318 if ( position
< this->list
[ i
]->frame_count
)
320 // Found it, now break
321 producer
= this->list
[ i
]->producer
;
326 // Decrement position by length of this entry
327 position
-= this->list
[ i
]->frame_count
;
331 // Seek in real producer to relative position
332 if ( producer
!= NULL
)
334 int count
= this->list
[ i
]->frame_count
/ this->list
[ i
]->repeat
;
335 mlt_producer_seek( producer
, position
% count
);
337 else if ( !strcmp( eof
, "pause" ) && total
> 0 )
339 playlist_entry
*entry
= this->list
[ this->count
- 1 ];
340 mlt_producer this_producer
= mlt_playlist_producer( this );
341 mlt_producer_seek( this_producer
, original
- 1 );
342 producer
= entry
->producer
;
343 mlt_producer_seek( producer
, entry
->frame_out
);
344 mlt_producer_set_speed( this_producer
, 0 );
345 mlt_producer_set_speed( producer
, 0 );
347 else if ( !strcmp( eof
, "loop" ) && total
> 0 )
349 playlist_entry
*entry
= this->list
[ 0 ];
350 mlt_producer this_producer
= mlt_playlist_producer( this );
351 mlt_producer_seek( this_producer
, 0 );
352 producer
= entry
->producer
;
353 mlt_producer_seek( producer
, 0 );
357 producer
= &this->blank
;
360 return mlt_producer_service( producer
);
363 /** Invoked when a producer indicates that it has prematurely reached its end.
366 static mlt_producer
mlt_playlist_virtual_set_out( mlt_playlist
this )
368 // Default producer to blank
369 mlt_producer producer
= &this->blank
;
371 // Map playlist position to real producer in virtual playlist
372 mlt_position position
= mlt_producer_frame( &this->parent
);
374 // Loop through the virtual playlist
377 for ( i
= 0; i
< this->count
; i
++ )
379 if ( position
< this->list
[ i
]->frame_count
)
381 // Found it, now break
382 producer
= this->list
[ i
]->producer
;
387 // Decrement position by length of this entry
388 position
-= this->list
[ i
]->frame_count
;
392 // Seek in real producer to relative position
393 if ( i
< this->count
&& this->list
[ i
]->frame_out
!= position
)
395 // Update the frame_count for the changed clip (hmmm)
396 this->list
[ i
]->frame_out
= position
;
397 this->list
[ i
]->frame_count
= this->list
[ i
]->frame_out
- this->list
[ i
]->frame_in
+ 1;
399 // Refresh the playlist
400 mlt_playlist_virtual_refresh( this );
406 /** Obtain the current clips index.
409 int mlt_playlist_current_clip( mlt_playlist
this )
411 // Map playlist position to real producer in virtual playlist
412 mlt_position position
= mlt_producer_frame( &this->parent
);
414 // Loop through the virtual playlist
417 for ( i
= 0; i
< this->count
; i
++ )
419 if ( position
< this->list
[ i
]->frame_count
)
421 // Found it, now break
426 // Decrement position by length of this entry
427 position
-= this->list
[ i
]->frame_count
;
434 /** Obtain the current clips producer.
437 mlt_producer
mlt_playlist_current( mlt_playlist
this )
439 int i
= mlt_playlist_current_clip( this );
440 if ( i
< this->count
)
441 return this->list
[ i
]->producer
;
446 /** Get the position which corresponds to the start of the next clip.
449 mlt_position
mlt_playlist_clip( mlt_playlist
this, mlt_whence whence
, int index
)
451 mlt_position position
= 0;
452 int absolute_clip
= index
;
455 // Determine the absolute clip
458 case mlt_whence_relative_start
:
459 absolute_clip
= index
;
462 case mlt_whence_relative_current
:
463 absolute_clip
= mlt_playlist_current_clip( this ) + index
;
466 case mlt_whence_relative_end
:
467 absolute_clip
= this->count
- index
;
471 // Check that we're in a valid range
472 if ( absolute_clip
< 0 )
474 else if ( absolute_clip
> this->count
)
475 absolute_clip
= this->count
;
477 // Now determine the position
478 for ( i
= 0; i
< absolute_clip
; i
++ )
479 position
+= this->list
[ i
]->frame_count
;
484 /** Get all the info about the clip specified.
487 int mlt_playlist_get_clip_info( mlt_playlist
this, mlt_playlist_clip_info
*info
, int index
)
489 int error
= index
< 0 || index
>= this->count
;
490 memset( info
, 0, sizeof( mlt_playlist_clip_info
) );
493 mlt_producer producer
= mlt_producer_cut_parent( this->list
[ index
]->producer
);
494 mlt_properties properties
= mlt_producer_properties( producer
);
496 info
->producer
= producer
;
497 info
->cut
= this->list
[ index
]->producer
;
498 info
->start
= mlt_playlist_clip( this, mlt_whence_relative_start
, index
);
499 info
->resource
= mlt_properties_get( properties
, "resource" );
500 info
->frame_in
= this->list
[ index
]->frame_in
;
501 info
->frame_out
= this->list
[ index
]->frame_out
;
502 info
->frame_count
= this->list
[ index
]->frame_count
;
503 info
->repeat
= this->list
[ index
]->repeat
;
504 info
->length
= mlt_producer_get_length( producer
);
505 info
->fps
= mlt_producer_get_fps( producer
);
511 /** Get number of clips in the playlist.
514 int mlt_playlist_count( mlt_playlist
this )
519 /** Clear the playlist.
522 int mlt_playlist_clear( mlt_playlist
this )
525 for ( i
= 0; i
< this->count
; i
++ )
527 mlt_event_close( this->list
[ i
]->event
);
528 mlt_producer_close( this->list
[ i
]->producer
);
531 mlt_properties_set_double( mlt_playlist_properties( this ), "first_fps", 0 );
532 return mlt_playlist_virtual_refresh( this );
535 /** Append a producer to the playlist.
538 int mlt_playlist_append( mlt_playlist
this, mlt_producer producer
)
540 // Append to virtual list
541 return mlt_playlist_virtual_append( this, producer
, 0, mlt_producer_get_playtime( producer
) - 1 );
544 /** Append a producer to the playlist with in/out points.
547 int mlt_playlist_append_io( mlt_playlist
this, mlt_producer producer
, mlt_position in
, mlt_position out
)
549 // Append to virtual list
550 if ( in
!= -1 && out
!= -1 )
551 return mlt_playlist_virtual_append( this, producer
, in
, out
);
553 return mlt_playlist_append( this, producer
);
556 /** Append a blank to the playlist of a given length.
559 int mlt_playlist_blank( mlt_playlist
this, mlt_position length
)
561 // Append to the virtual list
562 return mlt_playlist_virtual_append( this, &this->blank
, 0, length
);
565 /** Insert a producer into the playlist.
568 int mlt_playlist_insert( mlt_playlist
this, mlt_producer producer
, int where
, mlt_position in
, mlt_position out
)
571 mlt_events_block( mlt_playlist_properties( this ), this );
572 mlt_playlist_append_io( this, producer
, in
, out
);
574 // Move to the position specified
575 mlt_playlist_move( this, this->count
- 1, where
);
576 mlt_events_unblock( mlt_playlist_properties( this ), this );
578 return mlt_playlist_virtual_refresh( this );
581 /** Remove an entry in the playlist.
584 int mlt_playlist_remove( mlt_playlist
this, int where
)
586 int error
= where
< 0 || where
>= this->count
;
587 if ( error
== 0 && mlt_playlist_unmix( this, where
) != 0 )
589 // We need to know the current clip and the position within the playlist
590 int current
= mlt_playlist_current_clip( this );
591 mlt_position position
= mlt_producer_position( mlt_playlist_producer( this ) );
593 // We need all the details about the clip we're removing
594 mlt_playlist_clip_info where_info
;
595 playlist_entry
*entry
= this->list
[ where
];
601 mlt_playlist_get_clip_info( this, &where_info
, where
);
603 // Make sure the clip to be removed is valid and correct if necessary
606 if ( where
>= this->count
)
607 where
= this->count
- 1;
609 // Close the producer associated to the clip info
610 mlt_event_close( entry
->event
);
611 mlt_producer_close( entry
->producer
);
612 if ( entry
->mix_in
!= NULL
)
613 entry
->mix_in
->mix_out
= NULL
;
614 if ( entry
->mix_out
!= NULL
)
615 entry
->mix_out
->mix_in
= NULL
;
617 // Reorganise the list
618 for ( i
= where
+ 1; i
< this->count
; i
++ )
619 this->list
[ i
- 1 ] = this->list
[ i
];
623 if ( where
== current
)
624 mlt_producer_seek( mlt_playlist_producer( this ), where_info
.start
);
625 else if ( where
< current
&& this->count
> 0 )
626 mlt_producer_seek( mlt_playlist_producer( this ), position
- where_info
.frame_count
);
627 else if ( this->count
== 0 )
628 mlt_producer_seek( mlt_playlist_producer( this ), 0 );
633 // Refresh the playlist
634 mlt_playlist_virtual_refresh( this );
640 /** Move an entry in the playlist.
643 int mlt_playlist_move( mlt_playlist
this, int src
, int dest
)
647 /* We need to ensure that the requested indexes are valid and correct it as necessary */
650 if ( src
>= this->count
)
651 src
= this->count
- 1;
655 if ( dest
>= this->count
)
656 dest
= this->count
- 1;
658 if ( src
!= dest
&& this->count
> 1 )
660 int current
= mlt_playlist_current_clip( this );
661 mlt_position position
= mlt_producer_position( mlt_playlist_producer( this ) );
662 playlist_entry
*src_entry
= NULL
;
664 // We need all the details about the current clip
665 mlt_playlist_clip_info current_info
;
667 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
668 position
-= current_info
.start
;
670 if ( current
== src
)
672 else if ( current
> src
&& current
< dest
)
674 else if ( current
== dest
)
677 src_entry
= this->list
[ src
];
680 for ( i
= src
; i
> dest
; i
-- )
681 this->list
[ i
] = this->list
[ i
- 1 ];
685 for ( i
= src
; i
< dest
; i
++ )
686 this->list
[ i
] = this->list
[ i
+ 1 ];
688 this->list
[ dest
] = src_entry
;
690 mlt_playlist_get_clip_info( this, ¤t_info
, current
);
691 mlt_producer_seek( mlt_playlist_producer( this ), current_info
.start
+ position
);
692 mlt_playlist_virtual_refresh( this );
698 /** Repeat the specified clip n times.
701 int mlt_playlist_repeat_clip( mlt_playlist
this, int clip
, int repeat
)
703 int error
= repeat
< 1 || clip
< 0 || clip
>= this->count
;
706 playlist_entry
*entry
= this->list
[ clip
];
707 entry
->repeat
= repeat
;
708 mlt_playlist_virtual_refresh( this );
713 /** Resize the specified clip.
716 int mlt_playlist_resize_clip( mlt_playlist
this, int clip
, mlt_position in
, mlt_position out
)
718 int error
= clip
< 0 || clip
>= this->count
;
719 if ( error
== 0 && mlt_playlist_resize_mix( this, clip
, in
, out
) != 0 )
721 playlist_entry
*entry
= this->list
[ clip
];
722 mlt_producer producer
= entry
->producer
;
726 if ( out
<= -1 || out
>= mlt_producer_get_length( producer
) )
727 out
= mlt_producer_get_length( producer
) - 1;
736 mlt_producer_set_in_and_out( producer
, in
, out
);
741 /** Split a clip on the playlist at the given position.
744 int mlt_playlist_split( mlt_playlist
this, int clip
, mlt_position position
)
746 int error
= clip
< 0 || clip
>= this->count
;
749 playlist_entry
*entry
= this->list
[ clip
];
750 if ( position
> 0 && position
< entry
->frame_count
)
752 mlt_producer split
= NULL
;
753 int in
= entry
->frame_in
;
754 int out
= entry
->frame_out
;
755 mlt_events_block( mlt_playlist_properties( this ), this );
756 mlt_playlist_resize_clip( this, clip
, in
, in
+ position
);
757 split
= mlt_producer_cut( entry
->producer
, in
+ position
+ 1, out
);
758 mlt_playlist_insert( this, split
, clip
+ 1, 0, -1 );
759 mlt_events_unblock( mlt_playlist_properties( this ), this );
760 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
770 /** Join 1 or more consecutive clips.
773 int mlt_playlist_join( mlt_playlist
this, int clip
, int count
, int merge
)
775 int error
= clip
< 0 || ( clip
) >= this->count
;
779 mlt_playlist new_clip
= mlt_playlist_init( );
780 mlt_events_block( mlt_playlist_properties( this ), this );
781 if ( clip
+ count
>= this->count
)
782 count
= this->count
- clip
;
783 for ( i
= 0; i
<= count
; i
++ )
785 playlist_entry
*entry
= this->list
[ clip
];
786 mlt_playlist_append( new_clip
, entry
->producer
);
787 mlt_playlist_repeat_clip( new_clip
, i
, entry
->repeat
);
788 mlt_playlist_remove( this, clip
);
790 mlt_events_unblock( mlt_playlist_properties( this ), this );
791 mlt_playlist_insert( this, mlt_playlist_producer( new_clip
), clip
, 0, -1 );
792 mlt_playlist_close( new_clip
);
797 int mlt_playlist_mix( mlt_playlist
this, int clip
, int length
, mlt_transition transition
)
799 int error
= ( clip
< 0 || clip
+ 1 >= this->count
) && this->list
[ clip
]->mix_out
!= NULL
;
802 playlist_entry
*clip_a
= this->list
[ clip
];
803 playlist_entry
*clip_b
= this->list
[ clip
+ 1 ];
804 mlt_producer track_a
;
805 mlt_producer track_b
;
806 mlt_tractor tractor
= mlt_tractor_new( );
807 mlt_events_block( mlt_playlist_properties( this ), this );
809 track_a
= mlt_producer_cut( clip_a
->producer
, clip_a
->frame_out
- length
+ 1, clip_a
->frame_out
);
810 mlt_properties_set_int( mlt_producer_properties( track_a
), "cut", 1 );
811 track_b
= mlt_producer_cut( clip_b
->producer
, clip_b
->frame_in
, clip_b
->frame_in
+ length
- 1 );
812 mlt_properties_set_int( mlt_producer_properties( track_b
), "cut", 1 );
814 mlt_tractor_set_track( tractor
, track_a
, 0 );
815 mlt_tractor_set_track( tractor
, track_b
, 1 );
816 mlt_playlist_insert( this, mlt_tractor_producer( tractor
), clip
+ 1, -1, -1 );
817 mlt_properties_set_data( mlt_tractor_properties( tractor
), "mlt_mix", tractor
, 0, NULL
, NULL
);
819 if ( transition
!= NULL
)
821 mlt_field field
= mlt_tractor_field( tractor
);
822 mlt_field_plant_transition( field
, transition
, 0, 1 );
823 mlt_transition_set_in_and_out( transition
, 0, length
- 1 );
826 if ( clip_b
->frame_out
- clip_b
->frame_in
> length
)
827 mlt_playlist_resize_clip( this, clip
+ 2, clip_b
->frame_in
+ length
, clip_b
->frame_out
);
829 mlt_playlist_remove( this, clip
+ 2 );
831 if ( clip_a
->frame_out
- clip_a
->frame_in
> length
)
832 mlt_playlist_resize_clip( this, clip
, clip_a
->frame_in
, clip_a
->frame_out
- length
);
834 mlt_playlist_remove( this, clip
);
836 mlt_events_unblock( mlt_playlist_properties( this ), this );
837 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
838 mlt_producer_close( track_a
);
839 mlt_producer_close( track_b
);
840 mlt_tractor_close( tractor
);
845 static int mlt_playlist_unmix( mlt_playlist
this, int clip
)
847 int error
= ( clip
< 0 || clip
>= this->count
);
849 // Ensure that the clip request is actually a mix
852 mlt_producer producer
= this->list
[ clip
]->producer
;
853 mlt_properties properties
= mlt_producer_properties( producer
);
854 error
= !mlt_properties_get_int( properties
, "mlt_mix" );
859 playlist_entry
*mix
= this->list
[ clip
];
860 playlist_entry
*clip_a
= mix
->mix_in
;
861 playlist_entry
*clip_b
= mix
->mix_out
;
862 int length
= mix
->mix_in_length
;
863 mlt_events_block( mlt_playlist_properties( this ), this );
865 if ( clip_a
!= NULL
)
867 clip_a
->frame_out
+= length
;
868 clip_a
->frame_count
+= length
;
869 clip_a
->mix_out
= NULL
;
870 clip_a
->mix_out_length
= 0;
874 mlt_tractor tractor
= ( mlt_tractor
)mix
->producer
;
875 mlt_playlist playlist
= ( mlt_playlist
)mlt_tractor_get_track( tractor
, 0 );
876 mlt_producer producer
= playlist
->list
[ 0 ]->producer
;
877 mlt_playlist_insert( this, producer
, clip
, playlist
->list
[0]->frame_in
, playlist
->list
[0]->frame_out
);
881 if ( clip_b
!= NULL
)
883 clip_b
->frame_in
-= length
;
884 clip_b
->frame_count
+= length
;
885 clip_b
->mix_in
= NULL
;
886 clip_b
->mix_in_length
= 0;
890 mlt_tractor tractor
= ( mlt_tractor
)mix
->producer
;
891 mlt_playlist playlist
= ( mlt_playlist
)mlt_tractor_get_track( tractor
, 1 );
892 mlt_producer producer
= playlist
->list
[ 0 ]->producer
;
893 mlt_playlist_insert( this, producer
, clip
+ 1, playlist
->list
[0]->frame_in
, playlist
->list
[0]->frame_out
);
896 mlt_properties_set_int( mlt_producer_properties( mix
->producer
), "mlt_mix", 0 );
897 mlt_playlist_remove( this, clip
);
898 mlt_events_unblock( mlt_playlist_properties( this ), this );
899 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
904 static int mlt_playlist_resize_mix( mlt_playlist
this, int clip
, int in
, int out
)
906 int error
= ( clip
< 0 || clip
>= this->count
);
908 // Ensure that the clip request is actually a mix
911 mlt_producer producer
= this->list
[ clip
]->producer
;
912 mlt_properties properties
= mlt_producer_properties( producer
);
913 error
= !mlt_properties_get_int( properties
, "mlt_mix" );
918 playlist_entry
*mix
= this->list
[ clip
];
919 playlist_entry
*clip_a
= mix
->mix_in
;
920 playlist_entry
*clip_b
= mix
->mix_out
;
921 int length
= out
- in
+ 1;
922 int length_diff
= length
- mix
->mix_in_length
;
923 mlt_events_block( mlt_playlist_properties( this ), this );
925 if ( clip_a
!= NULL
)
927 clip_a
->frame_out
-= length_diff
;
928 clip_a
->frame_count
-= length_diff
;
929 clip_a
->mix_out_length
-= length_diff
;
932 if ( clip_b
!= NULL
)
934 clip_b
->frame_in
+= length_diff
;
935 clip_b
->frame_count
-= length_diff
;
936 clip_b
->mix_in_length
-= length_diff
;
940 mix
->frame_out
= length
- 1;
941 mix
->frame_count
= length
;
942 mix
->mix_in_length
= length
;
943 mix
->mix_out_length
= length
;
945 mlt_events_unblock( mlt_playlist_properties( this ), this );
946 mlt_events_fire( mlt_playlist_properties( this ), "producer-changed", NULL
);
951 /** Get the current frame.
954 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
)
956 // Get this mlt_playlist
957 mlt_playlist
this = producer
->child
;
959 // Get the real producer
960 mlt_service real
= mlt_playlist_virtual_seek( this );
963 mlt_service_get_frame( real
, frame
, index
);
965 // Check if we're at the end of the clip
966 mlt_properties properties
= mlt_frame_properties( *frame
);
967 if ( mlt_properties_get_int( properties
, "end_of_clip" ) )
968 mlt_playlist_virtual_set_out( this );
970 // Check for notifier and call with appropriate argument
971 mlt_properties playlist_properties
= mlt_producer_properties( producer
);
972 void ( *notifier
)( void * ) = mlt_properties_get_data( playlist_properties
, "notifier", NULL
);
973 if ( notifier
!= NULL
)
975 void *argument
= mlt_properties_get_data( playlist_properties
, "notifier_arg", NULL
);
976 notifier( argument
);
979 // Update position on the frame we're creating
980 mlt_frame_set_position( *frame
, mlt_producer_frame( producer
) );
982 // Position ourselves on the next frame
983 mlt_producer_prepare_next( producer
);
988 /** Close the playlist.
991 void mlt_playlist_close( mlt_playlist
this )
993 if ( this != NULL
&& mlt_properties_dec_ref( mlt_playlist_properties( this ) ) <= 0 )
996 this->parent
.close
= NULL
;
997 for ( i
= 0; i
< this->count
; i
++ )
999 mlt_event_close( this->list
[ i
]->event
);
1000 mlt_producer_close( this->list
[ i
]->producer
);
1001 free( this->list
[ i
] );
1003 mlt_producer_close( &this->blank
);
1004 mlt_producer_close( &this->parent
);