Max 5 API Reference
00001 /* 00002 Copyright 2001-2002 - Cycling '74 00003 Joshua Kit Clayton jkc@cycling74.com 00004 */ 00005 00006 #include "jit.common.h" 00007 #include "max.jit.mop.h" 00008 00009 typedef struct _max_jit_notify 00010 { 00011 t_object ob; 00012 void *obex; 00013 t_symbol *servername; //NOTIFY EXAMPLE 00014 } t_max_jit_notify; 00015 00016 t_jit_err jit_notify_init(void); 00017 00018 void max_jit_notify_notify(t_max_jit_notify *x, t_symbol *s, t_symbol *msg, void *ob, void *data); 00019 void *max_jit_notify_new(t_symbol *s, long argc, t_atom *argv); 00020 void max_jit_notify_free(t_max_jit_notify *x); 00021 void *max_jit_notify_class; 00022 00023 void main(void) 00024 { 00025 void *p,*q; 00026 00027 jit_notify_init(); 00028 setup(&max_jit_notify_class, max_jit_notify_new, (method)max_jit_notify_free, (short)sizeof(t_max_jit_notify), 00029 0L, A_GIMME, 0); 00030 00031 p = max_jit_classex_setup(calcoffset(t_max_jit_notify,obex)); 00032 q = jit_class_findbyname(gensym("jit_notify")); 00033 00034 //NOTIFY EXAMPLE: WE NEED TO OVERRIDE THE DEFAULT MOP NOTIFY METHOD 00035 max_jit_classex_mop_wrap(p,q,MAX_JIT_MOP_FLAGS_OWN_NOTIFY); //name/type/dim/planecount/bang/outputmatrix/etc 00036 00037 max_jit_classex_standard_wrap(p,q,0); //getattributes/dumpout/maxjitclassaddmethods/etc 00038 addmess((method)max_jit_mop_assist, "assist", A_CANT,0); //standard mop assist fn 00039 00040 //NOTIFY EXAMPLE: HERE'S WHERE WE DECLARE OUR OWN NOTIFY METHOD 00041 addmess((method)max_jit_notify_notify, "notify", A_CANT,0); 00042 00043 } 00044 00045 //NOTIFY EXAMPLE: HERE'S WHERE WE GET INFO FROM SERVERS WE ARE ATTACHED TO 00046 //s is the servername, msg is the message, ob is the server object pointer, 00047 //and data is extra data the server might provide for a given message 00048 void max_jit_notify_notify(t_max_jit_notify *x, t_symbol *s, t_symbol *msg, void *ob, void *data) 00049 { 00050 if (msg==gensym("splat")) { 00051 post("notify: server=%s message=%s",s->s_name,msg->s_name); 00052 if (!data) { 00053 error("splat message NULL pointer"); 00054 return; 00055 } 00056 //here's where we output using the rightmost outlet 00057 //we just happen to know that "data" points to a t_atom[3] 00058 //alternately you could use max_jit_obex_dumpout_get just to get 00059 //the outlet pointer 00060 max_jit_obex_dumpout(x,msg,3,(t_atom *)data); 00061 } else { 00062 //since we are a MOP, we are also attached to all the matrices for each input/output 00063 //so we need to deal with this by calling the default mop notify method 00064 //(this is how mops handle their matrices getting new names/freed/modified) 00065 //mop notify ignores the data element and you should also ignore the error that 00066 //max_jit_mop_notify has msg prototyped as a long *, it is really a symbol *(oops) 00067 max_jit_mop_notify(x,s,msg); 00068 } 00069 } 00070 00071 00072 void max_jit_notify_free(t_max_jit_notify *x) 00073 { 00074 00075 //NOTIFY EXAMPLE: DETACH FROM JIT OBJECT(SERVER) 00076 jit_object_detach(x->servername,x); 00077 00078 max_jit_mop_free(x); 00079 jit_object_free(max_jit_obex_jitob_get(x)); 00080 max_jit_obex_free(x); 00081 } 00082 00083 void *max_jit_notify_new(t_symbol *s, long argc, t_atom *argv) 00084 { 00085 t_max_jit_notify *x; 00086 void *o; 00087 00088 if (x=(t_max_jit_notify *)max_jit_obex_new(max_jit_notify_class,gensym("jit_notify"))) { 00089 if (o=jit_object_new(gensym("jit_notify"))) { 00090 max_jit_mop_setup_simple(x,o,argc,argv); 00091 max_jit_attr_args(x,argc,argv); 00092 00093 //NOTIFY EXAMPLE: GENERATING A UNIQUE NAME + ASSOCIATING WITH JIT OBJECT(SERVER) 00094 x->servername = jit_symbol_unique(); 00095 jit_object_method(o,_jit_sym_register,x->servername); //this registers w/ the name 00096 jit_object_attach(x->servername,x); //this attaches max object(client) with jit object(server) 00097 } else { 00098 error("jit.notify: could not allocate object"); 00099 freeobject(x); 00100 } 00101 } 00102 return (x); 00103 }
Copyright © 2008, Cycling '74