Max 5 API Reference
00001 /** 00002 @file 00003 whosyourdaddy - who's the parent patcher 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 "ext_strings.h" 00012 #include "jpatcher_api.h" 00013 00014 ////////////////////////// object struct 00015 typedef struct _whosyourdaddy 00016 { 00017 t_object a_ob; // the object itself (must be first) 00018 } t_whosyourdaddy; 00019 00020 ///////////////////////// function prototypes 00021 //// standard set 00022 void *whosyourdaddy_new(t_symbol *s, long argc, t_atom *argv); 00023 void whosyourdaddy_free(t_whosyourdaddy *x); 00024 void whosyourdaddy_assist(t_whosyourdaddy *x, void *b, long m, long a, char *s); 00025 //// additional methods 00026 void whosyourdaddy_bang(t_whosyourdaddy *x); // incoming bang message 00027 00028 //////////////////////// global class pointer variable 00029 void *whosyourdaddy_class; 00030 00031 int main(void) 00032 { 00033 t_class *c; 00034 00035 c = class_new("whosyourdaddy", (method)whosyourdaddy_new, (method)whosyourdaddy_free, (long)sizeof(t_whosyourdaddy), 0L, A_GIMME, 0); 00036 00037 class_addmethod(c, (method)whosyourdaddy_bang, "bang", 0); 00038 class_addmethod(c, (method)whosyourdaddy_assist, "assist", A_CANT, 0); 00039 00040 class_register(CLASS_BOX, c); 00041 whosyourdaddy_class = c; 00042 00043 return 0; 00044 } 00045 00046 void whosyourdaddy_assist(t_whosyourdaddy *x, void *b, long m, long a, char *s) 00047 { 00048 if (m == ASSIST_INLET) { //inlet 00049 snprintf_zero(s, 256, "I am inlet %ld", a); 00050 } 00051 else { // outlet 00052 snprintf_zero(s, 256, "I am outlet %ld", a); 00053 } 00054 } 00055 00056 void whosyourdaddy_bang(t_whosyourdaddy *x) 00057 { 00058 t_object *jp; 00059 t_object *jbx; 00060 t_object *o; 00061 t_max_err err; 00062 00063 // get the object's parent patcher 00064 err = object_obex_lookup(x, gensym("#P"), (t_object **)&jp); 00065 if (err != MAX_ERR_NONE) 00066 return; 00067 00068 // some kind of patcher in a box 00069 if (jbx = jpatcher_get_box(jp)) { 00070 t_symbol *filepath = object_attr_getsym((t_object *)jp, gensym("filepath")); 00071 00072 // post("object_classname(jbx): %s, object_classname(o): %s, filepath: %s", object_classname(jbx)->s_name, object_classname(jbox_get_object(jbx))->s_name, filepath->s_name); 00073 if (object_classname(jbx) == gensym("bpatcher")) { 00074 post("bpatcher"); 00075 } else { 00076 if (filepath && filepath != gensym("")) { 00077 post("abstraction"); 00078 } else { 00079 post("subpatcher"); 00080 } 00081 } 00082 } else { 00083 t_object *p2; 00084 t_object *target; 00085 t_object *nextbox; 00086 method m; 00087 00088 object_method(jp, gensym("getassoc"), &target); 00089 if (target) { 00090 if (m = zgetfn(target, gensym("parentpatcher"))) 00091 (*m)(target, &p2); 00092 if (p2) { 00093 nextbox = jpatcher_get_firstobject(p2); 00094 while (nextbox) { 00095 o = jbox_get_object(nextbox); 00096 if (o == target) { 00097 post("%s", object_classname(o)->s_name); 00098 return; 00099 } 00100 nextbox = jbox_get_nextobject(nextbox); 00101 } 00102 } 00103 } 00104 } 00105 } 00106 00107 void whosyourdaddy_free(t_whosyourdaddy *x) 00108 { 00109 } 00110 00111 void *whosyourdaddy_new(t_symbol *s, long argc, t_atom *argv) 00112 { 00113 t_whosyourdaddy *x = NULL; 00114 00115 if (x = (t_whosyourdaddy *)object_alloc(whosyourdaddy_class)) { 00116 } 00117 return (x); 00118 }
Copyright © 2008, Cycling '74