]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_multitrack.c
transition region
[mlt] / src / framework / mlt_multitrack.c
index 47bc271d1e421a4d7ff4ba4b3f46ba2897b0b3ed..323d1ee9e3da4ac5807bc053646a6b3e600f4eb4 100644 (file)
@@ -61,6 +61,7 @@ mlt_multitrack mlt_multitrack_init( )
                        producer->get_frame = producer_get_frame;
                        mlt_properties_set_data( properties, "multitrack", this, 0, NULL, NULL );
                        mlt_properties_set( properties, "log_id", "multitrack" );
+                       mlt_properties_set( properties, "resource", "<multitrack>" );
                }
                else
                {
@@ -147,7 +148,7 @@ void mlt_multitrack_refresh( mlt_multitrack this )
 
        // Update multitrack properties now - we'll not destroy the in point here
        mlt_properties_set_position( properties, "length", length );
-       mlt_properties_set_position( properties, "out", length );
+       mlt_properties_set_position( properties, "out", length - 1 );
        mlt_properties_set_double( properties, "fps", fps );
 }
 
@@ -188,6 +189,43 @@ int mlt_multitrack_connect( mlt_multitrack this, mlt_producer producer, int trac
        return result;
 }
 
+/** Get the number of tracks.
+*/
+
+int mlt_multitrack_count( mlt_multitrack this )
+{
+       return this->count;     
+}
+
+/** Get an individual track as a producer.
+*/
+
+mlt_producer mlt_multitrack_track( mlt_multitrack this, int track )
+{
+       mlt_producer producer = NULL;
+       
+       if ( this->list != NULL && track < this->count )
+               producer = this->list[ track ];
+
+       return producer;
+}
+
+static int position_compare( const void *p1, const void *p2 )
+{
+       return *( mlt_position * )p1 - *( mlt_position * )p2;
+}
+
+static int add_unique( mlt_position *array, int size, mlt_position position )
+{
+       int i = 0;
+       for ( i = 0; i < size; i ++ )
+               if ( array[ i ] == position )
+                       break;
+       if ( i == size )
+               array[ size ++ ] = position;
+       return size;
+}
+
 /** Determine the clip point.
 
        Special case here: a 'producer' has no concept of multiple clips - only the 
@@ -210,11 +248,12 @@ int mlt_multitrack_connect( mlt_multitrack this, mlt_producer producer, int trac
 
 mlt_position mlt_multitrack_clip( mlt_multitrack this, mlt_whence whence, int index )
 {
-       int first = 1;
        mlt_position position = 0;
        int i = 0;
+       int j = 0;
+       mlt_position *map = malloc( 1000 * sizeof( mlt_position ) );
+       int count = 0;
 
-       // Loop through each of the tracks
        for ( i = 0; i < this->count; i ++ )
        {
                // Get the producer for this track
@@ -229,35 +268,59 @@ mlt_position mlt_multitrack_clip( mlt_multitrack this, mlt_whence whence, int in
                        // Determine if it's a playlist
                        mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
 
-                       // We only consider playlists
+                       // Special case consideration of playlists
                        if ( playlist != NULL )
                        {
-                               // Locate the smallest position
-                               if ( first )
-                               {
-                                       // First position found
-                                       position = mlt_playlist_clip( playlist, whence, index );
-       
-                                       // We're no longer first
-                                       first = 0;
-                               }
-                               else
-                               {
-                                       // Obtain the clip position in this playlist
-                                       //mlt_position position2 = mlt_playlist_clip( playlist, whence, index );
-
-                                       // If this position is prior to the first, then use it
-                                       //if ( position2 < position )
-                                               //position = position2;
-                               }
+                               for ( j = 0; j < mlt_playlist_count( playlist ); j ++ )
+                                       count = add_unique( map, count, mlt_playlist_clip( playlist, mlt_whence_relative_start, j ) );
+                               count = add_unique( map, count, mlt_producer_get_out( producer ) + 1 );
                        }
                        else
                        {
-                               fprintf( stderr, "track %d isn't a playlist\n", index );
+                               count = add_unique( map, count, 0 );
+                               count = add_unique( map, count, mlt_producer_get_out( producer ) + 1 );
                        }
                }
        }
 
+       // Now sort the map
+       qsort( map, count, sizeof( mlt_position ), position_compare );
+
+       // Now locate the requested index
+       switch( whence )
+       {
+               case mlt_whence_relative_start:
+                       if ( index < count )
+                               position = map[ index ];
+                       else
+                               position = map[ count - 1 ];
+                       break;
+
+               case mlt_whence_relative_current:
+                       position = mlt_producer_position( mlt_multitrack_producer( this ) );
+                       for ( i = 0; i < count - 2; i ++ ) 
+                               if ( position >= map[ i ] && position < map[ i + 1 ] )
+                                       break;
+                       index += i;
+                       if ( index >= 0 && index < count )
+                               position = map[ index ];
+                       else if ( index < 0 )
+                               position = map[ 0 ];
+                       else
+                               position = map[ count - 1 ];
+                       break;
+
+               case mlt_whence_relative_end:
+                       if ( index < count )
+                               position = map[ count - index - 1 ];
+                       else
+                               position = map[ 0 ];
+                       break;
+       }
+
+       // Free the map
+       free( map );
+
        return position;
 }
 
@@ -298,7 +361,7 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int ind
                mlt_producer producer = this->list[ index ];
 
                // Obtain the current position
-               uint64_t position = mlt_producer_frame( parent );
+               mlt_position position = mlt_producer_frame( parent );
 
                // Make sure we're at the same point
                mlt_producer_seek( producer, position );
@@ -308,9 +371,9 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int ind
 
                // Indicate speed of this producer
                mlt_properties producer_properties = mlt_producer_properties( parent );
-               double speed = mlt_properties_get_double( producer_properties, "speed" );
+               double speed = mlt_properties_get_double( producer_properties, "_speed" );
                mlt_properties properties = mlt_frame_properties( *frame );
-               mlt_properties_set_double( properties, "speed", speed );
+               mlt_properties_set_double( properties, "_speed", speed );
        }
        else
        {
@@ -331,7 +394,7 @@ static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int ind
                }
 
                // Refresh our stats
-               mlt_multitrack_refresh( this );
+               //mlt_multitrack_refresh( this );
        }
 
        return 0;