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;
51 We construct a multitrack and a tractor here.
54 mlt_field mlt_field_init( )
56 // Initialise the field
57 mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
62 // Construct a multitrack
63 this->multitrack = mlt_multitrack_init( );
65 // Construct a tractor
66 this->tractor = mlt_tractor_init( );
68 // The first plant will be connected to the mulitrack
69 this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
71 // Connect the tractor to the multitrack
72 mlt_tractor_connect( this->tractor, this->producer );
79 mlt_field mlt_field_new( mlt_multitrack multitrack, mlt_tractor tractor )
81 // Initialise the field
82 mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
87 // Construct a multitrack
88 this->multitrack = multitrack;
90 // Construct a tractor
91 this->tractor = tractor;
93 // The first plant will be connected to the mulitrack
94 this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
96 // Connect the tractor to the multitrack
97 mlt_tractor_connect( this->tractor, this->producer );
104 /** Get the service associated to this field.
107 mlt_service mlt_field_service( mlt_field this )
109 return MLT_TRACTOR_SERVICE( this->tractor );
112 /** Get the multi track.
115 mlt_multitrack mlt_field_multitrack( mlt_field this )
117 return this != NULL ? this->multitrack : NULL;
123 mlt_tractor mlt_field_tractor( mlt_field this )
125 return this != NULL ? this->tractor : NULL;
128 /** Get the properties associated to this field.
131 mlt_properties mlt_field_properties( mlt_field this )
133 return MLT_SERVICE_PROPERTIES( mlt_field_service( this ) );
139 int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
141 // Connect the filter to the last producer
142 int result = mlt_filter_connect( that, this->producer, track );
144 // If sucessful, then we'll use this for connecting in the future
147 // This is now the new producer
148 this->producer = MLT_FILTER_SERVICE( that );
150 // Reconnect tractor to new producer
151 mlt_tractor_connect( this->tractor, this->producer );
154 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
160 /** Plant a transition.
163 int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track, int b_track )
165 // Connect the transition to the last producer
166 int result = mlt_transition_connect( that, this->producer, a_track, b_track );
168 // If sucessful, then we'll use this for connecting in the future
171 // This is now the new producer
172 this->producer = MLT_TRANSITION_SERVICE( that );
174 // Reconnect tractor to new producer
175 mlt_tractor_connect( this->tractor, this->producer );
178 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
187 void mlt_field_close( mlt_field this )
189 if ( this != NULL && mlt_properties_dec_ref( mlt_field_properties( this ) ) <= 0 )
191 //mlt_tractor_close( this->tractor );
192 //mlt_multitrack_close( this->multitrack );
197 void mlt_field_disconnect_service( mlt_field self, mlt_service service )
199 mlt_service p = mlt_service_producer( service );
200 mlt_service c = mlt_service_consumer( service);
202 switch ( mlt_service_identify(c) )
205 i = mlt_filter_get_track( MLT_FILTER(c) );
206 mlt_service_connect_producer( c, p, i );
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;
215 mlt_tractor_connect( MLT_TRACTOR(c), p );
219 mlt_events_fire( mlt_field_properties( self ), "service-changed", NULL );