]> git.sesse.net Git - mlt/blob - src/mlt++/MltProperties.cpp
Add mlt_color and mlt_properties_get_color().
[mlt] / src / mlt++ / MltProperties.cpp
1 /**
2  * MltProperties.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 "MltProperties.h"
22 #include "MltEvent.h"
23 using namespace Mlt;
24
25 Properties::Properties( ) :
26         instance( NULL )
27 {
28         instance = mlt_properties_new( );
29 }
30
31 Properties::Properties( bool /*dummy*/ ) :
32         instance( NULL )
33 {
34 }
35
36 Properties::Properties( Properties &properties ) :
37         instance( properties.get_properties( ) )
38 {
39         inc_ref( );
40 }
41
42 Properties::Properties( mlt_properties properties ) :
43         instance( properties )
44 {
45         inc_ref( );
46 }
47
48 Properties::Properties( void *properties ) :
49         instance( mlt_properties( properties ) )
50 {
51         inc_ref( );
52 }
53
54 Properties::Properties( const char *file ) :
55         instance( NULL )
56 {
57         instance = mlt_properties_load( file );
58 }
59
60 Properties::~Properties( )
61 {
62         mlt_properties_close( instance );
63 }
64
65 mlt_properties Properties::get_properties( )
66 {
67         return instance;
68 }
69
70 int Properties::inc_ref( )
71 {
72         return mlt_properties_inc_ref( get_properties( ) );
73 }
74
75 int Properties::dec_ref( )
76 {
77         return mlt_properties_dec_ref( get_properties( ) );
78 }
79
80 int Properties::ref_count( )
81 {
82         return mlt_properties_ref_count( get_properties( ) );
83 }
84
85 void Properties::lock( )
86 {
87         mlt_properties_lock( get_properties( ) );
88 }
89
90 void Properties::unlock( )
91 {
92         mlt_properties_unlock( get_properties( ) );
93 }
94
95 void Properties::block( void *object )
96 {
97         mlt_events_block( get_properties( ), object != NULL ? object : get_properties( ) );
98 }
99
100 void Properties::unblock( void *object )
101 {
102         mlt_events_unblock( get_properties( ), object != NULL ? object : get_properties( ) );
103 }
104
105 void Properties::fire_event( const char *event )
106 {
107         mlt_events_fire( get_properties( ), event, NULL );
108 }
109
110 bool Properties::is_valid( )
111 {
112         return get_properties( ) != NULL;
113 }
114
115 int Properties::count( )
116 {
117         return mlt_properties_count( get_properties( ) );
118 }
119
120 char *Properties::get( const char *name )
121 {
122         return mlt_properties_get( get_properties( ), name );
123 }
124
125 int Properties::get_int( const char *name )
126 {
127         return mlt_properties_get_int( get_properties( ), name );
128 }
129
130 int64_t Properties::get_int64( const char *name )
131 {
132         return mlt_properties_get_int64( get_properties( ), name );
133 }
134
135 double Properties::get_double( const char *name )
136 {
137         return mlt_properties_get_double( get_properties( ), name );
138 }
139
140 void *Properties::get_data( const char *name, int &size )
141 {
142         return mlt_properties_get_data( get_properties( ), name, &size );
143 }
144
145 void *Properties::get_data( const char *name )
146 {
147         return mlt_properties_get_data( get_properties( ), name, NULL );
148 }
149
150 int Properties::set( const char *name, const char *value )
151 {
152         return mlt_properties_set( get_properties( ), name, value );
153 }
154
155 int Properties::set( const char *name, int value )
156 {
157         return mlt_properties_set_int( get_properties( ), name, value );
158 }
159
160 int Properties::set( const char *name, int64_t value )
161 {
162         return mlt_properties_set_int64( get_properties( ), name, value );
163 }
164
165 int Properties::set( const char *name, double value )
166 {
167         return mlt_properties_set_double( get_properties( ), name, value );
168 }
169
170 int Properties::set( const char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
171 {
172         return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
173 }
174
175 void Properties::pass_property( Properties &that, const char *name )
176 {
177         return mlt_properties_pass_property( get_properties( ), that.get_properties( ), name );
178 }
179
180 int Properties::pass_values( Properties &that, const char *prefix )
181 {
182         return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
183 }
184
185 int Properties::pass_list( Properties &that, const char *list )
186 {
187         return mlt_properties_pass_list( get_properties( ), that.get_properties( ), list );
188 }
189
190 int Properties::parse( const char *namevalue )
191 {
192         return mlt_properties_parse( get_properties( ), namevalue );
193 }
194
195 char *Properties::get_name( int index )
196 {
197         return mlt_properties_get_name( get_properties( ), index );
198 }
199
200 char *Properties::get( int index )
201 {
202         return mlt_properties_get_value( get_properties( ), index );
203 }
204
205 void *Properties::get_data( int index, int &size )
206 {
207         return mlt_properties_get_data_at( get_properties( ), index, &size );
208 }
209
210 void Properties::mirror( Properties &that )
211 {
212         mlt_properties_mirror( get_properties( ), that.get_properties( ) );
213 }
214
215 int Properties::inherit( Properties &that )
216 {
217         return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
218 }
219
220 int Properties::rename( const char *source, const char *dest )
221 {
222         return mlt_properties_rename( get_properties( ), source, dest );
223 }
224
225 void Properties::dump( FILE *output )
226 {
227         mlt_properties_dump( get_properties( ), output );
228 }
229
230 void Properties::debug( const char *title, FILE *output )
231 {
232         mlt_properties_debug( get_properties( ), title, output );
233 }
234
235 void Properties::load( const char *file )
236 {
237         mlt_properties properties = mlt_properties_load( file );
238         if ( properties != NULL )
239                 mlt_properties_pass( get_properties( ), properties, "" );
240         mlt_properties_close( properties );
241 }
242
243 int Properties::save( const char *file )
244 {
245 #ifdef WIN32
246         return mlt_properties_save( get_properties( ), file );
247 #else
248         int error = 0;
249         FILE *f = fopen( file, "w" );
250         if ( f != NULL )
251         {
252                 dump( f );
253                 fclose( f );
254         }
255         else
256         {
257                 error = 1;
258         }
259         return error;
260 #endif
261 }
262
263 #if defined( __DARWIN__ ) && GCC_VERSION < 40000
264
265 Event *Properties::listen( const char *id, void *object, void (*listener)( ... ) )
266 {
267         mlt_event event = mlt_events_listen( get_properties( ), object, id, ( mlt_listener )listener );
268         return new Event( event );
269 }
270
271 #else
272
273 Event *Properties::listen( const char *id, void *object, mlt_listener listener )
274 {
275         mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
276         return new Event( event );
277 }
278
279 #endif
280
281 Event *Properties::setup_wait_for( const char *id )
282 {
283         return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
284 }
285
286 void Properties::delete_event( Event *event )
287 {
288         delete event;
289 }
290
291 void Properties::wait_for( Event *event, bool destroy )
292 {
293         mlt_events_wait_for( get_properties( ), event->get_event( ) );
294         if ( destroy )
295                 mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
296 }
297
298 void Properties::wait_for( const char *id )
299 {
300         Event *event = setup_wait_for( id );
301         wait_for( event );
302         delete event;
303 }
304
305 bool Properties::is_sequence( )
306 {
307         return mlt_properties_is_sequence( get_properties( ) );
308 }
309
310 Properties *Properties::parse_yaml( const char *file )
311 {
312         return new Properties( mlt_properties_parse_yaml( file ) );
313 }
314
315 char *Properties::serialise_yaml( )
316 {
317         return mlt_properties_serialise_yaml( get_properties( ) );
318 }
319
320 int Properties::preset( const char *name )
321 {
322         return mlt_properties_preset( get_properties(), name );
323 }
324
325 int Properties::set_lcnumeric( const char *locale )
326 {
327         return mlt_properties_set_lcnumeric( get_properties(), locale );
328 }
329
330 const char *Properties::get_lcnumeric( )
331 {
332         return mlt_properties_get_lcnumeric( get_properties() );
333 }
334
335 char *Properties::get_time( const char *name, mlt_time_format format )
336 {
337         return mlt_properties_get_time( get_properties(), name, format );
338 }
339
340 mlt_color Properties::get_color( const char *name )
341 {
342         return mlt_properties_get_color( get_properties(), name );
343 }
344
345 char *Properties::anim_get( const char *name, int position, int length )
346 {
347         return mlt_properties_anim_get( get_properties(), name, position, length );
348 }
349
350 int Properties::anim_set( const char *name, const char *value, int position, int length )
351 {
352         return mlt_properties_anim_set( get_properties(), name, value, position, length );
353 }
354
355 int Properties::anim_get_int( const char *name, int position, int length )
356 {
357         return mlt_properties_anim_get_int( get_properties(), name, position, length );
358 }
359
360 int Properties::anim_set( const char *name, int value, int position, int length, mlt_keyframe_type keyframe_type )
361 {
362         return mlt_properties_anim_set_int( get_properties(), name, value, keyframe_type, position, length );
363 }
364
365 double Properties::anim_get_double(const char *name, int position, int length)
366 {
367         return mlt_properties_anim_get_double( get_properties(), name, position, length );
368 }
369
370 int Properties::anim_set(const char *name, double value, int position, int length, mlt_keyframe_type keyframe_type)
371 {
372         return mlt_properties_anim_set_double( get_properties(), name, value, keyframe_type, position, length );
373 }
374
375 int Properties::set( const char *name, mlt_rect value )
376 {
377         return mlt_properties_set_rect( get_properties(), name, value );
378 }
379
380 int Properties::set( const char *name, double x, double y, double w, double h, double opacity )
381 {
382         mlt_rect value = { x, y, w, h, opacity };
383         return mlt_properties_set_rect( get_properties(), name, value );
384 }
385
386 mlt_rect Properties::get_rect( const char *name )
387 {
388         return mlt_properties_get_rect( get_properties(), name );
389 }
390
391 int Properties::anim_set(const char *name, mlt_rect value, int position, int length, mlt_keyframe_type keyframe_type)
392 {
393         return mlt_properties_anim_set_rect( get_properties(), name, value, keyframe_type, position, length );
394 }
395
396 mlt_rect Properties::anim_get_rect(const char *name, int position, int length)
397 {
398         return mlt_properties_anim_get_rect( get_properties(), name, position, length );
399 }