<commit_before>/* 
 * jcom.ramp
 * External for Jamoma: ramp values using Jamoma's RampLib library
 * By <NAME>, Copyright � 2006
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "Jamoma.h"

enum outlets {
	k_outlet_value = 0,
	k_outlet_dumpout,
	num_outlets
};


/** The Ramp. jcom.ramp can be considered an extended object comapred to of a line object.
  * It use the RampLib to drive values in different ways, as well as the Function Lib to
  * do the ramp to new values according to an extendable set of functions.  */
typedef struct _ramp {
	t_object	 ob;					///< Data Structure for this object
	void		*outlets[num_outlets];	///< Outlet array
	t_symbol	*attr_rampunit;			///< Attribute: Name of the current rampunit
	t_symbol	*attr_function;			///< Attribute: Name of the current function
	RampUnit	*rampUnit;				///< Instance of the current rampunit
	TTHashPtr	parameterNames;			// cache of parameter names, mapped from lowercase (Max) to uppercase (TT)
} t_ramp;


// Prototypes

/** The jcom.ramp constructor */
void*		ramp_new(t_symbol *s, long argc, t_atom *argv);

/** The ramp deconstructor, free's any memory used by the object */
void		ramp_free(t_ramp *x);

/** Method for Assistance Messages */
void		ramp_assist(t_ramp *x, void *b, long msg, long arg, char *dst);

/** Set what mechanism (RampUnit) is used to drive the ramp. */
t_max_err 	ramp_setrampunit(t_ramp *x, void *attr, long argc, t_atom *argv);

/** Set the function to use when ramping. */
void		ramp_setFunction(t_ramp *x, void *attr, long argc, t_atom *argv);

/** Get the function currently used when ramping. */
void		ramp_getFunction(t_ramp *x);

/** Get value of an additional parameter used for the function. */
void		ramp_getFunctionParameter(t_ramp *obj, t_symbol *msg, long argc, t_atom *argv);

/** Set additional parameters for the function currently used. */
void		ramp_setFunctionParameter(t_ramp *obj, t_symbol *msg, long argc, t_atom *argv);

/** Connect to a setclock object. */
void		ramp_clock(t_ramp *x, t_symbol *clockName);

/** Get a new value now. */
void		ramp_bang(t_ramp *x);

/** Method for int input, instantly updates current value of the object. */
void		ramp_int(t_ramp *x, long n);

/** Method for float input, instantly updates current value of the object. */ 
void		ramp_float(t_ramp *x, double f);

/** Set current value while surpressing new value(s from being output. */
void		ramp_set(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);

/** Stop ongoing ramp */
void ramp_stop(t_ramp *x);

/** Method for list input <value(s), "ramp", ramptime> */
void		ramp_list(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);

/** Triggered by our Ramp Unit's tick function */
void		ramp_callback(void *v, long numvalues, double *values);

/** Set attribute value. */
void 		ramp_attrset(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);

/** Get attribute value. */
void 		ramp_attrget(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);


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


/************************************************************************************/
// Class Definition

