Max 5 API Reference
00001 <?xml version="1.0" encoding="UTF-8"?> 00002 00003 <category> 00004 <cattitle>Class Functions</cattitle> 00005 00006 // function: class_new 00007 /** 00008 * Initializes a class by informing Max of its name, instance creation and free functions, size and argument types. Developers wishing to use obex class features (attributes, etc.) <em>must</em> use <tt>class_new</tt> instead of the traditional <tt>setup</tt> function. 00009 * 00010 * @param name The class's name, as a C-string 00011 * @param mnew The instance creation function 00012 * @param mfree The instance free function 00013 * @param size The size of the object's data structure in bytes. Usually 00014 * you use the C sizeof operator here. 00015 * @param mmenu The function called when the user creates a new object of the 00016 * class from the Patch window's palette (UI objects only). 00017 * Pass 0L if you're not defining a UI object. 00018 * @param type A standard Max <em>type list</em> as explained in Chapter 3 00019 * of the Writing Externals in Max document (in the Max SDK). 00020 * The final argument of the type list should be a 0. 00021 * <em>Generally, obex objects have a single type argument</em>, 00022 * <tt>A_GIMME</tt>, followed by a 0. 00023 * 00024 * @return This function returns the class pointer for the new object class. 00025 * <em>This pointer is used by numerous other functions and should be 00026 * stored in a global variable.</em> 00027 * 00028 */ 00029 00030 // function: class_free 00031 /** 00032 * Frees a previously defined object class. <em>This function is not typically used by external developers.</em> 00033 * 00034 * @param c The class pointer 00035 * 00036 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00037 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00038 * 00039 */ 00040 00041 // function: class_register 00042 /** 00043 * Registers a previously defined object class. This function is required, and should be called at the end of <tt>main()</tt>. 00044 * 00045 * @param name_space The desired class's name space. Typically, either the 00046 * constant <tt>CLASS_BOX</tt>, for obex classes which can 00047 * instantiate inside of a Max patcher (e.g. boxes, UI objects, 00048 * etc.), or the constant <tt>CLASS_NOBOX</tt>, for classes 00049 * which will only be used internally. Developers can define 00050 * their own name spaces as well, but this functionality is 00051 * currently undocumented. 00052 * @param c The class pointer 00053 * 00054 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00055 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00056 * 00057 */ 00058 00059 // function: class_addmethod 00060 /** 00061 * Adds a method to a previously defined object class. 00062 * 00063 * @param c The class pointer 00064 * @param m Function to be called when the method is invoked 00065 * @param name C-string defining the message (message selector) 00066 * @param ... One or more integers specifying the arguments to the message, 00067 * in the standard Max type list format (see Chapter 3 of the 00068 * Writing Externals in Max document for more information). 00069 * 00070 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00071 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00072 * 00073 * @remark The <tt>class_addmethod</tt> function works essentially like the 00074 * traditional <tt>addmess</tt> function, adding the function pointed to 00075 * by <tt>m</tt>, to respond to the message string <tt>name</tt> in the 00076 * leftmost inlet of the object. 00077 * 00078 */ 00079 00080 // function: class_addattr 00081 /** 00082 * Adds an attribute to a previously defined object class. 00083 * 00084 * @param c The class pointer 00085 * @param attr The attribute to add. The attribute will be a pointer returned 00086 * by <tt>attribute_new</tt>, <tt>attr_offset_new</tt> or 00087 * <tt>attr_offset_array_new</tt>. 00088 * 00089 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00090 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00091 * 00092 */ 00093 00094 // function: class_addadornment 00095 /** 00096 * Adds an adornment to a previously defined object class. At this time, this function is non-functional and undocumented. 00097 * 00098 * @param c Undocumented 00099 * @param o Undocumented 00100 * 00101 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00102 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00103 * 00104 */ 00105 00106 // function: class_obexoffset_set 00107 /** 00108 * Registers the byte-offset of the obex member of the class's data structure with the previously defined object class. Use of this function is required for obex-class objects. It must be called from <tt>main()</tt>. 00109 * 00110 * @param c The class pointer 00111 * @param offset The byte-offset to the obex member of the object's data structure. 00112 * Conventionally, the macro <tt>calcoffset</tt> is used to calculate the offset. 00113 * 00114 */ 00115 00116 // function: class_obexoffset_get 00117 /** 00118 * Retrieves the byte-offset of the obex member of the class's data structure. 00119 * 00120 * @param c The class pointer 00121 * 00122 * @return This function returns the byte-offset of the obex member of the class's data structure. 00123 * 00124 */ 00125 00126 // function: class_name_get 00127 /** 00128 * Retrieves the name of a class, given the class's pointer. 00129 * 00130 * @param c The class pointer 00131 * 00132 * @return If successful, this function returns the name of the class as a t_symbol *. 00133 * 00134 */ 00135 00136 // function: class_findbyname 00137 /** 00138 * Finds the class pointer for a class, given the class's namespace and name. 00139 * 00140 * @param name_space The desired class's name space. Typically, either the 00141 * constant <tt>CLASS_BOX</tt>, for obex classes which can 00142 * instantiate inside of a Max patcher (e.g. boxes, UI objects, 00143 * etc.), or the constant <tt>CLASS_NOBOX</tt>, for classes 00144 * which will only be used internally. Developers can define 00145 * their own name spaces as well, but this functionality is 00146 * currently undocumented. 00147 * @param classname The name of the class to be looked up 00148 * 00149 * @return If successful, this function returns the class's data pointer. Otherwise, it returns NULL. 00150 * 00151 */ 00152 00153 // function: calcoffset 00154 /** 00155 * The macro <tt>calcoffset</tt> is used as follows: 00156 * 00157 * @param classtype The class's defined type (e.g. <tt>t_myobject</tt>) 00158 * @param varname The name of a variable in the class's data structure. 00159 * 00160 * @return The macro returns the byte-offset of the specified variable within 00161 * the class data structure for the specified class type. 00162 * 00163 */ 00164 00165 </category> 00166 00167 <category> 00168 <cattitle>Object Functions: instantiation and freeing</cattitle> 00169 00170 // function: object_alloc 00171 /** 00172 * Allocates the memory for an instance of an object class and initialize its object header. It is used like the traditional function <tt>newobject</tt>, inside of an object's <tt>new</tt> method, but its use is required with obex-class objects. 00173 * 00174 * @param c The class pointer, returned by <tt>class_new</tt> 00175 * 00176 * @return This function returns a new instance of an object class if successful, or NULL if unsuccessful. 00177 * 00178 */ 00179 00180 // function: object_new 00181 /** 00182 * Allocates the memory for an instance of an object class and initialize its object header <em>internal to Max</em>. It is used similarly to the traditional function <tt>newinstance</tt>, but its use is required with obex-class objects. 00183 * 00184 * @param name_space The desired object's name space. Typically, either the 00185 * constant <tt>CLASS_BOX</tt>, for obex classes which can 00186 * instantiate inside of a Max patcher (e.g. boxes, UI objects, 00187 * etc.), or the constant <tt>CLASS_NOBOX</tt>, for classes 00188 * which will only be used internally. Developers can define 00189 * their own name spaces as well, but this functionality is 00190 * currently undocumented. 00191 * @param classname The name of the class of the object to be created 00192 * @param ... Any arguments expected by the object class being instantiated 00193 * 00194 * @return This function returns a new instance of the object class if successful, or NULL if unsuccessful. 00195 * 00196 */ 00197 00198 // function: object_new_typed 00199 /** 00200 * Allocates the memory for an instance of an object class and initialize its object header <em>internal to Max</em>. It is used similarly to the traditional function <tt>newinstance</tt>, but its use is required with obex-class objects. The <tt>object_new_typed</tt> function differs from <tt>object_new</tt> by its use of an atom list for object arguments—in this way, it more resembles the effect of typing something into an object box from the Max interface. 00201 * 00202 * @param name_space The desired object's name space. Typically, either the 00203 * constant <tt>CLASS_BOX</tt>, for obex classes which can 00204 * instantiate inside of a Max patcher (e.g. boxes, UI objects, 00205 * etc.), or the constant <tt>CLASS_NOBOX</tt>, for classes 00206 * which will only be used internally. Developers can define 00207 * their own name spaces as well, but this functionality is 00208 * currently undocumented. 00209 * @param classname The name of the class of the object to be created 00210 * @param ac Count of arguments in <tt>av</tt> 00211 * @param av Array of t_atoms; arguments to the class's instance creation function. 00212 * 00213 * @return This function returns a new instance of the object class if successful, or NULL if unsuccessful. 00214 * 00215 */ 00216 00217 // function: object_free 00218 /** 00219 * Call the free function and release the memory for an instance of an internal object class previously instantiated using <tt>object_new</tt>, <tt>object_new_typed</tt> or other new-style object constructor functions (e.g. <tt>hashtab_new</tt>). It is, at the time of this writing, a wrapper for the traditional function <tt>freeobject</tt>, but its use is suggested with obex-class objects. 00220 * 00221 * @param x The pointer to the object to be freed. 00222 * 00223 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00224 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00225 * 00226 */ 00227 00228 </category> 00229 00230 <category> 00231 <cattitle>Object Functions: sending messages</cattitle> 00232 00233 // function: object_method 00234 /** 00235 * Sends an untyped message to an object. 00236 * 00237 * @param x The object that will receive the message 00238 * @param s The message selector 00239 * @param ... Any arguments to the message 00240 * 00241 * @return If the receiver object can respond to the message, <tt>object_method</tt> returns the result. Otherwise, the function will return 0. 00242 * 00243 * @remark Example: To send the message <tt>bang</tt> to the object <tt>bang_me</tt>: 00244 @code 00245 void *bang_result; 00246 bang_result = object_method(bang_me, gensym("bang"));</proto> 00247 @endcode 00248 * 00249 */ 00250 00251 // function: object_method_typed 00252 /** 00253 * Sends a type-checked message to an object. 00254 * 00255 * @param x The object that will receive the message 00256 * @param s The message selector 00257 * @param ac Count of message arguments in <tt>av</tt> 00258 * @param av Array of t_atoms; the message arguments 00259 * @param rv Return value of function, if available 00260 * 00261 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00262 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00263 * 00264 * @remark If the receiver object can respond to the message, <tt>object_method_typed</tt> returns the result in <tt>rv</tt>. Otherwise, <tt>rv</tt> will contain an <tt>A_NOTHING</tt> atom. 00265 * 00266 */ 00267 00268 // function: object_method_typedfun 00269 /** 00270 * Currently undocumented. 00271 * 00272 * @param x The object that will receive the message 00273 * @param mp Undocumented 00274 * @param s The message selector 00275 * @param ac Count of message arguments in <tt>av</tt> 00276 * @param av Array of t_atoms; the message arguments 00277 * @param rv Return value of function, if available 00278 * 00279 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00280 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00281 * 00282 * @remark If the receiver object can respond to the message, <tt>object_method_typedfun</tt> returns the result in <tt>rv</tt>. Otherwise, <tt>rv</tt> will contain an <tt>A_NOTHING</tt> atom. 00283 * 00284 */ 00285 00286 // function: object_getmethod 00287 /** 00288 * Retrieves an object's <tt>method</tt> for a particular message selector. 00289 * 00290 * @param x The object whose method is being queried 00291 * @param s The message selector 00292 * 00293 * @return This function returns the <tt>method</tt> if successful, or 0 if unsuccessful. 00294 * 00295 */ 00296 00297 </category> 00298 00299 <category> 00300 <cattitle>Object Functions: obex</cattitle> 00301 00302 // function: object_obex_store 00303 /** 00304 * Stores data in the object's obex. 00305 * 00306 * @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>). 00307 * @param key A symbolic name for the data to be stored 00308 * @param val A <tt>t_object *</tt>, to be stored in the obex, referenced under the <tt>key</tt>. 00309 * 00310 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00311 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00312 * 00313 * @remark Most developers will need to use this function for the specific purpose of storing the dumpout outlet in the obex (the dumpout outlet is used by attributes to report data in response to 'get' queries). For this, the developer should use something like the following in the object's <tt>new</tt> method: 00314 @code 00315 object_obex_store(x, _sym_dumpout, outlet_new(x, NULL)); 00316 @endcode 00317 * 00318 */ 00319 00320 // function: object_obex_lookup 00321 /** 00322 * Retrieves the value of a data stored in the obex. 00323 * 00324 * @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>). 00325 * @param key The symbolic name for the data to be retrieved 00326 * @param val A pointer to a <tt>t_object *</tt>, to be filled with the data retrieved from the obex. 00327 * 00328 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00329 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00330 * 00331 * @remark By default, pointers to the object's containing t_patcher and t_box objects are stored in the obex, under the keys '#P' and '#B', respectively. To retrieve them, the developer could do something like the following: 00332 @code 00333 void post_containers(t_obexobj *x) 00334 { 00335 t_patcher *p; 00336 t_box *b; 00337 00338 p = object_obex_lookup(x, gensym("#P"), (t_object **)&p); 00339 b = object_obex_lookup(x, gensym("#B"), (t_object **)&b); 00340 00341 post("my patcher is located at 0x%X", p); 00342 post("my box is located at 0x%X", b); 00343 } 00344 @endcode 00345 * 00346 */ 00347 00348 // function: object_obex_dumpout 00349 /** 00350 * Sends data from the object's dumpout outlet. The dumpout outlet is stored in the obex using the <tt>object_obex_store</tt> function (see above) It is used approximately like <tt>outlet_anything</tt>. 00351 * 00352 * @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>). 00353 * @param s The message selector t_symbol * 00354 * @param argc Number of elements in the argument list in argv 00355 * @param argv t_atoms constituting the message arguments 00356 * 00357 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00358 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00359 * 00360 */ 00361 00362 // function: object_obex_set 00363 /** 00364 * Currently undocumented. 00365 * 00366 * @param x <em>undocumented</em> 00367 * @param obex <em>undocumented</em> 00368 * 00369 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00370 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00371 * 00372 */ 00373 00374 // function: object_obex_get 00375 /** 00376 * Currently undocumented. 00377 * 00378 * @param x <em>undocumented</em> 00379 * 00380 * @return The return value is undocumented. 00381 * 00382 */ 00383 00384 </category> 00385 00386 <category> 00387 <cattitle>Object Functions: miscellaneous</cattitle> 00388 00389 // function: object_classname_compare 00390 /** 00391 * Determines if a particular object is an instance of a given class. 00392 * 00393 * @param x The object to test 00394 * @param name The name of the class to test the object against 00395 * 00396 * @return This function returns 1 if the object is an instance of the named class. Otherwise, 0 is returned. 00397 * 00398 * @remark For instance, to determine whether an unknown object pointer is a pointer to a print object, you'd call: 00399 @code 00400 long isprint = object_classname_compare(x, gensym("print")); 00401 @endcode 00402 * 00403 */ 00404 00405 // function: object_class 00406 /** 00407 * Determines the class of a given object. 00408 * 00409 * @param x The object to test 00410 * 00411 * @return This function returns the t_class * of the object's class, if successful, or <tt>NULL</tt>, if unsuccessful. 00412 * 00413 */ 00414 00415 // function: object_getvalueof 00416 /** 00417 * 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. 00418 * 00419 * @param x The object whose value is of interest 00420 * @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. 00421 * @param av Pointer to a t_atom *, to receive object data. The t_atom * itself should be set to <tt>NULL</tt> previous to calling this function. 00422 * 00423 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00424 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00425 * 00426 * @remark Calling the <tt>object_getvalueof</tt> function allocates memory for any data it returns. It is the developer's responsibility to free it, using the <tt>freebytes</tt> function. 00427 * 00428 * @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: 00429 @code 00430 class_addmethod(c, (method)myobject_getvalueof, "getvalueof", A_CANT, 0); 00431 @endcode 00432 * 00433 * @remark The <tt>getvalueof</tt> method should be prototyped as: 00434 @code 00435 t_max_err myobject_getvalueof(t_myobject *x, long *ac, t_atom **av); 00436 @endcode 00437 * 00438 * @remark And implemented, generally, as: 00439 @code 00440 t_max_err myobj_getvalueof(t_myobj *x, long *ac, t_atom **av) 00441 { 00442 if (ac && av) { 00443 if (*ac && *av) { 00444 // memory has been passed in; use it. 00445 } else { 00446 // allocate enough memory for your data 00447 *av = (t_atom *)getbytes(sizeof(t_atom)); 00448 } 00449 *ac = 1; // our data is a single floating point value 00450 atom_setfloat(*av, x->objvalue); 00451 } 00452 return MAX_ERR_NONE; 00453 } 00454 * 00455 * @remark By convention, and to permit the interoperability of objects using the obex API, developers should allocate memory in their <tt>getvalueof</tt> methods using the <tt>getbytes</tt> function. 00456 @endcode 00457 * 00458 */ 00459 00460 // function: object_setvalueof 00461 /** 00462 * Sets 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. 00463 * 00464 * @param x The object whose value is of interest 00465 * @param ac The count of arguments in <tt>av</tt> 00466 * @param av Array of t_atoms; the new desired data for the object 00467 * 00468 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00469 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00470 * 00471 * @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: 00472 @code 00473 class_addmethod(c, (method)myobject_setvalueof, "setvalueof", A_CANT, 0); 00474 @endcode 00475 * 00476 * @remark The <tt>setvalueof</tt> method should be prototyped as: 00477 @code 00478 t_max_err myobject_setvalueof(t_myobject *x, long *ac, t_atom **av); 00479 @endcode 00480 * 00481 * @remark And implemented, generally, as: 00482 @code 00483 t_max_err myobject_setvalueof(t_myobject *x, long ac, t_atom *av) 00484 { 00485 if (ac && av) { 00486 // simulate receipt of a float value 00487 myobject_float(x, atom_getfloat(av)); 00488 } 00489 return MAX_ERR_NONE; 00490 } 00491 @endcode 00492 * 00493 */ 00494 00495 </category> 00496 00497 <category> 00498 <cattitle>Object Functions: registration/notification</cattitle> 00499 00500 // function: object_register 00501 /** 00502 * Registers an object in a namespace. 00503 * 00504 * @param name_space The namespace in which to register the object. The namespace c 00505 * an be any symbol. If the namespace does not already exist, 00506 * it is created automatically. 00507 * @param s The name of the object in the namespace. This name will be 00508 * used by other objects to attach and detach from the registered object. 00509 * @param x The object to register 00510 * 00511 * @return The function returns a pointer to the registered object. Under some 00512 * circumstances, object_register will <em>duplicate</em> the object, 00513 * and return a pointer to the duplicate—the developer should not assume 00514 * that the pointer passed in is the same pointer that has been registered. 00515 * To be safe, the returned pointer should be stored and used with the 00516 * <tt>object_unregister()</tt> function. 00517 * 00518 */ 00519 00520 // function: object_unregister 00521 /** 00522 * Removes a registered object from a namespace. 00523 * 00524 * @param x The object to unregister. This should be the pointer returned from the <tt>object_register</tt> function. 00525 * 00526 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00527 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00528 * 00529 */ 00530 00531 // function: object_attach 00532 /** 00533 * Attaches a client to a registered object. Once attached, the object will receive notifications sent from the registered object (via the <tt>object_notify</tt> function), if it has a <tt>notify</tt> method defined and implemented. See below for more information, in the reference for <tt>object_notify</tt>. 00534 * 00535 * @param name_space The namespace of the registered object. This should be the 00536 * same value used in <tt>object_register</tt> to register the 00537 * object. If you don't know the registered object's namespace, 00538 * the <tt>object_findregisteredbyptr</tt> function can be 00539 * used to determine it. 00540 * @param s The name of the registered object in the namespace. If you 00541 * don't know the name of the registered object, the 00542 * <tt>object_findregisteredbyptr</tt> function can be used to 00543 * determine it. 00544 * @param x The client object to attach. Generally, this is the pointer to your Max object. 00545 * 00546 * @return This function returns a pointer to the registered object (to the object 00547 * referred to by the combination of <tt>name_space</tt> and <tt>s</tt> 00548 * arguments) if successful, or NULL if unsuccessful. 00549 * 00550 */ 00551 00552 // function: object_detach 00553 /** 00554 * Detach a client from a registered object. 00555 * 00556 * @param name_space The namespace of the registered object. This should be the 00557 * same value used in <tt>object_register</tt> to register the 00558 * object. If you don't know the registered object's namespace, 00559 * the <tt>object_findregisteredbyptr</tt> function can be 00560 * used to determine it. 00561 * @param s The name of the registered object in the namespace. If you 00562 * don't know the name of the registered object, the 00563 * <tt>object_findregisteredbyptr</tt> function can be used to 00564 * determine it. 00565 * @param x The client object to detach. Generally, this is the pointer to your Max object. 00566 * 00567 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00568 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00569 * 00570 */ 00571 00572 // function: object_notify 00573 /** 00574 * Broadcast a message (with an optional argument) from a registered object to any attached client objects. 00575 * 00576 * @param x Pointer to the registered object 00577 * @param s The message to send 00578 * @param data An optional argument which will be passed with the message. 00579 * Sets this argument to <tt>NULL</tt> if it will be unused. 00580 * 00581 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00582 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00583 * 00584 * @remark In order for client objects to receive notifications, they must define and implement a special method, <tt>notify</tt>, like so: 00585 @code 00586 class_addmethod(c, (method)myobject_notify, "notify", A_CANT, 0); 00587 @endcode 00588 * 00589 * @remark The <tt>notify</tt> method should be prototyped as: 00590 @code 00591 void myobject_notify(t_myobject *x, t_symbol *s, t_symbol *msg, void *sender, void *data); 00592 @endcode 00593 * where 00594 * <tt>x</tt> is the pointer to the receiving object, 00595 * <tt>s</tt> is the name of the sending (registered) object in its namespace, 00596 * <tt>msg</tt> is the sent message, 00597 * <tt>sender</tt> is the pointer to the sending object, and 00598 * <tt>data</tt>is an optional argument sent with the message. 00599 * This value corresponds to the data argument in the <tt>object_notify</tt> method. 00600 * 00601 */ 00602 00603 // function: object_findregistered 00604 /** 00605 * Determines a registered object's pointer, given its namespace and name. 00606 * 00607 * @param name_space The namespace of the registered object 00608 * @param s The name of the registered object in the namespace 00609 * 00610 * @return This function returns the pointer of the registered object, 00611 * if successful, or NULL, if unsuccessful. 00612 * 00613 */ 00614 00615 // function: object_findregisteredbyptr 00616 /** 00617 * Determines the namespace and/or name of a registered object, given the object's pointer. 00618 * 00619 * @param name_space Pointer to a t_symbol *, to receive the namespace of the registered object 00620 * @param s Pointer to a t_symbol *, to receive the name of the registered object within the namespace 00621 * @param x Pointer to the registered object 00622 * 00623 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00624 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00625 * 00626 */ 00627 00628 </category> 00629 00630 <category> 00631 <cattitle>Attribute Functions: attribute creation and filters</cattitle> 00632 /** 00633 * 00634 * @remark Attributes have been described at length elsewhere. They can be added to a class using the <tt>class_addattr</tt> function. The following functions provide means of creating and modifying attribute filter properties. 00635 * 00636 */ 00637 00638 // function: attribute_new 00639 /** 00640 * Create a new attribute. The attribute will allocate memory and store its own data. Attributes created using <tt>attribute_new</tt> can be assigned either to classes (using the <tt>class_addattr</tt> function) or to objects (using the <tt>object_addattr</tt> function). 00641 * 00642 * @param name A name for the attribute, as a C-string 00643 * @param type A t_symbol * representing a valid attribute type. At the time of this writing, the valid type-symbols are: <tt>_sym_char</tt> (char), <tt>_sym_long</tt> (long), <tt>_sym_float32</tt> (32-bit float), <tt>_sym_float64</tt> (64-bit float), <tt>_sym_atom</tt> (Max t_atom pointer), <tt>_sym_symbol</tt> (Max t_symbol pointer), <tt>_sym_pointer</tt> (generic pointer) and <tt>_sym_object</tt> (Max t_object pointer). 00644 * @param flags Any attribute flags, expressed as a bitfield. Attribute flags are used to determine if an attribute is accessible for setting or querying. The following accessor flags are currently available:ATTR_GET_OPAQUE: The attribute cannot be queried by either max message when used inside of a CLASS_BOX object, nor from C code.ATTR_SET_OPAQUE: The attribute cannot be set by either max message when used inside of a CLASS_BOX object, nor from C code.ATTR_GET_OPAQUE_USER: 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.ATTR_SET_OPAQUE_USER: 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.<text:tab-stop/> 00645 * @param mget The method to use for the attribute's <tt>get</tt> functionality. If <tt>mget</tt> is <tt>NULL</tt>, the default method is used. 00646 * @param mset The method to use for the attribute's <tt>set</tt> functionality. If <tt>mset</tt> is <tt>NULL</tt>, the default method is used. 00647 * 00648 * @return This function returns the new attribute's object pointer if successful, or <tt>NULL</tt> if unsuccessful. 00649 * 00650 * @remark Developers wishing to define custom methods for <tt>get</tt> or <tt>set</tt> functionality need to prototype them as: 00651 @code 00652 t_max_err myobject_myattr_get(t_myobject *x, void *attr, long *ac, t_atom **av); 00653 @endcode 00654 @code 00655 t_max_err myobject_myattr_set(t_myobject *x, void *attr, long ac, t_atom *av); 00656 @endcode 00657 * 00658 * @remark Implementation will vary, of course, but need to follow the following basic models. Note that, as with custom <tt>getvalueof</tt> and <tt>setvalueof</tt> methods for the object, assumptions are made throughout Max that <tt>getbytes</tt> has been used for memory allocation. Developers are strongly urged to do the same: 00659 @code 00660 t_max_err myobject_myattr_get(t_myobject *x, void *attr, long *ac, t_atom **av) 00661 { 00662 if (*ac && *av) 00663 // memory passed in; use it 00664 else { 00665 *ac = 1; // size of attr data 00666 *av = (t_atom *)getbytes(sizeof(t_atom) * (*ac)); 00667 if (!(*av)) { 00668 *ac = 0; 00669 return MAX_ERR_OUT_OF_MEM; 00670 } 00671 } 00672 atom_setlong(*av, x->some_value); 00673 return MAX_ERR_NONE; 00674 } 00675 00676 t_max_err myobject_myattr_set(t_myobject *x, void *attr, long ac, t_atom *av) 00677 { 00678 if (ac && av) { 00679 x->some_value = atom_getlong(av); 00680 } 00681 return MAX_ERR_NONE; 00682 } 00683 @endcode 00684 * 00685 */ 00686 00687 // function: attr_offset_new 00688 /** 00689 * Create a new attribute. The attribute references memory stored outside of itself, in the object's data structure. Attributes created using <tt>attr_offset_new</tt> can be assigned either to classes (using the <tt>class_addattr</tt> function) or to objects (using the <tt>object_addattr</tt> function). 00690 * 00691 * @param name A name for the attribute, as a C-string 00692 * @param type A t_symbol * representing a valid attribute type. At the time of this writing, the valid type-symbols are: <tt>_sym_char</tt> (char), <tt>_sym_long</tt> (long), <tt>_sym_float32</tt> (32-bit float), <tt>_sym_float64</tt> (64-bit float), <tt>_sym_atom</tt> (Max t_atom pointer), <tt>_sym_symbol</tt> (Max t_symbol pointer), <tt>_sym_pointer</tt> (generic pointer) and <tt>_sym_object</tt> (Max t_object pointer). This type should match the size of the data at the byte offset specified in the <tt>offset</tt> argument. 00693 * @param flags Any attribute flags, expressed as a bitfield. See the discussion of attribute flags above, under <tt>attribute_new()</tt>. 00694 * @param mget The method to use for the attribute's <tt>get</tt> functionality. If <tt>mget</tt> is <tt>NULL</tt>, the default method is used. See the discussion under <tt>attribute_new</tt>, above, for more information. 00695 * @param mset The method to use for the attribute's <tt>set</tt> functionality. If <tt>mset</tt> is <tt>NULL</tt>, the default method is used. See the discussion under <tt>attribute_new</tt>, above, for more information. 00696 * @param offset Byte offset into the class data structure of the object which will "own" the attribute. The offset should point to the data to be referenced by the attribute. Typically, the <tt>calcoffset</tt> macro (described above) is used to calculate this offset. 00697 * 00698 * @return This function returns the new attribute's object pointer if successful, or <tt>NULL</tt> if unsuccessful. 00699 * 00700 * @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: 00701 @code 00702 t_object *attr = attr_offset_new("myattr", _sym_float64 / * matches data size * /, 0 / * no flags * /, (method)0L, (method)0L, calcoffset(t_myobject, val)); 00703 @endcode 00704 * 00705 */ 00706 00707 // function: attr_offset_array_new 00708 /** 00709 * Create a new attribute. The attribute references an array of memory stored outside of itself, in the object's data structure. Attributes created using <tt>attr_offset_array_new</tt> can be assigned either to classes (using the <tt>class_addattr</tt> function) or to objects (using the <tt>object_addattr</tt> function). 00710 * 00711 * @param name A name for the attribute, as a C-string 00712 * @param type A t_symbol * representing a valid attribute type. At the time of this writing, the valid type-symbols are: <tt>_sym_char</tt> (char), <tt>_sym_long</tt> (long), <tt>_sym_float32</tt> (32-bit float), <tt>_sym_float64</tt> (64-bit float), <tt>_sym_atom</tt> (Max t_atom pointer), <tt>_sym_symbol</tt> (Max t_symbol pointer), <tt>_sym_pointer</tt> (generic pointer) and <tt>_sym_object</tt> (Max t_object pointer). This type should match the size of the data at the byte offset specified in the <tt>offset</tt> argument. 00713 * @param size The maximum number of elements the array of data will contain. 00714 * @param flags Any attribute flags, expressed as a bitfield. See the discussion of attribute flags above, under <tt>attribute_new()</tt>. 00715 * @param mget The method to use for the attribute's <tt>get</tt> functionality. If <tt>mget</tt> is <tt>NULL</tt>, the default method is used. See the discussion under <tt>attribute_new</tt>, above, for more information. 00716 * @param mset The method to use for the attribute's <tt>set</tt> functionality. If <tt>mset</tt> is <tt>NULL</tt>, the default method is used. See the discussion under <tt>attribute_new</tt>, above, for more information. 00717 * @param offsetcount Byte offset into the object class's data structure of a long variable describing how many array elements (up to <tt>size</tt>) comprise the data to be referenced by the attribute. Typically, the <tt>calcoffset</tt> macro (described above) is used to calculate this offset. 00718 * @param offset Byte offset into the class data structure of the object which will "own" the attribute. The offset should point to the data to be referenced by the attribute. Typically, the <tt>calcoffset</tt> macro (described above) is used to calculate this offset. 00719 * 00720 * @return This function returns the new attribute's object pointer if successful, or <tt>NULL</tt> if unsuccessful. 00721 * 00722 * @remark For instance, to create a new attribute which references an array of 10 t_atoms (<tt>atm</tt>; the current number of "active" elements in the array is held in the variable <tt>atmcount</tt>) in an object class's data structure: 00723 @code 00724 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 * /); 00725 @endcode 00726 * 00727 */ 00728 00729 // function: attr_addfilter_clip 00730 /** 00731 * Attaches a clip filter to an attribute. 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. 00732 * 00733 * @param x Pointer to the attribute to receive the filter 00734 * @param min Minimum value for the clip filter 00735 * @param max Maximum value for the clip filter 00736 * @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. 00737 * @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. 00738 * 00739 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00740 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00741 * 00742 */ 00743 00744 // function: attr_addfilter_clip_scale 00745 /** 00746 * Attaches a clip/scale filter to an attribute. 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. 00747 * 00748 * @param x Pointer to the attribute to receive the filter 00749 * @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. <em>Scaling occurs previous to clipping</em>. 00750 * @param min Minimum value for the clip filter 00751 * @param max Maximum value for the clip filter 00752 * @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. 00753 * @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. 00754 * 00755 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00756 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00757 * 00758 */ 00759 00760 // function: attr_addfilterset_clip 00761 /** 00762 * Attaches a clip filter to an attribute. The filter will <em>only</em> clip values sent to the attribute using the attribute's <tt>set</tt> function. 00763 * 00764 * @param x Pointer to the attribute to receive the filter 00765 * @param min Minimum value for the clip filter 00766 * @param max Maximum value for the clip filter 00767 * @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. 00768 * @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. 00769 * 00770 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00771 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00772 * 00773 */ 00774 00775 // function: attr_addfilterset_clip_scale 00776 /** 00777 * Attaches a clip/scale filter to an attribute. The filter will <em>only</em> clip and scale values sent to the attribute using the attribute's <tt>set</tt> function. 00778 * 00779 * @param x Pointer to the attribute to receive the filter 00780 * @param scale Scale value. Data sent to the attribute will be scaled by this amount. <em>Scaling occurs previous to clipping</em>. 00781 * @param min Minimum value for the clip filter 00782 * @param max Maximum value for the clip filter 00783 * @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. 00784 * @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. 00785 * 00786 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00787 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00788 * 00789 */ 00790 00791 // function: attr_addfilterget_clip 00792 /** 00793 * Attaches a clip filter to an attribute. The filter will <em>only</em> clip values retrieved from the attribute using the attribute's <tt>get</tt> function. 00794 * 00795 * @param x Pointer to the attribute to receive the filter 00796 * @param min Minimum value for the clip filter 00797 * @param max Maximum value for the clip filter 00798 * @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. 00799 * @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. 00800 * 00801 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00802 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00803 * 00804 */ 00805 00806 // function: attr_addfilterget_clip_scale 00807 /** 00808 * Attaches a clip/scale filter to an attribute. The filter will <em>only</em> clip and scale values retrieved from the attribute using the attribute's <tt>get</tt> function. 00809 * 00810 * @param x Pointer to the attribute to receive the filter 00811 * @param scale Scale value. Data retrieved from the attribute will be scaled by this amount. <em>Scaling occurs previous to clipping</em>. 00812 * @param min Minimum value for the clip filter 00813 * @param max Maximum value for the clip filter 00814 * @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. 00815 * @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. 00816 * 00817 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00818 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00819 * 00820 */ 00821 00822 // function: attr_addfilterset_proc 00823 /** 00824 * 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>set</tt> function. 00825 * 00826 * @param x Pointer to the attribute to receive the filter 00827 * @param proc A filter method 00828 * 00829 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00830 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00831 * 00832 * @remark The filter method should be prototyped and implemented as follows: 00833 @code 00834 t_max_err myfiltermethod(void *parent, void *attr, long ac, t_atom *av); 00835 00836 t_max_err myfiltermethod(void *parent, void *attr, long ac, t_atom *av) 00837 { 00838 long i; 00839 float temp, 00840 00841 // this filter rounds off all values 00842 // assumes that the data is float 00843 for (i = 0; i < ac; i++) { 00844 temp = atom_getfloat(av + i); 00845 temp = (float)((long)(temp + 0.5)); 00846 atom_setfloat(av + i, temp); 00847 } 00848 return MAX_ERR_NONE; 00849 } 00850 @endcode 00851 * 00852 */ 00853 00854 // function: attr_addfilterget_proc 00855 /** 00856 * 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. 00857 * 00858 * @param x Pointer to the attribute to receive the filter 00859 * @param proc A filter method 00860 * 00861 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00862 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00863 * 00864 * @remark The filter method should be prototyped and implemented as described above for the <tt>attr_addfilterset_proc</tt> function. 00865 * 00866 */ 00867 00868 </category> 00869 00870 <category> 00871 <cattitle>Object Functions: attributes (general)</cattitle> 00872 00873 // function: object_attr_getvalueof 00874 /** 00875 * Retrieves the value of an object's attribute. 00876 * 00877 * @param x Pointer to the object whose attribute is of interest 00878 * @param s The attribute's name 00879 * @param argc Pointer to a long variable to receive the count of arguments in <tt>argv</tt>. The long variable itself should be set to 0 previous to calling this function. 00880 * @param argv Pointer to a t_atom *, to receive object data. The t_atom * itself should be set to <tt>NULL</tt> previous to calling this function. 00881 * 00882 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00883 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00884 * 00885 * @remark Calling the <tt>object_getvalueof</tt> function allocates memory for any data it returns. It is the developer's responsibility to free it, using the <tt>freebytes</tt> function. 00886 * 00887 */ 00888 00889 // function: object_attr_setvalueof 00890 /** 00891 * Sets the value of an object's attribute. 00892 * 00893 * @param x Pointer to the object whose attribute is of interest 00894 * @param s The attribute's name 00895 * @param argc The count of arguments in <tt>argv</tt> 00896 * @param argv Array of t_atoms; the new desired data for the attribute 00897 * 00898 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00899 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00900 * 00901 */ 00902 00903 // function: object_attr_get 00904 /** 00905 * Returns the pointer to an attribute, given its name. 00906 * 00907 * @param x Pointer to the object whose attribute is of interest 00908 * @param attrname The attribute's name 00909 * 00910 * @return This function returns a pointer to the attribute, if successful, or <tt>NULL</tt>, if unsuccessful. 00911 * 00912 */ 00913 00914 // function: object_attr_method 00915 /** 00916 * 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. 00917 * 00918 * @param x Pointer to the object whose attribute is of interest 00919 * @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>. 00920 * @param attr A pointer to a void *, which will be set to the attribute pointer upon successful completion of the function 00921 * @param get A pointer to a long variable, which will be set to 1 upon successful completion of the function, if the queried method corresponds to the <tt>get</tt> function of the attribute. 00922 * 00923 * @return This function returns the requested method, if successful, or <tt>NULL</tt>, if unsuccessful. 00924 * 00925 */ 00926 00927 // function: object_attr_usercanset 00928 /** 00929 * Determines if an object's attribute can be set from the Max interface (i.e. if its <tt>ATTR_SET_OPAQUE_USER</tt> flag is set). 00930 * 00931 * @param x Pointer to the object whose attribute is of interest 00932 * @param s The attribute's name 00933 * 00934 * @return This function returns 1 if the attribute can be set from the Max interface. Otherwise, it returns 0. 00935 * 00936 */ 00937 00938 // function: object_attr_usercanget 00939 /** 00940 * Determines if the value of an object's attribute can be queried from the Max interface (i.e. if its <tt>ATTR_GET_OPAQUE_USER</tt> flag is set). 00941 * 00942 * @param x Pointer to the object whose attribute is of interest 00943 * @param s The attribute's name 00944 * 00945 * @return This function returns 1 if the value of the attribute can be queried from the Max interface. Otherwise, it returns 0. 00946 * 00947 */ 00948 00949 // function: object_attr_getdump 00950 /** 00951 * Forces a specified object's attribute to send its value from the object's dumpout outlet in the Max interface. 00952 * 00953 * @param x Pointer to the object whose attribute is of interest 00954 * @param s The attribute's name 00955 * @param argc Unused 00956 * @param argv Unused 00957 * 00958 */ 00959 00960 </category> 00961 00962 <category> 00963 <cattitle>Object Functions: attributes (object attributes)</cattitle> 00964 00965 // function: object_addattr 00966 /** 00967 * Attaches an attribute directly to an object. 00968 * 00969 * @param x An object to which the attribute should be attached 00970 * @param attr The attribute's pointer—this should be a pointer returned from <tt>attribute_new</tt>, <tt>attr_offset_new</tt> or <tt>attr_offset_array_new</tt>. 00971 * 00972 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00973 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00974 * 00975 */ 00976 00977 // function: object_deleteattr 00978 /** 00979 * Detach an attribute from an object that was previously attached with <tt>object_addattr</tt>. The function will also free all memory associated with the attribute. If you only wish to detach the attribute, without freeing it, see the <tt>object_chuckattr</tt> function, below. 00980 * 00981 * @param x The object to which the attribute is attached 00982 * @param attrsym The attribute's name 00983 * 00984 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00985 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00986 * 00987 */ 00988 00989 // function: object_chuckattr 00990 /** 00991 * Detach an attribute from an object that was previously attached with <tt>object_addattr</tt>. This function will not free the attribute (use <tt>object_free</tt> to do this manually). 00992 * 00993 * @param x The object to which the attribute is attached 00994 * @param attrsym The attribute's name 00995 * 00996 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 00997 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 00998 * 00999 */ 01000 01001 </category> 01002 01003 <category> 01004 <cattitle>Attribute Functions: attribute arguments</cattitle> 01005 /** 01006 * 01007 * @remark Most objects which implement attributes support the use of attributes on a Max object's "command line"—written directly in the object box using the form <tt>@attributename value</tt>. The following functions implement this functionality. 01008 * 01009 * @remark NOTE: Because attribute arguments rely on atom lists of the <tt>argc</tt>/<tt>argv</tt> variety, developers who wish to support them must implement their objects as <tt>A_GIMME</tt> in their call to <tt>class_new</tt>. 01010 */ 01011 01012 // function: attr_args_process 01013 /** 01014 * Take 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. 01015 * 01016 * @param x The object whose attributes will be processed 01017 * @param ac The count of t_atoms in <tt>av</tt> 01018 * @param av An atom list 01019 * 01020 * @remark Here is a typical example of usage: 01021 @code 01022 void *myobject_new(t_symbol *s, long ac, t_atom *av) 01023 { 01024 t_myobject *x = NULL; 01025 01026 if (x=(t_myobject *)object_alloc(myobject_class)) 01027 { 01028 // initialize any data before processing 01029 // attributes to avoid overwriting 01030 // attribute argument-set values 01031 x->data = 0; 01032 01033 // process attr args, if any 01034 attr_args_process(x, ac, av); 01035 } 01036 return x; 01037 } 01038 @endcode 01039 * 01040 */ 01041 01042 // function: attr_args_offset 01043 /** 01044 * Determines the point in an atom list where attribute arguments begin. Developers can use this function to assist in the manual processing of attribute arguments, when attr_args_process doesn't provide the correct functionality for a particular purpose. 01045 * 01046 * @param ac The count of t_atoms in <tt>av</tt> 01047 * @param av An atom list 01048 * 01049 * @return This function returns an offset into the atom list, where the first attribute argument occurs. For instance, the atom list <tt>foo bar 3.0 @mode 6</tt> would cause <tt>attr_args_offset</tt> to return 3 (the attribute <tt>mode</tt> appears at position 3 in the atom list). 01050 * 01051 */ 01052 01053 </category> 01054 01055 <category> 01056 <cattitle>Object Functions: attribute utility functions (single value functions)</cattitle> 01057 01058 // function: object_attr_getlong 01059 /** 01060 * Retrieves the value of an attribute, given its parent object and name. 01061 * 01062 * @param x The attribute's parent object 01063 * @param s The attribute's name 01064 * 01065 * @return This function returns the value of the specified attribute, if successful, or 0, if unsuccessful. 01066 * 01067 * @remark If the attribute is not of the type specified by the function, the 01068 * function will attempt to coerce a valid value from the attribute. 01069 * 01070 */ 01071 01072 // function: object_attr_getfloat 01073 /** 01074 * Retrieves the value of an attribute, given its parent object and name. 01075 * 01076 * @param x The attribute's parent object 01077 * @param s The attribute's name 01078 * 01079 * @return This function returns the value of the specified attribute, if successful, or 0, if unsuccessful. 01080 * 01081 * @remark If the attribute is not of the type specified by the function, the 01082 * function will attempt to coerce a valid value from the attribute. 01083 * 01084 */ 01085 01086 // function: object_attr_getsym 01087 /** 01088 * Retrieves the value of an attribute, given its parent object and name. 01089 * 01090 * @param x The attribute's parent object 01091 * @param s The attribute's name 01092 * 01093 * @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. 01094 * 01095 */ 01096 01097 // function: object_attr_setlong 01098 /** 01099 * 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. 01100 * 01101 * @param x The attribute's parent object 01102 * @param s The attribute's name 01103 * @param c An integer value; the new value for the attribute 01104 * 01105 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01106 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01107 * 01108 */ 01109 01110 // function: object_attr_setfloat 01111 /** 01112 * 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. 01113 * 01114 * @param x The attribute's parent object 01115 * @param s The attribute's name 01116 * @param c An floating point value; the new value for the attribute 01117 * 01118 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01119 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01120 * 01121 */ 01122 01123 // function: object_attr_setsym 01124 /** 01125 * 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. 01126 * 01127 * @param x The attribute's parent object 01128 * @param s The attribute's name 01129 * @param c A t_symbol *; the new value for the attribute 01130 * 01131 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01132 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01133 * 01134 */ 01135 01136 </category> 01137 01138 <category> 01139 <cattitle>Object Functions: attribute utility functions (multiple value functions)</cattitle> 01140 * 01141 * @remark The following functions provide access to arrays of attribute values. They can be used with any attribute. 01142 01143 // function: object_attr_getlong_array 01144 /** 01145 * Retrieves the value of an attribute, given its parent object and name. This function uses a developer-allocated array to copy data to. Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the <tt>object_attr_getvalueof</tt> function. 01146 * 01147 * @param x The attribute's parent object 01148 * @param s The attribute's name 01149 * @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01150 * @param vals Pointer to the first element of a pre-allocated array of long data. 01151 * 01152 * @return This function returns the number of elements copied into <tt>vals</tt>. 01153 * 01154 * @remark If the attribute is not of the type specified by the function, the 01155 * function will attempt to coerce a valid value from the attribute. 01156 * 01157 */ 01158 01159 // function: object_attr_getchar_array 01160 /** 01161 * Retrieves the value of an attribute, given its parent object and name. This function uses a developer-allocated array to copy data to. Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the <tt>object_attr_getvalueof</tt> function. 01162 * 01163 * @param x The attribute's parent object 01164 * @param s The attribute's name 01165 * @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01166 * @param vals Pointer to the first element of a pre-allocated array of unsigned char data. 01167 * 01168 * @return This function returns the number of elements copied into <tt>vals</tt>. 01169 * 01170 * @remark If the attribute is not of the type specified by the function, the 01171 * function will attempt to coerce a valid value from the attribute. 01172 * 01173 */ 01174 01175 // function: object_attr_getfloat_array 01176 /** 01177 * Retrieves the value of an attribute, given its parent object and name. This function uses a developer-allocated array to copy data to. Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the <tt>object_attr_getvalueof</tt> function. 01178 * 01179 * @param x The attribute's parent object 01180 * @param s The attribute's name 01181 * @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01182 * @param vals Pointer to the first element of a pre-allocated array of float data. 01183 * 01184 * @return This function returns the number of elements copied into <tt>vals</tt>. 01185 * 01186 * @remark If the attribute is not of the type specified by the function, the 01187 * function will attempt to coerce a valid value from the attribute. 01188 * 01189 */ 01190 01191 // function: object_attr_getdouble_array 01192 /** 01193 * Retrieves the value of an attribute, given its parent object and name. This function uses a developer-allocated array to copy data to. Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the <tt>object_attr_getvalueof</tt> function. 01194 * 01195 * @param x The attribute's parent object 01196 * @param s The attribute's name 01197 * @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01198 * @param vals Pointer to the first element of a pre-allocated array of double data. 01199 * 01200 * @return This function returns the number of elements copied into <tt>vals</tt>. 01201 * 01202 * @remark If the attribute is not of the type specified by the function, the 01203 * function will attempt to coerce a valid value from the attribute. 01204 * 01205 */ 01206 01207 // function: object_attr_getsym_array 01208 /** 01209 * Retrieves the value of an attribute, given its parent object and name. This function uses a developer-allocated array to copy data to. Developers wishing to retrieve the value of an attribute without pre-allocating memory should refer to the <tt>object_attr_getvalueof</tt> function. 01210 * 01211 * @param x The attribute's parent object 01212 * @param s The attribute's name 01213 * @param max The number of array elements in <tt>vals</tt>. The function will take care not to overwrite the bounds of the array. 01214 * @param vals Pointer to the first element of a pre-allocated array of t_symbol *s. 01215 * 01216 * @return This function returns the number of elements copied into <tt>vals</tt>. 01217 * 01218 */ 01219 01220 // function: object_attr_setlong_array 01221 /** 01222 * 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. 01223 * 01224 * @param x The attribute's parent object 01225 * @param s The attribute's name 01226 * @param count The number of array elements in vals 01227 * @param vals Pointer to the first element of an array of long data 01228 * 01229 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01230 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01231 * 01232 */ 01233 01234 // function: object_attr_setchar_array 01235 /** 01236 * 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. 01237 * 01238 * @param x The attribute's parent object 01239 * @param s The attribute's name 01240 * @param count The number of array elements in vals 01241 * @param vals Pointer to the first element of an array of unsigned char data 01242 * 01243 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01244 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01245 * 01246 */ 01247 01248 // function: object_attr_setfloat_array 01249 /** 01250 * 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. 01251 * 01252 * @param x The attribute's parent object 01253 * @param s The attribute's name 01254 * @param count The number of array elements in vals 01255 * @param vals Pointer to the first element of an array of float data 01256 * 01257 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01258 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01259 * 01260 */ 01261 01262 // function: object_attr_setdouble_array 01263 /** 01264 * 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. 01265 * 01266 * @param x The attribute's parent object 01267 * @param s The attribute's name 01268 * @param count The number of array elements in vals 01269 * @param vals Pointer to the first element of an array of double data 01270 * 01271 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01272 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01273 * 01274 */ 01275 01276 // function: object_attr_setsym_array 01277 /** 01278 * 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. 01279 * 01280 * @param x The attribute's parent object 01281 * @param s The attribute's name 01282 * @param count The number of array elements in vals 01283 * @param vals Pointer to the first element of an array of t_symbol *s 01284 * 01285 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01286 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01287 * 01288 */ 01289 01290 </category> 01291 01292 <category> 01293 <cattitle>Atom Utilities</cattitle> 01294 * 01295 * @remark Also present in "ext_obex.c" are some new atom utilities, used to get and set t_atom values. Direct access to t_atoms continues to be supported, but many developers may find these utilities more succinct and safe. 01296 01297 // function: atom_setlong 01298 /** 01299 * Inserts an integer into a t_atom and change the t_atom's type to <tt>A_LONG</tt>. 01300 * 01301 * @param a Pointer to a t_atom whose value and type will be modified 01302 * @param b Integer value to copy into the t_atom 01303 * 01304 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01305 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01306 * 01307 */ 01308 01309 // function: atom_setfloat 01310 /** 01311 * Inserts a floating point number into a t_atom and change the t_atom's type to <tt>A_FLOAT</tt>. 01312 * 01313 * @param a Pointer to a t_atom whose value and type will be modified 01314 * @param b Floating point value to copy into the t_atom 01315 * 01316 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01317 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01318 * 01319 */ 01320 01321 // function: atom_setsym 01322 /** 01323 * Inserts a t_symbol * into a t_atom and change the t_atom's type to <tt>A_SYM</tt>. 01324 * 01325 * @param a Pointer to a t_atom whose value and type will be modified 01326 * @param b Pointer to a t_symbol to copy into the t_atom 01327 * 01328 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01329 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01330 * 01331 */ 01332 01333 // function: atom_setobj 01334 /** 01335 * Inserts a generic pointer value into a t_atom and change the t_atom's type to <tt>A_OBJ</tt>. 01336 * 01337 * @param a Pointer to a t_atom whose value and type will be modified 01338 * @param b Pointer value to copy into the t_atom 01339 * 01340 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01341 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01342 * 01343 */ 01344 01345 // function: atom_getlong 01346 /** 01347 * Retrieves a long integer value from a t_atom. 01348 * 01349 * @param a Pointer to a t_atom whose value is of interest 01350 * 01351 * @return This function returns the value of the specified t_atom as an integer, if possible. Otherwise, it returns 0. 01352 * 01353 * @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. For instance, if the t_atom <tt>at</tt> is set to type <tt>A_FLOAT</tt> with a value of <tt>3.7</tt>, the <tt>atom_getlong</tt> function will return the truncated integer value of <tt>at</tt>, or <tt>3</tt>. An attempt is also made to coerce t_symbol data. 01354 * 01355 */ 01356 01357 // function: atom_getfloat 01358 /** 01359 * Retrieves a floating point value from a t_atom. 01360 * 01361 * @param a Pointer to a t_atom whose value is of interest 01362 * 01363 * @return This function returns the value of the specified t_atom as a floating point number, if possible. Otherwise, it returns 0. 01364 * 01365 * @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. For instance, if the t_atom <tt>at</tt> is set to type <tt>A_LONG</tt> with a value of <tt>5</tt>, the <tt>atom_getfloat</tt> function will return the value of <tt>at</tt> as a float, or <tt>5.0</tt>. An attempt is also made to coerce t_symbol data. 01366 * 01367 */ 01368 01369 // function: atom_getsym 01370 /** 01371 * Retrieves a t_symbol * value from a t_atom. 01372 * 01373 * @param a Pointer to a t_atom whose value is of interest 01374 * 01375 * @return This function returns the value of the specified <tt>A_SYM</tt>-typed t_atom, if possible. Otherwise, it returns an empty, but valid, t_symbol *, equivalent to <tt>gensym("")</tt>, or <tt>_sym_nothing</tt>. 01376 * 01377 * @remark No attempt is made to coerce non-matching data types. 01378 * 01379 */ 01380 01381 // function: atom_getobj 01382 /** 01383 * Retrieves a generic pointer value from a t_atom. 01384 * 01385 * @param a Pointer to a t_atom whose value is of interest 01386 * 01387 * @return This function returns the value of the specified <tt>A_OBJ</tt>-typed t_atom, if possible. Otherwise, it returns <tt>NULL</tt>. 01388 * 01389 * @remark If the t_atom is typed <tt>A_LONG</tt>, but the data falls outside of the range 0-255, the data is truncated to that range before output. 01390 * 01391 */ 01392 01393 // function: atom_getcharfix 01394 /** 01395 * Retrieves an unsigned integer value between 0 and 255 from a t_atom. 01396 * 01397 * @param a Pointer to a t_atom whose value is of interest 01398 * 01399 * @return This function returns the value of the specified t_atom as an integer between 0 and 255, if possible. Otherwise, it returns 0. 01400 * 01401 * @remark If the t_atom is typed <tt>A_LONG</tt>, but the data falls outside of the range 0-255, the data is truncated to that range before output. 01402 * 01403 * @remark If the t_atom is typed <tt>A_FLOAT</tt>, the floating point value is multiplied by 255. and truncated to the range 0-255 before output. 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). 01404 * 01405 * @remark No attempt is also made to coerce t_symbol data. 01406 * 01407 */ 01408 01409 // function: atom_arg_getlong 01410 /** 01411 * Retrieves the integer value of a particular t_atom from an atom list, if the atom exists. 01412 * 01413 * @param c Pointer to a long variable to receive the atom's data if the function is successful. 01414 * @param idx Offset into the atom list of the atom of interest, starting from 0. For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01415 * @param ac Count of av. 01416 * @param av Pointer to the first t_atom of an atom list. 01417 * 01418 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01419 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01420 * 01421 * @remark The <tt>atom_arg_getlong</tt> function only changes the value of <tt>c</tt> if the function is successful. For instance, the following code snippet illustrates a simple, but typical use: 01422 @code 01423 void myobject_mymessage(t_myobject *x, t_symbol *s, long ac, t_atom *av) 01424 { 01425 long var = -1; 01426 01427 // here, we are expecting a value of 0 or greater 01428 atom_arg_getlong(&var, 0, ac, av); 01429 if (val == -1) // i.e. unchanged 01430 post("it is likely that the user did not provide a valid argument"); 01431 else { 01432 ... 01433 } 01434 } 01435 @endcode 01436 * 01437 */ 01438 01439 // function: atom_arg_getfloat 01440 /** 01441 * Retrieves the floating point value of a particular t_atom from an atom list, if the atom exists. 01442 * 01443 * @param c Pointer to a float variable to receive the atom's data if the function is successful. Otherwise, the value is left unchanged. 01444 * @param idx Offset into the atom list of the atom of interest, starting from 0. For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01445 * @param ac Count of av. 01446 * @param av Pointer to the first t_atom of an atom list. 01447 * 01448 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01449 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01450 * 01451 */ 01452 01453 // function: atom_arg_getdouble 01454 /** 01455 * Retrieves the floating point value, as a double, of a particular t_atom from an atom list, if the atom exists. 01456 * 01457 * @param c Pointer to a double variable to receive the atom's data if the function is successful. Otherwise the value is left unchanged. 01458 * @param idx Offset into the atom list of the atom of interest, starting from 0. For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01459 * @param ac Count of av. 01460 * @param av Pointer to the first t_atom of an atom list. 01461 * 01462 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01463 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01464 * 01465 */ 01466 01467 // function: atom_arg_getsym 01468 /** 01469 * Retrieves the t_symbol * value of a particular t_atom from an atom list, if the atom exists. 01470 * 01471 * @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. 01472 * @param idx Offset into the atom list of the atom of interest, starting from 0. For instance, if you want data from the 3rd atom in the atom list, <tt>idx</tt> should be set to 2. 01473 * @param ac Count of av. 01474 * @param av Pointer to the first t_atom of an atom list. 01475 * 01476 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01477 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01478 * 01479 * @remark The <tt>atom_arg_getsym</tt> function only changes the value of <tt>c</tt> if the function is successful. For instance, the following code snippet illustrates a simple, but typical use: 01480 @code 01481 void myobject_open(t_myobject *x, t_symbol *s, long ac, t_atom *av) 01482 { 01483 t_symbol *filename = _sym_nothing; 01484 01485 // here, we are expecting a file name. 01486 // if we don't get it, open a dialog box 01487 atom_arg_getsym(&filename, 0, ac, av); 01488 if (filename == _sym_nothing) { // i.e. unchanged 01489 // open the file dialog box, 01490 // get a value for filename 01491 } 01492 // do something with the filename 01493 } 01494 @endcode 01495 * 01496 */ 01497 01498 </category> 01499 01500 <category> 01501 <cattitle>Miscellaneous Utilities</cattitle> 01502 01503 // function: symbol_unique 01504 /** 01505 * Generates a unique t_symbol *. The symbol will be formatted somewhat like "u123456789". 01506 * 01507 * 01508 * @return This function returns a unique t_symbol *. 01509 * 01510 */ 01511 01512 // function: error_sym 01513 /** 01514 * Posts an error message to the Max window. This function is interrupt safe. 01515 * 01516 * @param x The object's pointer 01517 * @param s Symbol to be posted as an error in the Max window 01518 * 01519 */ 01520 01521 // function: post_sym 01522 /** 01523 * Posts a message to the Max window. This function is interrupt safe. 01524 * 01525 * @param x The object's pointer 01526 * @param s Symbol to be posted in the Max window 01527 * 01528 */ 01529 01530 // function: symbolarray_sort 01531 /** 01532 * Performs an ASCII sort on an array of t_symbol *s. 01533 * 01534 * @param ac The count of t_symbol *s in <tt>av</tt> 01535 * @param av An array of t_symbol *s to be sorted 01536 * 01537 * @return This function returns the error code <tt>MAX_ERR_NONE</tt> if successful, 01538 * or one of the other error codes defined in "ext_obex.h" if unsuccessful. 01539 * 01540 */ 01541 01542 // function: object_obex_quickref 01543 /** 01544 * Developers do not need to directly use the <tt>object_obex_quickref</tt> function. However, to take advantage of a new quickref appearance, which provides support for attributes, developers should define the following method in <tt>main()</tt>. 01545 * 01546 @code 01547 class_addmethod(c / * your object class * /, (method)object_obex_quickref, "quickref", A_CANT,0); 01548 @endcode 01549 * 01550 */ 01551 01552 </category> 01553
Copyright © 2008, Cycling '74