1 /**
2  * MltPlaylist.cpp - MLT Wrapper
3  * Copyright (C) 2004-2015 Meltytech, LLC
4  * Author: Charles Yates <charles.yates@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 #include <string.h>
22 #include <stdlib.h>
23 #include "MltPlaylist.h"
24 #include "MltTransition.h"
25 #include "MltProfile.h"
26 using namespace Mlt;
27 
ClipInfo()28 ClipInfo::ClipInfo( ) :
29 	clip( 0 ),
30 	producer( NULL ),
31 	cut( NULL ),
32 	start( 0 ),
33 	resource( NULL ),
34 	frame_in( 0 ),
35 	frame_out( 0 ),
36 	frame_count( 0 ),
37 	length( 0 ),
38 	fps( 0 ),
39 	repeat( 0 )
40 {
41 }
42 
ClipInfo(mlt_playlist_clip_info * info)43 ClipInfo::ClipInfo( mlt_playlist_clip_info *info ) :
44 	clip( info->clip ),
45 	producer( new Producer( info->producer ) ),
46 	cut( new Producer( info->cut ) ),
47 	start( info->start ),
48 	resource( info->resource? strdup( info->resource )  : 0 ),
49 	frame_in( info->frame_in ),
50 	frame_out( info->frame_out ),
51 	frame_count( info->frame_count ),
52 	length( info->length ),
53 	fps( info->fps ),
54 	repeat( info->repeat )
55 {
56 }
57 
~ClipInfo()58 ClipInfo::~ClipInfo( )
59 {
60 	delete producer;
61 	delete cut;
62 	free( resource );
63 }
64 
update(mlt_playlist_clip_info * info)65 void ClipInfo::update( mlt_playlist_clip_info *info )
66 {
67 	delete producer;
68 	delete cut;
69 	free( resource );
70 	clip = info->clip;
71 	producer = new Producer( info->producer );
72 	cut = new Producer( info->cut );
73 	start = info->start;
74 	resource = info->resource ? strdup( info->resource ) : 0;
75 	frame_in = info->frame_in;
76 	frame_out = info->frame_out;
77 	frame_count = info->frame_count;
78 	length = info->length;
79 	fps = info->fps;
80 	repeat = info->repeat;
81 }
82 
Playlist()83 Playlist::Playlist( ) :
84 	instance( NULL )
85 {
86 	instance = mlt_playlist_init( );
87 }
88 
Playlist(Profile & profile)89 Playlist::Playlist( Profile& profile ) :
90 	instance( NULL )
91 {
92 	instance = mlt_playlist_new( profile.get_profile() );
93 }
94 
Playlist(Service & producer)95 Playlist::Playlist( Service &producer ) :
96 	instance( NULL )
97 {
98 	if ( producer.type( ) == mlt_service_playlist_type )
99 	{
100 		instance = ( mlt_playlist )producer.get_service( );
101 		inc_ref( );
102 	}
103 }
104 
Playlist(Playlist & playlist)105 Playlist::Playlist( Playlist &playlist ) :
106 	Mlt::Producer( playlist ),
107 	instance( playlist.get_playlist( ) )
108 {
109 	inc_ref( );
110 }
111 
Playlist(mlt_playlist playlist)112 Playlist::Playlist( mlt_playlist playlist ) :
113 	instance( playlist )
114 {
115 	inc_ref( );
116 }
117 
~Playlist()118 Playlist::~Playlist( )
119 {
120 	mlt_playlist_close( instance );
121 }
122 
get_playlist()123 mlt_playlist Playlist::get_playlist( )
124 {
125 	return instance;
126 }
127 
get_producer()128 mlt_producer Playlist::get_producer( )
129 {
130 	return mlt_playlist_producer( get_playlist( ) );
131 }
132 
count()133 int Playlist::count( )
134 {
135 	return mlt_playlist_count( get_playlist( ) );
136 }
137 
clear()138 int Playlist::clear( )
139 {
140 	return mlt_playlist_clear( get_playlist( ) );
141 }
142 
append(Producer & producer,int in,int out)143 int Playlist::append( Producer &producer, int in, int out )
144 {
145 	return mlt_playlist_append_io( get_playlist( ), producer.get_producer( ), in, out );
146 }
147 
blank(int out)148 int Playlist::blank( int out )
149 {
150 	return mlt_playlist_blank( get_playlist( ), out );
151 }
152 
blank(const char * length)153 int Playlist::blank( const char *length )
154 {
155 	return mlt_playlist_blank_time( get_playlist( ), length );
156 }
157 
clip(mlt_whence whence,int index)158 int Playlist::clip( mlt_whence whence, int index )
159 {
160 	return mlt_playlist_clip( get_playlist( ), whence, index );
161 }
162 
current_clip()163 int Playlist::current_clip( )
164 {
165 	return mlt_playlist_current_clip( get_playlist( ) );
166 }
167 
current()168 Producer *Playlist::current( )
169 {
170 	return new Producer( mlt_playlist_current( get_playlist( ) ) );
171 }
172 
clip_info(int index,ClipInfo * info)173 ClipInfo *Playlist::clip_info( int index, ClipInfo *info )
174 {
175 	mlt_playlist_clip_info clip_info;
176 	if ( mlt_playlist_get_clip_info( get_playlist( ), &clip_info, index ) )
177 		return NULL;
178 	if ( info == NULL )
179 		return new ClipInfo( &clip_info );
180 	info->update( &clip_info );
181 	return info;
182 }
183 
delete_clip_info(ClipInfo * info)184 void Playlist::delete_clip_info( ClipInfo *info )
185 {
186 	delete info;
187 }
188 
insert(Producer & producer,int where,int in,int out)189 int Playlist::insert( Producer &producer, int where, int in, int out )
190 {
191 	return mlt_playlist_insert( get_playlist( ), producer.get_producer( ), where, in, out );
192 }
193 
remove(int where)194 int Playlist::remove( int where )
195 {
196 	return mlt_playlist_remove( get_playlist( ), where );
197 }
198 
move(int from,int to)199 int Playlist::move( int from, int to )
200 {
201 	return mlt_playlist_move( get_playlist( ), from, to );
202 }
203 
reorder(const int * indices)204 int Playlist::reorder( const int *indices )
205 {
206 	return mlt_playlist_reorder( get_playlist( ), indices );
207 }
208 
resize_clip(int clip,int in,int out)209 int Playlist::resize_clip( int clip, int in, int out )
210 {
211 	return mlt_playlist_resize_clip( get_playlist( ), clip, in, out );
212 }
213 
split(int clip,int position)214 int Playlist::split( int clip, int position )
215 {
216 	return mlt_playlist_split( get_playlist( ), clip, position );
217 }
218 
split_at(int position,bool left)219 int Playlist::split_at( int position, bool left )
220 {
221 	return mlt_playlist_split_at( get_playlist( ), position, left );
222 }
223 
join(int clip,int count,int merge)224 int Playlist::join( int clip, int count, int merge )
225 {
226 	return mlt_playlist_join( get_playlist( ), clip, count, merge );
227 }
228 
mix(int clip,int length,Transition * transition)229 int Playlist::mix( int clip, int length, Transition *transition )
230 {
231 	return mlt_playlist_mix( get_playlist( ), clip, length, transition == NULL ? NULL : transition->get_transition( ) );
232 }
233 
mix_in(int clip,int length)234 int Playlist::mix_in(int clip, int length)
235 {
236 	return mlt_playlist_mix_in( get_playlist( ), clip, length );
237 }
238 
mix_out(int clip,int length)239 int Playlist::mix_out(int clip, int length)
240 {
241 	return mlt_playlist_mix_out( get_playlist( ), clip, length );
242 }
243 
mix_add(int clip,Transition * transition)244 int Playlist::mix_add( int clip, Transition *transition )
245 {
246 	return mlt_playlist_mix_add( get_playlist( ), clip, transition == NULL ? NULL : transition->get_transition( ) );
247 }
248 
repeat(int clip,int count)249 int Playlist::repeat( int clip, int count )
250 {
251 	return mlt_playlist_repeat_clip( get_playlist( ), clip, count );
252 }
253 
get_clip(int clip)254 Producer *Playlist::get_clip( int clip )
255 {
256 	mlt_producer producer = mlt_playlist_get_clip( get_playlist( ), clip );
257 	return producer != NULL ? new Producer( producer ) : NULL;
258 }
259 
get_clip_at(int position)260 Producer *Playlist::get_clip_at( int position )
261 {
262 	mlt_producer producer = mlt_playlist_get_clip_at( get_playlist( ), position );
263 	return producer != NULL ? new Producer( producer ) : NULL;
264 }
265 
get_clip_index_at(int position)266 int Playlist::get_clip_index_at( int position )
267 {
268 	return mlt_playlist_get_clip_index_at( get_playlist( ), position );
269 }
270 
is_mix(int clip)271 bool Playlist::is_mix( int clip )
272 {
273 	return mlt_playlist_clip_is_mix( get_playlist( ), clip ) != 0;
274 }
275 
is_blank(int clip)276 bool Playlist::is_blank( int clip )
277 {
278 	return mlt_playlist_is_blank( get_playlist( ), clip ) != 0;
279 }
280 
is_blank_at(int position)281 bool Playlist::is_blank_at( int position )
282 {
283 	return mlt_playlist_is_blank_at( get_playlist( ), position ) != 0;
284 }
285 
replace_with_blank(int clip)286 Producer *Playlist::replace_with_blank( int clip )
287 {
288 	mlt_producer producer = mlt_playlist_replace_with_blank( get_playlist( ), clip );
289 	Producer *object = producer != NULL ? new Producer( producer ) : NULL;
290 	mlt_producer_close( producer );
291 	return object;
292 }
293 
consolidate_blanks(int keep_length)294 void Playlist::consolidate_blanks( int keep_length )
295 {
296 	return mlt_playlist_consolidate_blanks( get_playlist( ), keep_length );
297 }
298 
insert_blank(int clip,int out)299 void Playlist::insert_blank(int clip, int out )
300 {
301 	mlt_playlist_insert_blank( get_playlist( ), clip, out );
302 }
303 
pad_blanks(int position,int length,int find)304 void Playlist::pad_blanks( int position, int length, int find )
305 {
306 	mlt_playlist_pad_blanks( get_playlist( ), position, length, find );
307 }
308 
insert_at(int position,Producer * producer,int mode)309 int Playlist::insert_at( int position, Producer *producer, int mode )
310 {
311 	return mlt_playlist_insert_at( get_playlist( ), position, producer->get_producer( ), mode );
312 }
313 
insert_at(int position,Producer & producer,int mode)314 int Playlist::insert_at( int position, Producer &producer, int mode )
315 {
316 	return mlt_playlist_insert_at( get_playlist( ), position, producer.get_producer( ), mode );
317 }
318 
clip_start(int clip)319 int Playlist::clip_start( int clip )
320 {
321 	return mlt_playlist_clip_start( get_playlist( ), clip );
322 }
323 
blanks_from(int clip,int bounded)324 int Playlist::blanks_from( int clip, int bounded )
325 {
326 	return mlt_playlist_blanks_from( get_playlist( ), clip, bounded );
327 }
328 
clip_length(int clip)329 int Playlist::clip_length( int clip )
330 {
331 	return mlt_playlist_clip_length( get_playlist( ), clip );
332 }
333 
remove_region(int position,int length)334 int Playlist::remove_region( int position, int length )
335 {
336 	return mlt_playlist_remove_region( get_playlist( ), position, length );
337 }
338