]> git.sesse.net Git - mlt/blob - src/mlt++/MltPlaylist.cpp
a13faf35a5e0e1c3b4934139c3818f8767352ef9
[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 using namespace Mlt;
26
27 ClipInfo::ClipInfo( ) :
28         clip( 0 ),
29         producer( NULL ),
30         cut( NULL ),
31         start( 0 ),
32         resource( NULL ),
33         frame_in( 0 ),
34         frame_out( 0 ),
35         frame_count( 0 ),
36         length( 0 ),
37         fps( 0 ),
38         repeat( 0 )
39 {
40 }
41
42 ClipInfo::ClipInfo( mlt_playlist_clip_info *info ) :
43         clip( info->clip ),
44         producer( new Producer( info->producer ) ),
45         cut( new Producer( info->cut ) ),
46         start( info->start ),
47         resource( info->resource? strdup( info->resource )  : 0 ),
48         frame_in( info->frame_in ),
49         frame_out( info->frame_out ),
50         frame_count( info->frame_count ),
51         length( info->length ),
52         fps( info->fps ),
53         repeat( info->repeat )
54 {
55 }
56
57 ClipInfo::~ClipInfo( )
58 {
59         delete producer;
60         delete cut;
61         free( resource );
62 }
63
64 void ClipInfo::update( mlt_playlist_clip_info *info )
65 {
66         delete producer;
67         delete cut;
68         free( resource );
69         clip = info->clip;
70         producer = new Producer( info->producer );
71         cut = new Producer( info->cut );
72         start = info->start;
73         resource = strdup( info->resource );
74         frame_in = info->frame_in;
75         frame_out = info->frame_out;
76         frame_count = info->frame_count;
77         length = info->length;
78         fps = info->fps;
79         repeat = info->repeat;
80 }
81
82 Playlist::Playlist( ) :
83         instance( NULL )
84 {
85         instance = mlt_playlist_init( );
86 }
87
88 Playlist::Playlist( Service &producer ) :
89         instance( NULL )
90 {
91         if ( producer.type( ) == playlist_type )
92         {
93                 instance = ( mlt_playlist )producer.get_service( );
94                 inc_ref( );
95         }
96 }
97
98 Playlist::Playlist( Playlist &playlist ) :
99         Mlt::Producer( playlist ),
100         instance( playlist.get_playlist( ) )
101 {
102         inc_ref( );
103 }
104
105 Playlist::Playlist( mlt_playlist playlist ) :
106         instance( playlist )
107 {
108         inc_ref( );
109 }
110
111 Playlist::~Playlist( )
112 {
113         mlt_playlist_close( instance );
114 }
115
116 mlt_playlist Playlist::get_playlist( )
117 {
118         return instance;
119 }
120
121 mlt_producer Playlist::get_producer( )
122 {
123         return mlt_playlist_producer( get_playlist( ) );
124 }
125
126 int Playlist::count( )
127 {
128         return mlt_playlist_count( get_playlist( ) );
129 }
130
131 int Playlist::clear( )
132 {
133         return mlt_playlist_clear( get_playlist( ) );
134 }
135
136 int Playlist::append( Producer &producer, int in, int out )
137 {
138         return mlt_playlist_append_io( get_playlist( ), producer.get_producer( ), in, out );
139 }
140
141 int Playlist::blank( int length )
142 {
143         return mlt_playlist_blank( get_playlist( ), length );
144 }
145
146 int Playlist::clip( mlt_whence whence, int index )
147 {
148         return mlt_playlist_clip( get_playlist( ), whence, index );
149 }
150
151 int Playlist::current_clip( )
152 {
153         return mlt_playlist_current_clip( get_playlist( ) );
154 }
155
156 Producer *Playlist::current( )
157 {
158         return new Producer( mlt_playlist_current( get_playlist( ) ) );
159 }
160
161 ClipInfo *Playlist::clip_info( int index, ClipInfo *info )
162 {
163         mlt_playlist_clip_info clip_info;
164         if ( mlt_playlist_get_clip_info( get_playlist( ), &clip_info, index ) )
165                 return NULL;
166         if ( info == NULL )
167                 return new ClipInfo( &clip_info );
168         info->update( &clip_info );
169         return info;
170 }
171
172 void Playlist::delete_clip_info( ClipInfo *info )
173 {
174         delete info;
175 }
176
177 int Playlist::insert( Producer &producer, int where, int in, int out )
178 {
179         return mlt_playlist_insert( get_playlist( ), producer.get_producer( ), where, in, out );
180 }
181
182 int Playlist::remove( int where )
183 {
184         return mlt_playlist_remove( get_playlist( ), where );
185 }
186
187 int Playlist::move( int from, int to )
188 {
189         return mlt_playlist_move( get_playlist( ), from, to );
190 }
191
192 int Playlist::resize_clip( int clip, int in, int out )
193 {
194         return mlt_playlist_resize_clip( get_playlist( ), clip, in, out );
195 }
196
197 int Playlist::split( int clip, int position )
198 {
199         return mlt_playlist_split( get_playlist( ), clip, position );
200 }
201
202 int Playlist::split_at( int position, bool left )
203 {
204         return mlt_playlist_split_at( get_playlist( ), position, left );
205 }
206
207 int Playlist::join( int clip, int count, int merge )
208 {
209         return mlt_playlist_join( get_playlist( ), clip, count, merge );
210 }
211
212 int Playlist::mix( int clip, int length, Transition *transition )
213 {
214         return mlt_playlist_mix( get_playlist( ), clip, length, transition == NULL ? NULL : transition->get_transition( ) );
215 }
216
217 int Playlist::mix_add( int clip, Transition *transition )
218 {
219         return mlt_playlist_mix_add( get_playlist( ), clip, transition == NULL ? NULL : transition->get_transition( ) );
220 }
221
222 int Playlist::repeat( int clip, int count )
223 {
224         return mlt_playlist_repeat_clip( get_playlist( ), clip, count );
225 }
226
227 Producer *Playlist::get_clip( int clip )
228 {
229         mlt_producer producer = mlt_playlist_get_clip( get_playlist( ), clip );
230         return producer != NULL ? new Producer( producer ) : NULL;
231 }
232
233 Producer *Playlist::get_clip_at( int position )
234 {
235         mlt_producer producer = mlt_playlist_get_clip_at( get_playlist( ), position );
236         return producer != NULL ? new Producer( producer ) : NULL;
237 }
238
239 int Playlist::get_clip_index_at( int position )
240 {
241         return mlt_playlist_get_clip_index_at( get_playlist( ), position );
242 }
243
244 bool Playlist::is_mix( int clip )
245 {
246         return mlt_playlist_clip_is_mix( get_playlist( ), clip ) != 0;
247 }
248
249 bool Playlist::is_blank( int clip )
250 {
251         return mlt_playlist_is_blank( get_playlist( ), clip ) != 0;
252 }
253
254 bool Playlist::is_blank_at( int position )
255 {
256         return mlt_playlist_is_blank_at( get_playlist( ), position ) != 0;
257 }
258
259 Producer *Playlist::replace_with_blank( int clip )
260 {
261         mlt_producer producer = mlt_playlist_replace_with_blank( get_playlist( ), clip );
262         Producer *object = producer != NULL ? new Producer( producer ) : NULL;
263         mlt_producer_close( producer );
264         return object;
265 }
266
267 void Playlist::consolidate_blanks( int keep_length )
268 {
269         return mlt_playlist_consolidate_blanks( get_playlist( ), keep_length );
270 }
271
272 void Playlist::insert_blank( int clip, int length )
273 {
274         mlt_playlist_insert_blank( get_playlist( ), clip, length );
275 }
276
277 void Playlist::pad_blanks( int position, int length, int find )
278 {
279         mlt_playlist_pad_blanks( get_playlist( ), position, length, find );
280 }
281
282 int Playlist::insert_at( int position, Producer *producer, int mode )
283 {
284         return mlt_playlist_insert_at( get_playlist( ), position, producer->get_producer( ), mode );
285 }
286
287 int Playlist::insert_at( int position, Producer &producer, int mode )
288 {
289         return mlt_playlist_insert_at( get_playlist( ), position, producer.get_producer( ), mode );
290 }
291
292 int Playlist::clip_start( int clip )
293 {
294         return mlt_playlist_clip_start( get_playlist( ), clip );
295 }
296
297 int Playlist::blanks_from( int clip, int bounded )
298 {
299         return mlt_playlist_blanks_from( get_playlist( ), clip, bounded );
300 }
301
302 int Playlist::clip_length( int clip )
303 {
304         return mlt_playlist_clip_length( get_playlist( ), clip );
305 }
306
307 int Playlist::remove_region( int position, int length )
308 {
309         return mlt_playlist_remove_region( get_playlist( ), position, length );
310 }
311
312 int Playlist::move_region( int position, int length, int new_position )
313 {
314         return mlt_playlist_move_region( get_playlist( ), position, length, new_position );
315 }
316