<commit_before>/* 
 *	tt.filter~
 *	External object for Max/MSP
 *	Wannabe Max wrapper (external) for all filter units in ttblue
 *	Example project for TTBlue
 *	Copyright © 2008 by <NAME> & <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "TTClassWrapperMax.h"
#include "ext.h"						// Max Header
#include "z_dsp.h"						// MSP Header
#include "ext_strings.h"				// String Functions
#include "commonsyms.h"					// Common symbols used by the Max 4.5 API
#include "ext_obex.h"					// Max Object Extensions (attributes) Header

#include "TTDSP.h"						// TTBlue Interfaces...

#define DEFAULT_F 1000
#define DEFAULT_Q 18


/** Data structure for the tt.filter~ object. */
typedef struct _filter	{
    t_pxobject 				obj;						///< REQUIRED: The MSP 'base class'
	TTAudioObjectPtr		filter;						///< The TTBlue filter unit used
	TTAudioSignalPtr		audioIn;					///< The TTBlue audio signal object that is used for filter input
	TTAudioSignalPtr		audioOut;					///< The TTBlue audio signal object that us used for filter output
	TTUInt16				maxNumChannels;				///< The maximum number of audio channels permitted
	TTUInt16				numChannels;				///< The actual number of audio channels used
	TTUInt16				vs;							///< The vector size (number of samples per processing block)
	long					sr;							///< The sample rate
	long					attrBypass;					///< ATTRIBUTE: Bypass filtering
	float					attrFrequency;				///< ATTRIBUTE: Filter cutoff or center frequency, depending on the kind of filter
	float					attrQ;						///< ATTRIBUTE: Filter resonance
	t_symbol				*attrType;					///< ATTRIBUTE: what kind of filter to use
} t_filter;


// Prototypes for methods: need a method for each incoming message type

/** New object create method. */
void*		filter_new(t_symbol *msg, short argc, t_atom *argv);

/** Free memory etc. when an object is destroyed. */
void		filter_free(t_filter *x);

/** Assist strings for object inlets and outlets. */
void		filter_assist(t_filter *x, void *b, long msg, long arg, char *dst);

/** This method is called on each audio vector: Frequency and resonance set at control rate. */
t_int*		filter_perform(t_int *w);

/** This method is called on each audio vector: Frequency set at signal rate. */
t_int*		filter_perform_freq(t_int *w);

/** This method is called on each audio vector: Resonance set at signal rate. */
t_int*		filter_perform_q(t_int *w);

/** This method is called on each audio vector: Frequency and resonance set at signal rate. */
t_int*		filter_perform_freq_q(t_int *w);

/** This method is called when audio is started in order to compile the audio chain. */
void		filter_dsp(t_filter *x, t_signal **sp, short *count);

/** Clear the filter in case it has blown up (NaN). */
void		filter_clear(t_filter *x);

/** Method setting the value of the bypass attribute. */
t_max_err	filter_setBypass(t_filter *x, void *attr, long argc, t_atom *argv);

/** Method setting the value of the frequency attribute. */
t_max_err 	filter_setFrequency(t_filter *x, void *attr, long argc, t_atom *argv);

/** Method setting the value of the resonance (Q) attribute. */
t_max_err 	filter_setQ(t_filter *x, void *attr, long argc, t_atom *argv);

/** Method setting the type of the filter to use. */
t_max_err 	filter_setType(t_filter *x, void *attr, long argc, t_atom *argv);

/**	Spew the available filter names to the dumpout for a umenu. */
void filter_gettypes(t_filter *x);


// Globals
t_class *filter_class;				// Required. Global pointing to this class


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

