4b7dd0e864c027969bbed961e0737ee61b1ee0fe
[melted] / mlt++ / src / 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 program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * 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( const char *file ) :
49 instance( NULL )
50 {
51 instance = mlt_properties_load( file );
52 }
53
54 Properties::~Properties( )
55 {
56 mlt_properties_close( instance );
57 }
58
59 mlt_properties Properties::get_properties( )
60 {
61 return instance;
62 }
63
64 int Properties::inc_ref( )
65 {
66 return mlt_properties_inc_ref( get_properties( ) );
67 }
68
69 int Properties::dec_ref( )
70 {
71 return mlt_properties_dec_ref( get_properties( ) );
72 }
73
74 int Properties::ref_count( )
75 {
76 return mlt_properties_ref_count( get_properties( ) );
77 }
78
79 void Properties::block( void *object )
80 {
81 mlt_events_block( get_properties( ), object != NULL ? object : get_properties( ) );
82 }
83
84 void Properties::unblock( void *object )
85 {
86 mlt_events_unblock( get_properties( ), object != NULL ? object : get_properties( ) );
87 }
88
89 void Properties::fire_event( const char *event )
90 {
91 mlt_events_fire( get_properties( ), ( char * )event, NULL );
92 }
93
94 bool Properties::is_valid( )
95 {
96 return get_properties( ) != NULL;
97 }
98
99 int Properties::count( )
100 {
101 return mlt_properties_count( get_properties( ) );
102 }
103
104 char *Properties::get( const char *name )
105 {
106 return mlt_properties_get( get_properties( ), name );
107 }
108
109 int Properties::get_int( const char *name )
110 {
111 return mlt_properties_get_int( get_properties( ), name );
112 }
113
114 double Properties::get_double( const char *name )
115 {
116 return mlt_properties_get_double( get_properties( ), name );
117 }
118
119 void *Properties::get_data( const char *name, int &size )
120 {
121 return mlt_properties_get_data( get_properties( ), name, &size );
122 }
123
124 void *Properties::get_data( const char *name )
125 {
126 return mlt_properties_get_data( get_properties( ), name, NULL );
127 }
128
129 int Properties::set( const char *name, const char *value )
130 {
131 return mlt_properties_set( get_properties( ), name, value );
132 }
133
134 int Properties::set( const char *name, int value )
135 {
136 return mlt_properties_set_int( get_properties( ), name, value );
137 }
138
139 int Properties::set( const char *name, double value )
140 {
141 return mlt_properties_set_double( get_properties( ), name, value );
142 }
143
144 int Properties::set( const char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
145 {
146 return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
147 }
148
149 int Properties::pass_values( Properties &that, const char *prefix )
150 {
151 return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
152 }
153
154 int Properties::parse( const char *namevalue )
155 {
156 return mlt_properties_parse( get_properties( ), namevalue );
157 }
158
159 char *Properties::get_name( int index )
160 {
161 return mlt_properties_get_name( get_properties( ), index );
162 }
163
164 char *Properties::get( int index )
165 {
166 return mlt_properties_get_value( get_properties( ), index );
167 }
168
169 void *Properties::get_data( int index, int &size )
170 {
171 return mlt_properties_get_data_at( get_properties( ), index, &size );
172 }
173
174 void Properties::mirror( Properties &that )
175 {
176 mlt_properties_mirror( get_properties( ), that.get_properties( ) );
177 }
178
179 int Properties::inherit( Properties &that )
180 {
181 return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
182 }
183
184 int Properties::rename( const char *source, const char *dest )
185 {
186 return mlt_properties_rename( get_properties( ), source, dest );
187 }
188
189 void Properties::dump( FILE *output )
190 {
191 mlt_properties_dump( get_properties( ), output );
192 }
193
194 void Properties::debug( const char *title, FILE *output )
195 {
196 mlt_properties_debug( get_properties( ), title, output );
197 }
198
199 void Properties::load( const char *file )
200 {
201 mlt_properties properties = mlt_properties_load( file );
202 if ( properties != NULL )
203 mlt_properties_pass( get_properties( ), properties, "" );
204 mlt_properties_close( properties );
205 }
206
207 int Properties::save( const char *file )
208 {
209 #ifdef WIN32
210 return mlt_properties_save( get_properties( ), file );
211 #else
212 int error = 0;
213 FILE *f = fopen( file, "w" );
214 if ( f != NULL )
215 {
216 dump( f );
217 fclose( f );
218 }
219 else
220 {
221 error = 1;
222 }
223 return error;
224 #endif
225 }
226
227 #if defined( __DARWIN__ ) && GCC_VERSION < 40000
228
229 Event *Properties::listen( char *id, void *object, void (*listener)( ... ) )
230 {
231 mlt_event event = mlt_events_listen( get_properties( ), object, id, ( mlt_listener )listener );
232 return new Event( event );
233 }
234
235 #else
236
237 Event *Properties::listen( char *id, void *object, mlt_listener listener )
238 {
239 mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
240 return new Event( event );
241 }
242
243 #endif
244
245 Event *Properties::setup_wait_for( const char *id )
246 {
247 return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
248 }
249
250 void Properties::delete_event( Event *event )
251 {
252 delete event;
253 }
254
255 void Properties::wait_for( Event *event, bool destroy )
256 {
257 mlt_events_wait_for( get_properties( ), event->get_event( ) );
258 if ( destroy )
259 mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
260 }
261