3 * \brief a field for planting multiple transitions and filters
6 * Copyright (C) 2003-2009 Ushodaya Enterprises Limited
7 * \author Charles Yates <charles.yates@pandora.be>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "mlt_field.h"
25 #include "mlt_service.h"
26 #include "mlt_filter.h"
27 #include "mlt_transition.h"
28 #include "mlt_multitrack.h"
29 #include "mlt_tractor.h"
34 /** \brief Field class
36 * The field is a convenience class that works with the tractor and multitrack classes to manage track filters and transitions.
41 /// This is the producer we're connected to
45 mlt_multitrack multitrack
;
51 /** Construct a field, mulitrack, and tractor.
53 * \public \memberof mlt_field_s
57 mlt_field
mlt_field_init( )
59 // Initialise the field
60 mlt_field
this = calloc( sizeof( struct mlt_field_s
), 1 );
65 // Construct a multitrack
66 this->multitrack
= mlt_multitrack_init( );
68 // Construct a tractor
69 this->tractor
= mlt_tractor_init( );
71 // The first plant will be connected to the mulitrack
72 this->producer
= MLT_MULTITRACK_SERVICE( this->multitrack
);
74 // Connect the tractor to the multitrack
75 mlt_tractor_connect( this->tractor
, this->producer
);
82 /** Construct a field and initialize with supplied multitrack and tractor.
84 * \public \memberof mlt_field_s
85 * \param multitrack a multitrack
86 * \param tractor a tractor
90 mlt_field
mlt_field_new( mlt_multitrack multitrack
, mlt_tractor tractor
)
92 // Initialise the field
93 mlt_field
this = calloc( sizeof( struct mlt_field_s
), 1 );
98 // Construct a multitrack
99 this->multitrack
= multitrack
;
101 // Construct a tractor
102 this->tractor
= tractor
;
104 // The first plant will be connected to the mulitrack
105 this->producer
= MLT_MULTITRACK_SERVICE( this->multitrack
);
107 // Connect the tractor to the multitrack
108 mlt_tractor_connect( this->tractor
, this->producer
);
115 /** Get the service associated to this field.
117 * \public \memberof mlt_field_s
118 * \param this a field
119 * \return the tractor as a service
122 mlt_service
mlt_field_service( mlt_field
this )
124 return MLT_TRACTOR_SERVICE( this->tractor
);
127 /** Get the multitrack.
129 * \public \memberof mlt_field_s
130 * \param this a field
131 * \return the multitrack
134 mlt_multitrack
mlt_field_multitrack( mlt_field
this )
136 return this != NULL ?
this->multitrack
: NULL
;
141 * \public \memberof mlt_field_s
142 * \param this a field
143 * \return the tractor
146 mlt_tractor
mlt_field_tractor( mlt_field
this )
148 return this != NULL ?
this->tractor
: NULL
;
151 /** Get the properties associated to this field.
153 * \public \memberof mlt_field_s
154 * \param this a field
155 * \return a properties list
158 mlt_properties
mlt_field_properties( mlt_field
this )
160 return MLT_SERVICE_PROPERTIES( mlt_field_service( this ) );
165 * \public \memberof mlt_field_s
166 * \param this a field
167 * \param that a filter
168 * \param track the track index
169 * \return true if there was an error
172 int mlt_field_plant_filter( mlt_field
this, mlt_filter that
, int track
)
174 // Connect the filter to the last producer
175 int result
= mlt_filter_connect( that
, this->producer
, track
);
177 // If sucessful, then we'll use this for connecting in the future
180 // This is now the new producer
181 this->producer
= MLT_FILTER_SERVICE( that
);
183 // Reconnect tractor to new producer
184 mlt_tractor_connect( this->tractor
, this->producer
);
187 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL
);
193 /** Plant a transition.
195 * \public \memberof mlt_field_s
196 * \param this a field
197 * \param that a transition
198 * \param a_track input A's track index
199 * \param b_track input B's track index
200 * \return true if there was an error
203 int mlt_field_plant_transition( mlt_field
this, mlt_transition that
, int a_track
, int b_track
)
205 // Connect the transition to the last producer
206 int result
= mlt_transition_connect( that
, this->producer
, a_track
, b_track
);
208 // If sucessful, then we'll use this for connecting in the future
211 // This is now the new producer
212 this->producer
= MLT_TRANSITION_SERVICE( that
);
214 // Reconnect tractor to new producer
215 mlt_tractor_connect( this->tractor
, this->producer
);
218 mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL
);
226 * \public \memberof mlt_field_s
227 * \param this a field
230 void mlt_field_close( mlt_field
this )
232 if ( this != NULL
&& mlt_properties_dec_ref( mlt_field_properties( this ) ) <= 0 )
234 //mlt_tractor_close( this->tractor );
235 //mlt_multitrack_close( this->multitrack );
240 /** Remove a filter or transition from the field.
242 * \public \memberof mlt_field_s
243 * \param self a field
244 * \param service the filter or transition to remove
247 void mlt_field_disconnect_service( mlt_field self
, mlt_service service
)
249 mlt_service p
= mlt_service_producer( service
);
250 mlt_service c
= mlt_service_consumer( service
);
252 switch ( mlt_service_identify(c
) )
255 i
= mlt_filter_get_track( MLT_FILTER(c
) );
256 mlt_service_connect_producer( c
, p
, i
);
258 case transition_type
:
259 i
= mlt_transition_get_a_track ( MLT_TRANSITION(c
) );
260 mlt_service_connect_producer( c
, p
, i
);
261 MLT_TRANSITION(c
)->producer
= p
;
265 mlt_tractor_connect( MLT_TRACTOR(c
), p
);
269 mlt_events_fire( mlt_field_properties( self
), "service-changed", NULL
);