int TTCLASSWRAPPERMAX_EXPORT main(void)
{
	t_class *c;
	
	common_symbols_init();
	TTDSPInit();

	c = class_new("jcom.filter~",(method)filter_new, (method)filter_free, sizeof(t_filter), (method)0L, A_GIMME, 0);

	class_addmethod(c, (method)filter_gettypes,			"gettypes",		0L);
 	class_addmethod(c, (method)filter_clear, 			"clear",		0L);		
 	class_addmethod(c, (method)filter_dsp, 				"dsp",			A_CANT, 0L);		
	class_addmethod(c, (method)filter_assist, 			"assist",		A_CANT, 0L); 
	class_addmethod(c, (method)object_obex_dumpout,		"dumpout",		A_CANT, 0);  
	class_addmethod(c, (method)stdinletinfo,			"inletinfo",	A_CANT, 0);

	CLASS_ATTR_LONG(c,		"bypass",		0,	t_filter, attrBypass);
	CLASS_ATTR_ACCESSORS(c,	"bypass",		NULL, filter_setBypass);
	CLASS_ATTR_STYLE(c,		"bypass",		0, "onoff");

	CLASS_ATTR_FLOAT(c,		"frequency",	0,	t_filter, attrFrequency);
	CLASS_ATTR_ACCESSORS(c,	"frequency",	NULL, filter_setFrequency);

	CLASS_ATTR_FLOAT(c,		"q",	0,	t_filter, attrQ);
	CLASS_ATTR_ACCESSORS(c,	"q",	NULL, filter_setQ);

	CLASS_ATTR_SYM(c,		"type",	0,	t_filter, attrType);
	CLASS_ATTR_ACCESSORS(c,	"type",	NULL, filter_setType);

	class_dspinit(c);
	class_register(CLASS_BOX, c);
	filter_class = c;

	return 0;
}


/************************************************************************************/
// Object Creation Method

void* filter_new(t_symbol *msg, short argc, t_atom *argv)
{
    t_filter	*x;
	TTValue		sr(sys_getsr());
 	long		attrstart = attr_args_offset(argc, argv);		// support normal arguments
	short		i;
   
    x = (t_filter *)object_alloc(filter_class);
    if(x){
		// Setting default attribute values
		x->attrBypass = 0;
		x->attrFrequency = DEFAULT_F;
		x->attrQ = DEFAULT_Q;
		
		x->maxNumChannels = 2;		// An initial argument to this object will set the maximum number of channels
		if(attrstart && argv)
			x->maxNumChannels = atom_getlong(argv);

		x->sr = sr;
		ttEnvironment->setAttributeValue(kTTSym_SampleRate, sr);
		object_attr_setsym(x, _sym_type, gensym("lowpass.butterworth.2"));

		TTObjectInstantiate(kTTSym_audiosignal, &x->audioIn, x->maxNumChannels);
		TTObjectInstantiate(kTTSym_audiosignal, &x->audioOut, x->maxNumChannels);

		attr_args_process(x,argc,argv);				// handle attribute args	

    	object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout	
	    dsp_setup((t_pxobject *)x, x->maxNumChannels + 2);		// inlets: signals + freq + q
		for(i=0; i < x->maxNumChannels; i++)
			outlet_new((t_pxobject *)x, "signal");				// outlets
		
		x->obj.z_misc = Z_NO_INPLACE;
	}
	return (x);										// Return the pointer
}

// Memory Deallocation
void filter_free(t_filter *x)
{
	dsp_free((t_pxobject *)x);
	TTObjectRelease(&x->filter);
	TTObjectRelease(&x->audioIn);
	TTObjectRelease(&x->audioOut);
}


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

// Method for Assistance Messages
void filter_assist(t_filter *x, void *b, long msg, long arg, char *dst)
{
	if(msg==1) 	// Inlets
		strcpy(dst, "(signal) input, control messages");		
	else if(msg==2) // Outlets
		strcpy(dst, "(signal) Filtered output");
}


void filter_clear(t_filter *x)
{
	x->filter->sendMessage(TT("Clear"));
}
<commit_msg>{changed : proper assist messages for jcom.filter~}<commit_after>/* 
 *	tt.filter~
 *	External object for Max/MSP
 *	Wannabe Max wrapper (external) for all filter units in ttblue
 *	Example project for TTBlue
 *	Copyright © 2008 by <NAME> & <NAME>
 * 
 * License: This code is licensed under the terms of the GNU LGPL
 * http://www.gnu.org/licenses/lgpl.html 
 */

