Max 5 API Reference
00001 00002 #ifndef __OBEX_H__ 00003 #define __OBEX_H__ 00004 00005 #ifdef __cplusplus 00006 extern "C" { 00007 #endif // __cplusplus 00008 00009 00010 #ifndef TRUE 00011 #define TRUE 1 00012 #endif 00013 #ifndef FALSE 00014 #define FALSE 0 00015 #endif 00016 00017 /** The namespace for all Max object classes which can be instantiated in a box, i.e. in a patcher. 00018 @ingroup class */ 00019 #define CLASS_BOX gensym("box") 00020 00021 /** A namespace for creating hidden or internal object classes which are not a direct part of the user 00022 creating patcher. 00023 @ingroup class */ 00024 #define CLASS_NOBOX gensym("nobox") 00025 00026 00027 /** Attribute flags 00028 @ingroup attr 00029 00030 @remark To create a readonly attribute, for example, 00031 you should pass ATTR_SET_OPAQUE or ATTR_SET_OPAQUE_USER as a flag when you create your attribute. 00032 */ 00033 typedef enum { 00034 ATTR_FLAGS_NONE = 0x0000000, ///< No flags 00035 ATTR_GET_OPAQUE = 0x00000001, ///< The attribute cannot be queried by either max message when used inside of a CLASS_BOX object, nor from C code. 00036 ATTR_SET_OPAQUE = 0x00000002, ///< The attribute cannot be set by either max message when used inside of a CLASS_BOX object, nor from C code. 00037 ATTR_GET_OPAQUE_USER = 0x00000100, ///< The attribute cannot be queried by max message when used inside of a CLASS_BOX object, but <em>can</em> be queried from C code. 00038 ATTR_SET_OPAQUE_USER = 0x00000200, ///< The attribute cannot be set by max message when used inside of a CLASS_BOX object, but <em>can</em> be set from C code. 00039 ATTR_GET_DEFER = 0x00010000, ///< Any attribute queries will be called through a defer(). 00040 ATTR_GET_USURP = 0x00020000, ///< Any calls to query the attribute will be called through the equivalent of a defer(), repeated calls will be ignored until the getter is actually run. 00041 ATTR_GET_DEFER_LOW = 0x00040000, ///< Any attribute queries will be called through a defer_low(). 00042 ATTR_GET_USURP_LOW = 0x00080000, ///< Any calls to query the attribute will be called through the equivalent of a defer_low(), repeated calls will be ignored until the getter is actually run. 00043 ATTR_SET_DEFER = 0x01000000, ///< The attribute setter will be called through a defer(). 00044 ATTR_SET_USURP = 0x02000000, ///< Any calls to set the attribute will be called through the equivalent of a defer_low(), repeated calls will be ignored until the setter is actually run. 00045 ATTR_SET_DEFER_LOW = 0x04000000, ///< The attribute setter will be called through a defer_low(). 00046 ATTR_SET_USURP_LOW = 0x08000000 ///< Any calls to set the attribute will be called through the equivalent of a defer_low(), repeated calls will be ignored until the setter is actually run. 00047 } e_max_attrflags; 00048 00049 00050 /** Standard values returned by function calls with a return type of #t_max_err 00051 @ingroup misc */ 00052 typedef enum { 00053 MAX_ERR_NONE = 0, ///< No error 00054 MAX_ERR_GENERIC = -1, ///< Generic error 00055 MAX_ERR_INVALID_PTR = -2, ///< Invalid Pointer 00056 MAX_ERR_DUPLICATE = -3, ///< Duplicate 00057 MAX_ERR_OUT_OF_MEM = -4 ///< Out of memory 00058 } e_max_errorcodes; 00059 00060 00061 /** Flags used in linklist and hashtab objects 00062 @ingroup datastore */ 00063 typedef enum { 00064 OBJ_FLAG_OBJ = 0x00000000, ///< free using object_free() 00065 OBJ_FLAG_REF = 0x00000001, ///< don't free 00066 OBJ_FLAG_DATA = 0x00000002, ///< don't free data or call method 00067 OBJ_FLAG_MEMORY = 0x00000004, ///< don't call method, and when freeing use sysmem_freeptr() instead of freeobject 00068 OBJ_FLAG_SILENT = 0x00000100, ///< don't notify when modified 00069 OBJ_FLAG_INHERITABLE = 0x00000200 ///< obexprototype entry will be inherited by subpatchers and abstractions 00070 } e_max_datastore_flags; 00071 00072 00073 #ifdef calcoffset //find better place for this? 00074 // The ifdefs for this macro have been set up like this so that Doxygen can document this macro on a Mac [TAP] 00075 #else 00076 #ifdef WIN_VERSION 00077 // rbs truncation of pointer to long is safe if the struct is smaller than 2^32 bytes. 00078 // this seems like a good assumption. 00079 // PtrToLong is defined in Basetsd.h (windows) and is described here http://msdn2.microsoft.com/En-US/library/aa384242.aspx 00080 #define calcoffset(x,y) (PtrToLong(&(((x *)0L)->y))) 00081 #else 00082 /** 00083 Find byte offset of a named member of a struct, relative to the beginning of that struct. 00084 @ingroup misc 00085 @param x The name of the struct 00086 @param y The name of the member 00087 @return A long integer representing the number of bytes into the struct where the member begins. 00088 */ 00089 #define calcoffset(x,y) ((long)(&(((x *)0L)->y))) 00090 #endif 00091 #endif 00092 00093 #ifndef __JIT_COMMON_H__ 00094 /** An unsigned long integer. 00095 @ingroup datatypes */ 00096 typedef unsigned long ulong; 00097 00098 /** An unsigned integer. 00099 @ingroup datatypes */ 00100 typedef unsigned int uint; 00101 00102 /** An unsigned short integer. 00103 @ingroup datatypes */ 00104 typedef unsigned short ushort; 00105 00106 /** An unsigned char. 00107 @ingroup datatypes */ 00108 typedef unsigned char uchar; 00109 #endif 00110 00111 00112 /** 00113 A Max error code. Common error codes are defined in #e_max_errorcodes. 00114 @ingroup datatypes 00115 */ 00116 typedef long t_max_err; 00117 00118 #include "commonsyms.h" 00119 #include "ext_linklist.h" 00120 #include "ext_hashtab.h" 00121 #include "ext_atomarray.h" 00122 00123 #if C74_PRAGMA_STRUCT_PACKPUSH 00124 #pragma pack(push, 2) 00125 #elif C74_PRAGMA_STRUCT_PACK 00126 #pragma pack(2) 00127 #endif 00128 00129 //for passing on the stack in method calls 00130 /* 00131 typedef struct _stack_splat 00132 { 00133 char b[64]; 00134 } t_stack_splat; 00135 */ 00136 00137 /** Common attr struct. This struct is provided for debugging convenience, 00138 but should be considered opaque and is subject to change without notice. 00139 00140 @ingroup attr 00141 */ 00142 typedef struct _attr 00143 { 00144 t_object ob; 00145 t_symbol *name; 00146 t_symbol *type; 00147 long flags; //public/private get/set methods 00148 method get; //override default get method 00149 method set; //override default set method 00150 void *filterget; //filterobject for get method 00151 void *filterset; //filterobject for set method 00152 void *reserved; //for future use 00153 } t_attr; 00154 00155 00156 /** 00157 A method that always returns true. 00158 @ingroup misc 00159 */ 00160 long method_true(void *x); 00161 00162 00163 /** 00164 A method that always returns false. 00165 @ingroup misc 00166 */ 00167 long method_false(void *x); 00168 00169 00170 /** 00171 Initializes a class by informing Max of its name, instance creation and free functions, size and argument types. 00172 Developers wishing to use obex class features (attributes, etc.) <em>must</em> use class_new() 00173 instead of the traditional setup() function. 00174 00175 @ingroup class 00176 00177 @param name The class's name, as a C-string 00178 @param mnew The instance creation function 00179 @param mfree The instance free function 00180 @param size The size of the object's data structure in bytes. 00181 Usually you use the C sizeof operator here. 00182 @param mmenu The function called when the user creates a new object of the 00183 class from the Patch window's palette (UI objects only). 00184 Pass 0L if you're not defining a UI object. 00185 @param type A standard Max <em>type list</em> as explained in Chapter 3 00186 of the Writing Externals in Max document (in the Max SDK). 00187 The final argument of the type list should be a 0. 00188 <em>Generally, obex objects have a single type argument</em>, 00189 #A_GIMME, followed by a 0. 00190 00191 @return This function returns the class pointer for the new object class. 00192 <em>This pointer is used by numerous other functions and should be 00193 stored in a global or static variable.</em> 00194 */ 00195 t_class *class_new(char *name, method mnew, method mfree, long size, method mmenu, short type, ...); 00196 00197 00198 /** 00199 Frees a previously defined object class. <em>This function is not typically used by external developers.</em> 00200 00201 @ingroup class 00202 @param c The class pointer 00203 @return This function returns the error code #MAX_ERR_NONE if successful, 00204 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00205 */ 00206 t_max_err class_free(t_class *c); 00207 00208 00209 /** 00210 Registers a previously defined object class. This function is required, and should be called at the end of <tt>main()</tt>. 00211 00212 @ingroup class 00213 00214 @param name_space The desired class's name space. Typically, either the 00215 constant #CLASS_BOX, for obex classes which can 00216 instantiate inside of a Max patcher (e.g. boxes, UI objects, 00217 etc.), or the constant #CLASS_NOBOX, for classes 00218 which will only be used internally. Developers can define 00219 their own name spaces as well, but this functionality is 00220 currently undocumented. 00221 @param c The class pointer 00222 00223 @return This function returns the error code #MAX_ERR_NONE if successful, 00224 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00225 */ 00226 t_max_err class_register(t_symbol *name_space, t_class *c); 00227 00228 00229 /** 00230 Registers an alias for a previously defined object class. 00231 00232 @ingroup class 00233 @param c The class pointer 00234 @param aliasname A symbol who's name will become an alias for the given class 00235 00236 @return This function returns the error code #MAX_ERR_NONE if successful, 00237 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00238 */ 00239 t_max_err class_alias(t_class *c, t_symbol *aliasname); 00240 00241 00242 /** 00243 Adds a method to a previously defined object class. 00244 00245 @ingroup class 00246 00247 @param c The class pointer 00248 @param m Function to be called when the method is invoked 00249 @param name C-string defining the message (message selector) 00250 @param ... One or more integers specifying the arguments to the message, 00251 in the standard Max type list format (see Chapter 3 of the 00252 Writing Externals in Max document for more information). 00253 00254 @return This function returns the error code #MAX_ERR_NONE if successful, 00255 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00256 00257 @remark The class_addmethod() function works essentially like the 00258 traditional addmess() function, adding the function pointed to 00259 by <tt>m</tt>, to respond to the message string <tt>name</tt> in the 00260 leftmost inlet of the object. 00261 */ 00262 t_max_err class_addmethod(t_class *c, method m, char *name, ...); 00263 00264 00265 /** 00266 Adds an attribute to a previously defined object class. 00267 00268 @ingroup class 00269 00270 @param c The class pointer 00271 @param attr The attribute to add. The attribute will be a pointer returned 00272 by attribute_new(), attr_offset_new() or 00273 attr_offset_array_new(). 00274 00275 @return This function returns the error code #MAX_ERR_NONE if successful, 00276 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00277 */ 00278 t_max_err class_addattr(t_class *c,t_object *attr); 00279 00280 00281 // private 00282 t_max_err class_addadornment(t_class *c,t_object *o); 00283 00284 00285 // private 00286 void *class_adornment_get(t_class *c,t_symbol *classname); 00287 00288 00289 /** 00290 Retrieves the name of a class, given the class's pointer. 00291 00292 @ingroup class 00293 @param c The class pointer 00294 @return If successful, this function returns the name of the class as a t_symbol *. 00295 */ 00296 t_symbol *class_nameget(t_class *c); 00297 00298 00299 /** 00300 Finds the class pointer for a class, given the class's namespace and name. 00301 00302 @ingroup class 00303 00304 @param name_space The desired class's name space. Typically, either the 00305 constant #CLASS_BOX, for obex classes which can 00306 instantiate inside of a Max patcher (e.g. boxes, UI objects, 00307 etc.), or the constant #CLASS_NOBOX, for classes 00308 which will only be used internally. Developers can define 00309 their own name spaces as well, but this functionality is 00310 currently undocumented. 00311 @param classname The name of the class to be looked up 00312 00313 @return If successful, this function returns the class's data pointer. Otherwise, it returns NULL. 00314 */ 00315 t_class *class_findbyname(t_symbol *name_space, t_symbol *classname); 00316 00317 00318 /** 00319 Finds the class pointer for a class, given the class's namespace and name. 00320 00321 @ingroup class 00322 00323 @param name_space The desired class's name space. Typically, either the 00324 constant #CLASS_BOX, for obex classes which can 00325 instantiate inside of a Max patcher (e.g. boxes, UI objects, 00326 etc.), or the constant #CLASS_NOBOX, for classes 00327 which will only be used internally. Developers can define 00328 their own name spaces as well, but this functionality is 00329 currently undocumented. 00330 @param classname The name of the class to be looked up (case free) 00331 00332 @return If successful, this function returns the class's data pointer. Otherwise, it returns NULL. 00333 */ 00334 t_class *class_findbyname_casefree(t_symbol *name_space, t_symbol *classname); 00335 00336 00337 /** 00338 Wraps user gettable attributes with a method that gets the values and sends out dumpout outlet. 00339 00340 @ingroup class 00341 @param c The class pointer 00342 @return This function returns the error code #MAX_ERR_NONE if successful, 00343 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00344 */ 00345 t_max_err class_dumpout_wrap(t_class *c); 00346 00347 t_class *class_getifloaded(t_symbol *name_space, t_symbol *classname); 00348 t_class *class_getifloaded_casefree(t_symbol *name_space, t_symbol *classname); 00349 00350 00351 /** 00352 Determines if a particular object is an instance of a given class. 00353 00354 @ingroup obj 00355 00356 @param x The object to test 00357 @param name The name of the class to test this object against 00358 @return This function returns 1 if the object is an instance of the named class. Otherwise, 0 is returned. 00359 @remark For instance, to determine whether an unknown object pointer is a pointer to a print object, one would call: 00360 00361 @code 00362 long isprint = object_classname_compare(x, gensym("print")); 00363 @endcode 00364 */ 00365 long object_classname_compare(void *x, t_symbol *name); 00366 00367 00368 t_hashtab *reg_object_namespace_lookup(t_symbol *name_space); 00369 method class_method(t_class *x, t_symbol *methodname); 00370 t_messlist *class_mess(t_class *x, t_symbol *methodname); 00371 method class_attr_method(t_class *x, t_symbol *methodname, void **attr, long *get); 00372 void *class_attr_get(t_class *x, t_symbol *attrname); 00373 t_max_err class_extra_store(t_class *x,t_symbol *s,t_object *o); 00374 t_max_err class_extra_storeflags(t_class *x,t_symbol *s,t_object *o,long flags); 00375 void *class_extra_lookup(t_class *x,t_symbol *s); 00376 t_max_err class_addtypedwrapper(t_class *x, method m, char *name, ...); 00377 t_messlist *class_typedwrapper_get(t_class *x, t_symbol *s); 00378 t_hashtab *class_namespace_fromsym(t_symbol *name_space); 00379 t_max_err class_namespace_getclassnames(t_symbol *name_space, long *kc, t_symbol ***kv); 00380 t_max_err class_setpath(t_class *x, short vol); 00381 short class_getpath(t_class *x); 00382 00383 00384 /** 00385 Allocates the memory for an instance of an object class and initialize its object header. 00386 It is used like the traditional function newobject, inside of an object's <tt>new</tt> method, but its use is required with obex-class objects. 00387 00388 @ingroup obj 00389 @param c The class pointer, returned by class_new() 00390 @return This function returns a new instance of an object class if successful, or NULL if unsuccessful. 00391 */ 00392 void *object_alloc(t_class *c); 00393 00394 00395 /** 00396 Allocates the memory for an instance of an object class and initialize its object header <em>internal to Max</em>. 00397 It is used similarly to the traditional function newinstance(), but its use is required with obex-class objects. 00398 00399 @ingroup obj 00400 00401 @param name_space The desired object's name space. Typically, either the 00402 constant #CLASS_BOX, for obex classes which can 00403 instantiate inside of a Max patcher (e.g. boxes, UI objects, 00404 etc.), or the constant #CLASS_NOBOX, for classes 00405 which will only be used internally. Developers can define 00406 their own name spaces as well, but this functionality is 00407 currently undocumented. 00408 @param classname The name of the class of the object to be created 00409 @param ... Any arguments expected by the object class being instantiated 00410 00411 @return This function returns a new instance of the object class if successful, or NULL if unsuccessful. 00412 */ 00413 void *object_new(t_symbol *name_space, t_symbol *classname, ...); 00414 00415 00416 /** 00417 Allocates the memory for an instance of an object class and initialize its object header <em>internal to Max</em>. 00418 It is used similarly to the traditional function newinstance(), but its use is required with obex-class objects. 00419 The object_new_typed() function differs from object_new() by its use of an atom list for object arguments—in this way, 00420 it more resembles the effect of typing something into an object box from the Max interface. 00421 00422 @ingroup obj 00423 00424 @param name_space The desired object's name space. Typically, either the 00425 constant #CLASS_BOX, for obex classes which can 00426 instantiate inside of a Max patcher (e.g. boxes, UI objects, 00427 etc.), or the constant #CLASS_NOBOX, for classes 00428 which will only be used internally. Developers can define 00429 their own name spaces as well, but this functionality is 00430 currently undocumented. 00431 @param classname The name of the class of the object to be created 00432 @param ac Count of arguments in <tt>av</tt> 00433 @param av Array of t_atoms; arguments to the class's instance creation function. 00434 00435 @return This function returns a new instance of the object class if successful, or NULL if unsuccessful. 00436 */ 00437 void *object_new_typed(t_symbol *name_space, t_symbol *classname, long ac, t_atom *av); 00438 00439 void *object_new_menufun(t_symbol *name_space, t_symbol *classname, void *p, long h, long v, long f); 00440 00441 00442 /** 00443 Call the free function and release the memory for an instance of an internal object class previously instantiated using object_new(), 00444 object_new_typed() or other new-style object constructor functions (e.g. hashtab_new()). 00445 It is, at the time of this writing, a wrapper for the traditional function freeobject(), but its use is suggested with obex-class objects. 00446 00447 @ingroup obj 00448 @param x The pointer to the object to be freed. 00449 @return This function returns the error code #MAX_ERR_NONE if successful, 00450 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00451 */ 00452 t_max_err object_free(void *x); 00453 00454 00455 /** 00456 Sends an untyped message to an object. 00457 00458 @ingroup obj 00459 00460 @param x The object that will receive the message 00461 @param s The message selector 00462 @param ... Any arguments to the message 00463 00464 @return If the receiver object can respond to the message, object_method() returns the result. Otherwise, the function will return 0. 00465 00466 @remark Example: To send the message <tt>bang</tt> to the object <tt>bang_me</tt>: 00467 @code 00468 void *bang_result; 00469 bang_result = object_method(bang_me, gensym("bang")); 00470 @endcode 00471 */ 00472 void *object_method(void *x, t_symbol *s, ...); 00473 00474 00475 /** 00476 Sends a type-checked message to an object. 00477 00478 @ingroup obj 00479 00480 @param x The object that will receive the message 00481 @param s The message selector 00482 @param ac Count of message arguments in <tt>av</tt> 00483 @param av Array of t_atoms; the message arguments 00484 @param rv Return value of function, if available 00485 00486 @return This function returns the error code #MAX_ERR_NONE if successful, 00487 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00488 00489 @remark If the receiver object can respond to the message, object_method_typed() returns the result in <tt>rv</tt>. Otherwise, <tt>rv</tt> will contain an #A_NOTHING atom. 00490 */ 00491 t_max_err object_method_typed(void *x, t_symbol *s, long ac, t_atom *av, t_atom *rv); 00492 00493 00494 /** 00495 Currently undocumented. 00496 00497 @ingroup obj 00498 00499 @param x The object that will receive the message 00500 @param mp Undocumented 00501 @param s The message selector 00502 @param ac Count of message arguments in <tt>av</tt> 00503 @param av Array of t_atoms; the message arguments 00504 @param rv Return value of function, if available 00505 00506 @return This function returns the error code #MAX_ERR_NONE if successful, 00507 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00508 00509 @remark If the receiver object can respond to the message, object_method_typedfun() returns the result in <tt>rv</tt>. Otherwise, <tt>rv</tt> will contain an #A_NOTHING atom. 00510 */ 00511 t_max_err object_method_typedfun(void *x, t_messlist *mp, t_symbol *s, long ac, t_atom *av, t_atom *rv); 00512 00513 00514 /** 00515 Retrieves an object's #method for a particular message selector. 00516 00517 @ingroup obj 00518 @param x The object whose method is being queried 00519 @param s The message selector 00520 @return This function returns the #method if successful, or 0 if unsuccessful. 00521 */ 00522 method object_getmethod(void *x, t_symbol *s); 00523 00524 00525 /** 00526 Retrieves an object instance's class name 00527 00528 @ingroup obj 00529 @param x The object instance whose class name is being queried 00530 @return The classname, or NULL if unsuccessful. 00531 */ 00532 t_symbol *object_classname(void *x); 00533 00534 00535 t_symbol *object_namespace(t_object *x); // return the namespace this object's class is part of 00536 00537 00538 t_symbol *class_namespace(t_class *c); // return the namespace the class is part of 00539 00540 00541 /** 00542 Registers an object in a namespace. 00543 00544 @ingroup obj 00545 00546 @param name_space The namespace in which to register the object. The namespace can be any symbol. 00547 If the namespace does not already exist, it is created automatically. 00548 @param s The name of the object in the namespace. This name will be 00549 used by other objects to attach and detach from the registered object. 00550 @param x The object to register 00551 00552 @return The function returns a pointer to the registered object. Under some 00553 circumstances, object_register will <em>duplicate</em> the object, 00554 and return a pointer to the duplicate—the developer should not assume 00555 that the pointer passed in is the same pointer that has been registered. 00556 To be safe, the returned pointer should be stored and used with the 00557 bject_unregister() function. 00558 00559 @remark You should not register an object if the object is a UI object. 00560 UI objects automatically register and attach to themselves in jbox_new(). 00561 */ 00562 void *object_register(t_symbol *name_space, t_symbol *s, void *x); 00563 00564 00565 t_symbol *object_register_unique(t_symbol *name_space, t_symbol *s, void *x); 00566 00567 00568 /** 00569 Determines a registered object's pointer, given its namespace and name. 00570 00571 @ingroup obj 00572 00573 @param name_space The namespace of the registered object 00574 @param s The name of the registered object in the namespace 00575 00576 @return This function returns the pointer of the registered object, 00577 if successful, or NULL, if unsuccessful. 00578 */ 00579 void *object_findregistered(t_symbol *name_space, t_symbol *s); 00580 00581 00582 /** 00583 Determines the namespace and/or name of a registered object, given the object's pointer. 00584 00585 @ingroup obj 00586 00587 @param name_space Pointer to a t_symbol *, to receive the namespace of the registered object 00588 @param s Pointer to a t_symbol *, to receive the name of the registered object within the namespace 00589 @param x Pointer to the registered object 00590 00591 @return This function returns the error code #MAX_ERR_NONE if successful, 00592 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00593 */ 00594 t_max_err object_findregisteredbyptr(t_symbol **name_space, t_symbol **s, void *x); 00595 00596 00597 /** 00598 Attaches a client to a registered object. 00599 Once attached, the object will receive notifications sent from the registered object (via the object_notify() function), 00600 if it has a <tt>notify</tt> method defined and implemented. 00601 00602 @ingroup obj 00603 00604 @param name_space The namespace of the registered object. 00605 This should be the same value used in object_register() to register the object. 00606 If you don't know the registered object's namespace, the object_findregisteredbyptr() function can be used to determine it. 00607 @param s The name of the registered object in the namespace. 00608 If you don't know the name of the registered object, the object_findregisteredbyptr() function can be used to determine it. 00609 @param x The client object to attach. Generally, this is the pointer to your Max object. 00610 00611 @return This function returns a pointer to the registered object (to the object 00612 referred to by the combination of <tt>name_space</tt> and <tt>s</tt> 00613 arguments) if successful, or NULL if unsuccessful. 00614 00615 @remark You should not attach an object to itself if the object is a UI object. 00616 UI objects automatically register and attach to themselves in jbox_new(). 00617 00618 @see object_notify() 00619 @see object_detach() 00620 @see object_attach_byptr() 00621 @see object_register() 00622 */ 00623 void *object_attach(t_symbol *name_space, t_symbol *s, void *x); 00624 00625 00626 /** 00627 Detach a client from a registered object. 00628 00629 @ingroup obj 00630 00631 @param name_space The namespace of the registered object. 00632 This should be the same value used in object_register() to register the object. 00633 If you don't know the registered object's namespace, the object_findregisteredbyptr() function can be used to determine it. 00634 @param s The name of the registered object in the namespace. 00635 If you don't know the name of the registered object, the object_findregisteredbyptr() function can be used to determine it. 00636 @param x The client object to attach. Generally, this is the pointer to your Max object. 00637 00638 @return This function returns the error code #MAX_ERR_NONE if successful, 00639 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00640 */ 00641 t_max_err object_detach(t_symbol *name_space, t_symbol *s, void *x); 00642 00643 00644 /** 00645 Attaches a client to a registered object. 00646 Unlike object_attach(), the client is specified by providing a pointer to that object 00647 rather than the registered name of that object. 00648 00649 Once attached, the object will receive notifications sent from the registered object (via the object_notify() function), 00650 if it has a <tt>notify</tt> method defined and implemented. 00651 00652 @ingroup obj 00653 @param x The attaching client object. Generally, this is the pointer to your Max object. 00654 @param registeredobject A pointer to the registered object to which you wish to attach. 00655 @return A Max error code. 00656 00657 @remark You should not attach an object to itself if the object is a UI object. 00658 UI objects automatically register and attach to themselves in jbox_new(). 00659 00660 @see object_notify() 00661 @see object_detach() 00662 @see object_attach() 00663 @see object_register() 00664 @see object_attach_byptr_register() 00665 */ 00666 t_max_err object_attach_byptr(void *x, void *registeredobject); 00667 00668 00669 /** 00670 A convenience function wrapping object_register() and object_attach_byptr(). 00671 00672 @ingroup obj 00673 00674 @param x The attaching client object. Generally, this is the pointer to your Max object. 00675 @param object_to_attach A pointer to the object to which you wish to registered and then to which to attach. 00676 @param reg_name_space The namespace in which to register the object_to_attach. 00677 @return A Max error code. 00678 00679 @see object_register() 00680 @see object_attach_byptr() 00681 */ 00682 t_max_err object_attach_byptr_register(void *x, void *object_to_attach, t_symbol *reg_name_space); 00683 00684 00685 /** 00686 Detach a client from a registered object. 00687 00688 @ingroup obj 00689 @param x The attaching client object. Generally, this is the pointer to your Max object. 00690 @param registeredobject The object from which to detach. 00691 @return A Max error code. 00692 00693 @see object_detach() 00694 @see object_attach_byptr() 00695 */ 00696 t_max_err object_detach_byptr(void *x, void *registeredobject); 00697 00698 00699 /** 00700 Removes a registered object from a namespace. 00701 00702 @ingroup obj 00703 @param x The object to unregister. This should be the pointer returned from the object_register() function. 00704 @return This function returns the error code #MAX_ERR_NONE if successful, 00705 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00706 */ 00707 t_max_err object_unregister(void *x); 00708 00709 00710 /** 00711 Broadcast a message (with an optional argument) from a registered object to any attached client objects. 00712 00713 @ingroup obj 00714 00715 @param x Pointer to the registered object 00716 @param s The message to send 00717 @param data An optional argument which will be passed with the message. 00718 Sets this argument to NULL if it will be unused. 00719 00720 @return This function returns the error code #MAX_ERR_NONE if successful, 00721 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00722 00723 @remark In order for client objects to receive notifications, they must define and implement a special method, <tt>notify</tt>, like so: 00724 @code 00725 class_addmethod(c, (method)myobject_notify, "notify", A_CANT, 0); 00726 @endcode 00727 00728 @remark The <tt>notify</tt> method should be prototyped as: 00729 @code 00730 void myobject_notify(t_myobject *x, t_symbol *s, t_symbol *msg, void *sender, void *data); 00731 @endcode 00732 where 00733 <tt>x</tt> is the pointer to the receiving object, 00734 <tt>s</tt> is the name of the sending (registered) object in its namespace, 00735 <tt>msg</tt> is the sent message, 00736 <tt>sender</tt> is the pointer to the sending object, and 00737 <tt>data</tt> is an optional argument sent with the message. 00738 This value corresponds to the data argument in the object_notify() method. 00739 */ 00740 t_max_err object_notify(void *x, t_symbol *s, void *data); 00741 00742 00743 /** 00744 Determines the class of a given object. 00745 00746 @ingroup obj 00747 @param x The object to test 00748 @return This function returns the t_class * of the object's class, if successful, or NULL, if unsuccessful. 00749 */ 00750 t_class *object_class(void *x); 00751 00752 00753 /** 00754 Retrieves the value of an object which supports the <tt>getvalueof/setvalueof</tt> interface. See part 2 of the pattr SDK for more information on this interface. 00755 00756 @ingroup obj 00757 00758 @param x The object whose value is of interest 00759 @param ac Pointer to a long variable to receive the count of arguments in <tt>av</tt>. The long variable itself should be set to 0 previous to calling this function. 00760 @param av Pointer to a t_atom *, to receive object data. The t_atom * itself should be set to NULL previous to calling this function. 00761 00762 @return This function returns the error code #MAX_ERR_NONE if successful, 00763 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00764 00765 @remark Calling the object_getvalueof() function allocates memory for any data it returns. 00766 It is the developer's responsibility to free it, using the freebytes() function. 00767 00768 @remark Developers wishing to design objects which will support this function being called on them must define and implement a special method, <tt>getvalueof</tt>, like so: 00769 @code 00770 class_addmethod(c, (method)myobject_getvalueof, "getvalueof", A_CANT, 0); 00771 @endcode 00772 00773 @remark The <tt>getvalueof</tt> method should be prototyped as: 00774 @code 00775 t_max_err myobject_getvalueof(t_myobject *x, long *ac, t_atom **av); 00776 @endcode 00777 00778 @remark And implemented, generally, as: 00779 @code 00780 t_max_err myobj_getvalueof(t_myobj *x, long *ac, t_atom **av) 00781 { 00782 if (ac && av) { 00783 if (*ac && *av) { 00784 // memory has been passed in; use it. 00785 } else { 00786 // allocate enough memory for your data 00787 *av = (t_atom *)getbytes(sizeof(t_atom)); 00788 } 00789 *ac = 1; // our data is a single floating point value 00790 atom_setfloat(*av, x->objvalue); 00791 } 00792 return MAX_ERR_NONE; 00793 } 00794 00795 @remark By convention, and to permit the interoperability of objects using the obex API, 00796 developers should allocate memory in their <tt>getvalueof</tt> methods using the getbytes() function. 00797 @endcode 00798 */ 00799 t_max_err object_getvalueof(void *x, long *ac, t_atom **av); 00800 00801 00802 /** 00803 Sets the value of an object which supports the <tt>getvalueof/setvalueof</tt> interface. 00804 00805 @ingroup obj 00806 00807 @param x The object whose value is of interest 00808 @param ac The count of arguments in <tt>av</tt> 00809 @param av Array of t_atoms; the new desired data for the object 00810 00811 @return This function returns the error code #MAX_ERR_NONE if successful, 00812 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00813 00814 @remark Developers wishing to design objects which will support this function being called on them must define and implement a special method, <tt>setvalueof</tt>, like so: 00815 @code 00816 class_addmethod(c, (method)myobject_setvalueof, "setvalueof", A_CANT, 0); 00817 @endcode 00818 00819 @remark The <tt>setvalueof</tt> method should be prototyped as: 00820 @code 00821 t_max_err myobject_setvalueof(t_myobject *x, long *ac, t_atom **av); 00822 @endcode 00823 00824 @remark And implemented, generally, as: 00825 @code 00826 t_max_err myobject_setvalueof(t_myobject *x, long ac, t_atom *av) 00827 { 00828 if (ac && av) { 00829 // simulate receipt of a float value 00830 myobject_float(x, atom_getfloat(av)); 00831 } 00832 return MAX_ERR_NONE; 00833 } 00834 @endcode 00835 */ 00836 t_max_err object_setvalueof(void *x, long ac, t_atom *av); 00837 00838 00839 00840 t_max_err object_attr_getnames(void *x, long *argc, t_symbol ***argv); 00841 00842 00843 /** 00844 Returns the pointer to an attribute, given its name. 00845 00846 @ingroup attr 00847 00848 @param x Pointer to the object whose attribute is of interest 00849 @param attrname The attribute's name 00850 00851 @return This function returns a pointer to the attribute, if successful, or NULL, if unsuccessful. 00852 */ 00853 void *object_attr_get(void *x, t_symbol *attrname); 00854 00855 00856 /** 00857 Returns the method of an attribute's <tt>get</tt> or <tt>set</tt> function, as well as a pointer to the attribute itself, from a message name. 00858 00859 @ingroup attr 00860 00861 @param x Pointer to the object whose attribute is of interest 00862 @param methodname The Max message used to call the attribute's <tt>get</tt> or <tt>set</tt> function. For example, <tt>gensym("mode")</tt> or <tt>gensym("getthresh")</tt>. 00863 @param attr A pointer to a void *, which will be set to the attribute pointer upon successful completion of the function 00864 @param get A pointer to a long variable, which will be set to 1 upon successful completion of the function, 00865 if the queried method corresponds to the <tt>get</tt> function of the attribute. 00866 00867 @return This function returns the requested method, if successful, or NULL, if unsuccessful. 00868 */ 00869 method object_attr_method(void *x, t_symbol *methodname, void **attr, long *get); 00870 00871 00872 /** 00873 Determines if an object's attribute can be set from the Max interface (i.e. if its #ATTR_SET_OPAQUE_USER flag is set). 00874 00875 @ingroup attr 00876 00877 @param x Pointer to the object whose attribute is of interest 00878 @param s The attribute's name 00879 00880 @return This function returns 1 if the attribute can be set from the Max interface. Otherwise, it returns 0. 00881 */ 00882 long object_attr_usercanset(void *x,t_symbol *s); 00883 00884 00885 /** 00886 Determines if the value of an object's attribute can be queried from the Max interface (i.e. if its #ATTR_GET_OPAQUE_USER flag is set). 00887 00888 @ingroup attr 00889 00890 @param x Pointer to the object whose attribute is of interest 00891 @param s The attribute's name 00892 00893 @return This function returns 1 if the value of the attribute can be queried from the Max interface. Otherwise, it returns 0. 00894 */ 00895 long object_attr_usercanget(void *x,t_symbol *s); 00896 00897 00898 /** 00899 Forces a specified object's attribute to send its value from the object's dumpout outlet in the Max interface. 00900 00901 @ingroup attr 00902 00903 @param x Pointer to the object whose attribute is of interest 00904 @param s The attribute's name 00905 @param argc Unused 00906 @param argv Unused 00907 */ 00908 void object_attr_getdump(void *x, t_symbol *s, long argc, t_atom *argv); 00909 00910 00911 t_max_err object_attr_getvalueof(void *x, t_symbol *s, long *argc, t_atom **argv); 00912 00913 00914 /** 00915 Sets the value of an object's attribute. 00916 00917 @ingroup attr 00918 00919 @param x Pointer to the object whose attribute is of interest 00920 @param s The attribute's name 00921 @param argc The count of arguments in <tt>argv</tt> 00922 @param argv Array of t_atoms; the new desired data for the attribute 00923 00924 @return This function returns the error code #MAX_ERR_NONE if successful, 00925 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00926 */ 00927 t_max_err object_attr_setvalueof(void *x, t_symbol *s, long argc, t_atom *argv); 00928 00929 00930 //object specific attributes(dynamically add/delete) 00931 00932 /** 00933 Attaches an attribute directly to an object. 00934 00935 @ingroup attr 00936 00937 @param x An object to which the attribute should be attached 00938 @param attr The attribute's pointer—this should be a pointer returned from attribute_new(), attr_offset_new() or attr_offset_array_new(). 00939 00940 @return This function returns the error code #MAX_ERR_NONE if successful, 00941 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00942 */ 00943 t_max_err object_addattr(void *x, t_object *attr); 00944 00945 00946 /** 00947 Detach an attribute from an object that was previously attached with object_addattr(). 00948 The function will also free all memory associated with the attribute. 00949 If you only wish to detach the attribute, without freeing it, see the object_chuckattr() function. 00950 00951 @ingroup attr 00952 00953 @param x The object to which the attribute is attached 00954 @param attrsym The attribute's name 00955 00956 @return This function returns the error code #MAX_ERR_NONE if successful, 00957 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00958 */ 00959 t_max_err object_deleteattr(void *x, t_symbol *attrsym); 00960 00961 00962 /** 00963 Detach an attribute from an object that was previously attached with object_addattr(). 00964 This function will <em>not</em> free the attribute (use object_free() to do this manually). 00965 00966 @ingroup attr 00967 00968 @param x The object to which the attribute is attached 00969 @param attrsym The attribute's name 00970 00971 @return This function returns the error code #MAX_ERR_NONE if successful, 00972 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 00973 */ 00974 t_max_err object_chuckattr(void *x, t_symbol *attrsym); 00975 00976 00977 // obex 00978 00979 /** 00980 Registers the byte-offset of the obex member of the class's data structure with the previously defined object class. 00981 Use of this function is required for obex-class objects. It must be called from <tt>main()</tt>. 00982 00983 @ingroup class 00984 00985 @param c The class pointer 00986 @param offset The byte-offset to the obex member of the object's data structure. 00987 Conventionally, the macro #calcoffset is used to calculate the offset. 00988 */ 00989 void class_obexoffset_set(t_class *c, long offset); 00990 00991 00992 /** 00993 Retrieves the byte-offset of the obex member of the class's data structure. 00994 00995 @ingroup class 00996 @param c The class pointer 00997 @return This function returns the byte-offset of the obex member of the class's data structure. 00998 */ 00999 long class_obexoffset_get(t_class *c); 01000 01001 01002 /** 01003 Retrieves the value of a data stored in the obex. 01004 01005 @ingroup obj 01006 01007 @param x The object pointer. This function should only be called on instantiated objects (i.e. in the <tt>new</tt> method or later), not directly on classes (i.e. in <tt>main()</tt>). 01008 @param key The symbolic name for the data to be retrieved 01009 @param val A pointer to a #t_object *, to be filled with the data retrieved from the obex. 01010 01011 @return This function returns the error code #MAX_ERR_NONE if successful, 01012 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01013 01014 @remark By default, pointers to the object's containing patcher and box objects are stored in the obex, under the keys '#P' and '#B', respectively. 01015 To retrieve them, the developer could do something like the following: 01016 @code 01017 void post_containers(t_obexobj *x) 01018 { 01019 t_patcher *p; 01020 t_box *b; 01021 01022 p = object_obex_lookup(x, gensym("#P"), (t_object **)&p); 01023 b = object_obex_lookup(x, gensym("#B"), (t_object **)&b); 01024 01025 post("my patcher is located at 0x%X", p); 01026 post("my box is located at 0x%X", b); 01027 } 01028 @endcode 01029 */ 01030 t_max_err object_obex_lookup(void *x, t_symbol *key, t_object **val); 01031 01032 01033 /** 01034 Stores data in the object's obex. 01035 01036 @ingroup obj 01037 01038 @param x The object pointer. This function should only be called on instantiated objects (i.e. in the <tt>new</tt> method or later), not directly on classes (i.e. in <tt>main()</tt>). 01039 @param key A symbolic name for the data to be stored 01040 @param val A #t_object *, to be stored in the obex, referenced under the <tt>key</tt>. 01041 01042 @return This function returns the error code #MAX_ERR_NONE if successful, 01043 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01044 01045 @remark Most developers will need to use this function for the specific purpose of storing the dumpout outlet in the obex 01046 (the dumpout outlet is used by attributes to report data in response to 'get' queries). 01047 For this, the developer should use something like the following in the object's <tt>new</tt> method: 01048 @code 01049 object_obex_store(x, _sym_dumpout, outlet_new(x, NULL)); 01050 @endcode 01051 */ 01052 t_max_err object_obex_store(void *x,t_symbol *key, t_object *val); 01053 t_max_err object_obex_storeflags(void *x,t_symbol *key, t_object *val, long flags); 01054 01055 01056 // private 01057 t_max_err object_obex_set(void *x, t_hashtab *obex); 01058 01059 01060 // private 01061 t_hashtab *object_obex_get(void *x); 01062 01063 01064 // private 01065 t_hashtab *object_obex_enforce(void *x); 01066 01067 01068 /** 01069 Sends data from the object's dumpout outlet. 01070 The dumpout outlet is stored in the obex using the object_obex_store() function (see above). 01071 It is used approximately like outlet_anything(). 01072 01073 @ingroup obj 01074 01075 @param x The object pointer. 01076 This function should only be called on instantiated objects (i.e. in the <tt>new</tt> method or later), not directly on classes (i.e. in <tt>main()</tt>). 01077 @param s The message selector #t_symbol * 01078 @param argc Number of elements in the argument list in argv 01079 @param argv t_atoms constituting the message arguments 01080 01081 @return This function returns the error code #MAX_ERR_NONE if successful, 01082 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01083 */ 01084 void object_obex_dumpout(void *x, t_symbol *s, long argc, t_atom *argv); 01085 01086 01087 void object_obex_free(void *x); 01088 01089 01090 //atom functions 01091 01092 /** 01093 Inserts an integer into a #t_atom and change the t_atom's type to #A_LONG. 01094 01095 @ingroup atom 01096 01097 @param a Pointer to a #t_atom whose value and type will be modified 01098 @param b Integer value to copy into the #t_atom 01099 01100 @return This function returns the error code #MAX_ERR_NONE if successful, 01101 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01102 */ 01103 t_max_err atom_setlong(t_atom *a, long b); 01104 01105 01106 /** 01107 Inserts a floating point number into a #t_atom and change the t_atom's type to #A_FLOAT. 01108 01109 @ingroup atom 01110 01111 @param a Pointer to a #t_atom whose value and type will be modified 01112 @param b Floating point value to copy into the #t_atom 01113 01114 @return This function returns the error code #MAX_ERR_NONE if successful, 01115 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01116 */ 01117 t_max_err atom_setfloat(t_atom *a, double b); 01118 01119 01120 /** 01121 Inserts a #t_symbol * into a #t_atom and change the t_atom's type to #A_SYM. 01122 01123 @ingroup atom 01124 01125 @param a Pointer to a #t_atom whose value and type will be modified 01126 @param b Pointer to a #t_symbol to copy into the #t_atom 01127 01128 @return This function returns the error code #MAX_ERR_NONE if successful, 01129 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01130 */ 01131 t_max_err atom_setsym(t_atom *a, t_symbol *b); 01132 01133 01134 /** 01135 Inserts a generic pointer value into a #t_atom and change the t_atom's type to #A_OBJ. 01136 01137 @ingroup atom 01138 01139 @param a Pointer to a #t_atom whose value and type will be modified 01140 @param b Pointer value to copy into the #t_atom 01141 01142 @return This function returns the error code #MAX_ERR_NONE if successful, 01143 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01144 */ 01145 t_max_err atom_setobj(t_atom *a, void *b); 01146 01147 01148 /** 01149 Retrieves a long integer value from a #t_atom. 01150 01151 @ingroup atom 01152 01153 @param a Pointer to a #t_atom whose value is of interest 01154 @return This function returns the value of the specified #t_atom as an integer, if possible. Otherwise, it returns 0. 01155 @remark If the #t_atom is not of the type specified by the function, the function will attempt to coerce a valid value from the t_atom. 01156 For instance, if the t_atom <tt>at</tt> is set to type #A_FLOAT with a value of <tt>3.7</tt>, 01157 the atom_getlong() function will return the truncated integer value of <tt>at</tt>, or <tt>3</tt>. 01158 An attempt is also made to coerce #t_symbol data. 01159 */ 01160 long atom_getlong(t_atom *a); 01161 01162 01163 /** 01164 Retrieves a floating point value from a #t_atom. 01165 01166 @ingroup atom 01167 @param a Pointer to a #t_atom whose value is of interest 01168 @return This function returns the value of the specified #t_atom as a floating point number, if possible. Otherwise, it returns 0. 01169 01170 @remark If the #t_atom is not of the type specified by the function, the function will attempt to coerce a valid value from the t_atom. 01171 For instance, if the t_atom <tt>at</tt> is set to type #A_LONG with a value of <tt>5</tt>, 01172 the atom_getfloat() function will return the value of <tt>at</tt> as a float, or <tt>5.0</tt>. 01173 An attempt is also made to coerce #t_symbol data. 01174 */ 01175 float atom_getfloat(t_atom *a); 01176 01177 01178 /** 01179 Retrieves a t_symbol * value from a t_atom. 01180 01181 @ingroup atom 01182 @param a Pointer to a t_atom whose value is of interest 01183 @return This function returns the value of the specified #A_SYM-typed #t_atom, if possible. 01184 Otherwise, it returns an empty, but valid, #t_symbol *, equivalent to <tt>gensym("")</tt>, or <tt>_sym_nothing</tt>. 01185 01186 @remark No attempt is made to coerce non-matching data types. 01187 */ 01188 t_symbol *atom_getsym(t_atom *a); 01189 01190 01191 /** 01192 Retrieves a generic pointer value from a #t_atom. 01193 01194 @ingroup atom 01195 @param a Pointer to a #t_atom whose value is of interest 01196 @return This function returns the value of the specified #A_OBJ-typed t_atom, if possible. Otherwise, it returns NULL. 01197 */ 01198 void *atom_getobj(t_atom *a); 01199 01200 01201 /** 01202 Retrieves an unsigned integer value between 0 and 255 from a t_atom. 01203 01204 @ingroup atom 01205 @param a Pointer to a #t_atom whose value is of interest 01206 @return This function returns the value of the specified #t_atom as an integer between 0 and 255, if possible. Otherwise, it returns 0. 01207 01208 @remark If the #t_atom is typed #A_LONG, but the data falls outside of the range 0-255, the data is truncated to that range before output. 01209 01210 @remark If the t_atom is typed #A_FLOAT, the floating point value is multiplied by 255. and truncated to the range 0-255 before output. 01211 For example, the floating point value <tt>0.5</tt> would be output from atom_getcharfix as <tt>127</tt> (0.5 * 255. = 127.5). 01212 01213 @remark No attempt is also made to coerce #t_symbol data. 01214 */ 01215 long atom_getcharfix(t_atom *a); 01216 01217 01218 /** 01219 Retrieves type from a #t_atom. 01220 01221 @ingroup atom 01222 @param a Pointer to a #t_atom whose type is of interest 01223 @return This function returns the type of the specified t_atom as defined in #e_max_atomtypes 01224 */ 01225 long atom_gettype(t_atom *a); 01226 01227 01228 //the following are useful for setting the values _only_ if there is an arg 01229 //rather than setting it to 0 or _sym_nothing 01230 01231 /** 01232 Retrieves the integer value of a particular t_atom from an atom list, if the atom exists. 01233 01234 @ingroup atom 01235 01236 @param c Pointer to a long variable to receive the atom's data if the function is successful. 01237 @param idx Offset into the atom list of the atom of interest, starting from 0. 01238 For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01239 @param ac Count of av. 01240 @param av Pointer to the first t_atom of an atom list. 01241 01242 @return This function returns the error code #MAX_ERR_NONE if successful, 01243 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01244 01245 @remark The atom_arg_getlong() function only changes the value of <tt>c</tt> if the function is successful. 01246 For instance, the following code snippet illustrates a simple, but typical use: 01247 @code 01248 void myobject_mymessage(t_myobject *x, t_symbol *s, long ac, t_atom *av) 01249 { 01250 long var = -1; 01251 01252 // here, we are expecting a value of 0 or greater 01253 atom_arg_getlong(&var, 0, ac, av); 01254 if (val == -1) // i.e. unchanged 01255 post("it is likely that the user did not provide a valid argument"); 01256 else { 01257 ... 01258 } 01259 } 01260 @endcode 01261 */ 01262 long atom_arg_getlong(long *c, long idx, long ac, t_atom *av); 01263 01264 01265 /** 01266 Retrieves the floating point value of a particular t_atom from an atom list, if the atom exists. 01267 01268 @ingroup atom 01269 01270 @param c Pointer to a float variable to receive the atom's data if the function is successful. Otherwise, the value is left unchanged. 01271 @param idx Offset into the atom list of the atom of interest, starting from 0. 01272 For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01273 @param ac Count of av. 01274 @param av Pointer to the first t_atom of an atom list. 01275 01276 @return This function returns the error code #MAX_ERR_NONE if successful, 01277 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01278 */ 01279 long atom_arg_getfloat(float *c, long idx, long ac, t_atom *av); 01280 01281 01282 /** 01283 Retrieves the floating point value, as a double, of a particular t_atom from an atom list, if the atom exists. 01284 01285 @ingroup atom 01286 01287 @param c Pointer to a double variable to receive the atom's data if the function is successful. Otherwise the value is left unchanged. 01288 @param idx Offset into the atom list of the atom of interest, starting from 0. 01289 For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01290 @param ac Count of av. 01291 @param av Pointer to the first t_atom of an atom list. 01292 01293 @return This function returns the error code #MAX_ERR_NONE if successful, 01294 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01295 */ 01296 long atom_arg_getdouble(double *c, long idx, long ac, t_atom *av); 01297 01298 01299 /** 01300 Retrieves the t_symbol * value of a particular t_atom from an atom list, if the atom exists. 01301 01302 @ingroup atom 01303 01304 @param c Pointer to a t_symbol * variable to receive the atom's data if the function is successful. Otherwise, the value is left unchanged. 01305 @param idx Offset into the atom list of the atom of interest, starting from 0. 01306 For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01307 @param ac Count of av. 01308 @param av Pointer to the first t_atom of an atom list. 01309 01310 @return This function returns the error code #MAX_ERR_NONE if successful, 01311 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01312 01313 @remark The atom_arg_getsym() function only changes the value of <tt>c</tt> if the function is successful. 01314 For instance, the following code snippet illustrates a simple, but typical use: 01315 @code 01316 void myobject_open(t_myobject *x, t_symbol *s, long ac, t_atom *av) 01317 { 01318 t_symbol *filename = _sym_nothing; 01319 01320 // here, we are expecting a file name. 01321 // if we don't get it, open a dialog box 01322 atom_arg_getsym(&filename, 0, ac, av); 01323 if (filename == _sym_nothing) { // i.e. unchanged 01324 // open the file dialog box, 01325 // get a value for filename 01326 } 01327 // do something with the filename 01328 } 01329 @endcode 01330 */ 01331 long atom_arg_getsym(t_symbol **c, long idx, long ac, t_atom *av); 01332 01333 01334 //attr functions 01335 01336 /** 01337 Determines the point in an atom list where attribute arguments begin. 01338 Developers can use this function to assist in the manual processing of attribute arguments, when attr_args_process() 01339 doesn't provide the correct functionality for a particular purpose. 01340 01341 @ingroup attr 01342 01343 @param ac The count of t_atoms in <tt>av</tt> 01344 @param av An atom list 01345 01346 @return This function returns an offset into the atom list, where the first attribute argument occurs. 01347 For instance, the atom list <tt>foo bar 3.0 \@mode 6</tt> would cause <tt>attr_args_offset</tt> to return 3 01348 (the attribute <tt>mode</tt> appears at position 3 in the atom list). 01349 */ 01350 long attr_args_offset(short ac, t_atom *av); 01351 01352 01353 /** 01354 Takes an atom list and properly set any attributes described within. This function is typically used in an object's <tt>new</tt> method to conveniently process attribute arguments. 01355 01356 @ingroup attr 01357 01358 @param x The object whose attributes will be processed 01359 @param ac The count of t_atoms in <tt>av</tt> 01360 @param av An atom list 01361 01362 @remark Here is a typical example of usage: 01363 @code 01364 void *myobject_new(t_symbol *s, long ac, t_atom *av) 01365 { 01366 t_myobject *x = NULL; 01367 01368 if (x=(t_myobject *)object_alloc(myobject_class)) 01369 { 01370 // initialize any data before processing 01371 // attributes to avoid overwriting 01372 // attribute argument-set values 01373 x->data = 0; 01374 01375 // process attr args, if any 01376 attr_args_process(x, ac, av); 01377 } 01378 return x; 01379 } 01380 @endcode 01381 */ 01382 void attr_args_process(void *x, short ac, t_atom *av); 01383 01384 01385 //constructors 01386 01387 01388 /** 01389 Create a new attribute. The attribute will allocate memory and store its own data. Attributes created using attribute_new() can be assigned either to classes (using the class_addattr() function) or to objects (using the object_addattr() function). 01390 01391 @ingroup attr 01392 01393 @param name A name for the attribute, as a C-string 01394 @param type A t_symbol * representing a valid attribute type. 01395 At the time of this writing, the valid type-symbols are: 01396 <tt>_sym_char</tt> (char), 01397 <tt>_sym_long</tt> (long), 01398 <tt>_sym_float32</tt> (32-bit float), 01399 <tt>_sym_float64</tt> (64-bit float), 01400 <tt>_sym_atom</tt> (Max #t_atom pointer), 01401 <tt>_sym_symbol</tt> (Max #t_symbol pointer), 01402 <tt>_sym_pointer</tt> (generic pointer) and 01403 <tt>_sym_object</tt> (Max #t_object pointer). 01404 @param flags Any attribute flags, expressed as a bitfield. 01405 Attribute flags are used to determine if an attribute is accessible for setting or querying. 01406 The available accessor flags are defined in #e_max_attrflags. 01407 @param mget The method to use for the attribute's <tt>get</tt> functionality. If <tt>mget</tt> is NULL, the default method is used. 01408 @param mset The method to use for the attribute's <tt>set</tt> functionality. If <tt>mset</tt> is NULL, the default method is used. 01409 01410 @return This function returns the new attribute's object pointer if successful, or NULL if unsuccessful. 01411 01412 @remark Developers wishing to define custom methods for <tt>get</tt> or <tt>set</tt> functionality need to prototype them as: 01413 @code 01414 t_max_err myobject_myattr_get(t_myobject *x, void *attr, long *ac, t_atom **av); 01415 @endcode 01416 @code 01417 t_max_err myobject_myattr_set(t_myobject *x, void *attr, long ac, t_atom *av); 01418 @endcode 01419 01420 @remark Implementation will vary, of course, but need to follow the following basic models. 01421 Note that, as with custom <tt>getvalueof</tt> and <tt>setvalueof</tt> methods for the object, 01422 assumptions are made throughout Max that getbytes() has been used for memory allocation. 01423 Developers are strongly urged to do the same: 01424 @code 01425 t_max_err myobject_myattr_get(t_myobject *x, void *attr, long *ac, t_atom **av) 01426 { 01427 if (*ac && *av) 01428 // memory passed in; use it 01429 else { 01430 *ac = 1; // size of attr data 01431 *av = (t_atom *)getbytes(sizeof(t_atom) * (*ac)); 01432 if (!(*av)) { 01433 *ac = 0; 01434 return MAX_ERR_OUT_OF_MEM; 01435 } 01436 } 01437 atom_setlong(*av, x->some_value); 01438 return MAX_ERR_NONE; 01439 } 01440 01441 t_max_err myobject_myattr_set(t_myobject *x, void *attr, long ac, t_atom *av) 01442 { 01443 if (ac && av) { 01444 x->some_value = atom_getlong(av); 01445 } 01446 return MAX_ERR_NONE; 01447 } 01448 @endcode 01449 */ 01450 t_object *attribute_new(char *name, t_symbol *type, long flags, method mget, method mset); 01451 01452 01453 /** 01454 Create a new attribute. The attribute references memory stored outside of itself, in the object's data structure. Attributes created using attr_offset_new() can be assigned either to classes (using the class_addattr() function) or to objects (using the object_addattr() function). 01455 01456 @ingroup attr 01457 01458 @param name A name for the attribute, as a C-string 01459 @param type A t_symbol * representing a valid attribute type. 01460 At the time of this writing, the valid type-symbols are: 01461 <tt>_sym_char</tt> (char), 01462 <tt>_sym_long</tt> (long), 01463 <tt>_sym_float32</tt> (32-bit float), 01464 <tt>_sym_float64</tt> (64-bit float), 01465 <tt>_sym_atom</tt> (Max #t_atom pointer), 01466 <tt>_sym_symbol</tt> (Max #t_symbol pointer), 01467 <tt>_sym_pointer</tt> (generic pointer) and 01468 <tt>_sym_object</tt> (Max #t_object pointer). 01469 @param flags Any attribute flags, expressed as a bitfield. 01470 Attribute flags are used to determine if an attribute is accessible for setting or querying. 01471 The available accessor flags are defined in #e_max_attrflags. 01472 @param mget The method to use for the attribute's <tt>get</tt> functionality. 01473 If <tt>mget</tt> is NULL, the default method is used. See the discussion under attribute_new(), for more information. 01474 @param mset The method to use for the attribute's <tt>set</tt> functionality. 01475 If <tt>mset</tt> is NULL, the default method is used. See the discussion under attribute_new(), for more information. 01476 @param offset Byte offset into the class data structure of the object which will "own" the attribute. 01477 The offset should point to the data to be referenced by the attribute. 01478 Typically, the #calcoffset macro (described above) is used to calculate this offset. 01479 01480 @return This function returns the new attribute's object pointer if successful, or NULL if unsuccessful. 01481 01482 @remark For instance, to create a new attribute which references the value of a double variable (<tt>val</tt>) in an object class's data structure: 01483 @code 01484 t_object *attr = attr_offset_new("myattr", _sym_float64 / * matches data size * /, 0 / * no flags * /, (method)0L, (method)0L, calcoffset(t_myobject, val)); 01485 @endcode 01486 */ 01487 t_object *attr_offset_new(char *name, t_symbol *type, long flags, method mget, method mset, long offset); 01488 01489 01490 /** 01491 Create a new attribute. The attribute references an array of memory stored outside of itself, in the object's data structure. Attributes created using attr_offset_array_new() can be assigned either to classes (using the class_addattr() function) or to objects (using the object_addattr() function). 01492 01493 @ingroup attr 01494 01495 @param name A name for the attribute, as a C-string 01496 @param type A t_symbol * representing a valid attribute type. 01497 At the time of this writing, the valid type-symbols are: 01498 <tt>_sym_char</tt> (char), 01499 <tt>_sym_long</tt> (long), 01500 <tt>_sym_float32</tt> (32-bit float), 01501 <tt>_sym_float64</tt> (64-bit float), 01502 <tt>_sym_atom</tt> (Max #t_atom pointer), 01503 <tt>_sym_symbol</tt> (Max #t_symbol pointer), 01504 <tt>_sym_pointer</tt> (generic pointer) and 01505 <tt>_sym_object</tt> (Max #t_object pointer). 01506 @param size Maximum number of items that may be in the array. 01507 @param flags Any attribute flags, expressed as a bitfield. 01508 Attribute flags are used to determine if an attribute is accessible for setting or querying. 01509 The available accessor flags are defined in #e_max_attrflags. 01510 @param mget The method to use for the attribute's <tt>get</tt> functionality. 01511 If <tt>mget</tt> is NULL, the default method is used. See the discussion under attribute_new(), for more information. 01512 @param mset The method to use for the attribute's <tt>set</tt> functionality. 01513 If <tt>mset</tt> is NULL, the default method is used. See the discussion under attribute_new(), for more information. 01514 @param offsetcount Byte offset into the object class's data structure of a long variable describing how many array elements 01515 (up to <tt>size</tt>) comprise the data to be referenced by the attribute. 01516 Typically, the #calcoffset macro is used to calculate this offset. 01517 @param offset Byte offset into the class data structure of the object which will "own" the attribute. 01518 The offset should point to the data to be referenced by the attribute. 01519 Typically, the #calcoffset macro is used to calculate this offset. 01520 01521 @return This function returns the new attribute's object pointer if successful, or NULL if unsuccessful. 01522 01523 @remark For instance, to create a new attribute which references an array of 10 t_atoms (<tt>atm</tt>; 01524 the current number of "active" elements in the array is held in the variable <tt>atmcount</tt>) in an object class's data structure: 01525 @code 01526 t_object *attr = attr_offset_array_new("myattrarray", _sym_atom / * matches data size * /, 10 / * max * /, 0 / * no flags * /, (method)0L, (method)0L, calcoffset(t_myobject, atmcount) / * count * /, calcoffset(t_myobject, atm) / * data * /); 01527 @endcode 01528 */ 01529 t_object *attr_offset_array_new(char *name, t_symbol *type, long size, long flags, method mget, method mset, long offsetcount, long offset); 01530 01531 01532 t_object *attr_filter_clip_new(void); 01533 01534 01535 t_object *attr_filter_proc_new(method proc); 01536 01537 01538 //for easy access of simple attributes 01539 01540 /** 01541 Retrieves the value of an attribute, given its parent object and name. 01542 01543 @ingroup attr 01544 01545 @param x The attribute's parent object 01546 @param s The attribute's name 01547 01548 @return This function returns the value of the specified attribute, if successful, or 0, if unsuccessful. 01549 01550 @remark If the attribute is not of the type specified by the function, the 01551 function will attempt to coerce a valid value from the attribute. 01552 */ 01553 long object_attr_getlong(void *x, t_symbol *s); 01554 01555 01556 /** 01557 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01558 01559 @ingroup attr 01560 01561 @param x The attribute's parent object 01562 @param s The attribute's name 01563 @param c An integer value; the new value for the attribute 01564 01565 @return This function returns the error code #MAX_ERR_NONE if successful, 01566 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01567 */ 01568 t_max_err object_attr_setlong(void *x, t_symbol *s, long c); 01569 01570 01571 /** 01572 Retrieves the value of an attribute, given its parent object and name. 01573 01574 @ingroup attr 01575 01576 @param x The attribute's parent object 01577 @param s The attribute's name 01578 01579 @return This function returns the value of the specified attribute, if successful, or 0, if unsuccessful. 01580 01581 @remark If the attribute is not of the type specified by the function, the 01582 function will attempt to coerce a valid value from the attribute. 01583 */ 01584 float object_attr_getfloat(void *x, t_symbol *s); 01585 01586 01587 /** 01588 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01589 01590 @ingroup attr 01591 01592 @param x The attribute's parent object 01593 @param s The attribute's name 01594 @param c An floating point value; the new value for the attribute 01595 01596 @return This function returns the error code #MAX_ERR_NONE if successful, 01597 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01598 */ 01599 t_max_err object_attr_setfloat(void *x, t_symbol *s, float c); 01600 01601 01602 /** 01603 Retrieves the value of an attribute, given its parent object and name. 01604 01605 @ingroup attr 01606 01607 @param x The attribute's parent object 01608 @param s The attribute's name 01609 01610 @return This function returns the value of the specified attribute, if successful, or the empty symbol (equivalent to <tt>gensym("")</tt> or <tt>_sym_nothing</tt>), if unsuccessful. 01611 */ 01612 t_symbol *object_attr_getsym(void *x, t_symbol *s); 01613 01614 01615 /** 01616 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01617 01618 @ingroup attr 01619 01620 @param x The attribute's parent object 01621 @param s The attribute's name 01622 @param c A t_symbol *; the new value for the attribute 01623 01624 @return This function returns the error code #MAX_ERR_NONE if successful, 01625 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01626 */ 01627 t_max_err object_attr_setsym(void *x, t_symbol *s, t_symbol *c); 01628 01629 01630 char object_attr_getchar(void *x, t_symbol *s); 01631 t_max_err object_attr_setchar(void *x, t_symbol *s, char c); 01632 t_object* object_attr_getobj(void *x, t_symbol *s); 01633 t_max_err object_attr_setobj(void *x, t_symbol *s, t_object *o); 01634 01635 01636 /** 01637 Retrieves the value of an attribute, given its parent object and name. 01638 This function uses a developer-allocated array to copy data to. 01639 Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the object_attr_getvalueof() function. 01640 01641 @ingroup attr 01642 01643 @param x The attribute's parent object 01644 @param s The attribute's name 01645 @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01646 @param vals Pointer to the first element of a pre-allocated array of long data. 01647 01648 @return This function returns the number of elements copied into <tt>vals</tt>. 01649 01650 @remark If the attribute is not of the type specified by the function, the 01651 function will attempt to coerce a valid value from the attribute. 01652 */ 01653 long object_attr_getlong_array(void *x, t_symbol *s, long max, long *vals); 01654 01655 01656 /** 01657 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01658 01659 @ingroup attr 01660 01661 @param x The attribute's parent object 01662 @param s The attribute's name 01663 @param count The number of array elements in vals 01664 @param vals Pointer to the first element of an array of long data 01665 01666 @return This function returns the error code #MAX_ERR_NONE if successful, 01667 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01668 */ 01669 t_max_err object_attr_setlong_array(void *x, t_symbol *s, long count, long *vals); 01670 01671 01672 /** 01673 Retrieves the value of an attribute, given its parent object and name. 01674 This function uses a developer-allocated array to copy data to. 01675 Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the object_attr_getvalueof() function. 01676 01677 @ingroup attr 01678 01679 @param x The attribute's parent object 01680 @param s The attribute's name 01681 @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01682 @param vals Pointer to the first element of a pre-allocated array of unsigned char data. 01683 01684 @return This function returns the number of elements copied into <tt>vals</tt>. 01685 01686 @remark If the attribute is not of the type specified by the function, the 01687 function will attempt to coerce a valid value from the attribute. 01688 */ 01689 long object_attr_getchar_array(void *x, t_symbol *s, long max, uchar *vals); 01690 01691 01692 /** 01693 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01694 01695 @ingroup attr 01696 01697 @param x The attribute's parent object 01698 @param s The attribute's name 01699 @param count The number of array elements in vals 01700 @param vals Pointer to the first element of an array of unsigned char data 01701 01702 @return This function returns the error code #MAX_ERR_NONE if successful, 01703 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01704 */ 01705 t_max_err object_attr_setchar_array(void *x, t_symbol *s, long count, uchar *vals); 01706 01707 01708 /** 01709 Retrieves the value of an attribute, given its parent object and name. 01710 This function uses a developer-allocated array to copy data to. 01711 Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the object_attr_getvalueof() function. 01712 01713 @ingroup attr 01714 01715 @param x The attribute's parent object 01716 @param s The attribute's name 01717 @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01718 @param vals Pointer to the first element of a pre-allocated array of float data. 01719 01720 @return This function returns the number of elements copied into <tt>vals</tt>. 01721 01722 @remark If the attribute is not of the type specified by the function, the 01723 function will attempt to coerce a valid value from the attribute. 01724 */ 01725 long object_attr_getfloat_array(void *x, t_symbol *s, long max, float *vals); 01726 01727 01728 /** 01729 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01730 01731 @ingroup attr 01732 01733 @param x The attribute's parent object 01734 @param s The attribute's name 01735 @param count The number of array elements in vals 01736 @param vals Pointer to the first element of an array of float data 01737 01738 @return This function returns the error code #MAX_ERR_NONE if successful, 01739 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01740 */ 01741 t_max_err object_attr_setfloat_array(void *x, t_symbol *s, long count, float *vals); 01742 01743 01744 /** 01745 Retrieves the value of an attribute, given its parent object and name. 01746 This function uses a developer-allocated array to copy data to. 01747 Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the object_attr_getvalueof() function. 01748 01749 @ingroup attr 01750 01751 @param x The attribute's parent object 01752 @param s The attribute's name 01753 @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01754 @param vals Pointer to the first element of a pre-allocated array of double data. 01755 01756 @return This function returns the number of elements copied into <tt>vals</tt>. 01757 01758 @remark If the attribute is not of the type specified by the function, the 01759 function will attempt to coerce a valid value from the attribute. 01760 */ 01761 long object_attr_getdouble_array(void *x, t_symbol *s, long max, double *vals); 01762 01763 01764 /** 01765 Sets the value of an attribute, given its parent object and name. The function will call the attribute's <tt>set</tt> method, using the data provided. 01766 01767 @ingroup attr 01768 01769 @param x The attribute's parent object 01770 @param s The attribute's name 01771 @param count The number of array elements in vals 01772 @param vals Pointer to the first element of an array of double data 01773 01774 @return This function returns the error code #MAX_ERR_NONE if successful, 01775 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01776 */ 01777 t_max_err object_attr_setdouble_array(void *x, t_symbol *s, long count, double *vals); 01778 01779 01780 /** 01781 Retrieves the value of an attribute, given its parent object and name. 01782 This function uses a developer-allocated array to copy data to. 01783 Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the object_attr_getvalueof() function. 01784 01785 @ingroup attr 01786 01787 @param x The attribute's parent object 01788 @param s The attribute's name 01789 @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01790 @param vals Pointer to the first element of a pre-allocated array of #t_symbol *s. 01791 01792 @return This function returns the number of elements copied into <tt>vals</tt>. 01793 */ 01794 long object_attr_getsym_array(void *x, t_symbol *s, long max, t_symbol **vals); 01795 01796 01797 /** 01798 Sets the value of an attribute, given its parent object and name. 01799 The function will call the attribute's <tt>set</tt> method, using the data provided. 01800 01801 @ingroup attr 01802 01803 @param x The attribute's parent object 01804 @param s The attribute's name 01805 @param count The number of array elements in vals 01806 @param vals Pointer to the first element of an array of #t_symbol *s 01807 01808 @return This function returns the error code #MAX_ERR_NONE if successful, 01809 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01810 */ 01811 t_max_err object_attr_setsym_array(void *x, t_symbol *s, long count, t_symbol **vals); 01812 01813 01814 //attr filters util 01815 01816 /** 01817 Attaches a clip filter to an attribute. 01818 The filter will <em>only</em> clip values sent to the attribute using the attribute's <tt>set</tt> function. 01819 01820 @ingroup attr 01821 01822 @param x Pointer to the attribute to receive the filter 01823 @param min Minimum value for the clip filter 01824 @param max Maximum value for the clip filter 01825 @param usemin Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01826 @param usemax Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01827 01828 @return This function returns the error code #MAX_ERR_NONE if successful, 01829 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01830 */ 01831 t_max_err attr_addfilterset_clip(void *x, double min, double max, long usemin, long usemax); 01832 01833 01834 /** 01835 Attaches a clip/scale filter to an attribute. 01836 The filter will <em>only</em> clip and scale values sent to the attribute using the attribute's <tt>set</tt> function. 01837 01838 @ingroup attr 01839 01840 @param x Pointer to the attribute to receive the filter 01841 @param scale Scale value. Data sent to the attribute will be scaled by this amount. <em>Scaling occurs previous to clipping</em>. 01842 @param min Minimum value for the clip filter 01843 @param max Maximum value for the clip filter 01844 @param usemin Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01845 @param usemax Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01846 01847 @return This function returns the error code #MAX_ERR_NONE if successful, 01848 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01849 */ 01850 t_max_err attr_addfilterset_clip_scale(void *x, double scale, double min, double max, long usemin, long usemax); 01851 01852 01853 /** 01854 Attaches a clip filter to an attribute. 01855 The filter will <em>only</em> clip values retrieved from the attribute using the attribute's <tt>get</tt> function. 01856 01857 @ingroup attr 01858 01859 @param x Pointer to the attribute to receive the filter 01860 @param min Minimum value for the clip filter 01861 @param max Maximum value for the clip filter 01862 @param usemin Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01863 @param usemax Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01864 01865 @return This function returns the error code #MAX_ERR_NONE if successful, 01866 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01867 */ 01868 t_max_err attr_addfilterget_clip(void *x, double min, double max, long usemin, long usemax); 01869 01870 01871 /** 01872 Attaches a clip/scale filter to an attribute. 01873 The filter will <em>only</em> clip and scale values retrieved from the attribute using the attribute's <tt>get</tt> function. 01874 01875 @ingroup attr 01876 01877 @param x Pointer to the attribute to receive the filter 01878 @param scale Scale value. Data retrieved from the attribute will be scaled by this amount. <em>Scaling occurs previous to clipping</em>. 01879 @param min Minimum value for the clip filter 01880 @param max Maximum value for the clip filter 01881 @param usemin Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01882 @param usemax Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01883 01884 @return This function returns the error code #MAX_ERR_NONE if successful, 01885 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01886 */ 01887 t_max_err attr_addfilterget_clip_scale(void *x, double scale, double min, double max, long usemin, long usemax); 01888 01889 01890 /** 01891 Attaches a clip filter to an attribute. 01892 The filter will clip any values sent to or retrieved from the attribute using the attribute's <tt>get</tt> and <tt>set</tt> functions. 01893 01894 @ingroup attr 01895 01896 @param x Pointer to the attribute to receive the filter 01897 @param min Minimum value for the clip filter 01898 @param max Maximum value for the clip filter 01899 @param usemin Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01900 @param usemax Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01901 01902 @return This function returns the error code #MAX_ERR_NONE if successful, 01903 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01904 */ 01905 t_max_err attr_addfilter_clip(void *x, double min, double max, long usemin, long usemax); 01906 01907 01908 /** 01909 Attaches a clip/scale filter to an attribute. 01910 The filter will clip and scale any values sent to or retrieved from the attribute using the attribute's <tt>get</tt> and <tt>set</tt> functions. 01911 01912 @ingroup attr 01913 01914 @param x Pointer to the attribute to receive the filter 01915 @param scale Scale value. Data sent to the attribute will be scaled by this amount. Data retrieved from the attribute will be scaled by its reciprocal. 01916 <em>Scaling occurs previous to clipping</em>. 01917 @param min Minimum value for the clip filter 01918 @param max Maximum value for the clip filter 01919 @param usemin Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01920 @param usemax Sets this value to 0 if the minimum clip value should <em>not</em> be used. Otherwise, set the value to non-zero. 01921 01922 @return This function returns the error code #MAX_ERR_NONE if successful, 01923 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01924 */ 01925 t_max_err attr_addfilter_clip_scale(void *x, double scale, double min, double max, long usemin, long usemax); 01926 01927 01928 /** 01929 Attaches a custom filter method to an attribute. 01930 The filter will <em>only</em> be called for values retrieved from the attribute using the attribute's <tt>set</tt> function. 01931 01932 @ingroup attr 01933 01934 @param x Pointer to the attribute to receive the filter 01935 @param proc A filter method 01936 01937 @return This function returns the error code #MAX_ERR_NONE if successful, 01938 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01939 01940 @remark The filter method should be prototyped and implemented as follows: 01941 @code 01942 t_max_err myfiltermethod(void *parent, void *attr, long ac, t_atom *av); 01943 01944 t_max_err myfiltermethod(void *parent, void *attr, long ac, t_atom *av) 01945 { 01946 long i; 01947 float temp, 01948 01949 // this filter rounds off all values 01950 // assumes that the data is float 01951 for (i = 0; i < ac; i++) { 01952 temp = atom_getfloat(av + i); 01953 temp = (float)((long)(temp + 0.5)); 01954 atom_setfloat(av + i, temp); 01955 } 01956 return MAX_ERR_NONE; 01957 } 01958 @endcode 01959 */ 01960 t_max_err attr_addfilterset_proc(void *x, method proc); 01961 01962 01963 /** 01964 Attaches a custom filter method to an attribute. The filter will <em>only</em> be called for values retrieved from the attribute using the attribute's <tt>get</tt> function. 01965 01966 @ingroup attr 01967 01968 @param x Pointer to the attribute to receive the filter 01969 @param proc A filter method 01970 01971 @return This function returns the error code #MAX_ERR_NONE if successful, 01972 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 01973 01974 @remark The filter method should be prototyped and implemented as described above for the attr_addfilterset_proc() function. 01975 */ 01976 t_max_err attr_addfilterget_proc(void *x, method proc); 01977 01978 01979 //more util functions 01980 01981 /** 01982 Generates a unique #t_symbol *. The symbol will be formatted somewhat like "u123456789". 01983 01984 @ingroup misc 01985 @return This function returns a unique #t_symbol *. 01986 */ 01987 t_symbol *symbol_unique(); 01988 01989 01990 void error_code(void *x,t_max_err v); //interrupt safe 01991 01992 01993 /** 01994 Posts an error message to the Max window. This function is interrupt safe. 01995 01996 @ingroup misc 01997 01998 @param x The object's pointer 01999 @param s Symbol to be posted as an error in the Max window 02000 */ 02001 void error_sym(void *x,t_symbol *s); //interrupt safe 02002 02003 02004 /** 02005 Posts a message to the Max window. This function is interrupt safe. 02006 02007 @ingroup misc 02008 @param x The object's pointer 02009 @param s Symbol to be posted in the Max window 02010 */ 02011 void post_sym(void *x,t_symbol *s); //interrupt safe 02012 02013 02014 /** 02015 Performs an ASCII sort on an array of #t_symbol *s. 02016 02017 @ingroup misc 02018 02019 @param ac The count of #t_symbol *s in <tt>av</tt> 02020 @param av An array of #t_symbol *s to be sorted 02021 02022 @return This function returns the error code #MAX_ERR_NONE if successful, 02023 or one of the other error codes defined in #e_max_errorcodes if unsuccessful. 02024 */ 02025 t_max_err symbolarray_sort(long ac, t_symbol **av); 02026 02027 02028 /** 02029 Developers do not need to directly use the object_obex_quickref() function. 02030 It was used in Max 4 to add support for attributes to the quickref, but this is automatic in Max 5. 02031 02032 @ingroup misc 02033 */ 02034 void object_obex_quickref(void *x, long *numitems, t_symbol **items); 02035 02036 02037 method class_menufun_get(t_class *c); 02038 02039 02040 // new for Max 5 (some headers might change) 02041 #include "ext_obex_util.h" 02042 #include "ext_dictionary.h" 02043 #include "ext_obstring.h" 02044 02045 long class_clonable(t_class *x); 02046 long object_clonable(t_object *x); 02047 t_max_err class_buildprototype(t_class *x); 02048 t_dictionary *class_cloneprototype(t_class *x); 02049 02050 02051 /** 02052 Create a dictionary of attribute-name, attribute-value pairs 02053 from an array of atoms containing an attribute definition list. 02054 02055 @ingroup attr 02056 @param x A dictionary instance pointer. 02057 @param ac The number of atoms to parse in av. 02058 @param av A pointer to the first of the array of atoms containing the attribute values. 02059 02060 @remark The code example below shows the creation of a list of atoms using atom_setparse(), 02061 and then uses that list of atoms to fill the dictionary with attr_args_dictionary(). 02062 @code 02063 long ac = 0; 02064 t_atom *av = NULL; 02065 char parsebuf[4096]; 02066 t_dictionary *d = dictionary_new(); 02067 t_atom a; 02068 02069 sprintf(parsebuf,"@defrect %.6f %.6f %.6f %.6f @title Untitled @presentation 0 ", r->x, r->y, r->width, r->height); 02070 atom_setparse(&ac, &av, parsebuf); 02071 attr_args_dictionary(d, ac, av); 02072 atom_setobj(&a, d); 02073 @endcode 02074 */ 02075 void attr_args_dictionary(t_dictionary *x, short ac, t_atom *av); 02076 02077 02078 /** 02079 Set attributes for an object that are defined in a dictionary. 02080 Objects with dictionary constructors, such as UI objects, 02081 should call this method to set their attributes when an object is created. 02082 02083 @ingroup attr 02084 @param x The object instance pointer. 02085 @param d The dictionary containing the attributes. 02086 @see attr_args_process() 02087 */ 02088 void attr_dictionary_process(void *x, t_dictionary *d); 02089 02090 02091 /** 02092 Retrieve a pointer to a dictionary passed in as an atom argument. 02093 Use this function when working with classes that have dictionary constructors 02094 to fetch the dictionary. 02095 02096 @ingroup obj 02097 @param ac The number of atoms. 02098 @param av A pointer to the first atom in the array. 02099 @return The dictionary retrieved from the atoms. 02100 @see attr_dictionary_process() 02101 */ 02102 t_dictionary *object_dictionaryarg(long ac, t_atom *av); 02103 02104 02105 // use the macros for these in ext_obex_util.h 02106 t_max_err class_sticky(t_class *x, t_symbol *stickyname, t_symbol *s, t_object *o); 02107 t_max_err class_sticky_clear(t_class *x, t_symbol *stickyname, t_symbol *s); 02108 02109 02110 // private -- internal use only (and perhaps not exported?) 02111 t_max_err object_retain(t_object *x); 02112 t_max_err object_release(t_object *x); 02113 02114 typedef struct _method_object 02115 { 02116 t_object ob; 02117 t_messlist messlist_entry; 02118 } t_method_object; 02119 02120 t_method_object *method_object_new(method m, char *name, ...); 02121 t_method_object *method_object_new_messlist(t_messlist *m); 02122 void method_object_free(t_method_object *x); 02123 t_symbol *method_object_getname(t_method_object *x); 02124 void method_object_setname(t_method_object *x, t_symbol *s); 02125 method method_object_getmethod(t_method_object *x); 02126 void method_object_setmethod(t_method_object *x, method m); 02127 t_messlist *method_object_getmesslist(t_method_object *x); 02128 void method_object_setmesslist(t_method_object *x, t_messlist *m); 02129 02130 t_method_object *class_getmethod_object(t_class *x, t_symbol *methodname); 02131 02132 // these methods are private -- instance methods are not actually fully implemented at this time 02133 t_method_object *object_getmethod_object(t_object *x, t_symbol *methodname); 02134 02135 t_max_err object_attrhash_apply(t_object *x, t_hashtab *attrhash); 02136 t_max_err object_sticky(t_object *x, t_symbol *stickyname, t_symbol *s, t_object *o); 02137 t_max_err object_sticky_clear(t_object *x, t_symbol *stickyname, t_symbol *s); 02138 02139 // these methods are private -- instance methods are not actually fully implemented at this time 02140 t_max_err object_addmethod(t_object *x, method m, char *name, ...); 02141 t_max_err object_addmethod_object(t_object *x, t_object *mo); 02142 t_max_err object_deletemethod(t_object *x, t_symbol *methodsym); 02143 t_max_err object_chuckmethod(t_object *x, t_symbol *methodsym); 02144 02145 t_max_err attr_typedfun_set(void *parent, t_object *x, long ac, t_atom *av); 02146 02147 02148 /** 02149 Allocate a single atom. 02150 If ac and av are both zero then memory is allocated. 02151 Otherwise it is presumed that memory is already allocated and nothing will happen. 02152 02153 @ingroup atom 02154 @param ac The address of a variable that will contain the number of atoms allocated (1). 02155 @param av The address of a pointer that will be set with the new allocated memory for the atom. 02156 @param alloc Address of a variable that will be set true is memory is allocated, otherwise false. 02157 @return A Max error code. 02158 */ 02159 t_max_err atom_alloc(long *ac, t_atom **av, char *alloc); 02160 02161 02162 /** 02163 Allocate an array of atoms. 02164 If ac and av are both zero then memory is allocated. 02165 Otherwise it is presumed that memory is already allocated and nothing will happen. 02166 02167 @ingroup atom 02168 @param minsize The minimum number of atoms that this array will need to contain. 02169 This determines the amount of memory allocated. 02170 @param ac The address of a variable that will contain the number of atoms allocated. 02171 @param av The address of a pointer that will be set with the new allocated memory for the atoms. 02172 @param alloc Address of a variable that will be set true is memory is allocated, otherwise false. 02173 @return A Max error code. 02174 */ 02175 t_max_err atom_alloc_array(long minsize, long *ac, t_atom **av, char *alloc); 02176 02177 02178 02179 // private? 02180 long class_is_box(t_class *c); 02181 02182 02183 /** 02184 Determine if a class is a user interface object. 02185 02186 @ingroup class 02187 @param c The class pointer. 02188 @return True is the class defines a user interface object, otherwise false. 02189 */ 02190 long class_is_ui(t_class *c); 02191 02192 02193 #if C74_PRAGMA_STRUCT_PACKPUSH 02194 #pragma pack(pop) 02195 #elif C74_PRAGMA_STRUCT_PACK 02196 #pragma pack() 02197 #endif 02198 02199 #ifdef __cplusplus 02200 } 02201 #endif // __cplusplus 02202 02203 #endif // __OBEX_H__
Copyright © 2008, Cycling '74