<commit_before>/*
 * producer_inigo.c -- simple inigo test case
 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "producer_inigo.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <framework/mlt.h>

mlt_producer producer_inigo_file_init( char *file )
{
	FILE *input = fopen( file, "r" );
	char **args = calloc( sizeof( char * ), 1000 );
	int count = 0;
	char temp[ 2048 ];

	if ( input != NULL )
	{
		while( fgets( temp, 2048, input ) )
		{
			temp[ strlen( temp ) - 1 ] = '\0';
			if ( strcmp( temp, "" ) )
				args[ count ++ ] = strdup( temp );
		}
	}

	mlt_producer result = producer_inigo_init( args );

	if ( result != NULL )
	{
		mlt_properties properties = mlt_producer_properties( result );
		mlt_properties_set( properties, "resource", file );
	}

	while( count -- )
		free( args[ count ] );
	free( args );

	return result;
}

static void track_service( mlt_field field, void *service, mlt_destructor destructor )
{
	mlt_properties properties = mlt_field_properties( field );
	int registered = mlt_properties_get_int( properties, "registered" );
	char *key = mlt_properties_get( properties, "registered" );
	mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
	mlt_properties_set_int( properties, "registered", ++ registered );
}

static mlt_producer create_producer( mlt_field field, char *file )
{
	mlt_producer result = mlt_factory_producer( "fezzik", file );

	if ( result != NULL )
		track_service( field, result, ( mlt_destructor )mlt_producer_close );

	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, ':' );
	if ( arg != NULL )
		*arg ++ = '\0';
	mlt_filter filter = mlt_factory_filter( id, arg );
	if ( filter != NULL )
	{
		mlt_field_plant_filter( field, filter, track );
		track_service( field, filter, ( mlt_destructor )mlt_filter_close );
	}
	return filter;
}

static mlt_transition create_transition( mlt_field field, char *id, int track )
{
	char *arg = strchr( id, ':' );
	if ( arg != NULL )
		*arg ++ = '\0';
	mlt_transition transition = mlt_factory_transition( id, arg );
	if ( transition != NULL )
	{
		mlt_field_plant_transition( field, transition, track, track + 1 );
		track_service( field, transition, ( mlt_destructor )mlt_transition_close );
	}
	return transition;
}

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_tractor tractor = mlt_tractor_new( );
	mlt_field field = mlt_tractor_field( tractor );
	mlt_properties field_properties = mlt_field_properties( 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 );

	// Parse the arguments
	for ( i = 0; argv[ i ] != NULL; i ++ )
	{
		if ( !strcmp( argv[ i ], "-group" ) )
		{
			if ( mlt_properties_count( group ) != 0 )
			{
				mlt_properties_close( group );
				group = mlt_properties_new( );
			}
			if ( group != NULL )
				properties = group;
		}
		else if ( !strcmp( argv[ i ], "-attach" ) || !strcmp( argv[ i ], "-attach-cut" ) )
		{
			int type = !strcmp( argv[ i ], "-attach" ) ? 0 : 1;
			mlt_filter filter = create_attach( field, argv[ ++ i ], track );
			if ( producer != NULL && !mlt_producer_is_cut( producer ) )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_append( playlist, producer );
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				producer = info.cut;
			}

			if ( type == 1 )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				producer = info.cut;
			}

			if ( filter != NULL && mlt_playlist_count( playlist ) > 0 )
			{
				if ( type == 0 )
					mlt_service_attach( ( mlt_service )properties, filter );
				else
					mlt_service_attach( ( mlt_service )producer, filter );

				properties = mlt_filter_properties( filter );
				mlt_properties_inherit( properties, group );
			}
		}
		else if ( !strcmp( argv[ i ], "-repeat" ) )
		{
			int repeat = atoi( argv[ ++ i ] );
			if ( producer != NULL && !mlt_producer_is_cut( producer ) )
				mlt_playlist_append( playlist, producer );
			producer = NULL;
			if ( mlt_playlist_count( playlist ) > 0 )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_repeat_clip( playlist, mlt_playlist_count( playlist ) - 1, repeat );
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				producer = info.cut;
				properties = mlt_producer_properties( producer );
			}
		}
		else if ( !strcmp( argv[ i ], "-split" ) )
		{
			int split = atoi( argv[ ++ i ] );
			if ( producer != NULL && !mlt_producer_is_cut( producer ) )
				mlt_playlist_append( playlist, producer );
			producer = NULL;
			if ( mlt_playlist_count( playlist ) > 0 )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				split = split < 0 ? info.frame_out + split : split;<commit_msg>Allow filter attachment to clip<commit_after>/*
 * producer_inigo.c -- simple inigo test case
 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "producer_inigo.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <framework/mlt.h>

mlt_producer producer_inigo_file_init( char *file )
{
	FILE *input = fopen( file, "r" );
	char **args = calloc( sizeof( char * ), 1000 );
	int count = 0;
	char temp[ 2048 ];

	if ( input != NULL )
	{
		while( fgets( temp, 2048, input ) )
		{
			temp[ strlen( temp ) - 1 ] = '\0';
			if ( strcmp( temp, "" ) )
				args[ count ++ ] = strdup( temp );
		}
	}

	mlt_producer result = producer_inigo_init( args );

	if ( result != NULL )
	{
		mlt_properties properties = mlt_producer_properties( result );
		mlt_properties_set( properties, "resource", file );
	}

	while( count -- )
		free( args[ count ] );
	free( args );

	return result;
}

static void track_service( mlt_field field, void *service, mlt_destructor destructor )
{
	mlt_properties properties = mlt_field_properties( field );
	int registered = mlt_properties_get_int( properties, "registered" );
	char *key = mlt_properties_get( properties, "registered" );
	mlt_properties_set_data( properties, key, service, 0, destructor, NULL );
	mlt_properties_set_int( properties, "registered", ++ registered );
}

static mlt_producer create_producer( mlt_field field, char *file )
{
	mlt_producer result = mlt_factory_producer( "fezzik", file );

	if ( result != NULL )
		track_service( field, result, ( mlt_destructor )mlt_producer_close );

	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, ':' );
	if ( arg != NULL )
		*arg ++ = '\0';
	mlt_filter filter = mlt_factory_filter( id, arg );
	if ( filter != NULL )
	{
		mlt_field_plant_filter( field, filter, track );
		track_service( field, filter, ( mlt_destructor )mlt_filter_close );
	}
	return filter;
}

static mlt_transition create_transition( mlt_field field, char *id, int track )
{
	char *arg = strchr( id, ':' );
	if ( arg != NULL )
		*arg ++ = '\0';
	mlt_transition transition = mlt_factory_transition( id, arg );
	if ( transition != NULL )
	{
		mlt_field_plant_transition( field, transition, track, track + 1 );
		track_service( field, transition, ( mlt_destructor )mlt_transition_close );
	}
	return transition;
}

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_tractor tractor = mlt_tractor_new( );
	mlt_field field = mlt_tractor_field( tractor );
	mlt_properties field_properties = mlt_field_properties( 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 );

	// Parse the arguments
	for ( i = 0; argv[ i ] != NULL; i ++ )
	{
		if ( !strcmp( argv[ i ], "-group" ) )
		{
			if ( mlt_properties_count( group ) != 0 )
			{
				mlt_properties_close( group );
				group = mlt_properties_new( );
			}
			if ( group != NULL )
				properties = group;
		}
		else if ( !strcmp( argv[ i ], "-attach" ) || 
				  !strcmp( argv[ i ], "-attach-cut" ) ||
				  !strcmp( argv[ i ], "-attach-clip" ) )
		{
			int type = !strcmp( argv[ i ], "-attach" ) ? 0 : 
					   !strcmp( argv[ i ], "-attach-cut" ) ? 1 : 
					   2;
			mlt_filter filter = create_attach( field, argv[ ++ i ], track );
			if ( producer != NULL && !mlt_producer_is_cut( producer ) )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_append( playlist, producer );
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				producer = info.cut;
			}

			if ( type == 1 || type == 2 )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				producer = info.cut;
			}

			if ( filter != NULL && mlt_playlist_count( playlist ) > 0 )
			{
				if ( type == 0 )
					mlt_service_attach( ( mlt_service )properties, filter );
				else if ( type == 1 )
					mlt_service_attach( ( mlt_service )producer, filter );
				else if ( type == 2 )
					mlt_service_attach( ( mlt_service )mlt_producer_cut_parent( producer ), filter );

				properties = mlt_filter_properties( filter );
				mlt_properties_inherit( properties, group );
			}
		}
		else if ( !strcmp( argv[ i ], "-repeat" ) )
		{
			int repeat = atoi( argv[ ++ i ] );
			if ( producer != NULL && !mlt_producer_is_cut( producer ) )
				mlt_playlist_append( playlist, producer );
			producer = NULL;
			if ( mlt_playlist_count( playlist ) > 0 )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_repeat_clip( playlist, mlt_playlist_count( playlist ) - 1, repeat );
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				producer = info.cut;
				properties = mlt_producer_properties( producer );
			}
		}
		else if ( !strcmp( argv[ i ], "-split" ) )
		{
			int split = atoi( argv[ ++ i ] );
			if ( producer != NULL && !mlt_producer_is_cut( producer ) )
				mlt_playlist_append( playlist, producer );
			producer = NULL;
			if ( mlt_playlist_count( playlist ) > 0 )
			{
				mlt_playlist_clip_info info;
				mlt_playlist_get_clip_info( playlist, &info, mlt_playlist_count( playlist ) - 1 );
				split = split < 0 ? info.frame_out + split : split;
{'fraction_non_alphanumeric': 0.12062801181408363, 'fraction_numerical': 0.009637805067620084, 'mean_word_length': 3.709736456808199, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204229', 'n_tokens_mistral': 4940, 'n_tokens_neox': 4440, 'n_words': 1254}