Forums > Dev

non signal inlets in a MSP object (SDK 5)

April 4, 2009 | 8:24 pm

Hello,
I read the documentation of SDK 5 but I have not found how signal and non signal inlets can be combined.

I just want to have an object with 3 inlets (signal, int, int) and 1 outlet (signal)

The source is compiled fine but at runtime when I place the object in a patch I
get the folowing errors:

walkmodes~: doesn’t understand "in3"
walkmodes~: doesn’t understand "in2"
jpatchline_completeconnection: index out of range.
jpatchline_completeconnection: index out of range.

Help!

This is the code:

#include "ext.h" // Required for all Max external objects
#include "ext_obex.h" // Required for new style Max object
#include "z_dsp.h"
#include

static t_class *s_walkmodes_class; // global class pointer variable

typedef struct _walkmodes{ // Object struct

t_pxobject x_obj; // needed for all max objects
long FFT_SIZE; //number of samples of the fft
long FS; //Sample frequency
} t_walkmodes;

/************************************** FUNCTIONS PROTOTYPES *********************************************************************/

void *walkmodes_new(void);
void walkmodes_FFT_SIZE(t_walkmodes *x, long n);
void walkmodes_FS(t_walkmodes *x, long n);
void walkmodes_dsp(t_walkmodes *x, t_signal **sp, short *count);
t_int *walkmodes_perform(t_int *w);

/**************************************************************************************************************************************/

/* MAIN METHOD, CONTAINING THE MAX/MSP STUFF */
int main(void){

t_class *c;
c = class_new("walkmodes~", (method)walkmodes_new, (method)dsp_free, sizeof(t_walkmodes), 0L, A_GIMME, 0);

class_addmethod(c, (method)walkmodes_dsp, "dsp", A_CANT, 0);

addinx((method)walkmodes_FFT_SIZE, 2);//inlet 2 recives the FFT_SIZE
addinx((method)walkmodes_FS, 3);//inlet 3 recives the FS

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

return 0;
}

/* NEW METHOD, INITIALISING THE OBJECT WHEN IT IS CREATED IN MAX/MSP */
void *walkmodes_new(void){

t_walkmodes *x = (t_walkmodes *)object_alloc(s_walkmodes_class);

/* creating inlets and outlets. NOTE: rightmost order */
intin((t_pxobject *)x, 3); // inlet for receiving the FS
intin((t_pxobject *)x, 2); // inlet for receiving the FFT SIZE
dsp_setup((t_pxobject *)x, 1);// NUMBER OF SIGNAL-INLETS OF THE OBJECTS
outlet_new((t_pxobject *)x, "signal"); // audio outlet: THE RESIDUAL SIGNAL

/* setting the global variables (internal state of the object)*/
x->FFT_SIZE = 1024;
x->FS = 44100;

return (x);
}

/* DSP METHOD, ADDS PERFORM METHOD TO BE TRIGGERED UPON DSP INPUT. ALSO ADDS THE VECTORS USED */
void walkmodes_dsp(t_walkmodes *x, t_signal **sp, short *count){
dsp_add(walkmodes_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);

}

/* PERFORM METHOD (THIS IS WHERE THE FUN BEGINS), HAPPENS EVERY TIME A DSP SIGNAL IS INPUT TO THE OBJECT */

t_int *walkmodes_perform(t_int *w){

t_walkmodes *x = (t_walkmodes *)(w[1]); // for the x object in which we can get the global variables and pointers (internal state)

t_float *in1 = (t_float *)(w[2]); // for the input DSP signal
t_float *out1 = (t_float *)(w[3]); // for the left DSP outlet
int n = (int)(w[4]); // vector size

//OPTIMIZATION
if (x->x_obj.z_disabled) // check for object being disabled
return w + 5;// must return next DSP chain location; always add one more than the 2nd argument in dsp_add()

while (n–){ // perform calculation on all samples
*out1++ = *in1++;
}

return w + 5;// must return next DSP chain location; always add one more than the 2nd argument in dsp_add()
}

/* This method takes in the inlet the value of FFT SIZE and store it into the object internal state*/
void walkmodes_FFT_SIZE(t_walkmodes *x, long n){
x->FFT_SIZE = n;
post("The value of the FFT SIZE is %ld",x->FFT_SIZE);
}

/* This method takes in the inlet the value of FFT SIZE and store it into the object internal state*/
void walkmodes_FS(t_walkmodes *x, long n){
x->FS = n;
post("The value of the FS is %ld",x->FS);
}

Thanks in advance

Luca


April 5, 2009 | 5:45 pm

A closer reading of the "Inlets and Oulets" chapter of the Max5 API Reference would answer some of your questions.

In walkmodes_new(), your inlet #’s are off by 1. Try:

intin((t_pxobject *)x, 2); // inlet for receiving the FS
intin((t_pxobject *)x, 1); // inlet for receiving the FFT SIZE

Then in main(), since you’re using class_new(), try:

class_addmethod(c, (method)walkmodes_FFT_SIZE, "in1", A_LONG, 0);
class_addmethod(c, (method)walkmodes_FS, "in2", A_LONG, 0);

I think addinx() only works when you use setup().

Davis


April 5, 2009 | 6:31 pm

THANKS.

I HAVE NO WORDS TO THANK YOU!

Now it works.

Best regards


Viewing 3 posts - 1 through 3 (of 3 total)