Corrects cuts with filters
[melted] / src / modules / inigo / producer_inigo.c
index 35e84ad..94a63eb 100644 (file)
@@ -77,6 +77,17 @@ static mlt_producer create_producer( mlt_field field, char *file )
        return result;
 }
 
+static mlt_filter create_attach( mlt_field field, char *id, int track )
+{
+       char *arg = strchr( id, ':' );
+       if ( arg != NULL )
+               *arg ++ = '\0';
+       mlt_filter filter = mlt_factory_filter( id, arg );
+       if ( filter != NULL )
+               track_service( field, filter, ( mlt_destructor )mlt_filter_close );
+       return filter;
+}
+
 static mlt_filter create_filter( mlt_field field, char *id, int track )
 {
        char *arg = strchr( id, ':' );
@@ -110,12 +121,15 @@ mlt_producer producer_inigo_init( char **argv )
        int i;
        int track = 0;
        mlt_producer producer = NULL;
+       mlt_tractor mix = NULL;
        mlt_playlist playlist = mlt_playlist_init( );
        mlt_properties group = mlt_properties_new( );
        mlt_properties properties = group;
-       mlt_field field = mlt_field_init( );
+       mlt_tractor tractor = mlt_tractor_new( );
+       mlt_field field = mlt_tractor_field( tractor );
        mlt_properties field_properties = mlt_field_properties( field );
-       mlt_multitrack multitrack = mlt_field_multitrack( field );
+       mlt_multitrack multitrack = mlt_tractor_multitrack( tractor );
+       char *title = NULL;
 
        // We need to track the number of registered filters
        mlt_properties_set_int( field_properties, "registered", 0 );
@@ -133,6 +147,43 @@ mlt_producer producer_inigo_init( char **argv )
                        if ( group != NULL )
                                properties = group;
                }
+               else if ( !strcmp( argv[ i ], "-attach" ) )
+               {
+                       mlt_filter filter = create_attach( field, argv[ ++ i ], track );
+                       if ( filter != NULL )
+                       {
+                               if ( properties != NULL )
+                                       mlt_service_attach( ( mlt_service )properties, filter );
+                               properties = mlt_filter_properties( filter );
+                               mlt_properties_inherit( properties, group );
+                       }
+               }
+               else if ( !strcmp( argv[ i ], "-mix" ) )
+               {
+                       int length = atoi( argv[ ++ i ] );
+                       if ( producer != NULL )
+                               mlt_playlist_append( playlist, producer );
+                       producer = NULL;
+                       if ( mlt_playlist_count( playlist ) >= 2 )
+                       {
+                               if ( mlt_playlist_mix( playlist, mlt_playlist_count( playlist ) - 2, length, NULL ) == 0 )
+                               {
+                                       mlt_playlist_clip_info info;
+                                       mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
+                                       if ( mlt_properties_get_data( ( mlt_properties )info.producer, "mlt_mix", NULL ) == NULL )
+                                               mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 2 );
+                                       mix = ( mlt_tractor )mlt_properties_get_data( ( mlt_properties )info.producer, "mlt_mix", NULL );
+                               }
+                               else
+                               {
+                                       fprintf( stderr, "Mix failed?\n" );
+                               }
+                       }
+                       else
+                       {
+                               fprintf( stderr, "Invalid position for a mix...\n" );
+                       }
+               }
                else if ( !strcmp( argv[ i ], "-filter" ) )
                {
                        mlt_filter filter = create_filter( field, argv[ ++ i ], track );
@@ -151,6 +202,33 @@ mlt_producer producer_inigo_init( char **argv )
                                mlt_properties_inherit( properties, group );
                        }
                }
+               else if ( !strcmp( argv[ i ], "-mixer" ) )
+               {
+                       if ( mix != NULL )
+                       {
+                               char *id = strdup( argv[ ++ i ] );
+                               char *arg = strchr( id, ':' );
+                               mlt_field field = mlt_tractor_field( mix );
+                               mlt_transition transition = NULL;
+                               if ( arg != NULL )
+                                       *arg ++ = '\0';
+                               transition = mlt_factory_transition( id, arg );
+                               if ( transition != NULL )
+                               {
+                                       properties = mlt_transition_properties( transition );
+                                       mlt_properties_inherit( properties, group );
+                                       mlt_field_plant_transition( field, transition, 0, 1 );
+                                       mlt_properties_set_position( properties, "in", 0 );
+                                       mlt_properties_set_position( properties, "out", mlt_producer_get_out( ( mlt_producer )mix ) );
+                                       mlt_transition_close( transition );
+                               }
+                               free( id );
+                       }
+                       else
+                       {
+                               fprintf( stderr, "Invalid mixer...\n" );
+                       }
+               }
                else if ( !strcmp( argv[ i ], "-blank" ) )
                {
                        if ( producer != NULL )
@@ -188,6 +266,8 @@ mlt_producer producer_inigo_init( char **argv )
                {
                        if ( producer != NULL )
                                mlt_playlist_append( playlist, producer );
+                       if ( title == NULL )
+                               title = argv[ i ];
                        producer = create_producer( field, argv[ i ] );
                        if ( producer != NULL )
                        {
@@ -220,15 +300,14 @@ mlt_producer producer_inigo_init( char **argv )
        if ( mlt_playlist_count( playlist ) > 0 )
                mlt_multitrack_connect( multitrack, mlt_playlist_producer( playlist ), track );
 
-       mlt_tractor tractor = mlt_field_tractor( field );
        mlt_producer prod = mlt_tractor_producer( tractor );
        mlt_properties props = mlt_tractor_properties( tractor );
-       mlt_properties_set_data( props, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
-       mlt_properties_set_data( props, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
        mlt_properties_set_data( props, "group", group, 0, ( mlt_destructor )mlt_properties_close, NULL );
        mlt_properties_set_position( props, "length", mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) + 1 );
        mlt_producer_set_in_and_out( prod, 0, mlt_producer_get_out( mlt_multitrack_producer( multitrack ) ) );
        mlt_properties_set_double( props, "fps", mlt_producer_get_fps( mlt_multitrack_producer( multitrack ) ) );
+       if ( title != NULL )
+               mlt_properties_set( props, "title", strchr( title, '/' ) ? strrchr( title, '/' ) + 1 : title );
 
-       return mlt_tractor_producer( tractor );
+       return prod;
 }