Max 5 API Reference
00001 /** 00002 @file 00003 iterate2 - object that iterates through a patcher and its subpatchers 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 #include "jpatcher_api.h" 00012 00013 ////////////////////////// object struct 00014 typedef struct _iterate2 00015 { 00016 t_object a_ob; // the object itself (must be first) 00017 } t_iterate2; 00018 00019 ///////////////////////// function prototypes 00020 //// standard set 00021 void *iterate2_new(t_symbol *s, long argc, t_atom *argv); 00022 void iterate2_free(t_iterate2 *x); 00023 long iterate2_callback(t_iterate2 *x, t_object *obj); 00024 void iterate2_assist(t_iterate2 *x, void *b, long m, long a, char *s); 00025 //// additional methods 00026 void iterate2_bang(t_iterate2 *x); // incoming bang message 00027 00028 //////////////////////// global class pointer variable 00029 void *iterate2_class; 00030 00031 int main(void) 00032 { 00033 t_class *c; 00034 00035 c = class_new("iterate2", (method)iterate2_new, (method)iterate2_free, (long)sizeof(t_iterate2), 0L, A_GIMME, 0); 00036 00037 class_addmethod(c, (method)iterate2_bang, "bang", 0); 00038 class_addmethod(c, (method)iterate2_assist, "assist", A_CANT, 0); 00039 00040 class_register(CLASS_BOX, c); 00041 iterate2_class = c; 00042 00043 post("I am the iterate2 object"); 00044 return 0; 00045 } 00046 00047 void iterate2_assist(t_iterate2 *x, void *b, long m, long a, char *s) 00048 { 00049 if (m == ASSIST_INLET) { //inlet 00050 sprintf(s, "I am inlet %ld", a); 00051 } 00052 else { // outlet 00053 sprintf(s, "I am outlet %ld", a); 00054 } 00055 } 00056 00057 void iterate2_bang(t_iterate2 *x) 00058 { 00059 t_object *jp; 00060 t_max_err err; 00061 long result = 0; 00062 00063 err = object_obex_lookup(x, gensym("#P"), (t_object **)&jp); 00064 if (err != MAX_ERR_NONE) 00065 return; 00066 object_method(jp, gensym("iterate"), (method)iterate2_callback, x, PI_DEEP | PI_WANTBOX, &result); 00067 } 00068 00069 long iterate2_callback(t_iterate2 *x, t_object *obj) 00070 { 00071 t_rect jr; 00072 t_object *p; 00073 t_symbol *s; 00074 00075 jbox_get_patching_rect(obj, &jr); 00076 p = jbox_get_patcher(obj); 00077 s = jpatcher_get_name(p); 00078 object_post((t_object *)x, "in %s, box @ x %ld y %ld, w %ld, h %ld", s->s_name, (long)jr.x, (long)jr.y, (long)jr.width, (long)jr.height); 00079 return 0; 00080 } 00081 00082 void iterate2_free(t_iterate2 *x) 00083 { 00084 ; 00085 } 00086 00087 void *iterate2_new(t_symbol *s, long argc, t_atom *argv) 00088 { 00089 t_iterate2 *x = NULL; 00090 00091 if (x = (t_iterate2 *)object_alloc(iterate2_class)) { 00092 ; 00093 } 00094 return (x); 00095 }
Copyright © 2008, Cycling '74