/* absolut.c -- 02/10/01 IF ** ** Accepts either integers or floats depending on the argument ** provides assist messages without Resource */ #include "ext.h" // Required for all Max external objects void *this_class; // Required. Global pointing to this class typedef struct _abs // Data structure for this object { t_object a_ob; // Must always be the first field; used by Max short a_mode; // Integer or float mode void *a_out; // Pointer to outlet, need one for each outlet } t_abs; // Prototypes for methods: you need a method for each message you want to respond to void *abs_new(Symbol *s, short ac, Atom *av); // Object creation method void abs_int(t_abs *abs, long value); // Method for message "int" in left inlet void abs_flt(t_abs *abs, float value); // Method for message "float" in left inlet int main(void) { // set up our class: create a class definition setup((t_messlist **) &this_class, (method)abs_new, 0L, (short)sizeof(t_abs), 0L, A_GIMME, 0); addint((method)abs_int); // bind method "abs_int" to int received in the left inlet addfloat((method)abs_flt); // bind method "abs_flt" to float received in the left inlet return(0); } void *abs_new(Symbol *s, short ac, t_atom *av) { t_abs *abs = (t_abs *)newobject(this_class); // Create the new instance abs->a_mode = A_LONG; // Initialize the values if (ac && av[0].a_type == A_FLOAT) { abs->a_out = floatout(abs); // Create float outlet abs->a_mode = A_FLOAT; } else abs->a_out = intout(abs); // Create int outlet return(abs); // Must return a pointer to the new instance } void abs_int(t_abs *abs, long value) { if (abs->a_mode == A_LONG) outlet_int(abs->a_out, (value >= 0) ? value: -value); else outlet_float(abs->a_out, (float)((value >= 0) ? value: -value)); } void abs_flt(t_abs *abs, float value) { if (abs->a_mode == A_LONG) outlet_int(abs->a_out, (long)((value >= 0) ? value: -value)); else outlet_float(abs->a_out, (value >= 0) ? value: -value); }