#include "TTClassWrapperMax.h"
#include "ext.h"						// Max Header
#include "z_dsp.h"						// MSP Header
#include "ext_strings.h"				// String Functions
#include "commonsyms.h"					// Common symbols used by the Max 4.5 API
#include "ext_obex.h"					// Max Object Extensions (attributes) Header

#include "TTDSP.h"						// TTBlue Interfaces...

#define DEFAULT_F 1000
#define DEFAULT_Q 18


/** Data structure for the tt.filter~ object. */
typedef struct _filter	{
    t_pxobject 				obj;						///< REQUIRED: The MSP 'base class'
	TTAudioObjectPtr		filter;						///< The TTBlue filter unit used
	TTAudioSignalPtr		audioIn;					///< The TTBlue audio signal object that is used for filter input
	TTAudioSignalPtr		audioOut;					///< The TTBlue audio signal object that us used for filter output
	TTUInt16				maxNumChannels;				///< The maximum number of audio channels permitted
	TTUInt16				numChannels;				///< The actual number of audio channels used
	TTUInt16				vs;							///< The vector size (number of samples per processing block)
	long					sr;							///< The sample rate
	long					attrBypass;					///< ATTRIBUTE: Bypass filtering
	float					attrFrequency;				///< ATTRIBUTE: Filter cutoff or center frequency, depending on the kind of filter
	float					attrQ;						///< ATTRIBUTE: Filter resonance
	t_symbol				*attrType;					///< ATTRIBUTE: what kind of filter to use
} t_filter;


// Prototypes for methods: need a method for each incoming message type

/** New object create method. */
void*		filter_new(t_symbol *msg, short argc, t_atom *argv);

/** Free memory etc. when an object is destroyed. */
void		filter_free(t_filter *x);

/** Assist strings for object inlets and outlets. */
void		filter_assist(t_filter *x, void *b, long msg, long arg, char *dst);

/** This method is called on each audio vector: Frequency and resonance set at control rate. */
t_int*		filter_perform(t_int *w);

/** This method is called on each audio vector: Frequency set at signal rate. */
t_int*		filter_perform_freq(t_int *w);

/** This method is called on each audio vector: Resonance set at signal rate. */
t_int*		filter_perform_q(t_int *w);

/** This method is called on each audio vector: Frequency and resonance set at signal rate. */
t_int*		filter_perform_freq_q(t_int *w);

/** This method is called when audio is started in order to compile the audio chain. */
void		filter_dsp(t_filter *x, t_signal **sp, short *count);

/** Clear the filter in case it has blown up (NaN). */
void		filter_clear(t_filter *x);

/** Method setting the value of the bypass attribute. */
t_max_err	filter_setBypass(t_filter *x, void *attr, long argc, t_atom *argv);

/** Method setting the value of the frequency attribute. */
t_max_err 	filter_setFrequency(t_filter *x, void *attr, long argc, t_atom *argv);

/** Method setting the value of the resonance (Q) attribute. */
t_max_err 	filter_setQ(t_filter *x, void *attr, long argc, t_atom *argv);

/** Method setting the type of the filter to use. */
t_max_err 	filter_setType(t_filter *x, void *attr, long argc, t_atom *argv);

/**	Spew the available filter names to the dumpout for a umenu. */
void filter_gettypes(t_filter *x);


// Globals
t_class *filter_class;				// Required. Global pointing to this class


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

