]> git.sesse.net Git - mlt/blob - src/mlt++/MltProperties.cpp
Add mlt_consumer_position (Mlt::Consumer::position).
[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::block( void *object )
86 {
87         mlt_events_block( get_properties( ), object != NULL ? object : get_properties( ) );
88 }
89
90 void Properties::unblock( void *object )
91 {
92         mlt_events_unblock( get_properties( ), object != NULL ? object : get_properties( ) );
93 }
94
95 void Properties::fire_event( const char *event )
96 {
97         mlt_events_fire( get_properties( ), event, NULL );
98 }
99
100 bool Properties::is_valid( )
101 {
102         return get_properties( ) != NULL;
103 }
104
105 int Properties::count( )
106 {
107         return mlt_properties_count( get_properties( ) );
108 }
109
110 char *Properties::get( const char *name )
111 {
112         return mlt_properties_get( get_properties( ), name );
113 }
114
115 int Properties::get_int( const char *name )
116 {
117         return mlt_properties_get_int( get_properties( ), name );
118 }
119
120 int64_t Properties::get_int64( const char *name )
121 {
122         return mlt_properties_get_int64( get_properties( ), name );
123 }
124
125 double Properties::get_double( const char *name )
126 {
127         return mlt_properties_get_double( get_properties( ), name );
128 }
129
130 void *Properties::get_data( const char *name, int &size )
131 {
132         return mlt_properties_get_data( get_properties( ), name, &size );
133 }
134
135 void *Properties::get_data( const char *name )
136 {
137         return mlt_properties_get_data( get_properties( ), name, NULL );
138 }
139
140 int Properties::set( const char *name, const char *value )
141 {
142         return mlt_properties_set( get_properties( ), name, value );
143 }
144
145 int Properties::set( const char *name, int value )
146 {
147         return mlt_properties_set_int( get_properties( ), name, value );
148 }
149
150 int Properties::set( const char *name, int64_t value )
151 {
152         return mlt_properties_set_int64( get_properties( ), name, value );
153 }
154
155 int Properties::set( const char *name, double value )
156 {
157         return mlt_properties_set_double( get_properties( ), name, value );
158 }
159
160 int Properties::set( const char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
161 {
162         return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
163 }
164
165 void Properties::pass_property( Properties &that, const char *name )
166 {
167         return mlt_properties_pass_property( get_properties( ), that.get_properties( ), name );
168 }
169
170 int Properties::pass_values( Properties &that, const char *prefix )
171 {
172         return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
173 }
174
175 int Properties::pass_list( Properties &that, const char *list )
176 {
177         return mlt_properties_pass_list( get_properties( ), that.get_properties( ), list );
178 }
179
180 int Properties::parse( const char *namevalue )
181 {
182         return mlt_properties_parse( get_properties( ), namevalue );
183 }
184
185 char *Properties::get_name( int index )
186 {
187         return mlt_properties_get_name( get_properties( ), index );
188 }
189
190 char *Properties::get( int index )
191 {
192         return mlt_properties_get_value( get_properties( ), index );
193 }
194
195 void *Properties::get_data( int index, int &size )
196 {
197         return mlt_properties_get_data_at( get_properties( ), index, &size );
198 }
199
200 void Properties::mirror( Properties &that )
201 {
202         mlt_properties_mirror( get_properties( ), that.get_properties( ) );
203 }
204
205 int Properties::inherit( Properties &that )
206 {
207         return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
208 }
209
210 int Properties::rename( const char *source, const char *dest )
211 {
212         return mlt_properties_rename( get_properties( ), source, dest );
213 }
214
215 void Properties::dump( FILE *output )
216 {
217         mlt_properties_dump( get_properties( ), output );
218 }
219
220 void Properties::debug( const char *title, FILE *output )
221 {
222         mlt_properties_debug( get_properties( ), title, output );
223 }
224
225 void Properties::load( const char *file )
226 {
227         mlt_properties properties = mlt_properties_load( file );
228         if ( properties != NULL )
229                 mlt_properties_pass( get_properties( ), properties, "" );
230         mlt_properties_close( properties );
231 }
232
233 int Properties::save( const char *file )
234 {
235 #ifdef WIN32
236         return mlt_properties_save( get_properties( ), file );
237 #else
238         int error = 0;
239         FILE *f = fopen( file, "w" );
240         if ( f != NULL )
241         {
242                 dump( f );
243                 fclose( f );
244         }
245         else
246         {
247                 error = 1;
248         }
249         return error;
250 #endif
251 }
252
253 #if defined( __DARWIN__ ) && GCC_VERSION < 40000
254
255 Event *Properties::listen( const char *id, void *object, void (*listener)( ... ) )
256 {
257         mlt_event event = mlt_events_listen( get_properties( ), object, id, ( mlt_listener )listener );
258         return new Event( event );
259 }
260
261 #else
262
263 Event *Properties::listen( const char *id, void *object, mlt_listener listener )
264 {
265         mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
266         return new Event( event );
267 }
268
269 #endif
270
271 Event *Properties::setup_wait_for( const char *id )
272 {
273         return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
274 }
275
276 void Properties::delete_event( Event *event )
277 {
278         delete event;
279 }
280
281 void Properties::wait_for( Event *event, bool destroy )
282 {
283         mlt_events_wait_for( get_properties( ), event->get_event( ) );
284         if ( destroy )
285                 mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
286 }
287
288 bool Properties::is_sequence( )
289 {
290         return mlt_properties_is_sequence( get_properties( ) );
291 }
292
293 Properties *Properties::parse_yaml( const char *file )
294 {
295         return new Properties( mlt_properties_parse_yaml( file ) );
296 }
297
298 char *Properties::serialise_yaml( )
299 {
300         return mlt_properties_serialise_yaml( get_properties( ) );
301 }