int JAMOMA_EXPORT_MAXOBJ main(void)
{
	t_class *c;
	
	jamoma_init();
	common_symbols_init();

	// Define our class
	c = class_new("jcom.ramp",(method)ramp_new, (method)ramp_free, sizeof(t_ramp), (method)0L, A_GIMME, 0);
	
	// Make methods accessible for our class:
	class_addmethod(c, (method)ramp_bang,					"bang",					0);
	class_addmethod(c, (method)ramp_int,					"int",					A_DEFLONG,	0);
	class_addmethod(c, (method)ramp_float,					"float",				A_DEFFLOAT,	0);
 	class_addmethod(c, (method)ramp_list,					"list",					A_GIMME,	0);
	class_addmethod(c, (method)ramp_set,					"set",					A_GIMME,	0);
	class_addmethod(c, (method)ramp_stop,					"stop",					0);
	class_addmethod(c, (method)ramp_attrset,				"attrset",				A_GIMME, 	0);
	class_addmethod(c, (method)ramp_attrget,				"attrget",				A_GIMME,	0);
	class_addmethod(c, (method)ramp_setFunction,			"function",				A_SYM,		0);
	class_addmethod(c, (method)ramp_getFunctionParameter,	"function.parameter.get",	A_GIMME,	0);
	class_addmethod(c, (method)ramp_setFunctionParameter,	"function.parameter",	A_GIMME,	0);
	class_addmethod(c, (method)ramp_clock,					"clock",				A_SYM,		0);
	class_addmethod(c, (method)ramp_assist,					"assist",				A_CANT,		0); 
    class_addmethod(c, (method)object_obex_dumpout,			"dumpout",				A_CANT,		0);

	// ATTRIBUTE: rampunit
	class_addattr(c, 
		attr_offset_new("drive", _sym_symbol, 0,
		(method)0, (method)ramp_setrampunit, calcoffset(t_ramp, attr_rampunit)));
	
	// ATTRIBUTE: function
	class_addattr(c, 
		attr_offset_new("function", _sym_symbol, 0,
		(method)0, (method)ramp_setFunction, calcoffset(t_ramp, attr_function)));	

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


#pragma mark -
#pragma mark life cycle
/************************************************************************************/
// Object Life

void *ramp_new(t_symbol *s, long argc, t_atom *argv)
{
	t_ramp	*x = (t_ramp *)object_alloc(ramp_class);
	t_atom	a;

	if (x) {
		x->outlets[k_outlet_dumpout] = outlet_new(x, 0L);
		x->outlets[k_outlet_value]   = outlet_new(x, 0L);
		object_obex_store((void *)x, _sym_dumpout, (t_object *)x->outlets[k_outlet_dumpout]);
		x->parameterNames = new TTHash;

		x->rampUnit = NULL;
		x->attr_rampunit = _sym_nothing;
		x->attr_function = _sym_nothing;
		attr_args_process(x, argc, argv);	// handle attribute args

		if (x->attr_rampunit == _sym_nothing) {
			atom_setsym(&a, gensym("scheduler"));
			object_attr_setvalueof(x, gensym("drive"), 1, &a);
		}
		if (x->attr_function == _sym_nothing) {
			atom_setsym(&a, gensym("linear"));
			object_attr_setvalueof(x, gensym("function"), 1, &a);
		}
	}
	return (x);		// return the pointer to our new instantiation
}


void ramp_free(t_ramp *x)
{
	delete x->rampUnit;
	delete x->parameterNames;
}


#pragma mark -
#pragma mark methods
/************************************************************************************/
// Methods bound to input/inlets
<commit_msg>Trying to copy code across from jcom.parameter. Still crashes, but I have a hunch about why<commit_after>/* 
 * jcom.ramp
 * External for Jamoma: ramp values using Jamoma's RampLib library
 * By <NAME>, Copyright � 2006
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "Jamoma.h"

enum outlets {
	k_outlet_value = 0,
	k_outlet_dumpout,
	num_outlets
};


/** The Ramp. jcom.ramp can be considered an extended object comapred to of a line object.
  * It use the RampLib to drive values in different ways, as well as the Function Lib to
  * do the ramp to new values according to an extendable set of functions.  */
typedef struct _ramp {
	t_object	 ob;					///< Data Structure for this object
	void		*outlets[num_outlets];	///< Outlet array
	t_symbol	*attr_rampunit;			///< Attribute: Name of the current rampunit
	t_symbol	*attr_function;			///< Attribute: Name of the current function
	RampUnit	*rampUnit;				///< Instance of the current rampunit
	TTHashPtr	parameterNames;			// cache of parameter names, mapped from lowercase (Max) to uppercase (TT)
} t_ramp;


// Prototypes

/** The jcom.ramp constructor */
void*		ramp_new(t_symbol *s, long argc, t_atom *argv);

/** The ramp deconstructor, free's any memory used by the object */
void		ramp_free(t_ramp *x);

/** Method for Assistance Messages */
void		ramp_assist(t_ramp *x, void *b, long msg, long arg, char *dst);

/** Set what mechanism (RampUnit) is used to drive the ramp. */
t_max_err 	ramp_setrampunit(t_ramp *x, void *attr, long argc, t_atom *argv);

/** Set the function to use when ramping. */
void		ramp_setFunction(t_ramp *x, void *attr, long argc, t_atom *argv);

/** Get the function currently used when ramping. */
void		ramp_getFunction(t_ramp *x);

/** Get value of an additional parameter used for the function. */
void		ramp_getFunctionParameter(t_ramp *obj, t_symbol *msg, long argc, t_atom *argv);

/** Set additional parameters for the function currently used. */
void		ramp_setFunctionParameter(t_ramp *obj, t_symbol *msg, long argc, t_atom *argv);

/** Connect to a setclock object. */
void		ramp_clock(t_ramp *x, t_symbol *clockName);

/** Get a new value now. */
void		ramp_bang(t_ramp *x);

/** Method for int input, instantly updates current value of the object. */
void		ramp_int(t_ramp *x, long n);

/** Method for float input, instantly updates current value of the object. */ 
void		ramp_float(t_ramp *x, double f);

/** Set current value while surpressing new value(s from being output. */
void		ramp_set(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);

/** Stop ongoing ramp */
void ramp_stop(t_ramp *x);

/** Method for list input <value(s), "ramp", ramptime> */
void		ramp_list(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);

/** Triggered by our Ramp Unit's tick function */
void		ramp_callback(void *v, long numvalues, double *values);

/** Set attribute value. */
void 		ramp_attrset(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);

/** Get attribute value. */
void 		ramp_attrget(t_ramp *x, t_symbol *msg, long argc, t_atom *argv);


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


/************************************************************************************/
// Class Definition

int JAMOMA_EXPORT_MAXOBJ main(void)
{
	t_class *c;
	
	jamoma_init();
	common_symbols_init();

	// Define our class
	c = class_new("jcom.ramp",(method)ramp_new, (method)ramp_free, sizeof(t_ramp), (method)0L, A_GIMME, 0);
	
	// Make methods accessible for our class:
	class_addmethod(c, (method)ramp_bang,					"bang",					0);
	class_addmethod(c, (method)ramp_int,					"int",					A_DEFLONG,	0);
	class_addmethod(c, (method)ramp_float,					"float",				A_DEFFLOAT,	0);
 	class_addmethod(c, (method)ramp_list,					"list",					A_GIMME,	0);
	class_addmethod(c, (method)ramp_set,					"set",					A_GIMME,	0);
	class_addmethod(c, (method)ramp_stop,					"stop",					0);
	class_addmethod(c, (method)ramp_attrset,				"attrset",				A_GIMME, 	0);
	class_addmethod(c, (method)ramp_attrget,				"attrget",				A_GIMME,	0);
	class_addmethod(c, (method)ramp_setFunction,			"function",				A_SYM,		0);
	class_addmethod(c, (method)ramp_getFunctionParameter,	"function.parameter.get",	A_GIMME,	0);
	class_addmethod(c, (method)ramp_setFunctionParameter,	"function.parameter",	A_GIMME,	0);
	class_addmethod(c, (method)ramp_clock,					"clock",				A_SYM,		0);
	class_addmethod(c, (method)ramp_assist,					"assist",				A_CANT,		0); 
    class_addmethod(c, (method)object_obex_dumpout,			"dumpout",				A_CANT,		0);

	// ATTRIBUTE: rampunit
	class_addattr(c, 
		attr_offset_new("drive", _sym_symbol, 0,
		(method)0, (method)ramp_setrampunit, calcoffset(t_ramp, attr_rampunit)));
	
	// ATTRIBUTE: function
	class_addattr(c, 
		attr_offset_new("function", _sym_symbol, 0,
		(method)0, (method)ramp_setFunction, calcoffset(t_ramp, attr_function)));	

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


#pragma mark -
#pragma mark life cycle
/************************************************************************************/
// Object Life

void *ramp_new(t_symbol *s, long argc, t_atom *argv)
{
	t_ramp	*x = (t_ramp *)object_alloc(ramp_class);

	if (x) {
		x->outlets[k_outlet_dumpout] = outlet_new(x, 0L);
		x->outlets[k_outlet_value]   = outlet_new(x, 0L);
		object_obex_store((void *)x, _sym_dumpout, (t_object *)x->outlets[k_outlet_dumpout]);
		x->parameterNames = new TTHash;

		x->rampUnit = NULL;
		x->attr_rampunit = _sym_nothing;
		x->attr_function = _sym_nothing;
		attr_args_process(x, argc, argv);	// handle attribute args

		if (x->attr_rampunit == _sym_nothing) {
			Atom a;
			atom_setsym(&a, gensym("scheduler"));
			object_attr_setvalueof(x, gensym("drive"), 1, &a);
		}
		if (x->attr_function == _sym_nothing) {
			object_attr_setsym(x, gensym("function"), jps_linear);
		}
	}
	return (x);		// return the pointer to our new instantiation
}


void ramp_free(t_ramp *x)
{
	delete x->rampUnit;
	delete x->parameterNames;
}


#pragma mark -
#pragma mark methods
/************************************************************************************/
// Methods bound to input/inlets

{'fraction_non_alphanumeric': 0.1643370768360669, 'fraction_numerical': 0.004766906358568312, 'mean_word_length': 4.452863436123348, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '7478709', 'n_tokens_mistral': 4905, 'n_tokens_neox': 4570, 'n_words': 1222}