Max 5 API Reference
00001 /** 00002 @file 00003 simplemax - a max object shell 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 _simplemax 00014 { 00015 t_object ob; // the object itself (must be first) 00016 } t_simplemax; 00017 00018 ///////////////////////// function prototypes 00019 //// standard set 00020 void *simplemax_new(t_symbol *s, long argc, t_atom *argv); 00021 void simplemax_free(t_simplemax *x); 00022 void simplemax_assist(t_simplemax *x, void *b, long m, long a, char *s); 00023 00024 //////////////////////// global class pointer variable 00025 void *simplemax_class; 00026 00027 00028 int main(void) 00029 { 00030 // object initialization, OLD STYLE 00031 // setup((t_messlist **)&simplemax_class, (method)simplemax_new, (method)simplemax_free, (short)sizeof(t_simplemax), 00032 // 0L, A_GIMME, 0); 00033 // addmess((method)simplemax_assist, "assist", A_CANT, 0); 00034 00035 // object initialization, NEW STYLE 00036 t_class *c; 00037 00038 c = class_new("simplemax", (method)simplemax_new, (method)simplemax_free, (long)sizeof(t_simplemax), 00039 0L /* leave NULL!! */, A_GIMME, 0); 00040 00041 /* you CAN'T call this from the patcher */ 00042 class_addmethod(c, (method)simplemax_assist, "assist", A_CANT, 0); 00043 00044 class_register(CLASS_BOX, c); /* CLASS_NOBOX */ 00045 simplemax_class = c; 00046 00047 post("I am the simplemax object"); 00048 return 0; 00049 } 00050 00051 void simplemax_assist(t_simplemax *x, void *b, long m, long a, char *s) 00052 { 00053 if (m == ASSIST_INLET) { // inlet 00054 sprintf(s, "I am inlet %ld", a); 00055 } 00056 else { // outlet 00057 sprintf(s, "I am outlet %ld", a); 00058 } 00059 } 00060 00061 void simplemax_free(t_simplemax *x) 00062 { 00063 ; 00064 } 00065 00066 /* 00067 A_GIMME signature = 00068 t_symbol *s objectname 00069 long argc num additonal args 00070 t_atom *argv array of t_atom structs 00071 type = argv->a_type 00072 if (type == A_LONG) ; 00073 else if (type == A_FLOAT) ; 00074 else if (type == A_SYM) ; 00075 */ 00076 /* 00077 t_symbol { 00078 char *s_name; 00079 t_object *s_thing; 00080 } 00081 */ 00082 void *simplemax_new(t_symbol *s, long argc, t_atom *argv) 00083 { 00084 t_simplemax *x = NULL; 00085 long i; 00086 00087 // object instantiation, OLD STYLE 00088 // if (x = (t_simplemax *)newobject(simplemax_class)) { 00089 // ; 00090 // } 00091 00092 // object instantiation, NEW STYLE 00093 if (x = (t_simplemax *)object_alloc(simplemax_class)) { 00094 object_post((t_object *)x, "a new %s object was instantiated: 0x%X", s->s_name, x); 00095 object_post((t_object *)x, "it has %ld arguments", argc); 00096 00097 for (i = 0; i < argc; i++) { 00098 if ((argv + i)->a_type == A_LONG) { 00099 object_post((t_object *)x, "arg %ld: long (%ld)", i, atom_getlong(argv+i)); 00100 } else if ((argv + i)->a_type == A_FLOAT) { 00101 object_post((t_object *)x, "arg %ld: float (%f)", i, atom_getfloat(argv+i)); 00102 } else if ((argv + i)->a_type == A_SYM) { 00103 object_post((t_object *)x, "arg %ld: symbol (%s)", i, atom_getsym(argv+i)->s_name); 00104 } else { 00105 object_error((t_object *)x, "forbidden argument"); 00106 } 00107 } 00108 } 00109 return (x); 00110 }
Copyright © 2008, Cycling '74