Max 5 API Reference
00001 /* 00002 jit.atom.c 00003 00004 Copyright 2001-2005 - Cycling '74 00005 Joshua Kit Clayton jkc@cycling74.com 00006 00007 */ 00008 #include "jit.common.h" 00009 00010 /** 00011 * @defgroup atommod Atom Module 00012 @ingroup jitter 00013 */ 00014 00015 00016 /** 00017 * Sets atom value to long integer. 00018 * 00019 * @ingroup atommod 00020 * 00021 * @param a atom pointer 00022 * @param b integer value 00023 * 00024 * @return t_jit_err error code. 00025 * 00026 */ 00027 t_jit_err jit_atom_setlong(t_atom *a, long b) 00028 { 00029 if (a) { 00030 a->a_type = A_LONG; 00031 a->a_w.w_long = b; 00032 return JIT_ERR_NONE; 00033 } 00034 return JIT_ERR_INVALID_PTR; 00035 } 00036 00037 /** 00038 * Sets atom value to floating point number. 00039 * 00040 * @ingroup atommod 00041 * 00042 * @param a atom pointer 00043 * @param b floating point value 00044 * 00045 * @return t_jit_err error code. 00046 * 00047 */ 00048 t_jit_err jit_atom_setfloat(t_atom *a, double b) 00049 { 00050 if (a) { 00051 a->a_type = A_FLOAT; 00052 a->a_w.w_float = b; 00053 return JIT_ERR_NONE; 00054 } 00055 return JIT_ERR_INVALID_PTR; 00056 } 00057 00058 /** 00059 * Sets atom value to symbol. 00060 * 00061 * @ingroup atommod 00062 * 00063 * @param a atom pointer 00064 * @param b symbol value 00065 * 00066 * @return t_jit_err error code. 00067 * 00068 */ 00069 t_jit_err jit_atom_setsym(t_atom *a, t_symbol *b) 00070 { 00071 if (a) { 00072 a->a_type = A_SYM; 00073 a->a_w.w_sym = b; 00074 return JIT_ERR_NONE; 00075 } 00076 return JIT_ERR_INVALID_PTR; 00077 } 00078 00079 /** 00080 * Sets atom value to object pointer. 00081 * 00082 * @ingroup atommod 00083 * 00084 * @param a atom pointer 00085 * @param b object pointer 00086 * 00087 * @return t_jit_err error code. 00088 * 00089 */ 00090 t_jit_err jit_atom_setobj(t_atom *a, void *b) 00091 { 00092 if (a) { 00093 a->a_type = A_OBJ; 00094 a->a_w.w_obj = b; 00095 return JIT_ERR_NONE; 00096 } 00097 return JIT_ERR_INVALID_PTR; 00098 } 00099 00100 /** 00101 * Retrieves atom value as long integer. 00102 * 00103 * @ingroup atommod 00104 * 00105 * @param a atom pointer 00106 * 00107 * @return long integer value. 0 if atom has no numeric value. 00108 * 00109 */ 00110 long jit_atom_getlong(t_atom *a) 00111 { 00112 long b=0; 00113 00114 if (a) { 00115 switch (a->a_type) { 00116 case A_LONG: b = a->a_w.w_long; break; 00117 case A_FLOAT: b = a->a_w.w_float; break; 00118 } 00119 } 00120 return b; 00121 } 00122 00123 /** 00124 * Retrieves atom value as floating point number. 00125 * 00126 * @ingroup atommod 00127 * 00128 * @param a atom pointer 00129 * 00130 * @return floating point value. 0 if atom has no numeric value. 00131 * 00132 */ 00133 double jit_atom_getfloat(t_atom *a) 00134 { 00135 double b=0; 00136 00137 if (a) { 00138 switch (a->a_type) { 00139 case A_LONG: b = a->a_w.w_long; break; 00140 case A_FLOAT: b = a->a_w.w_float; break; 00141 } 00142 } 00143 return b; 00144 } 00145 00146 /** 00147 * Retrieves atom value as symbol pointer. 00148 * 00149 * @ingroup atommod 00150 * 00151 * @param a atom pointer 00152 * 00153 * @return symbol pointer. _jit_sym_nothing if atom has no symbolic value. 00154 * 00155 */ 00156 t_symbol *jit_atom_getsym(t_atom *a) 00157 { 00158 t_symbol *b=_jit_sym_nothing; 00159 00160 if (a) { 00161 switch (a->a_type) { 00162 case A_SYM: b = a->a_w.w_sym; break; 00163 } 00164 if (!b) b= _jit_sym_nothing; 00165 } 00166 return b; 00167 } 00168 00169 /** 00170 * Retrieves atom value as object pointer. 00171 * 00172 * @ingroup atommod 00173 * 00174 * @param a atom pointer 00175 * 00176 * @return object pointer. NULL if atom has no object value. 00177 * 00178 */ 00179 void *jit_atom_getobj(t_atom *a) 00180 { 00181 t_jit_object *b=NULL; 00182 00183 if (a) { 00184 switch (a->a_type) { 00185 case A_OBJ: b = a->a_w.w_obj; break; 00186 } 00187 } 00188 return b; 00189 } 00190 00191 /** 00192 * Retrieves atom value as an 8 bit fixed point number. 00193 * 00194 * @ingroup atommod 00195 * 00196 * @param a atom pointer 00197 * 00198 * @return 8 bit fixed point value in the range 0-255. 0 if atom has no numeric value. 00199 * 00200 */ 00201 long jit_atom_getcharfix(t_atom *a) 00202 { 00203 long b=0; 00204 00205 if (a) { 00206 switch (a->a_type) { 00207 case A_LONG: b = a->a_w.w_long; break; 00208 case A_FLOAT: b = a->a_w.w_float*255.; break; 00209 } 00210 } 00211 CLIP(b,0,255); 00212 return b; 00213 } 00214 00215 //the following are useful for setting the values _only_ if there is an arg 00216 //rather than setting it to 0 or _jit_sym_nothing 00217 00218 /** 00219 * Retrieves atom argument at index as long integer if present. 00220 * This function is useful for setting the values only if there is an 00221 * argument at the specified index, otherwise, the input value is untouched. 00222 * 00223 * @ingroup atommod 00224 * 00225 * @param c pointer to long (should contain desired default) 00226 * @param idx atom argument index 00227 * @param ac atom argument count 00228 * @param av atom argument vector 00229 * 00230 * @return t_jit_err error code. JIT_ERR_NONE if successful. 00231 * 00232 */ 00233 long jit_atom_arg_getlong(long *c, long idx, long ac, t_atom *av) 00234 { 00235 if (c&&ac&&av&&(idx<ac)) { 00236 *c = jit_atom_getlong(av+idx); 00237 return JIT_ERR_NONE; 00238 } else 00239 return JIT_ERR_GENERIC; 00240 } 00241 00242 /** 00243 * Retrieves atom argument at index as floating point number if present. 00244 * This function is useful for setting the values only if there is an 00245 * argument at the specified index, otherwise, the input value is untouched. 00246 * 00247 * @ingroup atommod 00248 * 00249 * @param c pointer to float (should contain desired default) 00250 * @param idx atom argument index 00251 * @param ac atom argument count 00252 * @param av atom argument vector 00253 * 00254 * @return t_jit_err error code. JIT_ERR_NONE if successful. 00255 * 00256 */ 00257 long jit_atom_arg_getfloat(float *c, long idx, long ac, t_atom *av) 00258 { 00259 if (c&&ac&&av&&(idx<ac)) { 00260 *c = jit_atom_getfloat(av+idx); 00261 return JIT_ERR_NONE; 00262 } else 00263 return JIT_ERR_GENERIC; 00264 } 00265 00266 /** 00267 * Retrieves atom argument at index as double precision floating point number if present. 00268 * This function is useful for setting the values only if there is an 00269 * argument at the specified index, otherwise, the input value is untouched. 00270 * 00271 * @ingroup atommod 00272 * 00273 * @param c pointer to double (should contain desired default) 00274 * @param idx atom argument index 00275 * @param ac atom argument count 00276 * @param av atom argument vector 00277 * 00278 * @return t_jit_err error code. JIT_ERR_NONE if successful. 00279 * 00280 */ 00281 long jit_atom_arg_getdouble(double *c, long idx, long ac, t_atom *av) 00282 { 00283 if (c&&ac&&av&&(idx<ac)) { 00284 *c = jit_atom_getfloat(av+idx); 00285 return JIT_ERR_NONE; 00286 } else 00287 return JIT_ERR_GENERIC; 00288 } 00289 00290 /** 00291 * Retrieves atom argument at index as symbol pointer if present. 00292 * This function is useful for setting the values only if there is an 00293 * argument at the specified index, otherwise, the input value is untouched. 00294 * 00295 * @ingroup atommod 00296 * 00297 * @param c pointer to symbol pointer (should contain desired default) 00298 * @param idx atom argument index 00299 * @param ac atom argument count 00300 * @param av atom argument vector 00301 * 00302 * @return t_jit_err error code. JIT_ERR_NONE if successful. 00303 * 00304 */ 00305 long jit_atom_arg_getsym(t_symbol **c, long idx, long ac, t_atom *av) 00306 { 00307 if (c&&ac&&av&&(idx<ac)) { 00308 *c = jit_atom_getsym(av+idx); 00309 return JIT_ERR_NONE; 00310 } else 00311 return JIT_ERR_GENERIC; 00312 }
Copyright © 2008, Cycling '74