1 /**
2 * MltProperties.cpp - MLT Wrapper
3 * Copyright (C) 2004-2021 Meltytech, LLC
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "MltProperties.h"
21 #include "MltEvent.h"
22 #include "MltAnimation.h"
23 using namespace Mlt;
24
Properties()25 Properties::Properties( ) :
26 instance( NULL )
27 {
28 instance = mlt_properties_new( );
29 }
30
Properties(bool)31 Properties::Properties( bool /*dummy*/ ) :
32 instance( NULL )
33 {
34 }
35
Properties(Properties & properties)36 Properties::Properties( Properties &properties ) :
37 instance( properties.get_properties( ) )
38 {
39 inc_ref( );
40 }
41
Properties(const Properties & properties)42 Properties::Properties( const Properties &properties )
43 : Properties(const_cast<Properties&>(properties))
44 {
45 }
46
Properties(mlt_properties properties)47 Properties::Properties( mlt_properties properties ) :
48 instance( properties )
49 {
50 inc_ref( );
51 }
52
Properties(void * properties)53 Properties::Properties( void *properties ) :
54 instance( mlt_properties( properties ) )
55 {
56 inc_ref( );
57 }
58
Properties(const char * file)59 Properties::Properties( const char *file ) :
60 instance( NULL )
61 {
62 instance = mlt_properties_load( file );
63 }
64
~Properties()65 Properties::~Properties( )
66 {
67 mlt_properties_close( instance );
68 }
69
operator =(const Properties & properties)70 Properties &Properties::operator=(const Properties &properties)
71 {
72 if (this != &properties)
73 {
74 mlt_properties_close( instance );
75 instance = properties.instance;
76 inc_ref( );
77 }
78 return *this;
79 }
80
get_properties()81 mlt_properties Properties::get_properties( )
82 {
83 return instance;
84 }
85
inc_ref()86 int Properties::inc_ref( )
87 {
88 return mlt_properties_inc_ref( get_properties( ) );
89 }
90
dec_ref()91 int Properties::dec_ref( )
92 {
93 return mlt_properties_dec_ref( get_properties( ) );
94 }
95
ref_count()96 int Properties::ref_count( )
97 {
98 return mlt_properties_ref_count( get_properties( ) );
99 }
100
lock()101 void Properties::lock( )
102 {
103 mlt_properties_lock( get_properties( ) );
104 }
105
unlock()106 void Properties::unlock( )
107 {
108 mlt_properties_unlock( get_properties( ) );
109 }
110
block(void * object)111 void Properties::block( void *object )
112 {
113 mlt_events_block( get_properties( ), object != NULL ? object : get_properties( ) );
114 }
115
unblock(void * object)116 void Properties::unblock( void *object )
117 {
118 mlt_events_unblock( get_properties( ), object != NULL ? object : get_properties( ) );
119 }
120
fire_event(const char * event)121 int Properties::fire_event( const char *event )
122 {
123 return mlt_events_fire( get_properties( ), event, mlt_event_data_none() );
124 }
125
is_valid()126 bool Properties::is_valid( )
127 {
128 return get_properties( ) != NULL;
129 }
130
count()131 int Properties::count( )
132 {
133 return mlt_properties_count( get_properties( ) );
134 }
135
get(const char * name)136 char *Properties::get( const char *name )
137 {
138 return mlt_properties_get( get_properties( ), name );
139 }
140
get_int(const char * name)141 int Properties::get_int( const char *name )
142 {
143 return mlt_properties_get_int( get_properties( ), name );
144 }
145
get_int64(const char * name)146 int64_t Properties::get_int64( const char *name )
147 {
148 return mlt_properties_get_int64( get_properties( ), name );
149 }
150
get_double(const char * name)151 double Properties::get_double( const char *name )
152 {
153 return mlt_properties_get_double( get_properties( ), name );
154 }
155
get_data(const char * name,int & size)156 void *Properties::get_data( const char *name, int &size )
157 {
158 return mlt_properties_get_data( get_properties( ), name, &size );
159 }
160
get_data(const char * name)161 void *Properties::get_data( const char *name )
162 {
163 return mlt_properties_get_data( get_properties( ), name, NULL );
164 }
165
set(const char * name,const char * value)166 int Properties::set( const char *name, const char *value )
167 {
168 return mlt_properties_set( get_properties( ), name, value );
169 }
170
set_string(const char * name,const char * value)171 int Properties::set_string(const char *name, const char *value)
172 {
173 return mlt_properties_set_string( get_properties( ), name, value );
174 }
175
set(const char * name,int value)176 int Properties::set( const char *name, int value )
177 {
178 return mlt_properties_set_int( get_properties( ), name, value );
179 }
180
set(const char * name,int64_t value)181 int Properties::set( const char *name, int64_t value )
182 {
183 return mlt_properties_set_int64( get_properties( ), name, value );
184 }
185
set(const char * name,double value)186 int Properties::set( const char *name, double value )
187 {
188 return mlt_properties_set_double( get_properties( ), name, value );
189 }
190
set(const char * name,void * value,int size,mlt_destructor destructor,mlt_serialiser serialiser)191 int Properties::set( const char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
192 {
193 return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
194 }
195
pass_property(Properties & that,const char * name)196 void Properties::pass_property( Properties &that, const char *name )
197 {
198 return mlt_properties_pass_property( get_properties( ), that.get_properties( ), name );
199 }
200
pass_values(Properties & that,const char * prefix)201 int Properties::pass_values( Properties &that, const char *prefix )
202 {
203 return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
204 }
205
pass_list(Properties & that,const char * list)206 int Properties::pass_list( Properties &that, const char *list )
207 {
208 return mlt_properties_pass_list( get_properties( ), that.get_properties( ), list );
209 }
210
parse(const char * namevalue)211 int Properties::parse( const char *namevalue )
212 {
213 return mlt_properties_parse( get_properties( ), namevalue );
214 }
215
get_name(int index)216 char *Properties::get_name( int index )
217 {
218 return mlt_properties_get_name( get_properties( ), index );
219 }
220
get(int index)221 char *Properties::get( int index )
222 {
223 return mlt_properties_get_value( get_properties( ), index );
224 }
225
get(int index,mlt_time_format format)226 char *Properties::get( int index , mlt_time_format format )
227 {
228 return mlt_properties_get_value_tf( get_properties( ), index, format );
229 }
230
get_data(int index,int & size)231 void *Properties::get_data( int index, int &size )
232 {
233 return mlt_properties_get_data_at( get_properties( ), index, &size );
234 }
235
mirror(Properties & that)236 void Properties::mirror( Properties &that )
237 {
238 mlt_properties_mirror( get_properties( ), that.get_properties( ) );
239 }
240
inherit(Properties & that)241 int Properties::inherit( Properties &that )
242 {
243 return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
244 }
245
rename(const char * source,const char * dest)246 int Properties::rename( const char *source, const char *dest )
247 {
248 return mlt_properties_rename( get_properties( ), source, dest );
249 }
250
dump(FILE * output)251 void Properties::dump( FILE *output )
252 {
253 mlt_properties_dump( get_properties( ), output );
254 }
255
debug(const char * title,FILE * output)256 void Properties::debug( const char *title, FILE *output )
257 {
258 mlt_properties_debug( get_properties( ), title, output );
259 }
260
load(const char * file)261 void Properties::load( const char *file )
262 {
263 mlt_properties properties = mlt_properties_load( file );
264 if ( properties != NULL )
265 mlt_properties_pass( get_properties( ), properties, "" );
266 mlt_properties_close( properties );
267 }
268
save(const char * file)269 int Properties::save( const char *file )
270 {
271 return mlt_properties_save( get_properties( ), file );
272 }
273
listen(const char * id,void * object,mlt_listener listener)274 Event *Properties::listen( const char *id, void *object, mlt_listener listener )
275 {
276 mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
277 return new Event( event );
278 }
279
setup_wait_for(const char * id)280 Event *Properties::setup_wait_for( const char *id )
281 {
282 return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
283 }
284
delete_event(Event * event)285 void Properties::delete_event( Event *event )
286 {
287 delete event;
288 }
289
wait_for(Event * event,bool destroy)290 void Properties::wait_for( Event *event, bool destroy )
291 {
292 mlt_events_wait_for( get_properties( ), event->get_event( ) );
293 if ( destroy )
294 mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
295 }
296
wait_for(const char * id)297 void Properties::wait_for( const char *id )
298 {
299 Event *event = setup_wait_for( id );
300 wait_for( event );
301 delete event;
302 }
303
is_sequence()304 bool Properties::is_sequence( )
305 {
306 return mlt_properties_is_sequence( get_properties( ) );
307 }
308
parse_yaml(const char * file)309 Properties *Properties::parse_yaml( const char *file )
310 {
311 return new Properties( mlt_properties_parse_yaml( file ) );
312 }
313
serialise_yaml()314 char *Properties::serialise_yaml( )
315 {
316 return mlt_properties_serialise_yaml( get_properties( ) );
317 }
318
preset(const char * name)319 int Properties::preset( const char *name )
320 {
321 return mlt_properties_preset( get_properties(), name );
322 }
323
set_lcnumeric(const char * locale)324 int Properties::set_lcnumeric( const char *locale )
325 {
326 return mlt_properties_set_lcnumeric( get_properties(), locale );
327 }
328
get_lcnumeric()329 const char *Properties::get_lcnumeric( )
330 {
331 return mlt_properties_get_lcnumeric( get_properties() );
332 }
333
clear(const char * name)334 void Properties::clear( const char *name )
335 {
336 return mlt_properties_clear( get_properties(), name );
337 }
338
property_exists(const char * name)339 bool Properties::property_exists( const char *name )
340 {
341 return mlt_properties_exists( get_properties(), name );
342 }
343
get_time(const char * name,mlt_time_format format)344 char *Properties::get_time( const char *name, mlt_time_format format )
345 {
346 return mlt_properties_get_time( get_properties(), name, format );
347 }
348
frames_to_time(int frames,mlt_time_format format)349 char *Properties::frames_to_time( int frames, mlt_time_format format )
350 {
351 return mlt_properties_frames_to_time( get_properties(), frames, format );
352 }
353
time_to_frames(const char * time)354 int Properties::time_to_frames( const char *time )
355 {
356 return mlt_properties_time_to_frames( get_properties(), time );
357 }
358
get_color(const char * name)359 mlt_color Properties::get_color( const char *name )
360 {
361 return mlt_properties_get_color( get_properties(), name );
362 }
363
set(const char * name,mlt_color value)364 int Properties::set( const char *name, mlt_color value )
365 {
366 return mlt_properties_set_color( get_properties(), name, value );
367 }
368
anim_get(const char * name,int position,int length)369 char *Properties::anim_get( const char *name, int position, int length )
370 {
371 return mlt_properties_anim_get( get_properties(), name, position, length );
372 }
373
anim_set(const char * name,const char * value,int position,int length)374 int Properties::anim_set( const char *name, const char *value, int position, int length )
375 {
376 return mlt_properties_anim_set( get_properties(), name, value, position, length );
377 }
378
anim_get_int(const char * name,int position,int length)379 int Properties::anim_get_int( const char *name, int position, int length )
380 {
381 return mlt_properties_anim_get_int( get_properties(), name, position, length );
382 }
383
anim_set(const char * name,int value,int position,int length,mlt_keyframe_type keyframe_type)384 int Properties::anim_set( const char *name, int value, int position, int length, mlt_keyframe_type keyframe_type )
385 {
386 return mlt_properties_anim_set_int( get_properties(), name, value, position, length, keyframe_type );
387 }
388
anim_get_double(const char * name,int position,int length)389 double Properties::anim_get_double(const char *name, int position, int length)
390 {
391 return mlt_properties_anim_get_double( get_properties(), name, position, length );
392 }
393
anim_set(const char * name,double value,int position,int length,mlt_keyframe_type keyframe_type)394 int Properties::anim_set( const char *name, double value, int position, int length, mlt_keyframe_type keyframe_type )
395 {
396 return mlt_properties_anim_set_double( get_properties(), name, value, position, length, keyframe_type );
397 }
398
set(const char * name,mlt_rect value)399 int Properties::set( const char *name, mlt_rect value )
400 {
401 return mlt_properties_set_rect( get_properties(), name, value );
402 }
403
set(const char * name,double x,double y,double w,double h,double opacity)404 int Properties::set( const char *name, double x, double y, double w, double h, double opacity )
405 {
406 mlt_rect value = { x, y, w, h, opacity };
407 return mlt_properties_set_rect( get_properties(), name, value );
408 }
409
get_rect(const char * name)410 mlt_rect Properties::get_rect( const char *name )
411 {
412 return mlt_properties_get_rect( get_properties(), name );
413 }
414
anim_set(const char * name,mlt_rect value,int position,int length,mlt_keyframe_type keyframe_type)415 int Properties::anim_set( const char *name, mlt_rect value, int position, int length, mlt_keyframe_type keyframe_type )
416 {
417 return mlt_properties_anim_set_rect( get_properties(), name, value, position, length, keyframe_type );
418 }
419
anim_get_rect(const char * name,int position,int length)420 mlt_rect Properties::anim_get_rect(const char *name, int position, int length)
421 {
422 return mlt_properties_anim_get_rect( get_properties(), name, position, length );
423 }
424
get_animation(const char * name)425 mlt_animation Properties::get_animation( const char *name )
426 {
427 return mlt_properties_get_animation( get_properties(), name );
428 }
429
get_anim(const char * name)430 Animation *Properties::get_anim(const char *name)
431 {
432 return new Animation( mlt_properties_get_animation( get_properties(), name ) );
433 }
434