3 * \brief a field for planting multiple transitions and filters
5 * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
6 * \author Charles Yates <charles.yates@pandora.be>
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.
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.
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
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"
33 /** \brief Field class
39 /// This is the producer we're connected to
43 mlt_multitrack multitrack;
49 /** Construct a field, mulitrack, and tractor.
51 * \public \memberof mlt_field_s
55 mlt_field mlt_field_init( )
57 // Initialise the field
58 mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
63 // Construct a multitrack
64 this->multitrack = mlt_multitrack_init( );
66 // Construct a tractor
67 this->tractor = mlt_tractor_init( );
69 // The first plant will be connected to the mulitrack
70 this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
72 // Connect the tractor to the multitrack
73 mlt_tractor_connect( this->tractor, this->producer );
80 /** Construct a field and initialize with supplied multitrack and tractor.
82 * \public \memberof mlt_field_s
83 * \param multitrack a multitrack
84 * \param tractor a tractor
88 mlt_field mlt_field_new( mlt_multitrack multitrack, mlt_tractor tractor )
90 // Initialise the field
91 mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
96 // Construct a multitrack
97 this->multitrack = multitrack;
99 // Construct a tractor
100 this->tractor = tractor;
102 // The first plant will be connected to the mulitrack
103 this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
105 // Connect the tractor to the multitrack
106 mlt_tractor_connect( this->tractor, this->producer );
113 /** Get the service associated to this field.
115 * \public \memberof mlt_field_s
116 * \param this a field
117 * \return the tractor as a service
120 mlt_service mlt_field_service( mlt_field this )
122 return MLT_TRACTOR_SERVICE( this->tractor );
125 /** Get the multitrack.
127 * \public \memberof mlt_field_s
128 * \param this a field
129 * \return the multitrack
132 mlt_multitrack mlt_field_multitrack( mlt_field this )
134 return this != NULL ? this->multitrack : NULL;
139 * \public \memberof mlt_field_s
140 * \param this a field
141 * \return the tractor
144 mlt_tractor mlt_field_tractor( mlt_field this )
146 return this != NULL ? this->tractor : NULL;
149 /** Get the properties associated to this field.
151 * \public \memberof mlt_field_s
152 * \param this a field
153 * \return a properties list
156 mlt_properties mlt_field_properties( mlt_field this )
158 return MLT_SERVICE_PROPERTIES( mlt_field_service( this ) );
163 * \public \memberof mlt_field_s
164 * \param this a field
165 * \param that a filter
166 * \param track the track index
167 * \return true if there was an error
170 int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
172 // Connect the filter to the last producer
173 int result = mlt_filter_connect( that, this->producer, track );
175 // If sucessful, then we'll use this for connecting in the future
178 // This is now the new producer
179 this->producer = MLT_FILTER_SERVICE( that );
181 // Reconnect tractor to new producer
182 mlt_tractor_connect( this->tractor, this->producer );
185 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
191 /** Plant a transition.
193 * \public \memberof mlt_field_s
194 * \param this a field
195 * \param that a transition
196 * \param a_track input A's track index
197 * \param b_track input B's track index
198 * \return true if there was an error
201 int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
203 // Connect the transition to the last producer
204 int result = mlt_transition_connect( that, this->producer, a_track, b_track );
206 // If sucessful, then we'll use this for connecting in the future
209 // This is now the new producer
210 this->producer = MLT_TRANSITION_SERVICE( that );
212 // Reconnect tractor to new producer
213 mlt_tractor_connect( this->tractor, this->producer );
216 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
224 * \public \memberof mlt_field_s
225 * \param this a field
228 void mlt_field_close( mlt_field this )
230 if ( this != NULL && mlt_properties_dec_ref( mlt_field_properties( this ) ) <= 0 )
232 //mlt_tractor_close( this->tractor );
233 //mlt_multitrack_close( this->multitrack );
238 /** Remove a filter or transition from the field.
240 * \public \memberof mlt_field_s
241 * \param self a field
242 * \param service the filter or transition to remove
245 void mlt_field_disconnect_service( mlt_field self, mlt_service service )
247 mlt_service p = mlt_service_producer( service );
248 mlt_service c = mlt_service_consumer( service);
250 switch ( mlt_service_identify(c) )
253 i = mlt_filter_get_track( MLT_FILTER(c) );
254 mlt_service_connect_producer( c, p, i );
256 case transition_type:
257 i = mlt_transition_get_a_track ( MLT_TRANSITION(c) );
258 mlt_service_connect_producer( c, p, i );
259 MLT_TRANSITION(c)->producer = p;
263 mlt_tractor_connect( MLT_TRACTOR(c), p );
267 mlt_events_fire( mlt_field_properties( self ), "service-changed", NULL );