Creating an external with a left inlet allowing floats

Apr 1, 2013 at 3:37pm

Creating an external with a left inlet allowing floats

I’m trying to create an external with a few inlets and I want the first one to allow floats. Regardless of what I try, however, when I send it a float in the left inlet, I see a message in the Max window that says that it doesn’t understand floats. This is what I have done so far:

In the main function:

class_addmethod(c, (method)DTNyqMultiply_f0, “ft0″, A_FLOAT, 0);
class_addmethod(c, (method)DTNyqMultiply_coefficients, “list”, A_GIMME, 0);
class_addmethod(c, (method)DTNyqMultiply_samplingRate, “ft2″, A_FLOAT, 0);

In the “new instance” function:

// create inlets (in reverse order), and the outlet
floatin(x, 2);
inlet_new(x, “list”);
floatin(x, 0); // I have tried removing this; it doesn’t make a difference
x->p_outlet = listout(x);

How can I get the left inlet to allow floats?

#67463
Apr 1, 2013 at 4:05pm

Hi Antony,

To accomplish what you want, you need:

in the main function:

class_addmethod(c, (method)DTNyqMultiply_float, "float", A_FLOAT, 0);
class_addmethod(c, (method)DTNyqMultiply_samplingRate, "ft1", A_FLOAT, 0);
class_addmethod(c, (method)DTNyqMultiply_coefficients, "list", A_GIMME, 0);

In the “new instance” function:

// create inlets (in reverse order), and the outlet
floatin(x, 1);
x->p_outlet = listout(x);

the method prototyped as:

void DTNyqMultiply_float(t_DTNyqMultiply *x, double f)
{

}

will receive floats sent to the left inlet (“float”).

———————————-

the method prototyped as:

void DTNyqMultiply_samplingRate(t_DTNyqMultiply *x, double f)
{

}

will receive floats sent to the right inlet (“ft1″).

———————————-

…and finally the method prototyped as:

void DTNyqMultiply_coefficients(t_DTNyqMultiply *x, t_symbol *sym, long argc, t_atom *argv)
{

}

will receive lists sent to the left inlet (“list”).

———————————-

You might want to read the MaxAPI SDK docs because it’s all there…

Hope this helps.

- Luigi

#242699
Apr 1, 2013 at 4:08pm

Hi,

oops.

To get a float in the leftmost inlet you just need to use “class_addmethod” in your main method.

int main(void)
{
    c = class_new("flop", (method)flop_new, NULL, (long)(sizeof(t_flop)), 0L, A_GIMME, 0);
    class_addmethod(c, (method)flop_float, "float", A_FLOAT, 0);
    class_register(CLASS_BOX, c);
    flop_class = c;

    return 0;
}

void flop_float(t_flop *x, double f)
{
    post("%lf", f);
}
Attachments:
  1. flop.c
#242700
Apr 1, 2013 at 5:17pm

That is helpful. Thanks. I think the problem is that I needed to write “float” instead of “ft0″. By the way, I have been reading the SDK documentation but the examples are a bit scarce in the “Inlets and Outlets” page.

#242701
Apr 1, 2013 at 7:49pm

No, the examples are not scarce at all…
The SDK docs come accompanied with many open source Max/MSP/Jitter externals.
You can check out the code and compile it on your platform.
Although reading the manual is helpful to get a general understanding of the underlying API structure, checking out the code of the examples is crucial to learn how to accomplish specific tasks in code.

- Luigi

#242702

You must be logged in to reply to this topic.