Max 5 API Reference
00001 00002 #ifndef __ATOMARRAY_H__ 00003 #define __ATOMARRAY_H__ 00004 00005 #if C74_PRAGMA_STRUCT_PACKPUSH 00006 #pragma pack(push, 2) 00007 #elif C74_PRAGMA_STRUCT_PACK 00008 #pragma pack(2) 00009 #endif 00010 00011 /** The atomarray flags. Currently the only flag is ATOMARRAY_FLAG_FREECHILDREN. 00012 If set via atomarray_flags() the atomarray will free any contained A_OBJ atoms when the 00013 atomarray is freed. 00014 00015 @ingroup atomarray 00016 */ 00017 00018 #define ATOMARRAY_FLAG_FREECHILDREN (1) 00019 00020 /** The atomarray object. This struct is provided for debugging convenience, 00021 but should be considered opaque and is subject to change without notice. 00022 00023 @ingroup atomarray 00024 */ 00025 typedef struct _atomarray 00026 { 00027 t_object ob; 00028 long ac; 00029 t_atom *av; 00030 long flags; 00031 } t_atomarray; 00032 00033 00034 #if C74_PRAGMA_STRUCT_PACKPUSH 00035 #pragma pack(pop) 00036 #elif C74_PRAGMA_STRUCT_PACK 00037 #pragma pack() 00038 #endif 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif // __cplusplus 00043 00044 00045 /** 00046 Create a new atomarray object. 00047 Note that atoms provided to this function will be <em>copied</em>. The copies stored internally to the atomarray instance. 00048 You can free the atomarray by calling object_free(). 00049 00050 @ingroup atomarray 00051 @param ac The number of atoms to be initially contained in the atomarray. 00052 @param av A pointer to the first of an array of atoms to initially copy into the atomarray. 00053 @return Pointer to the new atomarray object. 00054 00055 @remark Note that due to the unusual prototype of this method that you cannot instantiate this object using the 00056 object_new_typed() function. If you wish to use the dynamically bound creator to instantiate the object, 00057 you should instead should use object_new() as demonstrated below. The primary reason that you might choose 00058 to instantiate an atomarray using object_new() instead of atomarray_new() is for using the atomarray object 00059 in code that is also intended to run in Max 4. 00060 @code 00061 object_new(CLASS_NOBOX, gensym("atomarray"), argc, argv); 00062 @endcode 00063 00064 @see atomarray_duplicate() 00065 */ 00066 t_atomarray *atomarray_new(long ac, t_atom *av); 00067 00068 /** 00069 Set the atomarray flags. 00070 00071 @ingroup atomarray 00072 00073 @param x The atomarray instance. 00074 @param flags The new value for the flags. 00075 */ 00076 void atomarray_flags(t_atomarray *x, long flags); 00077 00078 /** 00079 Get the atomarray flags. 00080 00081 @ingroup atomarray 00082 00083 @param x The atomarray instance. 00084 @return The current value of the atomarray flags. 00085 */ 00086 long atomarray_getflags(t_atomarray *x); 00087 00088 /** 00089 Replace the existing array contents with a new set of atoms 00090 Note that atoms provided to this function will be <em>copied</em>. The copies stored internally to the atomarray instance. 00091 00092 @ingroup atomarray 00093 00094 @param x The atomarray instance. 00095 @param ac The number of atoms to be initially contained in the atomarray. 00096 @param av A pointer to the first of an array of atoms to initially copy into the atomarray. 00097 @return A Max error code. 00098 */ 00099 t_max_err atomarray_setatoms(t_atomarray *x, long ac, t_atom *av); 00100 00101 00102 /** 00103 Retrieve a pointer to the first atom in the internal array of atoms. 00104 This method does not copy the atoms, btu simply provides access to them. 00105 To retrieve a copy of the atoms use atomarray_copyatoms(). 00106 00107 @ingroup atomarray 00108 00109 @param x The atomarray instance. 00110 @param ac The address of a long where the number of atoms will be set. 00111 @param av The address of a #t_atom pointer where the address of the first atom of the array will be set. 00112 @return A Max error code. 00113 00114 @see atomarray_copyatoms() 00115 */ 00116 t_max_err atomarray_getatoms(t_atomarray *x, long *ac, t_atom **av); 00117 00118 00119 /** 00120 Retrieve a copy of the atoms in the array. 00121 This method does not copy the atoms, btu simply provides access to them. 00122 To retrieve a copy of the atoms use atomarray_copyatoms(). 00123 00124 @ingroup atomarray 00125 00126 @param x The atomarray instance. 00127 @param ac The address of a long where the number of atoms will be set. 00128 @param av The address of a #t_atom pointer where the atoms will be allocated and copied. 00129 @return A Max error code. 00130 00131 @remark You are responsible for freeing memory allocated for the copy of the atoms returned. 00132 @code 00133 long ac = 0; 00134 t_atom *av = NULL; 00135 00136 atomarray_copyatoms(anAtomarray, &ac, &av); 00137 if(ac && av){ 00138 // do something with ac and av here... 00139 sysmem_freeptr(av); 00140 } 00141 @endcode 00142 00143 @see atomarray_getatoms() 00144 */ 00145 t_max_err atomarray_copyatoms(t_atomarray *x, long *ac, t_atom **av); 00146 00147 00148 /** 00149 Return the number of atoms in the array. 00150 00151 @ingroup atomarray 00152 @param x The atomarray instance. 00153 @return The number of atoms in the array. 00154 */ 00155 long atomarray_getsize(t_atomarray *x); 00156 00157 00158 /** 00159 Copy an a specific atom from the array. 00160 00161 @ingroup atomarray 00162 @param x The atomarray instance. 00163 @param index The zero-based index into the array from which to retrieve an atom pointer. 00164 @param av The address of an atom to contain the copy. 00165 @return A Max error code. 00166 00167 @remark Example: 00168 @code 00169 { 00170 t_atom a; 00171 00172 // fetch a copy of the second atom in a previously existing array 00173 atomarray_getindex(anAtomarray, 1, &a); 00174 // do something with the atom here... 00175 } 00176 @endcode 00177 */ 00178 t_max_err atomarray_getindex(t_atomarray *x, long index, t_atom *av); 00179 00180 00181 /** 00182 Create a new atomarray object which is a copy of another atomarray object. 00183 00184 @ingroup atomarray 00185 @param x The atomarray instance which is to be copied. 00186 @return A new atomarray which is copied from x. 00187 00188 @see atomarray_new() 00189 */ 00190 void *atomarray_duplicate(t_atomarray *x); 00191 00192 00193 /** 00194 Copy a new atom onto the end of the array. 00195 00196 @ingroup atomarray 00197 @param x The atomarray instance. 00198 @param a A pointer to the new atom to append to the end of the array. 00199 00200 @see atomarray_appendatoms() 00201 @see atomarray_setatoms() 00202 */ 00203 void atomarray_appendatom(t_atomarray *x, t_atom *a); 00204 00205 00206 /** 00207 Copy multiple new atoms onto the end of the array. 00208 00209 @ingroup atomarray 00210 @param x The atomarray instance. 00211 @param ac The number of new atoms to be appended to the array. 00212 @param av A pointer to the first of the new atoms to append to the end of the array. 00213 00214 @see atomarray_appendatom() 00215 @see atomarray_setatoms() 00216 */ 00217 void atomarray_appendatoms(t_atomarray *x, long ac, t_atom *av); 00218 00219 00220 /** 00221 Remove an atom from any location within the array. 00222 The array will be resized and collapsed to fill in the gap. 00223 00224 @ingroup atomarray 00225 @param x The atomarray instance. 00226 @param index The zero-based index of the atom to remove from the array. 00227 */ 00228 void atomarray_chuckindex(t_atomarray *x, long index); 00229 00230 00231 /** 00232 Clear the array. Frees all of the atoms and sets the size to zero. 00233 This function does not perform a 'deep' free, meaning that any #A_OBJ atoms will not have their object's freed. 00234 Only the references to those objects contained in the atomarray will be freed. 00235 00236 @ingroup atomarray 00237 @param x The atomarray instance. 00238 @return The number of atoms in the array. 00239 */ 00240 void atomarray_clear(t_atomarray *x); 00241 00242 00243 /** 00244 Call the specified function for every item in the atom array. 00245 00246 @ingroup atomarray 00247 @param x The atomarray instance. 00248 @param fun The function to call, specified as function pointer cast to a Max #method. 00249 @param arg An argument that you would like to pass to the function being called. 00250 @return A max error code. 00251 00252 @remark The atomarray_funall() method will call your function for every item in the list. 00253 It will pass both a pointer to the item in the list, and any argument that you 00254 provide. The following example shows a function that could be called by hashtab_funall(). 00255 @code 00256 void myFun(t_atom *a, void *myArg) 00257 { 00258 // do something with a and myArg here 00259 // a is the atom in the atom array 00260 } 00261 @endcode 00262 00263 @see linklist_funall() 00264 @see hashtab_funall() 00265 */ 00266 void atomarray_funall(t_atomarray *x, method fun, void *arg); 00267 00268 00269 #ifdef __cplusplus 00270 } 00271 #endif // __cplusplus 00272 00273 #endif // __ATOMARRAY_H__
Copyright © 2008, Cycling '74