Max 5 API Reference
00001 /*************************/ 00002 /* Copyright 1988 IRCAM. */ 00003 /*************************/ 00004 00005 #ifndef _EXT_MESS_H_ 00006 #define _EXT_MESS_H_ 00007 00008 #ifdef __cplusplus 00009 extern "C" { 00010 #endif 00011 00012 #if C74_PRAGMA_STRUCT_PACKPUSH 00013 #pragma pack(push, 2) 00014 #elif C74_PRAGMA_STRUCT_PACK 00015 #pragma pack(2) 00016 #endif 00017 00018 /* mess.h -- define a symbol table and message-passing system. */ 00019 00020 00021 /** Function pointer type for generic methods. 00022 @ingroup datatypes 00023 */ 00024 typedef void *(*method)(void *, ...); 00025 00026 00027 /** Function pointer type for methods returning a long. 00028 @ingroup datatypes 00029 */ 00030 typedef long (*longmethod)(void *, ...); 00031 00032 00033 /** Function pointer type for a function with no arguments, returning a generic pointer. 00034 @ingroup datatypes 00035 */ 00036 typedef void *(*voidstarvoid)(); 00037 00038 00039 /** Generic pointer type. 00040 @ingroup datatypes 00041 */ 00042 typedef char *t_ptr; 00043 typedef char *ptr; 00044 00045 00046 /** Generic pointer-to-a-pointer type. 00047 @ingroup datatypes 00048 */ 00049 typedef char **t_handle; 00050 00051 00052 #ifndef VPTR_TYPEDEF 00053 /** Void pointer type. 00054 @ingroup datatypes 00055 */ 00056 typedef void *t_vptr; 00057 typedef void *vptr; 00058 00059 #define VPTR_TYPEDEF 00060 #endif 00061 00062 00063 /** The symbol. 00064 00065 Note: You should <em>never</em> manipulate the s_name field of the #t_symbol directly! 00066 Doing so will corrupt Max's symbol table. 00067 Instead, <em>always</em> use gensym() to get a symbol with the desired string 00068 contents for the s_name field. 00069 00070 @ingroup symbol 00071 */ 00072 typedef struct symbol 00073 { 00074 char *s_name; ///< name: a c-string 00075 struct object *s_thing; ///< possible binding to a t_object 00076 } Symbol, t_symbol; 00077 00078 #define CAREFUL 00079 00080 /** Magic number used to determine if memory pointed to by a #t_object* is valid. 00081 @ingroup obj 00082 */ 00083 #define MAGIC 1758379419L /* random (but odd) */ 00084 00085 #ifdef WIN_VERSION 00086 /** Returns true if a pointer is not a valid object. 00087 @ingroup obj 00088 */ 00089 #define NOGOOD(x) ( IsBadReadPtr((void *)(x),sizeof(struct object)) || ((struct object *)(x))->o_magic != MAGIC ) 00090 #else 00091 /** Returns true if a pointer is not a valid object. 00092 @ingroup obj 00093 */ 00094 #define NOGOOD(x) (((struct object *)x)->o_magic != MAGIC) 00095 #endif 00096 00097 00098 /** Maximum number of arguments that can be passed as a typed-list rather than using #A_GIMME. It is generally recommended to use #A_GIMME. 00099 @ingroup obj 00100 */ 00101 #define MAXARG 7 00102 00103 00104 /** A list of symbols and their corresponding methods, 00105 complete with typechecking information. 00106 @ingroup obj 00107 */ 00108 typedef struct messlist 00109 { 00110 struct symbol *m_sym; ///< Name of the message 00111 method m_fun; ///< Method associated with the message 00112 char m_type[MAXARG + 1]; ///< Argument type information 00113 } Messlist, t_messlist; 00114 00115 00116 /** The tiny object structure sits at the head of any object to which you may 00117 pass messages (and which you may feed to freeobject()). 00118 In general, you should use #t_object instead. 00119 @ingroup obj 00120 */ 00121 typedef struct tinyobject 00122 { 00123 struct messlist *t_messlist; ///< list of messages and methods 00124 // (also used as freelist link) 00125 #ifdef CAREFUL 00126 long t_magic; ///< magic number 00127 #endif 00128 } Tinyobject, t_tinyobject; 00129 00130 00131 /** The structure for the head of any object which wants to have inlets or outlets, 00132 or support attributes. 00133 @ingroup obj 00134 */ 00135 typedef struct object 00136 { 00137 struct messlist *o_messlist; ///< list of messages and methods. The -1 entry of the message list of an object contains a pointer to its #t_class entry. 00138 // (also used as freelist link) 00139 #ifdef CAREFUL 00140 long o_magic; ///< magic number 00141 #endif 00142 struct inlet *o_inlet; ///< list of inlets 00143 struct outlet *o_outlet; ///< list of outlets 00144 } Object, t_object; 00145 00146 00147 /** 00148 The data structure for a Max class. This struct is provided for debugging convenience, 00149 but should be considered opaque and is subject to change without notice. 00150 00151 @ingroup class 00152 */ 00153 typedef struct maxclass 00154 { 00155 struct symbol *c_sym; ///< symbol giving name of class 00156 struct object **c_freelist; // linked list of free ones 00157 method c_freefun; // function to call when freeing 00158 short c_size; // size of an instance 00159 char c_tiny; // flag indicating tiny header 00160 char c_noinlet; // flag indicating no first inlet for patcher 00161 struct symbol *c_filename; ///< name of file associated with this class 00162 t_messlist *c_newmess; // constructor method/type information 00163 method c_menufun; // function to call when creating from object pallette (default constructor) 00164 long c_flags; // class flags used to determine context in which class may be used 00165 long c_messcount; // size of messlist array 00166 t_messlist *c_messlist; // messlist arrray 00167 void *c_attributes; // t_hashtab object 00168 void *c_extra; // t_hashtab object 00169 long c_obexoffset; // if non zero, object struct contains obex pointer at specified byte offset 00170 } Maxclass, t_class; 00171 00172 00173 /** Class flags. If not box or polyglot, class is only accessible in C via known interface 00174 @ingroup class 00175 */ 00176 typedef enum { 00177 CLASS_FLAG_BOX = 0x00000001L, ///< for use in a patcher 00178 CLASS_FLAG_POLYGLOT = 0x00000002L, ///< for use by any text language (c/js/java/etc) 00179 CLASS_FLAG_NEWDICTIONARY = 0x00000004L, ///< dictionary based constructor 00180 CLASS_FLAG_REGISTERED = 0x00000008L, ///< for backward compatible messlist implementation (once reg'd can't grow) 00181 CLASS_FLAG_UIOBJECT = 0x00000010L, ///< for objects that don't go inside a newobj box. 00182 CLASS_FLAG_ALIAS = 0x00000020L, ///< for classes that are just copies of some other class (i.e. del is a copy of delay) 00183 CLASS_FLAG_SCHED_PURGE = 0x00000040L, ///< for classes that have called clock_new() or qelem_new() (don't need to set this yourself) 00184 CLASS_FLAG_DO_NOT_PARSE_ATTR_ARGS = 0x00000080L, ///< override dictionary based constructor attr arg parsing 00185 CLASS_FLAG_NOATTRIBUTES = 0x00010000L, ///< for efficiency 00186 CLASS_FLAG_OWNATTRIBUTES = 0x00020000L ///< for classes which support a custom attr interface (e.g. jitter) 00187 } e_max_class_flags; 00188 00189 00190 /** the list of officially recognized types, including pseudotypes for 00191 commas and semicolons. Used in two places: 1. the reader, when it reads 00192 a string, returns long, float, sym, comma, semi, or dollar; 00193 and 2. each object method comes with an array of them saying what types 00194 it needs, from among long, float, sym, obj, gimme, and cant. 00195 00196 @ingroup atom 00197 00198 @remark While these values are defined in an enum, you should use a long to represent the value. 00199 Using the enum type creates ambiguity in struct size and is subject to various inconsistent 00200 compiler settings. 00201 */ 00202 typedef enum { 00203 A_NOTHING = 0, ///< no type, thus no atom 00204 A_LONG, ///< long integer 00205 A_FLOAT, ///< 32-bit float 00206 A_SYM, ///< t_symbol pointer 00207 A_OBJ, ///< t_object pointer (for argtype lists; passes the value of sym) 00208 A_DEFLONG, ///< long but defaults to zero 00209 A_DEFFLOAT, ///< float, but defaults to zero 00210 A_DEFSYM, ///< symbol, defaults to "" 00211 A_GIMME, ///< request that args be passed as an array, the routine will check the types itself. 00212 A_CANT, ///< cannot typecheck args 00213 A_SEMI, ///< semicolon 00214 A_COMMA, ///< comma 00215 A_DOLLAR, ///< dollar 00216 A_DOLLSYM, ///< dollar 00217 A_GIMMEBACK, ///< request that args be passed as an array, the routine will check the types itself. can return atom value in final atom ptr arg. function returns long error code 0 = no err. see gimmeback_meth typedef 00218 00219 A_DEFER = 0x41, ///< A special signature for declaring methods. This is like A_GIMME, but the call is deferred. 00220 A_USURP = 0x42, ///< A special signature for declaring methods. This is like A_GIMME, but the call is deferred and multiple calls within one servicing of the queue are filtered down to one call. 00221 A_DEFER_LOW = 0x43, ///< A special signature for declaring methods. This is like A_GIMME, but the call is deferref to the back of the queue. 00222 A_USURP_LOW = 0x44 ///< A special signature for declaring methods. This is like A_GIMME, but the call is deferred to the back of the queue and multiple calls within one servicing of the queue are filtered down to one call. 00223 } e_max_atomtypes; 00224 00225 00226 /** Defines the largest possible string size for an atom 00227 @ingroup atom */ 00228 #define ATOM_MAX_STRLEN (32768) 00229 00230 00231 /** Union for packing any of the datum defined in #e_max_atomtypes. 00232 @ingroup atom 00233 */ 00234 union word 00235 { 00236 long w_long; ///< long integer 00237 float w_float; ///< 32-bit float 00238 struct symbol *w_sym; ///< pointer to a symbol in the Max symbol table 00239 struct object *w_obj; ///< pointer to a #t_object or other generic pointer 00240 }; 00241 00242 00243 /** An atom is a typed datum. 00244 @ingroup atom 00245 */ 00246 typedef struct atom 00247 { 00248 short a_type; ///< a value as defined in #e_max_atomtypes 00249 union word a_w; ///< the actual data 00250 } Atom, t_atom; 00251 00252 00253 00254 /** Function pointer type for methods with no arguments. 00255 @ingroup datatypes 00256 */ 00257 typedef void *(*zero_meth)(void *x); 00258 00259 00260 /** Function pointer type for methods with a single argument. 00261 @ingroup datatypes 00262 */ 00263 typedef void *(*one_meth)(void *x, void *z); 00264 00265 00266 /** Function pointer type for methods with two arguments. 00267 @ingroup datatypes 00268 */ 00269 typedef void *(*two_meth)(void *x, void *z, void *a); 00270 00271 00272 /** Function pointer type for methods that pass back a result value through the last parameter as a #t_atom, 00273 and return an error. 00274 @ingroup datatypes 00275 */ 00276 typedef long *(*gimmeback_meth)(void *x, t_symbol *s, long ac, t_atom *av, t_atom *rv); 00277 00278 00279 00280 // legacy macros... 00281 00282 #define BAG(s) {error(s); return (0);} 00283 #define BAG2(s,t) {error(s,t); return (0);} 00284 #define ob_messlist(x) (((struct object *)(x))->o_messlist - 1) 00285 #define ob_class(x) ((struct maxclass *) \ 00286 (((struct object *)(x))->o_messlist[-1].m_sym)) 00287 #define ob_name(x) (ob_class(x)->c_sym->s_name) 00288 #define ob_sym(x) (ob_class(x)->c_sym) 00289 #define ob_filename(x) (ob_class(x)->c_filename->s_name) 00290 #define ob_filesym(x) (ob_class(x)->c_filename) 00291 #define mess0(x, y) (*((zero_meth)(getfn(x, y))))(x) 00292 #define mess1(x, y, z1) (*((one_meth)(getfn(x, y))))(x, z1) 00293 #define mess2(x, y, z1,z2) (*((two_meth)(getfn(x, y))))(x, z1,z2) 00294 #define mess3(x, y, z1,z2,z3) (*(getfn(x, y)))(x, z1,z2,z3) 00295 #define mess4(x, y, z1,z2,z3,z4) (*(getfn(x, y)))(x, z1,z2,z3,z4) 00296 #define mess5(x, y, z1,z2,z3,z4,z5) (*(getfn(x, y)))(x, z1,z2,z3,z4,z5) 00297 #define NIL ((void *)0) 00298 #define SETCOMMA(ap) ((ap)->a_type = A_COMMA) 00299 #define SETSEMI(ap) ((ap)->a_type = A_SEMI) 00300 #define SETSYM(ap, x) ((ap)->a_type = A_SYM, (ap)->a_w.w_sym = (x)) 00301 #define SETOBJ(ap, x) ((ap)->a_type = A_OBJ, (ap)->a_w.w_obj = (x)) 00302 #define SETLONG(ap, x) ((ap)->a_type = A_LONG, (ap)->a_w.w_long = (x)) 00303 #define SETFLOAT(ap, x) ((ap)->a_type = A_FLOAT, (ap)->a_w.w_float = (x)) 00304 #define SETDOLLAR(ap, x) ((ap)->a_type = A_DOLLAR, (ap)->a_w.w_long = (x)) 00305 00306 00307 #if C74_PRAGMA_STRUCT_PACKPUSH 00308 #pragma pack(pop) 00309 #elif C74_PRAGMA_STRUCT_PACK 00310 #pragma pack() 00311 #endif 00312 00313 #ifdef __cplusplus 00314 } 00315 #endif 00316 00317 #endif /* _EXT_MESS_H_ */
Copyright © 2008, Cycling '74