int TTCLASSWRAPPERMAX_EXPORT main(void)
{
	t_class *c;
	
	common_symbols_init();
	TTDSPInit();

	c = class_new("jcom.filter~",(method)filter_new, (method)filter_free, sizeof(t_filter), (method)0L, A_GIMME, 0);

	class_addmethod(c, (method)filter_gettypes,			"gettypes",		0L);
 	class_addmethod(c, (method)filter_clear, 			"clear",		0L);		
 	class_addmethod(c, (method)filter_dsp, 				"dsp",			A_CANT, 0L);		
	class_addmethod(c, (method)filter_assist, 			"assist",		A_CANT, 0L); 
	class_addmethod(c, (method)object_obex_dumpout,		"dumpout",		A_CANT, 0);  
	class_addmethod(c, (method)stdinletinfo,			"inletinfo",	A_CANT, 0);

	CLASS_ATTR_LONG(c,		"bypass",		0,	t_filter, attrBypass);
	CLASS_ATTR_ACCESSORS(c,	"bypass",		NULL, filter_setBypass);
	CLASS_ATTR_STYLE(c,		"bypass",		0, "onoff");

	CLASS_ATTR_FLOAT(c,		"frequency",	0,	t_filter, attrFrequency);
	CLASS_ATTR_ACCESSORS(c,	"frequency",	NULL, filter_setFrequency);

	CLASS_ATTR_FLOAT(c,		"q",	0,	t_filter, attrQ);
	CLASS_ATTR_ACCESSORS(c,	"q",	NULL, filter_setQ);

	CLASS_ATTR_SYM(c,		"type",	0,	t_filter, attrType);
	CLASS_ATTR_ACCESSORS(c,	"type",	NULL, filter_setType);

	class_dspinit(c);
	class_register(CLASS_BOX, c);
	filter_class = c;

	return 0;
}


/************************************************************************************/
// Object Creation Method

void* filter_new(t_symbol *msg, short argc, t_atom *argv)
{
    t_filter	*x;
	TTValue		sr(sys_getsr());
 	long		attrstart = attr_args_offset(argc, argv);		// support normal arguments
	short		i;
   
    x = (t_filter *)object_alloc(filter_class);
    if(x){
		// Setting default attribute values
		x->attrBypass = 0;
		x->attrFrequency = DEFAULT_F;
		x->attrQ = DEFAULT_Q;
		
		x->maxNumChannels = 2;		// An initial argument to this object will set the maximum number of channels
		if(attrstart && argv)
			x->maxNumChannels = atom_getlong(argv);

		x->sr = sr;
		ttEnvironment->setAttributeValue(kTTSym_SampleRate, sr);
		object_attr_setsym(x, _sym_type, gensym("lowpass.butterworth.2"));

		TTObjectInstantiate(kTTSym_audiosignal, &x->audioIn, x->maxNumChannels);
		TTObjectInstantiate(kTTSym_audiosignal, &x->audioOut, x->maxNumChannels);

		attr_args_process(x,argc,argv);				// handle attribute args	

    	object_obex_store((void *)x, _sym_dumpout, (object *)outlet_new(x,NULL));	// dumpout	
	    dsp_setup((t_pxobject *)x, x->maxNumChannels + 2);		// inlets: signals + freq + q
		for(i=0; i < x->maxNumChannels; i++)
			outlet_new((t_pxobject *)x, "signal");				// outlets
		
		x->obj.z_misc = Z_NO_INPLACE;
	}
	return (x);										// Return the pointer
}

// Memory Deallocation
void filter_free(t_filter *x)
{
	dsp_free((t_pxobject *)x);
	TTObjectRelease(&x->filter);
	TTObjectRelease(&x->audioIn);
	TTObjectRelease(&x->audioOut);
}


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

// Method for Assistance Messages
void filter_assist(t_filter *x, void *b, long msg, long arg, char *dst)
{ 
	if(msg==1){ 	// Inlets		
		if(arg == x->maxNumChannels)
			strcpy(dst, "(signal) Frequency");
		else if(arg == x->maxNumChannels+1)
			strcpy(dst, "(signal) Q-value");
		else if(arg == 0)
			strcpy(dst, "(signal) input 1, control messages");
		else if(arg < x->maxNumChannels)
			snprintf(dst, 256, "(signal) input %ld", arg+1);
		}
				
	else if(msg==2) {// Outlets		
		if(arg == x->maxNumChannels)
			strcpy(dst, "dumpout");					
		else 
			snprintf(dst, 256, "(signal) Filtered output %ld", arg+1);  
		}		
}


void filter_clear(t_filter *x)
{
	x->filter->sendMessage(TT("Clear"));
}

{'fraction_non_alphanumeric': 0.15721015256978135, 'fraction_numerical': 0.006257470294593264, 'mean_word_length': 4.08, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 49, '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': '7244357', 'n_tokens_mistral': 5469, 'n_tokens_neox': 4963, 'n_words': 1405}