+/** Determine the clip point.
+ *
+ * <pre>
+ * Special case here: a 'producer' has no concept of multiple clips - only the
+ * playlist and multitrack producers have clip functionality. Further to that a
+ * multitrack determines clip information from any connected tracks that happen
+ * to be playlists.
+ *
+ * Additionally, it must locate clips in the correct order, for example, consider
+ * the following track arrangement:
+ *
+ * playlist1 |0.0 |b0.0 |0.1 |0.1 |0.2 |
+ * playlist2 |b1.0 |1.0 |b1.1 |1.1 |
+ *
+ * Note - b clips represent blanks. They are also reported as clip positions.
+ *
+ * When extracting clip positions from these playlists, we should get a sequence of:
+ *
+ * 0.0, 1.0, b0.0, 0.1, b1.1, 1.1, 0.1, 0.2, [out of playlist2], [out of playlist1]
+ * </pre>
+ *
+ * \public \memberof mlt_multitrack_s
+ * \param this a multitrack
+ * \param whence from where to extract
+ * \param index the 0-based index of which clip to extract
+ * \return the position of clip \p index relative to \p whence
+ */
+
+mlt_position mlt_multitrack_clip( mlt_multitrack this, mlt_whence whence, int index )
+{
+ mlt_position position = 0;
+ int i = 0;
+ int j = 0;
+ mlt_position *map = malloc( 1000 * sizeof( mlt_position ) );
+ int count = 0;
+
+ for ( i = 0; i < this->count; i ++ )
+ {
+ // Get the producer for this track
+ mlt_producer producer = this->list[ i ]->producer;
+
+ // If it's assigned and not a hidden track
+ if ( producer != NULL )
+ {
+ // Get the properties of this producer
+ mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
+
+ // Determine if it's a playlist
+ mlt_playlist playlist = mlt_properties_get_data( properties, "playlist", NULL );
+
+ // Special case consideration of playlists
+ if ( playlist != NULL )
+ {
+ 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
+ {
+ 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;
+}
+
+/** Get frame method.
+ *
+ * <pre>
+ * Special case here: The multitrack must be used in a conjunction with a downstream
+ * tractor-type service, ie:
+ *
+ * Producer1 \
+ * Producer2 - multitrack - { filters/transitions } - tractor - consumer
+ * Producer3 /
+ *
+ * The get_frame of a tractor pulls frames from it's connected service on all tracks and
+ * will terminate as soon as it receives a test card with a last_track property. The
+ * important case here is that the mulitrack does not move to the next frame until all
+ * tracks have been pulled.
+ *
+ * Reasoning: In order to seek on a network such as above, the multitrack needs to ensure
+ * that all producers are positioned on the same frame. It uses the 'last track' logic
+ * to determine when to move to the next frame.
+ *
+ * Flaw: if a transition is configured to read from a b-track which happens to trigger
+ * the last frame logic (ie: it's configured incorrectly), then things are going to go
+ * out of sync.
+ *
+ * See playlist logic too.
+ * </pre>
+ *
+ * \private \memberof mlt_multitrack_s
+ * \param parent the producer interface to a mulitrack
+ * \param[out] frame a frame by reference
+ * \param index the 0-based track index
+ * \return true if there was an error
+ */