+/** Get the number of tracks.
+ *
+ * \public \memberof mlt_multitrack_s
+ * \param self a multitrack
+ * \return the number of tracks
+ */
+
+int mlt_multitrack_count( mlt_multitrack self )
+{
+ return self->count;
+}
+
+/** Get an individual track as a producer.
+ *
+ * \public \memberof mlt_multitrack_s
+ * \param self a multitrack
+ * \param track the 0-based index of the producer to get
+ * \return the producer or NULL if not valid
+ */
+
+mlt_producer mlt_multitrack_track( mlt_multitrack self, int track )
+{
+ mlt_producer producer = NULL;
+
+ if ( self->list != NULL && track < self->count )
+ producer = self->list[ track ]->producer;
+
+ return producer;
+}
+
+/** Position comparison function for sorting.
+ *
+ * \private \memberof mlt_multitrack_s
+ * \param p1 a position
+ * \param p2 another position
+ * \return <0 if \p p1 is less than \p p2, 0 if equal, >0 if greater
+ */
+
+static int position_compare( const void *p1, const void *p2 )
+{
+ return *( const mlt_position * )p1 - *( const mlt_position * )p2;
+}
+
+/** Add a position to a set.
+ *
+ * \private \memberof mlt_multitrack_s
+ * \param array an array of positions (the set)
+ * \param size the current number of positions in the array (not the capacity of the array)
+ * \param position the position to add
+ * \return the new size of the array
+ */
+
+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.
+ *
+ * <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 self 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 self, mlt_whence whence, int index )
+{
+ mlt_position position = 0;
+ int i = 0;
+ int j = 0;
+ mlt_position *map = calloc( 1000, sizeof( mlt_position ) );
+ int count = 0;