]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_field.c
src/framework/*: improve the doxygen documentation (work in progress). This also...
[mlt] / src / framework / mlt_field.c
index eede159b871292add65de218fd80a819633d19b6..a86afa92cee0deb629fae28e5a19caa8524e2dab 100644 (file)
@@ -1,21 +1,23 @@
-/*
- * mlt_field.c -- A field for planting multiple transitions and filters
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
+/**
+ * \file mlt_field.c
+ * \brief a field for planting multiple transitions and filters
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
+ * \author Charles Yates <charles.yates@pandora.be>
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "mlt_field.h"
@@ -28,8 +30,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-/** Private structures.
-*/
+/** \brief Field class
+ *
+ */
 
 struct mlt_field_s
 {
@@ -44,7 +47,7 @@ struct mlt_field_s
 };
 
 /** Constructor.
-       
+
        We construct a multitrack and a tractor here.
 */
 
@@ -63,7 +66,32 @@ mlt_field mlt_field_init( )
                this->tractor = mlt_tractor_init( );
 
                // The first plant will be connected to the mulitrack
-               this->producer = mlt_multitrack_service( this->multitrack );
+               this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
+
+               // Connect the tractor to the multitrack
+               mlt_tractor_connect( this->tractor, this->producer );
+       }
+
+       // Return this
+       return this;
+}
+
+mlt_field mlt_field_new( mlt_multitrack multitrack, mlt_tractor tractor )
+{
+       // Initialise the field
+       mlt_field this = calloc( sizeof( struct mlt_field_s ), 1 );
+
+       // Initialise it
+       if ( this != NULL )
+       {
+               // Construct a multitrack
+               this->multitrack = multitrack;
+
+               // Construct a tractor
+               this->tractor = tractor;
+
+               // The first plant will be connected to the mulitrack
+               this->producer = MLT_MULTITRACK_SERVICE( this->multitrack );
 
                // Connect the tractor to the multitrack
                mlt_tractor_connect( this->tractor, this->producer );
@@ -78,7 +106,7 @@ mlt_field mlt_field_init( )
 
 mlt_service mlt_field_service( mlt_field this )
 {
-       return mlt_tractor_service( this->tractor );
+       return MLT_TRACTOR_SERVICE( this->tractor );
 }
 
 /** Get the multi track.
@@ -86,7 +114,7 @@ mlt_service mlt_field_service( mlt_field this )
 
 mlt_multitrack mlt_field_multitrack( mlt_field this )
 {
-       return this->multitrack;
+       return this != NULL ? this->multitrack : NULL;
 }
 
 /** Get the tractor.
@@ -94,7 +122,7 @@ mlt_multitrack mlt_field_multitrack( mlt_field this )
 
 mlt_tractor mlt_field_tractor( mlt_field this )
 {
-       return this->tractor;
+       return this != NULL ? this->tractor : NULL;
 }
 
 /** Get the properties associated to this field.
@@ -102,7 +130,7 @@ mlt_tractor mlt_field_tractor( mlt_field this )
 
 mlt_properties mlt_field_properties( mlt_field this )
 {
-       return mlt_service_properties( mlt_field_service( this ) );
+       return MLT_SERVICE_PROPERTIES( mlt_field_service( this ) );
 }
 
 /** Plant a filter.
@@ -117,10 +145,13 @@ int mlt_field_plant_filter( mlt_field this, mlt_filter that, int track )
        if ( result == 0 )
        {
                // This is now the new producer
-               this->producer = mlt_filter_service( that );
+               this->producer = MLT_FILTER_SERVICE( that );
 
                // Reconnect tractor to new producer
                mlt_tractor_connect( this->tractor, this->producer );
+
+               // Fire an event
+               mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
        }
 
        return result;
@@ -138,10 +169,13 @@ int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track
        if ( result == 0 )
        {
                // This is now the new producer
-               this->producer = mlt_transition_service( that );
+               this->producer = MLT_TRANSITION_SERVICE( that );
 
                // Reconnect tractor to new producer
                mlt_tractor_connect( this->tractor, this->producer );
+
+               // Fire an event
+               mlt_events_fire( mlt_field_properties( this ), "service-changed", NULL );
        }
 
        return 0;
@@ -152,6 +186,35 @@ int mlt_field_plant_transition( mlt_field this, mlt_transition that, int a_track
 
 void mlt_field_close( mlt_field this )
 {
-       free( this );
+       if ( this != NULL && mlt_properties_dec_ref( mlt_field_properties( this ) ) <= 0 )
+       {
+               //mlt_tractor_close( this->tractor );
+               //mlt_multitrack_close( this->multitrack );
+               free( this );
+       }
 }
 
+void mlt_field_disconnect_service( mlt_field self, mlt_service service )
+{
+       mlt_service p = mlt_service_producer( service );
+       mlt_service c = mlt_service_consumer( service);
+       int i;
+       switch ( mlt_service_identify(c) )
+       {
+               case filter_type:
+                       i = mlt_filter_get_track( MLT_FILTER(c) );
+                       mlt_service_connect_producer( c, p, i );
+                       break;
+               case transition_type:
+                       i = mlt_transition_get_a_track ( MLT_TRANSITION(c) );
+                       mlt_service_connect_producer( c, p, i );
+                       MLT_TRANSITION(c)->producer = p;
+                       break;
+               case tractor_type:
+                       self->producer = p;
+                       mlt_tractor_connect( MLT_TRACTOR(c), p );
+               default:
+                       break;
+       }
+       mlt_events_fire( mlt_field_properties( self ), "service-changed", NULL );
+}