]> git.sesse.net Git - mlt/blob - src/framework/mlt_field.c
src/framework/*: improve the doxygen documentation (work in progress). This also...
[mlt] / src / framework / mlt_field.c
1 /**
2  * \file mlt_field.c
3  * \brief a field for planting multiple transitions and filters
4  *
5  * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
6  * \author Charles Yates <charles.yates@pandora.be>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "mlt_field.h"
24 #include "mlt_service.h"
25 #include "mlt_filter.h"
26 #include "mlt_transition.h"
27 #include "mlt_multitrack.h"
28 #include "mlt_tractor.h"
29
30 #include <stdlib.h>
31 #include <string.h>
32
33 /** \brief Field class
34  *
35  */
36
37 struct mlt_field_s
38 {
39         // This is the producer we're connected to
40         mlt_service producer;
41
42         // Multitrack
43         mlt_multitrack multitrack;
44
45         // Tractor
46         mlt_tractor tractor;
47 };
48
49 /** Constructor.
50
51         We construct a multitrack and a tractor here.
52 */
53
54 mlt_field mlt_field_init( )
55 {
56         // Initialise the field
57         mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
58
59         // Initialise it
60         if ( this != NULL )
61         {
62                 // Construct a multitrack
63                 this->multitrack = mlt_multitrack_init( );
64
65                 // Construct a tractor
66                 this->tractor = mlt_tractor_init( );
67
68                 // The first plant will be connected to the mulitrack
69                 this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
70
71                 // Connect the tractor to the multitrack
72                 mlt_tractor_connect( this->tractor, this->producer );
73         }
74
75         // Return this
76         return this;
77 }
78
79 mlt_field mlt_field_new( mlt_multitrack multitrack, mlt_tractor tractor )
80 {
81         // Initialise the field
82         mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
83
84         // Initialise it
85         if ( this != NULL )
86         {
87                 // Construct a multitrack
88                 this->multitrack = multitrack;
89
90                 // Construct a tractor
91                 this->tractor = tractor;
92
93                 // The first plant will be connected to the mulitrack
94                 this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
95
96                 // Connect the tractor to the multitrack
97                 mlt_tractor_connect( this->tractor, this->producer );
98         }
99
100         // Return this
101         return this;
102 }
103
104 /** Get the service associated to this field.
105 */
106
107 mlt_service mlt_field_service( mlt_field this )
108 {
109         return MLT_TRACTOR_SERVICE( this->tractor );
110 }
111
112 /** Get the multi track.
113 */
114
115 mlt_multitrack mlt_field_multitrack( mlt_field this )
116 {
117         return this != NULL ? this->multitrack : NULL;
118 }
119
120 /** Get the tractor.
121 */
122
123 mlt_tractor mlt_field_tractor( mlt_field this )
124 {
125         return this != NULL ? this->tractor : NULL;
126 }
127
128 /** Get the properties associated to this field.
129 */
130
131 mlt_properties mlt_field_properties( mlt_field this )
132 {
133         return MLT_SERVICE_PROPERTIES( mlt_field_service( this ) );
134 }
135
136 /** Plant a filter.
137 */
138
139 int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
140 {
141         // Connect the filter to the last producer
142         int result = mlt_filter_connect( that, this->producer, track );
143
144         // If sucessful, then we'll use this for connecting in the future
145         if ( result == 0 )
146         {
147                 // This is now the new producer
148                 this->producer = MLT_FILTER_SERVICE( that );
149
150                 // Reconnect tractor to new producer
151                 mlt_tractor_connect( this->tractor, this->producer );
152
153                 // Fire an event
154                 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
155         }
156
157         return result;
158 }
159
160 /** Plant a transition.
161 */
162
163 int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
164 {
165         // Connect the transition to the last producer
166         int result = mlt_transition_connect( that, this->producer, a_track, b_track );
167
168         // If sucessful, then we'll use this for connecting in the future
169         if ( result == 0 )
170         {
171                 // This is now the new producer
172                 this->producer = MLT_TRANSITION_SERVICE( that );
173
174                 // Reconnect tractor to new producer
175                 mlt_tractor_connect( this->tractor, this->producer );
176
177                 // Fire an event
178                 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
179         }
180
181         return 0;
182 }
183
184 /** Close the field.
185 */
186
187 void mlt_field_close( mlt_field this )
188 {
189         if ( this != NULL && mlt_properties_dec_ref( mlt_field_properties( this ) ) <= 0 )
190         {
191                 //mlt_tractor_close( this->tractor );
192                 //mlt_multitrack_close( this->multitrack );
193                 free( this );
194         }
195 }
196
197 void mlt_field_disconnect_service( mlt_field self, mlt_service service )
198 {
199         mlt_service p = mlt_service_producer( service );
200         mlt_service c = mlt_service_consumer( service);
201         int i;
202         switch ( mlt_service_identify(c) )
203         {
204                 case filter_type:
205                         i = mlt_filter_get_track( MLT_FILTER(c) );
206                         mlt_service_connect_producer( c, p, i );
207                         break;
208                 case transition_type:
209                         i = mlt_transition_get_a_track ( MLT_TRANSITION(c) );
210                         mlt_service_connect_producer( c, p, i );
211                         MLT_TRANSITION(c)->producer = p;
212                         break;
213                 case tractor_type:
214                         self->producer = p;
215                         mlt_tractor_connect( MLT_TRACTOR(c), p );
216                 default:
217                         break;
218         }
219         mlt_events_fire( mlt_field_properties( self ), "service-changed", NULL );
220 }