Max 5 API Reference
00001 /** 00002 @file 00003 dummy - a dummy object 00004 jeremy bernstein - jeremy@bootsquad.com 00005 00006 @ingroup examples 00007 */ 00008 00009 #include "ext.h" // standard Max include, always required 00010 #include "ext_obex.h" // required for new style Max object 00011 00012 ////////////////////////// object struct 00013 typedef struct _dummy 00014 { 00015 t_object ob; 00016 t_atom val; 00017 t_symbol *name; 00018 void *out; 00019 } t_dummy; 00020 00021 ///////////////////////// function prototypes 00022 //// standard set 00023 void *dummy_new(t_symbol *s, long argc, t_atom *argv); 00024 void dummy_free(t_dummy *x); 00025 void dummy_assist(t_dummy *x, void *b, long m, long a, char *s); 00026 00027 void dummy_int(t_dummy *x, long n); 00028 void dummy_float(t_dummy *x, double f); 00029 void dummy_anything(t_dummy *x, t_symbol *s, long ac, t_atom *av); 00030 void dummy_bang(t_dummy *x); 00031 void dummy_identify(t_dummy *x); 00032 void dummy_dblclick(t_dummy *x); 00033 void dummy_acant(t_dummy *x); 00034 00035 //////////////////////// global class pointer variable 00036 void *dummy_class; 00037 00038 00039 int main(void) 00040 { 00041 t_class *c; 00042 00043 c = class_new("dummy", (method)dummy_new, (method)dummy_free, (long)sizeof(t_dummy), 00044 0L /* leave NULL!! */, A_GIMME, 0); 00045 00046 class_addmethod(c, (method)dummy_bang, "bang", 0); 00047 class_addmethod(c, (method)dummy_int, "int", A_LONG, 0); 00048 class_addmethod(c, (method)dummy_float, "float", A_FLOAT, 0); 00049 class_addmethod(c, (method)dummy_anything, "anything", A_GIMME, 0); 00050 class_addmethod(c, (method)dummy_identify, "identify", 0); 00051 CLASS_METHOD_ATTR_PARSE(c, "identify", "undocumented", gensym("long"), 0, "1"); 00052 00053 // we want to 'reveal' the otherwise hidden 'xyzzy' method 00054 class_addmethod(c, (method)dummy_anything, "xyzzy", A_GIMME, 0); 00055 // here's an otherwise undocumented method, which does something that the user can't actually 00056 // do from the patcher however, we want them to know about it for some weird documentation reason. 00057 // so let's make it documentable. it won't appear in the quickref, because we can't send it from a message. 00058 class_addmethod(c, (method)dummy_acant, "blooop", A_CANT, 0); 00059 CLASS_METHOD_ATTR_PARSE(c, "blooop", "documentable", gensym("long"), 0, "1"); 00060 00061 /* you CAN'T call this from the patcher */ 00062 class_addmethod(c, (method)dummy_assist, "assist", A_CANT, 0); 00063 class_addmethod(c, (method)dummy_dblclick, "dblclick", A_CANT, 0); 00064 00065 CLASS_ATTR_SYM(c, "name", 0, t_dummy, name); 00066 00067 class_register(CLASS_BOX, c); 00068 dummy_class = c; 00069 00070 return 0; 00071 } 00072 00073 void dummy_acant(t_dummy *x) 00074 { 00075 object_post((t_object *)x, "can't touch this!"); 00076 } 00077 00078 void dummy_assist(t_dummy *x, void *b, long m, long a, char *s) 00079 { 00080 if (m == ASSIST_INLET) { //inlet 00081 sprintf(s, "I am inlet %ld", a); 00082 } 00083 else { // outlet 00084 sprintf(s, "I am outlet %ld", a); 00085 } 00086 } 00087 00088 void dummy_free(t_dummy *x) 00089 { 00090 ; 00091 } 00092 00093 void dummy_dblclick(t_dummy *x) 00094 { 00095 object_post((t_object *)x, "I got a double-click"); 00096 } 00097 00098 void dummy_int(t_dummy *x, long n) 00099 { 00100 atom_setlong(&x->val, n); 00101 dummy_bang(x); 00102 } 00103 00104 void dummy_float(t_dummy *x, double f) 00105 { 00106 atom_setfloat(&x->val, f); 00107 dummy_bang(x); 00108 } 00109 00110 void dummy_anything(t_dummy *x, t_symbol *s, long ac, t_atom *av) 00111 { 00112 if (s == gensym("xyzzy")) { 00113 object_post((t_object *)x, "A hollow voice says 'Plugh'"); 00114 } else { 00115 atom_setsym(&x->val, s); 00116 dummy_bang(x); 00117 } 00118 } 00119 00120 void dummy_bang(t_dummy *x) 00121 { 00122 switch (x->val.a_type) { 00123 case A_LONG: outlet_int(x->out, atom_getlong(&x->val)); break; 00124 case A_FLOAT: outlet_float(x->out, atom_getfloat(&x->val)); break; 00125 case A_SYM: outlet_anything(x->out, atom_getsym(&x->val), 0, NULL); break; 00126 default: break; 00127 } 00128 } 00129 00130 void dummy_identify(t_dummy *x) 00131 { 00132 object_post((t_object *)x, "my name is %s", x->name->s_name); 00133 } 00134 00135 void *dummy_new(t_symbol *s, long argc, t_atom *argv) 00136 { 00137 t_dummy *x = NULL; 00138 00139 if (x = (t_dummy *)object_alloc(dummy_class)) { 00140 x->name = gensym(""); 00141 if (argc && argv) { 00142 x->name = atom_getsym(argv); 00143 } 00144 if (!x->name || x->name == gensym("")) 00145 x->name = symbol_unique(); 00146 00147 atom_setlong(&x->val, 0); 00148 x->out = outlet_new(x, NULL); 00149 } 00150 return (x); 00151 }
Copyright © 2008, Cycling '74