]> git.sesse.net Git - mlt/blob - src/mlt++/MltPlaylist.cpp
57c2c6acb54939fde219758d9364733c31f6e730
[mlt] / src / mlt++ / MltPlaylist.cpp
1 /**
2  * MltPlaylist.cpp - MLT Wrapper
3  * Copyright (C) 2004-2005 Charles Yates
4  * Author: Charles Yates <charles.yates@pandora.be>
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
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
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
58 ClipInfo::~ClipInfo( )
59 {
60         delete producer;
61         delete cut;
62         free( resource );
63 }
64
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 = strdup( info->resource );
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
83 Playlist::Playlist( ) :
84         instance( NULL )
85 {
86         instance = mlt_playlist_init( );
87 }
88
89 Playlist::Playlist( Profile& profile ) :
90         instance( NULL )
91 {
92         instance = mlt_playlist_new( profile.get_profile() );
93 }
94
95 Playlist::Playlist( Service &producer ) :
96         instance( NULL )
97 {
98         if ( producer.type( ) == playlist_type )
99         {
100                 instance = ( mlt_playlist )producer.get_service( );
101                 inc_ref( );
102         }
103 }
104
105 Playlist::Playlist( Playlist &playlist ) :
106         Mlt::Producer( playlist ),
107         instance( playlist.get_playlist( ) )
108 {
109         inc_ref( );
110 }
111
112 Playlist::Playlist( mlt_playlist playlist ) :
113         instance( playlist )
114 {
115         inc_ref( );
116 }
117
118 Playlist::~Playlist( )
119 {
120         mlt_playlist_close( instance );
121 }
122
123 mlt_playlist Playlist::get_playlist( )
124 {
125         return instance;
126 }
127
128 mlt_producer Playlist::get_producer( )
129 {
130         return mlt_playlist_producer( get_playlist( ) );
131 }
132
133 int Playlist::count( )
134 {
135         return mlt_playlist_count( get_playlist( ) );
136 }
137
138 int Playlist::clear( )
139 {
140         return mlt_playlist_clear( get_playlist( ) );
141 }
142
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
148 int Playlist::blank( int out )
149 {
150         return mlt_playlist_blank( get_playlist( ), out );
151 }
152
153 int Playlist::blank( const char *length )
154 {
155         return mlt_playlist_blank_time( get_playlist( ), length );
156 }
157
158 int Playlist::clip( mlt_whence whence, int index )
159 {
160         return mlt_playlist_clip( get_playlist( ), whence, index );
161 }
162
163 int Playlist::current_clip( )
164 {
165         return mlt_playlist_current_clip( get_playlist( ) );
166 }
167
168 Producer *Playlist::current( )
169 {
170         return new Producer( mlt_playlist_current( get_playlist( ) ) );
171 }
172
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
184 void Playlist::delete_clip_info( ClipInfo *info )
185 {
186         delete info;
187 }
188
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
194 int Playlist::remove( int where )
195 {
196         return mlt_playlist_remove( get_playlist( ), where );
197 }
198
199 int Playlist::move( int from, int to )
200 {
201         return mlt_playlist_move( get_playlist( ), from, to );
202 }
203
204 int Playlist::resize_clip( int clip, int in, int out )
205 {
206         return mlt_playlist_resize_clip( get_playlist( ), clip, in, out );
207 }
208
209 int Playlist::split( int clip, int position )
210 {
211         return mlt_playlist_split( get_playlist( ), clip, position );
212 }
213
214 int Playlist::split_at( int position, bool left )
215 {
216         return mlt_playlist_split_at( get_playlist( ), position, left );
217 }
218
219 int Playlist::join( int clip, int count, int merge )
220 {
221         return mlt_playlist_join( get_playlist( ), clip, count, merge );
222 }
223
224 int Playlist::mix( int clip, int length, Transition *transition )
225 {
226         return mlt_playlist_mix( get_playlist( ), clip, length, transition == NULL ? NULL : transition->get_transition( ) );
227 }
228
229 int Playlist::mix_add( int clip, Transition *transition )
230 {
231         return mlt_playlist_mix_add( get_playlist( ), clip, transition == NULL ? NULL : transition->get_transition( ) );
232 }
233
234 int Playlist::repeat( int clip, int count )
235 {
236         return mlt_playlist_repeat_clip( get_playlist( ), clip, count );
237 }
238
239 Producer *Playlist::get_clip( int clip )
240 {
241         mlt_producer producer = mlt_playlist_get_clip( get_playlist( ), clip );
242         return producer != NULL ? new Producer( producer ) : NULL;
243 }
244
245 Producer *Playlist::get_clip_at( int position )
246 {
247         mlt_producer producer = mlt_playlist_get_clip_at( get_playlist( ), position );
248         return producer != NULL ? new Producer( producer ) : NULL;
249 }
250
251 int Playlist::get_clip_index_at( int position )
252 {
253         return mlt_playlist_get_clip_index_at( get_playlist( ), position );
254 }
255
256 bool Playlist::is_mix( int clip )
257 {
258         return mlt_playlist_clip_is_mix( get_playlist( ), clip ) != 0;
259 }
260
261 bool Playlist::is_blank( int clip )
262 {
263         return mlt_playlist_is_blank( get_playlist( ), clip ) != 0;
264 }
265
266 bool Playlist::is_blank_at( int position )
267 {
268         return mlt_playlist_is_blank_at( get_playlist( ), position ) != 0;
269 }
270
271 Producer *Playlist::replace_with_blank( int clip )
272 {
273         mlt_producer producer = mlt_playlist_replace_with_blank( get_playlist( ), clip );
274         Producer *object = producer != NULL ? new Producer( producer ) : NULL;
275         mlt_producer_close( producer );
276         return object;
277 }
278
279 void Playlist::consolidate_blanks( int keep_length )
280 {
281         return mlt_playlist_consolidate_blanks( get_playlist( ), keep_length );
282 }
283
284 void Playlist::insert_blank(int clip, int out )
285 {
286         mlt_playlist_insert_blank( get_playlist( ), clip, out );
287 }
288
289 void Playlist::pad_blanks( int position, int length, int find )
290 {
291         mlt_playlist_pad_blanks( get_playlist( ), position, length, find );
292 }
293
294 int Playlist::insert_at( int position, Producer *producer, int mode )
295 {
296         return mlt_playlist_insert_at( get_playlist( ), position, producer->get_producer( ), mode );
297 }
298
299 int Playlist::insert_at( int position, Producer &producer, int mode )
300 {
301         return mlt_playlist_insert_at( get_playlist( ), position, producer.get_producer( ), mode );
302 }
303
304 int Playlist::clip_start( int clip )
305 {
306         return mlt_playlist_clip_start( get_playlist( ), clip );
307 }
308
309 int Playlist::blanks_from( int clip, int bounded )
310 {
311         return mlt_playlist_blanks_from( get_playlist( ), clip, bounded );
312 }
313
314 int Playlist::clip_length( int clip )
315 {
316         return mlt_playlist_clip_length( get_playlist( ), clip );
317 }
318
319 int Playlist::remove_region( int position, int length )
320 {
321         return mlt_playlist_remove_region( get_playlist( ), position, length );
322 }
323
324 int Playlist::move_region( int position, int length, int new_position )
325 {
326         return mlt_playlist_move_region( get_playlist( ), position, length, new_position );
327 }
328