<commit_before>/* 
 * jcom.route
 * External for Jamoma: route messages to an outlet if they meet our criteria
 * By <NAME>, Copyright  2005
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "Jamoma.h"

#define MAX_LIST_LENGTH 100

typedef struct _route{				// Data Structure for this object
	t_object		ob;								// REQUIRED: Our object
	void 			*my_outlet[2];					// my outlet array -- NOTE: the attribute dump outlet is handled automagically 

	t_symbol		*searchlist[MAX_LIST_LENGTH];	// ATTRIBUTE: storage of which inlets tigger output from the object (essentially an array of toggles)
	long			searchlistlen;
	long			searchpositions[MAX_LIST_LENGTH];
	long			searchpositionslen;	
//	long			stripmatch;						// ATTRIBUTE: toggle strip_match
	long			partialmatch;
	t_symbol		*searchsymbol;
} t_route;

// Prototypes for our methods:
void *route_new(t_symbol *s, long argc, t_atom *argv);
void route_assist(t_route *x, void *b, long msg, long arg, char *dst);
void route_symbol(t_route *x, t_symbol *msg, long argc, t_atom *argv);
void route_list(t_route *x, t_symbol *msg, long argc, t_atom *argv);
void route_bang(t_route *x);
char find_match(t_route *x, t_symbol *input, short position);

// Globals
t_class		*route_class;				// Required: Global pointer for our class

/************************************************************************************/
// Main() Function

int main(void)				// main recieves a copy of the Max function macros table
{
	long attrflags = 0;
	t_class *c;
	t_object *attr;
	
	jamoma_init();
common_symbols_init();

	// Define our class
	c = class_new("jcom.route",(method)route_new, (method)0L, sizeof(t_route), (method)0L, A_GIMME, 0);

	// Make methods accessible for our class: 
 	class_addmethod(c, (method)route_bang,				"bang", 0L);
  	class_addmethod(c, (method)route_list,				"list", A_GIMME, 0L);	
  	class_addmethod(c, (method)route_symbol,			"anything", A_GIMME, 0L);	
	class_addmethod(c, (method)route_assist,			"assist", A_CANT, 0L); 
    class_addmethod(c, (method)object_obex_dumpout, 	"dumpout", A_CANT,0);

	// ATTRIBUTE: searchstring
	attr = attr_offset_array_new("searchstring", _sym_symbol, MAX_LIST_LENGTH, attrflags, 
		(method)0, (method)0, calcoffset(t_route, searchlistlen), calcoffset(t_route, searchlist));
	class_addattr(c, attr);	

	// ATTRIBUTE: searchpositions
	attr = attr_offset_array_new("searchpositions", _sym_long, MAX_LIST_LENGTH, attrflags, 
		(method)0, (method)0, calcoffset(t_route, searchpositionslen), calcoffset(t_route, searchpositions));
	class_addattr(c, attr);	

	// ATTRIBUTE: partialmatch
	attr = attr_offset_new("partialmatch", _sym_long, attrflags,
		(method)0, (method)0, calcoffset(t_route, partialmatch));
	class_addattr(c, attr);	

	// ATTRIBUTE: stripmatch
//	attr = attr_offset_new("stripmatch", _sym_long, attrflags,
//		(method)0, (method)0, calcoffset(t_route, stripmatch));
//	class_addattr(c, attr);	


	// Finalize our class
	class_register(CLASS_BOX, c);
	route_class = c;
	return 0;
}


/************************************************************************************/
// Object Life

void *route_new(t_symbol *s, long argc, t_atom *argv)
{
	t_route	*x = (t_route *)object_alloc(route_class);
	if(x){
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout
			
		// Create Outlets
		x->my_outlet[1] = outlet_new(x, 0);
		x->my_outlet[0] = outlet_new(x, 0);
			
		// Set defaults before I go loading in values from the attributes
		x->searchlist[0] = gensym("default");
		x->searchlistlen = 1;
		x->searchpositions[0] = 1;
		x->searchpositionslen = 1;	
	//	x->stripmatch = 0;
		x->partialmatch = 0;
		
		attr_args_process(x,argc,argv); //handle attribute args	
	}
	return (x);											// return the pointer to our new instantiation
}


/************************************************************************************/
// Methods bound to input/inlets

// Method for Assistance Messages
void route_assist(t_route *x, void *b, long msg, long arg, char *dst)
{
	if(msg==1) 						// Inlet
		strcpy(dst, "Input");
	else if(msg==2){ 				// Outlets
		switch(arg){
			case 0: strcpy(dst, "Output"); break;
			case 1: strcpy(dst, "Attribute Stuff"); break;
			case 1: strcpy(dst, "Dumpout"); break;
 		}
 	}		
}


