X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_multitrack.c;h=6c24400f243993175a9c42b76ae8c66e3d9fd9c8;hb=ad829dbc7677a2acc063635db14ce717eb40be50;hp=59b2383227cf3fa2061eb3cc8124368c3dd695e2;hpb=1d46befd8150131541aa98e93573d5d6e54e9c3a;p=melted diff --git a/src/framework/mlt_multitrack.c b/src/framework/mlt_multitrack.c index 59b2383..6c24400 100644 --- a/src/framework/mlt_multitrack.c +++ b/src/framework/mlt_multitrack.c @@ -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", "" ); } else { @@ -126,7 +127,8 @@ void mlt_multitrack_refresh( mlt_multitrack this ) mlt_properties_set( mlt_producer_properties( producer ), "eof", "continue" ); // Determine the longest length - length = mlt_producer_get_playtime( producer ) > length ? mlt_producer_get_playtime( producer ) : length; + if ( !mlt_properties_get_int( mlt_producer_properties( producer ), "hide" ) ) + length = mlt_producer_get_playtime( producer ) > length ? mlt_producer_get_playtime( producer ) : length; // Handle fps if ( fps == 0 ) @@ -188,6 +190,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,17 +249,18 @@ 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 mlt_producer producer = this->list[ i ]; - // If it's assigned... + // If it's assigned and not a hidden track if ( producer != NULL ) { // Get the properties of this producer @@ -229,35 +269,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; } @@ -308,9 +372,10 @@ 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 ); + mlt_properties_set_int( properties, "hide", mlt_properties_get_int( mlt_producer_properties( producer ), "hide" ) ); } else { @@ -331,7 +396,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;