Event and frame handling
[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 fprintf( stderr, "Incrementing ref count on properties #1\n" );
40 inc_ref( );
41 }
42
43 Properties::Properties( mlt_properties properties ) :
44 instance( properties )
45 {
46 fprintf( stderr, "Incrementing ref count on properties #2\n" );
47 inc_ref( );
48 }
49
50 Properties::Properties( char *file ) :
51 instance( NULL )
52 {
53 instance = mlt_properties_load( file );
54 }
55
56 Properties::~Properties( )
57 {
58 mlt_properties_close( instance );
59 }
60
61 mlt_properties Properties::get_properties( )
62 {
63 return instance;
64 }
65
66 int Properties::inc_ref( )
67 {
68 return mlt_properties_inc_ref( get_properties( ) );
69 }
70
71 int Properties::dec_ref( )
72 {
73 return mlt_properties_dec_ref( get_properties( ) );
74 }
75
76 bool Properties::is_valid( )
77 {
78 return get_properties( ) != NULL;
79 }
80
81 int Properties::count( )
82 {
83 return mlt_properties_count( get_properties( ) );
84 }
85
86 char *Properties::get( char *name )
87 {
88 return mlt_properties_get( get_properties( ), name );
89 }
90
91 int Properties::get_int( char *name )
92 {
93 return mlt_properties_get_int( get_properties( ), name );
94 }
95
96 double Properties::get_double( char *name )
97 {
98 return mlt_properties_get_double( get_properties( ), name );
99 }
100
101 void *Properties::get_data( char *name, int &size )
102 {
103 return mlt_properties_get_data( get_properties( ), name, &size );
104 }
105
106 int Properties::set( char *name, char *value )
107 {
108 return mlt_properties_set( get_properties( ), name, value );
109 }
110
111 int Properties::set( char *name, int value )
112 {
113 return mlt_properties_set_int( get_properties( ), name, value );
114 }
115
116 int Properties::set( char *name, double value )
117 {
118 return mlt_properties_set_double( get_properties( ), name, value );
119 }
120
121 int Properties::set( char *name, void *value, int size, mlt_destructor destructor, mlt_serialiser serialiser )
122 {
123 return mlt_properties_set_data( get_properties( ), name, value, size, destructor, serialiser );
124 }
125
126 int Properties::pass_values( Properties &that, char *prefix )
127 {
128 return mlt_properties_pass( get_properties( ), that.get_properties( ), prefix );
129 }
130
131 int Properties::parse( char *namevalue )
132 {
133 return mlt_properties_parse( get_properties( ), namevalue );
134 }
135
136 char *Properties::get_name( int index )
137 {
138 return mlt_properties_get_name( get_properties( ), index );
139 }
140
141 char *Properties::get( int index )
142 {
143 return mlt_properties_get_value( get_properties( ), index );
144 }
145
146 void *Properties::get_data( int index, int &size )
147 {
148 return mlt_properties_get_data_at( get_properties( ), index, &size );
149 }
150
151 void Properties::mirror( Properties &that )
152 {
153 mlt_properties_mirror( get_properties( ), that.get_properties( ) );
154 }
155
156 int Properties::inherit( Properties &that )
157 {
158 return mlt_properties_inherit( get_properties( ), that.get_properties( ) );
159 }
160
161 int Properties::rename( char *source, char *dest )
162 {
163 return mlt_properties_rename( get_properties( ), source, dest );
164 }
165
166 void Properties::dump( FILE *output )
167 {
168 mlt_properties_dump( get_properties( ), output );
169 }
170
171 void Properties::debug( char *title, FILE *output )
172 {
173 mlt_properties_debug( get_properties( ), title, output );
174 }
175
176 int Properties::save( char *file )
177 {
178 int error = 0;
179 FILE *f = fopen( file, "w" );
180 if ( f != NULL )
181 {
182 dump( f );
183 fclose( f );
184 }
185 else
186 {
187 error = 1;
188 }
189 return error;
190 }
191
192 Event *Properties::listen( char *id, void *object, mlt_listener listener )
193 {
194 mlt_event event = mlt_events_listen( get_properties( ), object, id, listener );
195 return new Event( event );
196 }
197
198 Event *Properties::setup_wait_for( char *id )
199 {
200 return new Event( mlt_events_setup_wait_for( get_properties( ), id ) );
201 }
202
203 void Properties::wait_for( Event *event, bool destroy )
204 {
205 mlt_events_wait_for( get_properties( ), event->get_event( ) );
206 if ( destroy )
207 mlt_events_close_wait_for( get_properties( ), event->get_event( ) );
208 }
209