// generate a single symbol out of the multiple symbols given in the attribute
void route_bang(t_route *x)
{
	short		i;<commit_msg>giving adequate names to the outputs<commit_after>/* 
 * jcom.route
 * External for Jamoma: route messages to an outlet if they meet our criteria
 * By <NAME>, Copyright  2005
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "Jamoma.h"

#define MAX_LIST_LENGTH 100

typedef struct _route{				// Data Structure for this object
	t_object		ob;								// REQUIRED: Our object
	void 			*my_outlet[2];					// my outlet array -- NOTE: the attribute dump outlet is handled automagically 

	t_symbol		*searchlist[MAX_LIST_LENGTH];	// ATTRIBUTE: storage of which inlets tigger output from the object (essentially an array of toggles)
	long			searchlistlen;
	long			searchpositions[MAX_LIST_LENGTH];
	long			searchpositionslen;	
//	long			stripmatch;						// ATTRIBUTE: toggle strip_match
	long			partialmatch;
	t_symbol		*searchsymbol;
} t_route;

// Prototypes for our methods:
void *route_new(t_symbol *s, long argc, t_atom *argv);
void route_assist(t_route *x, void *b, long msg, long arg, char *dst);
void route_symbol(t_route *x, t_symbol *msg, long argc, t_atom *argv);
void route_list(t_route *x, t_symbol *msg, long argc, t_atom *argv);
void route_bang(t_route *x);
char find_match(t_route *x, t_symbol *input, short position);

// Globals
t_class		*route_class;				// Required: Global pointer for our class

/************************************************************************************/
// Main() Function

int main(void)				// main recieves a copy of the Max function macros table
{
	long attrflags = 0;
	t_class *c;
	t_object *attr;
	
	jamoma_init();
common_symbols_init();

	// Define our class
	c = class_new("jcom.route",(method)route_new, (method)0L, sizeof(t_route), (method)0L, A_GIMME, 0);

	// Make methods accessible for our class: 
 	class_addmethod(c, (method)route_bang,				"bang", 0L);
  	class_addmethod(c, (method)route_list,				"list", A_GIMME, 0L);	
  	class_addmethod(c, (method)route_symbol,			"anything", A_GIMME, 0L);	
	class_addmethod(c, (method)route_assist,			"assist", A_CANT, 0L); 
    class_addmethod(c, (method)object_obex_dumpout, 	"dumpout", A_CANT,0);

	// ATTRIBUTE: searchstring
	attr = attr_offset_array_new("searchstring", _sym_symbol, MAX_LIST_LENGTH, attrflags, 
		(method)0, (method)0, calcoffset(t_route, searchlistlen), calcoffset(t_route, searchlist));
	class_addattr(c, attr);	

	// ATTRIBUTE: searchpositions
	attr = attr_offset_array_new("searchpositions", _sym_long, MAX_LIST_LENGTH, attrflags, 
		(method)0, (method)0, calcoffset(t_route, searchpositionslen), calcoffset(t_route, searchpositions));
	class_addattr(c, attr);	

	// ATTRIBUTE: partialmatch
	attr = attr_offset_new("partialmatch", _sym_long, attrflags,
		(method)0, (method)0, calcoffset(t_route, partialmatch));
	class_addattr(c, attr);	

	// ATTRIBUTE: stripmatch
//	attr = attr_offset_new("stripmatch", _sym_long, attrflags,
//		(method)0, (method)0, calcoffset(t_route, stripmatch));
//	class_addattr(c, attr);	


	// Finalize our class
	class_register(CLASS_BOX, c);
	route_class = c;
	return 0;
}


/************************************************************************************/
// Object Life

void *route_new(t_symbol *s, long argc, t_atom *argv)
{
	t_route	*x = (t_route *)object_alloc(route_class);
	if(x){
		object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout
			
		// Create Outlets
		x->my_outlet[1] = outlet_new(x, 0);
		x->my_outlet[0] = outlet_new(x, 0);
			
		// Set defaults before I go loading in values from the attributes
		x->searchlist[0] = gensym("default");
		x->searchlistlen = 1;
		x->searchpositions[0] = 1;
		x->searchpositionslen = 1;	
	//	x->stripmatch = 0;
		x->partialmatch = 0;
		
		attr_args_process(x,argc,argv); //handle attribute args	
	}
	return (x);											// return the pointer to our new instantiation
}


/************************************************************************************/
// Methods bound to input/inlets

// Method for Assistance Messages
void route_assist(t_route *x, void *b, long msg, long arg, char *dst)
{
	if(msg==1) 						// Inlet
		strcpy(dst, "Input");
	else if(msg==2){ 				// Outlets
		switch(arg){
			case 0: strcpy(dst, "Matching Output"); break;
			case 1: strcpy(dst, "Unmatching Output"); break;
			case 2: strcpy(dst, "Dumpout"); break;
 		}
 	}		
}


// generate a single symbol out of the multiple symbols given in the attribute
void route_bang(t_route *x)
{
	short		i;
{'fraction_non_alphanumeric': 0.17728593784931812, 'fraction_numerical': 0.009389671361502348, 'mean_word_length': 4.539938080495356, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5537815', 'n_tokens_mistral': 3466, 'n_tokens_neox': 3154, 'n_words': 815}