Max 5 API Reference
00001 /* 00002 jit.attribute.c 00003 00004 Copyright 2001-2005 - Cycling '74 00005 Joshua Kit Clayton jkc@cycling74.com 00006 00007 */ 00008 00009 #include "jit.common.h" 00010 #include "ext_obex.h" 00011 00012 /** 00013 * t_jit_attribute object struct. 00014 * 00015 * @ingroup attrmod 00016 * 00017 * @warning This struct should not be accessed directly, 00018 * but is provided for reference. Attribute 00019 * objects do not typically use attributes 00020 * themselves to access members, but rather 00021 * accessor methods--i.e. use jit_object_method 00022 * in place of the jit_attr_* functions to access 00023 * attribute state. 00024 */ 00025 typedef struct _jit_attribute 00026 { 00027 t_jit_object ob; ///< common object header 00028 t_symbol *name; ///< attribute name 00029 t_symbol *type; ///< attribute type (char, long, float32, float64, symbol, atom, or obj) 00030 long flags; ///< flags for public/private get/set methods 00031 method get; ///< override default get method 00032 method set; ///< override default set method 00033 void *filterget; ///< filterobject for get method 00034 void *filterset; ///< filterobject for set method 00035 void *reserved; ///< for future use 00036 void *data; ///< interally stored data 00037 long size; ///< data size 00038 } t_jit_attribute; 00039 00040 /** 00041 * t_jit_attr_offset object struct. 00042 * 00043 * @ingroup attrmod 00044 * 00045 * @warning This struct should not be accessed directly, 00046 * but is provided for reference. Attribute 00047 * objects do not typically use attributes 00048 * themselves to access members, but rather 00049 * accessor methods--i.e. use jit_object_method 00050 * in place of the jit_attr_* functions to access 00051 * attribute state. 00052 */ 00053 typedef struct _jit_attr_offset 00054 { 00055 t_jit_object ob; ///< common object header 00056 t_symbol *name; ///< attribute name 00057 t_symbol *type; ///< attribute type (char, long, float32, float64, symbol, atom, or obj) 00058 long flags; ///< flags for public/private get/set methods 00059 method get; ///< override default get method 00060 method set; ///< override default set method 00061 void *filterget; ///< filterobject for get method 00062 void *filterset; ///< filterobject for set method 00063 void *reserved; ///< for future use 00064 long offset; ///< byte offset to the attribute data 00065 } t_jit_attr_offset; 00066 00067 /** 00068 * t_jit_attr_offset_array object struct. 00069 * 00070 * @ingroup attrmod 00071 * 00072 * @warning This struct should not be accessed directly, 00073 * but is provided for reference. Attribute 00074 * objects do not typically use attributes 00075 * themselves to access members, but rather 00076 * accessor methods--i.e. use jit_object_method 00077 * in place of the jit_attr_* functions to access 00078 * attribute state. 00079 */ 00080 typedef struct _jit_attr_offset_array 00081 { 00082 t_jit_object ob; ///< common object header 00083 t_symbol *name; ///< attribute name 00084 t_symbol *type; ///< attribute type (char, long, float32, float64, symbol, atom, or obj) 00085 long flags; ///< flags for public/private get/set methods 00086 method get; ///< override default get method 00087 method set; ///< override default set method 00088 void *filterget; ///< filterobject for get method 00089 void *filterset; ///< filterobject for set method 00090 void *reserved; ///< for future use 00091 long offset; ///< byte offset to the attribute data 00092 long size; ///< maximum size 00093 long offsetcount; ///< byte offset to the attribute count 00094 } t_jit_attr_offset_array; 00095 00096 /** 00097 * t_jit_attr_filter_clip object struct. 00098 * 00099 * @ingroup attrmod 00100 * 00101 * @warning This struct should not be accessed directly, 00102 * but is provided for reference when calling 00103 * Jitter attribute functions. 00104 */ 00105 typedef struct _jit_attr_filter_clip 00106 { 00107 t_jit_object ob; ///< common object header 00108 t_symbol *type; ///< "type" attribute 00109 double scale; ///< scaling factor; "scale" attribute 00110 double min; ///< minimum vlaue; "min" attribute 00111 double max; ///< maximum value; "max" attribute 00112 char usescale; ///< use scaling flag; "usescale" attribute 00113 char usemin; ///< clip to minimum flag; "usemin" attribute 00114 char usemax; ///< clip to maximum flag; "usemax" attribute 00115 } t_jit_attr_filter_clip; 00116 00117 /** 00118 * t_jit_attr_filter_proc object struct. 00119 * 00120 * @ingroup attrmod 00121 * 00122 * @warning This struct should not be accessed directly, 00123 * but is provided for reference when calling 00124 * Jitter attribute functions. 00125 */ 00126 typedef struct _jit_attr_filter_proc 00127 { 00128 t_jit_object ob; ///< common object header 00129 method proc; ///< filter procedure 00130 } t_jit_attr_filter_proc; 00131 00132 00133 void *_jit_attr_offset_class,*_jit_attr_offset_array_class; 00134 void *_jit_attribute_class; 00135 00136 t_jit_err jit_attr_setup_class(void *c); 00137 t_symbol *jit_attr_getname(t_jit_attr *x); 00138 t_symbol *jit_attr_gettype(t_jit_attr *x); 00139 long jit_attr_canget(t_jit_attr *x); 00140 long jit_attr_canset(t_jit_attr *x); 00141 long jit_attr_usercanget(t_jit_attr *x); 00142 long jit_attr_usercanset(t_jit_attr *x); 00143 method jit_attr_getmethod(t_jit_attr *x, t_symbol *methodtype); 00144 t_jit_err jit_attr_setmethod(t_jit_attr *x, t_symbol *methodtype, method m); 00145 long jit_attr_getmethodtype(t_jit_attr *x, t_symbol *methodname); 00146 t_jit_err jit_attr_filterget(t_jit_attr *x, void *y); 00147 t_jit_err jit_attr_filterset(t_jit_attr *x, void *y); 00148 t_jit_err jit_attr_filterget_wrap(void *parent, t_jit_attr *x, long *ac, t_atom **av); 00149 t_jit_err jit_attr_filterset_wrap(void *parent, t_jit_attr *x, long ac, t_atom *av); 00150 // jit_object_method versions, for compatibility with decorated attributes 00151 t_jit_err jit_attr_get(t_jit_attr *x, void *parent, long *ac, t_atom **av); 00152 t_jit_err jit_attr_set(t_jit_attr *x, void *parent, long ac, t_atom *av); 00153 void jit_attr_getformat(t_jit_attr *x, t_object *parent, long *argc, t_atom **argv); 00154 t_jit_err jit_attr_gettext(t_jit_attr *x, t_object *parent, long *textlen, char **text, long maxatoms, long maxlen, long flags); 00155 00156 t_jit_err jit_attribute_init(void); 00157 t_jit_object *jit_attribute_new(char *name, t_symbol *type, long flags, method mget, method mset); 00158 size_t jit_attribute_sizeof(t_symbol *s); 00159 t_jit_err jit_attribute_free(t_jit_attribute *x); 00160 t_jit_attribute *jit_attribute_clone(t_jit_attribute *x); 00161 long jit_attribute_getsize(t_jit_attribute *x); 00162 t_symbol *jit_attribute_getattach_name(t_jit_attribute *x); 00163 t_jit_err jit_attribute_method_get(void *parent, t_jit_attribute *x, long *ac, t_atom **av); 00164 t_jit_err jit_attribute_method_set(void *parent, t_jit_attribute *x, long ac, t_atom *av); 00165 00166 t_jit_err jit_attr_offset_init(void); 00167 t_jit_object *jit_attr_offset_new(char *name, t_symbol *type, long flags, method mget, method mset, long offset); 00168 t_jit_err jit_attr_offset_free(t_jit_attr_offset *x); 00169 t_jit_attr_offset *jit_attr_offset_clone(t_jit_attr_offset *x); 00170 t_jit_err jit_attr_offset_get(void *parent, t_jit_attr_offset *x, long *ac, t_atom **av); 00171 t_jit_err jit_attr_offset_set(void *parent, t_jit_attr_offset *x, long ac, t_atom *av); 00172 t_jit_err jit_attr_offset_offset(t_jit_attr_offset *x, long offset); 00173 long jit_attr_offset_getoffset(t_jit_attr_offset *x); 00174 long jit_attr_offset_getsize(t_jit_attr_offset *x); 00175 00176 t_jit_err jit_attr_offset_array_init(void); 00177 t_jit_object *jit_attr_offset_array_new(char *name, t_symbol *type, long size, long flags, method mget, method mset, long offsetcount, long offset); 00178 t_jit_err jit_attr_offset_array_free(t_jit_attr_offset_array *x); 00179 t_jit_attr_offset_array *jit_attr_offset_array_clone(t_jit_attr_offset_array *x); 00180 t_jit_err jit_attr_offset_array_get(void *parent, t_jit_attr_offset_array *x, long *ac, t_atom **av); 00181 t_jit_err jit_attr_offset_array_set(void *parent, t_jit_attr_offset_array *x, long ac, t_atom *av); 00182 t_jit_err jit_attr_offset_array_offsetcount(t_jit_attr_offset_array *x, long offsetcount); 00183 long jit_attr_offset_array_getoffsetcount(t_jit_attr_offset_array *x); 00184 t_jit_err jit_attr_offset_array_size(t_jit_attr_offset_array *x, long size); 00185 long jit_attr_offset_array_getsize(t_jit_attr_offset_array *x); 00186 00187 void *_jit_attr_filter_clip_class; 00188 00189 t_jit_err jit_attr_filter_clip_init(void); 00190 t_jit_object *jit_attr_filter_clip_new(void); 00191 t_jit_err jit_attr_filter_clip_free(t_jit_attr_filter_clip *x); 00192 t_jit_err jit_attr_filter_clip_filter(t_jit_attr_filter_clip *x, t_symbol *s, long ac, t_atom *av, void *parent, void *attr); 00193 00194 void *_jit_attr_filter_proc_class; 00195 00196 t_jit_err jit_attr_filter_proc_init(void); 00197 t_jit_object *jit_attr_filter_proc_new(method proc); 00198 t_jit_err jit_attr_filter_proc_free(t_jit_attr_filter_proc *x); 00199 t_jit_err jit_attr_filter_proc_filter(t_jit_attr_filter_proc *x, t_symbol *s, long ac, t_atom *av, void *parent, void *attr); 00200 t_jit_err jit_attr_filter_proc_setproc(t_jit_attr_filter_proc *x, method proc); 00201 00202 00203 t_jit_err jit_attr_init(void) 00204 { 00205 t_jit_err err=JIT_ERR_NONE; 00206 00207 err = jit_attribute_init(); 00208 err = jit_attr_offset_init(); 00209 err = jit_attr_offset_array_init(); 00210 err = jit_attr_filter_clip_init(); 00211 err = jit_attr_filter_proc_init(); 00212 00213 00214 return err; 00215 } 00216 00217 t_jit_err jit_attr_setup_class(void *c) 00218 { 00219 jit_class_addmethod(c, (method)jit_attr_getname, "getname", A_CANT, 0L); 00220 jit_class_addmethod(c, (method)jit_attr_gettype, "gettype", A_CANT, 0L); 00221 jit_class_addmethod(c, (method)jit_attr_getmethod, "getmethod", A_CANT, 0L); 00222 jit_class_addmethod(c, (method)jit_attr_setmethod, "setmethod", A_CANT, 0L); 00223 jit_class_addmethod(c, (method)jit_attr_getmethodtype, "getmethodtype",A_CANT, 0L); 00224 jit_class_addmethod(c, (method)jit_attr_canget, "canget", A_CANT, 0L); 00225 jit_class_addmethod(c, (method)jit_attr_canset, "canset", A_CANT, 0L); 00226 jit_class_addmethod(c, (method)jit_attr_usercanget, "usercanget", A_CANT, 0L); 00227 jit_class_addmethod(c, (method)jit_attr_usercanset, "usercanset", A_CANT, 0L); 00228 jit_class_addmethod(c, (method)jit_attr_filterget, "filterget", A_CANT, 0L); 00229 jit_class_addmethod(c, (method)jit_attr_filterset, "filterset", A_CANT, 0L); 00230 jit_class_addmethod(c, (method)jit_attr_get, "get", A_CANT, 0L); 00231 jit_class_addmethod(c, (method)jit_attr_set, "set", A_CANT, 0L); 00232 jit_class_addmethod(c, (method)jit_attr_get, "getvalueof", A_CANT, 0L); 00233 jit_class_addmethod(c, (method)jit_attr_set, "setvalueof", A_CANT, 0L); 00234 jit_class_addmethod(c, (method)jit_attr_getformat, "getformat", A_CANT, 0L); 00235 jit_class_addmethod(c, (method)jit_attr_gettext, "gettext", A_CANT, 0L); 00236 jit_class_addmethod(c, (method)jit_object_register, "register", A_CANT, 0L); 00237 jit_class_addmethod(c, (method)jit_method_true, "class_jit_attribute", A_CANT, 0L); 00238 return JIT_ERR_NONE; 00239 } 00240 00241 /** 00242 * Retrieves attribute name. 00243 * 00244 * @ingroup attrmod 00245 * 00246 * @param x attribute object pointer 00247 * 00248 * @return attribute name 00249 * 00250 * @warning This function is not exported, but is provided 00251 * for reference when calling via jit_object_method 00252 * on an intance of any attribute obejct. 00253 */ 00254 t_symbol *jit_attr_getname(t_jit_attr *x) 00255 { 00256 if (x) 00257 return x->name; 00258 else 00259 return _jit_sym_nothing; 00260 } 00261 00262 /** 00263 * Retrieves attribute type. 00264 * 00265 * @ingroup attrmod 00266 * 00267 * @param x attribute object pointer 00268 * 00269 * @return attribute type 00270 * 00271 * @warning This function is not exported, but is provided 00272 * for reference when calling via jit_object_method 00273 * on an intance of any attribute obejct. 00274 */ 00275 t_symbol *jit_attr_gettype(t_jit_attr *x) 00276 { 00277 if (x) 00278 return x->type; 00279 else 00280 return _jit_sym_nothing; 00281 } 00282 00283 /** 00284 * Retrieves attribute gettable flag. 00285 * 00286 * @ingroup attrmod 00287 * 00288 * @param x attribute object pointer 00289 * 00290 * @return gettable flag 00291 * 00292 * @warning This function is not exported, but is provided 00293 * for reference when calling via jit_object_method 00294 * on an intance of any attribute obejct. 00295 */ 00296 long jit_attr_canget(t_jit_attr *x) 00297 { 00298 if (x) return (!(x->flags&JIT_ATTR_GET_OPAQUE)); 00299 else return 0; 00300 } 00301 00302 /** 00303 * Retrieves attribute settable flag. 00304 * 00305 * @ingroup attrmod 00306 * 00307 * @param x attribute object pointer 00308 * 00309 * @return settable flag 00310 * 00311 * @warning This function is not exported, but is provided 00312 * for reference when calling via jit_object_method 00313 * on an intance of any attribute obejct. 00314 */ 00315 long jit_attr_canset(t_jit_attr *x) 00316 { 00317 if (x) return (!(x->flags&JIT_ATTR_SET_OPAQUE)); 00318 else return 0; 00319 } 00320 00321 /** 00322 * Retrieves attribute user gettable flag. 00323 * 00324 * @ingroup attrmod 00325 * 00326 * @param x attribute object pointer 00327 * 00328 * @return user gettable flag 00329 * 00330 * @warning This function is not exported, but is provided 00331 * for reference when calling via jit_object_method 00332 * on an intance of any attribute obejct. 00333 */ 00334 long jit_attr_usercanget(t_jit_attr *x) 00335 { 00336 if (x) return (!(x->flags&JIT_ATTR_GET_OPAQUE_USER)); 00337 else return 0; 00338 } 00339 00340 /** 00341 * Retrieves attribute user settable flag. 00342 * 00343 * @ingroup attrmod 00344 * 00345 * @param x attribute object pointer 00346 * 00347 * @return user settable flag 00348 * 00349 * @warning This function is not exported, but is provided 00350 * for reference when calling via jit_object_method 00351 * on an intance of any attribute obejct. 00352 */ 00353 long jit_attr_usercanset(t_jit_attr *x) 00354 { 00355 if (x) return (!(x->flags&JIT_ATTR_SET_OPAQUE_USER)); 00356 else return 0; 00357 } 00358 00359 /** 00360 * Retrieves attribute getter or setter method. 00361 * 00362 * @ingroup attrmod 00363 * 00364 * @param x attribute object pointer 00365 * @param methodname "get" or "set" symbol 00366 * 00367 * @return getter or setter method 00368 * 00369 * @warning This function is not exported, but is provided 00370 * for reference when calling via jit_object_method 00371 * on an intance of any attribute obejct. 00372 */ 00373 method jit_attr_getmethod(t_jit_attr *x, t_symbol *methodname) 00374 { 00375 if (x) { 00376 if (methodname==_jit_sym_get) 00377 return x->filterget?(method)jit_attr_filterget_wrap:x->get; 00378 else if (methodname==_jit_sym_set) 00379 return x->filterset?(method)jit_attr_filterset_wrap:x->set; 00380 } 00381 return 0; 00382 } 00383 00384 t_jit_err jit_attr_setmethod(t_jit_attr *x, t_symbol *methodtype, method m) 00385 { 00386 if (x&&m) { 00387 if (methodtype==_jit_sym_get) 00388 x->get = m; 00389 else if (methodtype==_jit_sym_set) 00390 x->set = m; 00391 } 00392 return JIT_ERR_NONE; 00393 } 00394 00395 00396 long jit_attr_getmethodtype(t_jit_attr *x, t_symbol *methodname) 00397 { 00398 long type = A_GIMME; 00399 00400 if (x) { 00401 if (methodname==_jit_sym_get) { 00402 if (x->flags&JIT_ATTR_GET_USURP_LOW) { 00403 type = A_USURP_LOW; 00404 } else if (x->flags&JIT_ATTR_GET_USURP) { 00405 type = A_USURP; 00406 } else if (x->flags&JIT_ATTR_GET_DEFER_LOW) { 00407 type = A_DEFER_LOW; 00408 } else if (x->flags&JIT_ATTR_GET_DEFER) { 00409 type = A_DEFER; 00410 } 00411 } else if (methodname==_jit_sym_set) { 00412 if (x->flags&JIT_ATTR_SET_USURP_LOW) { 00413 type = A_USURP_LOW; 00414 } else if (x->flags&JIT_ATTR_SET_USURP) { 00415 type = A_USURP; 00416 } else if (x->flags&JIT_ATTR_SET_DEFER_LOW) { 00417 type = A_DEFER_LOW; 00418 } else if (x->flags&JIT_ATTR_SET_DEFER) { 00419 type = A_DEFER; 00420 } 00421 } 00422 } 00423 return type; 00424 00425 } 00426 00427 /** 00428 * Sets attribute getter filter. 00429 * 00430 * @ingroup attrmod 00431 * 00432 * @param x attribute object pointer 00433 * @param y getter filter object 00434 * 00435 * @return t_jit_err error code 00436 * 00437 * @warning This function is not exported, but is provided 00438 * for reference when calling via jit_object_method 00439 * on an intance of any attribute obejct. 00440 */ 00441 t_jit_err jit_attr_filterget(t_jit_attr *x, void *y) 00442 { 00443 if (x) { 00444 if (y) { 00445 static method mf=NULL; 00446 if (!mf) 00447 mf = jit_object_getmethod(NULL,NULL); 00448 //check object for filter method 00449 if (jit_object_getmethod(y,_jit_sym_filter)!=mf) 00450 x->filterget = y; 00451 else 00452 return JIT_ERR_GENERIC; 00453 } else { 00454 x->filterget = NULL; 00455 } 00456 return JIT_ERR_NONE; 00457 } 00458 return JIT_ERR_INVALID_PTR; 00459 } 00460 00461 /** 00462 * Sets attribute setter filter. 00463 * 00464 * @ingroup attrmod 00465 * 00466 * @param x attribute object pointer 00467 * @param y setter filter object 00468 * 00469 * @return t_jit_err error code 00470 * 00471 * @warning This function is not exported, but is provided 00472 * for reference when calling via jit_object_method 00473 * on an intance of any attribute obejct. 00474 */ 00475 t_jit_err jit_attr_filterset(t_jit_attr *x, void *y) 00476 { 00477 if (x) { 00478 if (y) { 00479 static method mf=NULL; 00480 if (!mf) 00481 mf = jit_object_getmethod(NULL,NULL); 00482 //check object for filter method 00483 if (jit_object_getmethod(y,_jit_sym_filter)!=mf) 00484 x->filterset = y; 00485 else 00486 return JIT_ERR_GENERIC; 00487 } else { 00488 x->filterset = NULL; 00489 } 00490 return JIT_ERR_NONE; 00491 } 00492 return JIT_ERR_INVALID_PTR; 00493 } 00494 00495 t_jit_err jit_attr_filterget_wrap(void *parent, t_jit_attr *x, long *ac, t_atom **av) 00496 { 00497 t_jit_err err; 00498 00499 if (x&&x->filterget) { 00500 err = (t_jit_err) x->get(parent,x,ac,av); 00501 jit_object_method(x->filterget,_jit_sym_filter,_jit_sym_filter,*ac,*av,parent,x); 00502 return err; 00503 } 00504 return JIT_ERR_INVALID_PTR; 00505 } 00506 00507 t_jit_err jit_attr_filterset_wrap(void *parent, t_jit_attr *x, long ac, t_atom *av) 00508 { 00509 long i,ac2; 00510 t_atom av2[256]; 00511 00512 if (x&&x->filterset) { 00513 //must copy 00514 CLIP(ac,0,256); 00515 ac2=ac; 00516 for (i=0;i<ac;i++) { 00517 av2[i]=av[i]; 00518 } 00519 jit_object_method(x->filterset,_jit_sym_filter,_jit_sym_filter,ac2,av2,parent,x); 00520 return (t_jit_err) x->set(parent,x,ac2,av2); 00521 } 00522 return JIT_ERR_INVALID_PTR; 00523 } 00524 00525 /** 00526 * Calls attribute getter to retrieve from parent object. 00527 * 00528 * @ingroup attrmod 00529 * 00530 * @param x attribute object pointer 00531 * @param parent target object pointer 00532 * @param ac pointer to argument count 00533 * @param av pointer to argument vector 00534 * 00535 * @return t_jit_err error code 00536 * 00537 * @warning This function is not exported, but is provided 00538 * for reference when calling via jit_object_method 00539 * on an intance of any attribute obejct. 00540 */ 00541 t_jit_err jit_attr_get(t_jit_attr *x, void *parent, long *ac, t_atom **av) 00542 { 00543 if (x) { 00544 if (x->filterget) 00545 jit_attr_filterget_wrap(parent, x, ac, av); 00546 else { 00547 (*x->get)(parent, x, ac, av); 00548 } 00549 } 00550 return JIT_ERR_NONE; 00551 } 00552 00553 /** 00554 * Calls attribute setter to set in parent object. 00555 * 00556 * @ingroup attrmod 00557 * 00558 * @param x attribute object pointer 00559 * @param parent target object pointer 00560 * @param ac argument count 00561 * @param av argument vector 00562 * 00563 * @return t_jit_err error code 00564 * 00565 * @warning This function is not exported, but is provided 00566 * for reference when calling via jit_object_method 00567 * on an intance of any attribute obejct. 00568 */ 00569 t_jit_err jit_attr_set(t_jit_attr *x, void *parent, long ac, t_atom *av) 00570 { 00571 if (x) { 00572 if (x->filterset) 00573 jit_attr_filterset_wrap(parent, x, ac, av); 00574 else 00575 (*x->set)(parent, x, ac, av); 00576 } 00577 return JIT_ERR_NONE; 00578 } 00579 00580 00581 void jit_attr_getformat(t_jit_attr *x, t_object *parent, long *argc, t_atom **argv) 00582 { 00583 long size; 00584 long i; 00585 char alloc; 00586 00587 size = (long)object_method(x, gensym("getsize")); 00588 00589 if (size > 4) { // is it really as big as all that? 00590 long ac = 0; 00591 t_atom *av = NULL; 00592 00593 jit_attr_get(x, parent, &ac, &av); 00594 if (ac && av) { 00595 size = ac; 00596 jit_freebytes(av, sizeof(t_atom) * ac); 00597 } 00598 } 00599 00600 size = CLIP(size, 1, 9); 00601 atom_alloc_array(size, argc, argv, &alloc); 00602 for (i = 0; i < size; i++) { 00603 ((*argv)+i)->a_type = A_DOLLAR; 00604 ((*argv)+i)->a_w.w_long = i+1; 00605 } 00606 } 00607 00608 t_jit_err jit_attr_gettext(t_jit_attr *x, t_object *parent, long *textlen, char **text, long maxatoms, long maxlen, long flags) 00609 { 00610 #ifdef COMMA_SEPARATED 00611 static t_symbol *ps_style = NULL; 00612 static t_symbol *ps_text_commaseparated = NULL; 00613 static t_symbol *ps_text_large_commaseparated = NULL; 00614 #endif 00615 00616 long ac=0; 00617 t_atom *av=NULL; 00618 t_symbol *typesym = (t_symbol *)jit_object_method(x,_jit_sym_gettype); 00619 t_jit_attr *at; 00620 t_jit_object *jitob; 00621 #ifdef COMMA_SEPARATED 00622 t_symbol *style = jit_attr_getsym(x, ps_style); 00623 char commasep; 00624 #endif 00625 00626 if (!(x && parent && textlen && text)) 00627 return JIT_ERR_GENERIC; 00628 00629 // verify that parent is really the parent 00630 if (jitob = max_jit_obex_jitob_get(parent)) { 00631 at = jit_object_attr_get(jitob, x->name); 00632 if (at && at == x) 00633 parent = jitob; 00634 } 00635 00636 #ifdef COMMA_SEPARATED 00637 if (!ps_style) { 00638 ps_style = gensym("style"); 00639 ps_text_commaseparated = gensym("text_commaseparated"); 00640 ps_text_large_commaseparated = gensym("text_large_commaseparated"); 00641 } 00642 commasep = (style == ps_text_commaseparated || style == ps_text_large_commaseparated); 00643 #endif 00644 object_attr_getvalueof(parent, x->name, &ac, &av); 00645 if (ac && av) { 00646 if ((typesym==_jit_sym_long) || 00647 (typesym==_jit_sym_char) || 00648 (typesym==_jit_sym_symbol) || 00649 (typesym==_jit_sym_float32) || 00650 (typesym==_jit_sym_float64) || 00651 (typesym==_jit_sym_atom)) 00652 { 00653 long textbufsize = 0; 00654 char *textbuf = NULL; 00655 long charcount; 00656 long getatoms; 00657 char cutoff; 00658 00659 #ifdef COMMA_SEPARATED 00660 if (commasep) 00661 flags |= OBEX_UTIL_ATOM_GETTEXT_COMMA_DELIM; 00662 #endif 00663 // truncate symbols and atoms to max string len, rather than # of items 00664 // this improves display of A_COMMA separated atom lists 00665 if (typesym == _jit_sym_symbol || typesym == _jit_sym_atom) 00666 getatoms = 0; 00667 else 00668 getatoms = MIN(maxatoms,ac); 00669 00670 // Note exemplary use of UTF8 funs! 00671 atom_gettext(getatoms ? getatoms : ac,av,&textbufsize,&textbuf,flags); 00672 if (textbufsize && textbuf) { 00673 charcount = charset_utf8_count(textbuf, NULL); 00674 if (maxlen > 0 && charcount > maxlen) { 00675 char *c = (char *)charset_utf8_offset(textbuf, maxlen, NULL); 00676 if (c) *c = '\0'; // truncate text pointer 00677 } 00678 cutoff = ((getatoms && maxatoms > 0 && ac > maxatoms) || (maxlen > 0 && charcount > maxlen)); 00679 if (*text && *textlen) { 00680 ; 00681 } else { 00682 *textlen = strlen(textbuf) + 1; 00683 if (cutoff) // something got cut off 00684 *textlen += strlen(" ..."); 00685 *text = jit_getbytes(*textlen); 00686 } 00687 strncpy(*text, textbuf, *textlen); 00688 if (cutoff) // something got cut off 00689 strncat_zero(*text," ...", *textlen); 00690 sysmem_freeptr(textbuf); 00691 } 00692 } 00693 } 00694 jit_freebytes((char *)av,sizeof(t_atom)*ac); 00695 return JIT_ERR_NONE; 00696 } 00697 00698 #pragma mark - 00699 00700 t_jit_err jit_attribute_init(void) 00701 { 00702 _jit_attribute_class = jit_class_new("jit_attribute",(method)jit_attribute_new,(method)jit_attribute_free, 00703 sizeof(t_jit_attribute),A_CANT,0L); //A_CANT = untyped 00704 00705 jit_attr_setup_class(_jit_attribute_class); 00706 jit_class_addmethod(_jit_attribute_class, (method)jit_attribute_getsize, "getsize", A_CANT, 0L); 00707 jit_class_addmethod(_jit_attribute_class, (method)jit_attribute_clone, "object_clone", A_CANT, 0L); 00708 00709 jit_class_register(_jit_attribute_class); 00710 00711 return JIT_ERR_NONE; 00712 } 00713 00714 /** 00715 * Constructs instance of t_jit_attribute. 00716 * 00717 * @ingroup attrmod 00718 * 00719 * @param name attribute name 00720 * @param type data type 00721 * @param flags privacy flags 00722 * @param mget getter method 00723 * @param mset setter method 00724 * 00725 * @return t_jit_attribute object pointer 00726 * 00727 * @warning This function is not exported, but is provided 00728 * for reference when calling via jit_object_new. 00729 */ 00730 t_jit_object *jit_attribute_new(char *name, t_symbol *type, long flags, method mget, method mset) 00731 { 00732 t_jit_attribute *x; 00733 method mget_default,mset_default; 00734 00735 if (x = (t_jit_attribute *)jit_object_alloc(_jit_attribute_class)) { 00736 x->name = gensym(name); 00737 x->type = type; 00738 x->flags = flags; 00739 x->get = mget?(method)mget:(method)jit_attribute_method_get; 00740 x->set = mset?(method)mset:(method)jit_attribute_method_set; 00741 x->filterget = NULL; 00742 x->filterset = NULL; 00743 x->reserved = NULL; 00744 x->data = NULL; 00745 x->size = 0; 00746 } 00747 00748 return (t_jit_object *)x; 00749 } 00750 00751 size_t jit_attribute_sizeof(t_symbol *s) 00752 { 00753 if (s == _jit_sym_char) 00754 return sizeof(char); 00755 else if (s == _jit_sym_long) 00756 return sizeof(long); 00757 else if (s == _jit_sym_float32) 00758 return sizeof(float); 00759 else if (s == _jit_sym_float64) 00760 return sizeof(double); 00761 else if (s == _jit_sym_atom) 00762 return sizeof(t_atom); 00763 else if (s == _jit_sym_symbol) 00764 return sizeof(void *); 00765 else if (s == _jit_sym_pointer) 00766 return sizeof(void *); 00767 else if (s == _jit_sym_object) 00768 return sizeof(void *); 00769 else { 00770 post("jit.attribute: unknown type"); 00771 return 0; 00772 } 00773 } 00774 00775 t_jit_err jit_attribute_free(t_jit_attribute *x) 00776 { 00777 if (x->filterget) jit_object_free(x->filterget); 00778 if (x->filterset) jit_object_free(x->filterset); 00779 if (x->data) jit_freebytes(x->data, jit_attribute_sizeof(x->type) * x->size); 00780 return JIT_ERR_NONE; 00781 } 00782 00783 t_jit_attribute *jit_attribute_clone(t_jit_attribute *x) 00784 { 00785 t_jit_attribute *clone; 00786 00787 clone = (t_jit_attribute *)object_clone_generic((t_object *)x); 00788 if (x&&clone) 00789 { 00790 if (x->filterget) 00791 clone->filterget = object_clone((t_object *)x->filterget); 00792 if (x->filterset) 00793 clone->filterset = object_clone((t_object *)x->filterset); 00794 // if the type is A_OBJ, should we be cloning here? 00795 // we don't free the object though, perhaps desirable? 00796 // unclear w/r/t reference counting. leaving for now -jkc 00797 if (x->data) 00798 { 00799 unsigned long bytecount; 00800 bytecount = jit_attribute_sizeof(x->type) * x->size; 00801 clone->data = (void *) jit_getbytes(bytecount); 00802 sysmem_copyptr((const void *)x->data,(void *)clone->data,bytecount); 00803 } 00804 } 00805 return clone; 00806 } 00807 00808 long jit_attribute_getsize(t_jit_attribute *x) 00809 { 00810 return x->size; 00811 } 00812 00813 t_jit_err jit_attribute_method_get(void *parent, t_jit_attribute *x, long *ac, t_atom **av) 00814 { 00815 long i; 00816 00817 if (x) { 00818 if (*ac && *av) 00819 *ac = MIN(*ac, x->size); 00820 else { 00821 *ac = x->size; 00822 if (!(*av = jit_getbytes(sizeof(t_atom) * (*ac)))) { 00823 *ac = 0; 00824 return JIT_ERR_OUT_OF_MEM; 00825 } 00826 } 00827 for (i = 0; i < *ac; i++) { 00828 if (x->type == _jit_sym_char) 00829 jit_atom_setlong((*av) + i, ((uchar *)x->data)[i]); 00830 else if (x->type == _jit_sym_long) 00831 jit_atom_setlong((*av) + i, ((long *)x->data)[i]); 00832 else if (x->type == _jit_sym_float32) 00833 jit_atom_setfloat((*av) + i, ((float *)x->data)[i]); 00834 else if (x->type == _jit_sym_float64) 00835 jit_atom_setfloat((*av) + i, ((double *)x->data)[i]); 00836 else if (x->type == _jit_sym_symbol) 00837 jit_atom_setsym((*av) + i, ((t_symbol **)x->data)[i]); 00838 else if (x->type == _jit_sym_object) 00839 jit_atom_setobj((*av) + i, ((void **)x->data)[i]); 00840 else if (x->type == _jit_sym_pointer) 00841 jit_atom_setobj((*av) + i, ((void **)x->data)[i]); 00842 else if (x->type == _jit_sym_atom) 00843 *((*av) + i) = ((t_atom *)x->data)[i]; 00844 else 00845 jit_atom_setlong((*av) + i, 0); 00846 } 00847 return JIT_ERR_NONE; 00848 } 00849 return JIT_ERR_INVALID_PTR; 00850 } 00851 00852 t_jit_err jit_attribute_method_set(void *parent, t_jit_attribute *x, long ac, t_atom *av) 00853 { 00854 long i, c; 00855 00856 if (x) { 00857 if (ac && av) { 00858 if (x->data) 00859 jit_freebytes(x->data, jit_attribute_sizeof(x->type) * x->size); 00860 if (x->data = jit_getbytes(jit_attribute_sizeof(x->type) * ac)) { 00861 x->size = ac; 00862 for (i = 0; i < ac; i++) { 00863 if (x->type == _jit_sym_char) 00864 ((uchar *)x->data)[i] = jit_atom_getlong(av + i); 00865 else if (x->type == _jit_sym_long) 00866 ((long *)x->data)[i] = jit_atom_getlong(av + i); 00867 else if (x->type == _jit_sym_float32) 00868 ((float *)x->data)[i] = jit_atom_getfloat(av + i); 00869 else if (x->type == _jit_sym_float64) 00870 ((double *)x->data)[i] = jit_atom_getfloat(av + i); 00871 else if (x->type == _jit_sym_symbol) 00872 ((t_symbol **)x->data)[i] = jit_atom_getsym(av + i); 00873 else if (x->type == _jit_sym_object) 00874 ((void **)x->data)[i] = jit_atom_getobj(av + i); 00875 else if (x->type == _jit_sym_pointer) 00876 ((void **)x->data)[i] = jit_atom_getobj(av + i); 00877 else if (x->type == _jit_sym_atom) 00878 ((t_atom *)x->data)[i] = *(av + i); 00879 } 00880 } 00881 else { 00882 x->size = 0; 00883 return JIT_ERR_OUT_OF_MEM; 00884 } 00885 } 00886 return JIT_ERR_NONE; 00887 } 00888 return JIT_ERR_INVALID_PTR; 00889 } 00890 00891 #pragma mark - 00892 // -------------------------------------------------------------------------------- 00893 // 00894 00895 t_jit_err jit_attr_offset_init(void) 00896 { 00897 _jit_attr_offset_class = jit_class_new("jit_attr_offset",(method)jit_attr_offset_new,(method)jit_attr_offset_free, 00898 sizeof(t_jit_attr_offset),A_CANT,0L); //A_CANT = untyped 00899 00900 jit_attr_setup_class(_jit_attr_offset_class); 00901 jit_class_addmethod(_jit_attr_offset_class, (method)jit_attr_offset_getsize, "getsize", A_CANT, 0L); 00902 jit_class_addmethod(_jit_attr_offset_class, (method)jit_attr_offset_offset, "offset", A_CANT, 0L); 00903 jit_class_addmethod(_jit_attr_offset_class, (method)jit_attr_offset_getoffset, "getoffset", A_CANT, 0L); 00904 jit_class_addmethod(_jit_attr_offset_class, (method)jit_attr_offset_clone, "object_clone", A_CANT, 0L); 00905 00906 jit_class_register(_jit_attr_offset_class); 00907 00908 return JIT_ERR_NONE; 00909 } 00910 00911 /** 00912 * Constructs instance of t_jit_attr_offset. 00913 * 00914 * @ingroup attrmod 00915 * 00916 * @param name attribute name 00917 * @param type data type 00918 * @param flags privacy flags 00919 * @param mget getter method 00920 * @param mset setter method 00921 * @param offset byte offset to struct member 00922 * 00923 * @return t_jit_attr_offset object pointer 00924 * 00925 * @warning This function is not exported, but is provided 00926 * for reference when calling via jit_object_new. 00927 */ 00928 t_jit_object *jit_attr_offset_new(char *name, t_symbol *type, long flags, method mget, method mset, long offset) 00929 { 00930 t_jit_attr_offset *x; 00931 method mget_default,mset_default; 00932 00933 if (x = (t_jit_attr_offset *)jit_object_alloc(_jit_attr_offset_class)) { 00934 x->name = gensym(name); 00935 x->type = type; 00936 x->flags = flags; 00937 x->get = mget?(method)mget:(method)jit_attr_offset_get; 00938 x->set = mset?(method)mset:(method)jit_attr_offset_set; 00939 x->filterget = NULL; 00940 x->filterset = NULL; 00941 x->reserved = NULL; 00942 x->offset = offset; 00943 } 00944 00945 return (t_jit_object *)x; 00946 } 00947 00948 t_jit_attr_offset *jit_attr_offset_clone(t_jit_attr_offset *x) 00949 { 00950 t_jit_attr_offset *clone; 00951 00952 clone = (t_jit_attr_offset *)object_clone_generic((t_object *)x); 00953 if (x&&clone) 00954 { 00955 if (x->filterget) 00956 clone->filterget = object_clone((t_object *)x->filterget); 00957 if (x->filterset) 00958 clone->filterset = object_clone((t_object *)x->filterset); 00959 } 00960 return clone; 00961 } 00962 00963 t_jit_err jit_attr_offset_free(t_jit_attr_offset *x) 00964 { 00965 if (x->filterget) jit_object_free(x->filterget); 00966 if (x->filterset) jit_object_free(x->filterset); 00967 return JIT_ERR_NONE; 00968 } 00969 00970 t_jit_err jit_attr_offset_offset(t_jit_attr_offset *x, long offset) 00971 { 00972 if (x) { 00973 x->offset=offset; 00974 return JIT_ERR_NONE; 00975 } 00976 return JIT_ERR_INVALID_PTR; 00977 } 00978 00979 long jit_attr_offset_getsize(t_jit_attr_offset *x) 00980 { 00981 return 1; 00982 } 00983 00984 long jit_attr_offset_getoffset(t_jit_attr_offset *x) 00985 { 00986 return x?x->offset:0; 00987 } 00988 00989 t_jit_err jit_attr_offset_get(void *parent, t_jit_attr_offset *x, long *ac, t_atom **av) 00990 { 00991 if (x) { 00992 if ((*ac)&&(*av)) { 00993 //memory passed in, use it 00994 } else { 00995 //otherwise allocate memory 00996 *ac = 0; 00997 if (!(*av = jit_getbytes(sizeof(t_atom)))) 00998 return JIT_ERR_OUT_OF_MEM; 00999 } 01000 *ac = 1; 01001 if (x->type==_jit_sym_char) 01002 jit_atom_setlong(*av,*((uchar *)(((char *)parent)+x->offset))); 01003 else if (x->type==_jit_sym_long) 01004 jit_atom_setlong(*av,*((long *)(((char *)parent)+x->offset))); 01005 else if (x->type==_jit_sym_float32) 01006 jit_atom_setfloat(*av,*((float *)(((char *)parent)+x->offset))); 01007 else if (x->type==_jit_sym_float64) 01008 jit_atom_setfloat(*av,*((double *)(((char *)parent)+x->offset))); 01009 else if (x->type==_jit_sym_symbol) 01010 jit_atom_setsym(*av,*((t_symbol **)(((char *)parent)+x->offset))); 01011 else if (x->type==_jit_sym_object) 01012 jit_atom_setobj(*av,*((void **)(((char *)parent)+x->offset))); 01013 else if (x->type==_jit_sym_pointer) 01014 jit_atom_setobj(*av,*((void **)(((char *)parent)+x->offset))); 01015 else if (x->type==_jit_sym_atom) 01016 **av = *((t_atom *)(((char *)parent)+x->offset)); 01017 else 01018 jit_atom_setlong(*av,0); 01019 01020 return JIT_ERR_NONE; 01021 } 01022 return JIT_ERR_INVALID_PTR; 01023 } 01024 01025 t_jit_err jit_attr_offset_set(void *parent, t_jit_attr_offset *x, long ac, t_atom *av) 01026 { 01027 if (x && ac && av) { 01028 if (x->type==_jit_sym_char) 01029 *((uchar *)(((char *)parent)+x->offset)) = jit_atom_getlong(av); 01030 else if (x->type==_jit_sym_long) 01031 *((long *)(((char *)parent)+x->offset)) = jit_atom_getlong(av); 01032 else if (x->type==_jit_sym_float32) 01033 *((float *)(((char *)parent)+x->offset)) = jit_atom_getfloat(av); 01034 else if (x->type==_jit_sym_float64) 01035 *((double *)(((char *)parent)+x->offset)) = jit_atom_getfloat(av); 01036 else if (x->type==_jit_sym_symbol) 01037 *((t_symbol **)(((char *)parent)+x->offset)) = jit_atom_getsym(av); 01038 else if (x->type==_jit_sym_object) 01039 *((void **)(((char *)parent)+x->offset)) = jit_atom_getobj(av); 01040 else if (x->type==_jit_sym_pointer) 01041 *((void **)(((char *)parent)+x->offset)) = jit_atom_getobj(av); 01042 else if (x->type==_jit_sym_atom) 01043 *((t_atom *)(((char *)parent)+x->offset)) = *av; 01044 01045 return JIT_ERR_NONE; 01046 } 01047 return JIT_ERR_INVALID_PTR; 01048 } 01049 01050 #pragma mark - 01051 // -------------------------------------------------------------------------------- 01052 // 01053 01054 t_jit_err jit_attr_offset_array_init(void) 01055 { 01056 _jit_attr_offset_array_class = jit_class_new("jit_attr_offset_array",(method)jit_attr_offset_array_new, 01057 (method)jit_attr_offset_array_free,sizeof(t_jit_attr_offset_array),A_CANT,0L); //A_CANT = untyped 01058 01059 jit_attr_setup_class(_jit_attr_offset_array_class); 01060 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_offset, "offset", A_CANT, 0L); 01061 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_getoffset, "getoffset", A_CANT, 0L); 01062 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_array_offsetcount, "offsetcount", A_CANT, 0L); 01063 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_array_getoffsetcount, "getoffsetcount", A_CANT, 0L); 01064 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_array_size, "size", A_CANT, 0L); 01065 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_array_getsize, "getsize", A_CANT, 0L); 01066 jit_class_addmethod(_jit_attr_offset_array_class, (method)jit_attr_offset_array_clone, "object_clone", A_CANT, 0L); 01067 01068 jit_class_register(_jit_attr_offset_array_class); 01069 01070 return JIT_ERR_NONE; 01071 } 01072 01073 /** 01074 * Constructs instance of t_jit_attr_offset_array. 01075 * 01076 * @ingroup attrmod 01077 * 01078 * @param name attribute name 01079 * @param type data type 01080 * @param size maximum size 01081 * @param flags privacy flags 01082 * @param mget getter method 01083 * @param mset setter method 01084 * @param offsetcount byte offset to count struct member (if zero, remain fixed size with max size) 01085 * @param offset byte offset to array struct member 01086 * 01087 * @return t_jit_attr_offset_array object pointer 01088 * 01089 * @warning This function is not exported, but is provided 01090 * for reference when calling via jit_object_new. 01091 */ 01092 t_jit_object *jit_attr_offset_array_new(char *name, t_symbol *type, long size, long flags, method mget, method mset, long offsetcount, long offset) 01093 { 01094 t_jit_attr_offset_array *x; 01095 method mget_default,mset_default; 01096 01097 if (x = (t_jit_attr_offset_array *)jit_object_alloc(_jit_attr_offset_array_class)) { 01098 x->name = gensym(name); 01099 x->type = type; 01100 x->flags = flags; 01101 x->get = mget?(method)mget:(method)jit_attr_offset_array_get; 01102 x->set = mset?(method)mset:(method)jit_attr_offset_array_set; 01103 x->filterget = NULL; 01104 x->filterset = NULL; 01105 x->reserved = NULL; 01106 x->offset = offset; 01107 x->size = size; 01108 x->offsetcount = offsetcount; 01109 } 01110 01111 return (t_jit_object *)x; 01112 } 01113 01114 t_jit_err jit_attr_offset_array_free(t_jit_attr_offset_array *x) 01115 { 01116 if (x->filterget) jit_object_free(x->filterget); 01117 if (x->filterset) jit_object_free(x->filterset); 01118 return JIT_ERR_NONE; 01119 } 01120 01121 t_jit_attr_offset_array *jit_attr_offset_array_clone(t_jit_attr_offset_array *x) 01122 { 01123 t_jit_attr_offset_array *clone; 01124 01125 clone = (t_jit_attr_offset_array *)object_clone_generic((t_object *)x); 01126 if (x&&clone) 01127 { 01128 if (x->filterget) 01129 clone->filterget = object_clone((t_object *)x->filterget); 01130 if (x->filterset) 01131 clone->filterset = object_clone((t_object *)x->filterset); 01132 } 01133 return clone; 01134 } 01135 01136 t_jit_err jit_attr_offset_array_get(void *parent, t_jit_attr_offset_array *x, long *ac, t_atom **av) 01137 { 01138 long i; 01139 01140 if (x) { 01141 if ((*ac)&&(*av)) { 01142 //memory passed in, use it 01143 if (x->offsetcount) *ac = MIN(*ac,*((long *)(((char *)parent)+x->offsetcount))); 01144 else *ac = MIN(*ac,x->size); 01145 } else { 01146 //otherwise allocate memory 01147 if (x->offsetcount) *ac = *((long *)(((char *)parent)+x->offsetcount)); 01148 else *ac = x->size; 01149 if (!(*av = jit_getbytes(sizeof(t_atom)*(*ac)))) { 01150 *ac = 0; 01151 return JIT_ERR_OUT_OF_MEM; 01152 } 01153 } 01154 for (i=0;i<*ac;i++) { 01155 if (x->type==_jit_sym_char) 01156 jit_atom_setlong((*av)+i,((uchar *)(((char *)parent)+x->offset))[i]); 01157 else if (x->type==_jit_sym_long) 01158 jit_atom_setlong((*av)+i,((long *)(((char *)parent)+x->offset))[i]); 01159 else if (x->type==_jit_sym_float32) 01160 jit_atom_setfloat((*av)+i,((float *)(((char *)parent)+x->offset))[i]); 01161 else if (x->type==_jit_sym_float64) 01162 jit_atom_setfloat((*av)+i,((double *)(((char *)parent)+x->offset))[i]); 01163 else if (x->type==_jit_sym_symbol) 01164 jit_atom_setsym((*av)+i,((t_symbol **)(((char *)parent)+x->offset))[i]); 01165 else if (x->type==_jit_sym_object) 01166 jit_atom_setobj((*av)+i,((void **)(((char *)parent)+x->offset))[i]); 01167 else if (x->type==_jit_sym_pointer) 01168 jit_atom_setobj((*av)+i,((void **)(((char *)parent)+x->offset))[i]); 01169 else if (x->type==_jit_sym_atom) 01170 *((*av)+i) = ((t_atom *)(((char *)parent)+x->offset))[i]; 01171 else 01172 jit_atom_setlong((*av)+i,0); 01173 } 01174 return JIT_ERR_NONE; 01175 } 01176 return JIT_ERR_INVALID_PTR; 01177 } 01178 01179 t_jit_err jit_attr_offset_array_set(void *parent, t_jit_attr_offset_array *x, long ac, t_atom *av) 01180 { 01181 long i,c; 01182 if (x) { 01183 c = MIN(ac,x->size); 01184 for (i=0;i<c;i++) { 01185 if (x->type==_jit_sym_char) 01186 ((uchar *)(((char *)parent)+x->offset))[i] = jit_atom_getlong(av+i); 01187 else if (x->type==_jit_sym_long) 01188 ((long *)(((char *)parent)+x->offset))[i] = jit_atom_getlong(av+i); 01189 else if (x->type==_jit_sym_float32) 01190 ((float *)(((char *)parent)+x->offset))[i] = jit_atom_getfloat(av+i); 01191 else if (x->type==_jit_sym_float64) 01192 ((double *)(((char *)parent)+x->offset))[i] = jit_atom_getfloat(av+i); 01193 else if (x->type==_jit_sym_symbol) 01194 ((t_symbol **)(((char *)parent)+x->offset))[i] = jit_atom_getsym(av+i); 01195 else if (x->type==_jit_sym_object) 01196 ((void **)(((char *)parent)+x->offset))[i] = jit_atom_getobj(av+i); 01197 else if (x->type==_jit_sym_pointer) 01198 ((void **)(((char *)parent)+x->offset))[i] = jit_atom_getobj(av+i); 01199 else if (x->type==_jit_sym_atom) 01200 ((t_atom *)(((char *)parent)+x->offset))[i] = *(av+i); 01201 } 01202 if (x->offsetcount) { 01203 *((long *)(((char *)parent)+x->offsetcount)) = c; 01204 } else { //fixed size array, set other elements to zero? 01205 if (c<x->size) { 01206 for (i=c;i<x->size;i++) { 01207 if (x->type==_jit_sym_char) 01208 ((uchar *)(((char *)parent)+x->offset))[i] = 0; 01209 else if (x->type==_jit_sym_long) 01210 ((long *)(((char *)parent)+x->offset))[i] = 0; 01211 else if (x->type==_jit_sym_float32) 01212 ((float *)(((char *)parent)+x->offset))[i] = 0; 01213 else if (x->type==_jit_sym_float64) 01214 ((double *)(((char *)parent)+x->offset))[i] = 0; 01215 else if (x->type==_jit_sym_symbol) 01216 ((t_symbol **)(((char *)parent)+x->offset))[i] = 0; 01217 else if (x->type==_jit_sym_object) 01218 ((void **)(((char *)parent)+x->offset))[i] = 0; 01219 else if (x->type==_jit_sym_pointer) 01220 ((void **)(((char *)parent)+x->offset))[i] = 0; 01221 //nothing for fixed atom arrays??? 01222 } 01223 } 01224 } 01225 return JIT_ERR_NONE; 01226 } 01227 return JIT_ERR_INVALID_PTR; 01228 } 01229 01230 t_jit_err jit_attr_offset_array_offsetcount(t_jit_attr_offset_array *x, long offsetcount) 01231 { 01232 if (x) { 01233 x->offsetcount=offsetcount; 01234 return JIT_ERR_NONE; 01235 } 01236 return JIT_ERR_INVALID_PTR; 01237 } 01238 01239 long jit_attr_offset_array_getoffsetcount(t_jit_attr_offset_array *x) 01240 { 01241 return x?x->offsetcount:0; 01242 } 01243 01244 t_jit_err jit_attr_offset_array_size(t_jit_attr_offset_array *x, long size) 01245 { 01246 if (x) { 01247 x->size=size; 01248 return JIT_ERR_NONE; 01249 } 01250 return JIT_ERR_INVALID_PTR; 01251 } 01252 01253 long jit_attr_offset_array_getsize(t_jit_attr_offset_array *x) 01254 { 01255 return x?x->size:0; 01256 } 01257 01258 #pragma mark - 01259 // -------------------------------------------------------------------------------- 01260 // 01261 01262 t_jit_err jit_attr_filter_clip_init(void) 01263 { 01264 long attrflags; 01265 void *attr; 01266 01267 _jit_attr_filter_clip_class = jit_class_new("jit_attr_filter_clip",(method)jit_attr_filter_clip_new, 01268 (method)jit_attr_filter_clip_free,sizeof(t_jit_attr_filter_clip),A_CANT,0L); //A_CANT = untyped 01269 01270 jit_class_addmethod(_jit_attr_filter_clip_class, (method)jit_attr_filter_clip_filter, "filter", A_CANT, 0L); 01271 01272 //add attributes 01273 attrflags = 0; 01274 attr = jit_object_new(_jit_sym_jit_attr_offset,"type",_jit_sym_symbol,attrflags, 01275 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,type)); 01276 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01277 attr = jit_object_new(_jit_sym_jit_attr_offset,"scale",_jit_sym_float64,attrflags, 01278 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,scale)); 01279 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01280 attr = jit_object_new(_jit_sym_jit_attr_offset,"min",_jit_sym_float64,attrflags, 01281 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,min)); 01282 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01283 attr = jit_object_new(_jit_sym_jit_attr_offset,"max",_jit_sym_float64,attrflags, 01284 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,max)); 01285 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01286 attr = jit_object_new(_jit_sym_jit_attr_offset,"usescale",_jit_sym_char,attrflags, 01287 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,usescale)); 01288 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01289 attr = jit_object_new(_jit_sym_jit_attr_offset,"usemin",_jit_sym_char,attrflags, 01290 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,usemin)); 01291 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01292 attr = jit_object_new(_jit_sym_jit_attr_offset,"usemax",_jit_sym_char,attrflags, 01293 (method)0L,(method)0L,calcoffset(t_jit_attr_filter_clip,usemax)); 01294 jit_class_addattr(_jit_attr_filter_clip_class,attr); 01295 01296 jit_class_register(_jit_attr_filter_clip_class); 01297 01298 return JIT_ERR_NONE; 01299 } 01300 01301 /** 01302 * Constructs instance of t_jit_attr_filter_clip. 01303 * 01304 * @ingroup attrmod 01305 * 01306 * @return t_jit_attr_filter_clip object pointer 01307 * 01308 * @warning This function is not exported, but is provided 01309 * for reference when calling via jit_object_new. 01310 */ 01311 t_jit_object *jit_attr_filter_clip_new(void) 01312 { 01313 t_jit_attr_filter_clip *x; 01314 01315 if (x = (t_jit_attr_filter_clip *)jit_object_alloc(_jit_attr_filter_clip_class)) { 01316 x->type = _jit_sym_float64; 01317 x->min = 0.; 01318 x->max = 1.; 01319 x->scale = 1.; 01320 x->usemin = 1; 01321 x->usemax = 1; 01322 x->usescale = 0; 01323 } 01324 01325 return (t_jit_object *)x; 01326 } 01327 01328 t_jit_err jit_attr_filter_clip_free(t_jit_attr_filter_clip *x) 01329 { 01330 return JIT_ERR_NONE; 01331 } 01332 01333 t_jit_err jit_attr_filter_clip_filter(t_jit_attr_filter_clip *x, t_symbol *s, long ac, t_atom *av, void *parent, void *attr) 01334 { 01335 long i; 01336 double f; 01337 01338 if (x) { 01339 for (i=0;i<ac;i++) { 01340 if (x->type==_jit_sym_char) { 01341 f=jit_atom_getfloat(av+i); 01342 if (x->usescale) f*=x->scale; 01343 if (x->usemin&&f<x->min) f=x->min; 01344 if (x->usemax&&f>x->max) f=x->max; 01345 jit_atom_setlong(av+i,f); 01346 } else if (x->type==_jit_sym_long) { 01347 f=jit_atom_getfloat(av+i); 01348 if (x->usescale) f*=x->scale; 01349 if (x->usemin&&f<x->min) f=x->min; 01350 if (x->usemax&&f>x->max) f=x->max; 01351 jit_atom_setlong(av+i,f); 01352 } else if (x->type==_jit_sym_float32) { 01353 f=jit_atom_getfloat(av+i); 01354 if (x->usescale) f*=x->scale; 01355 if (x->usemin&&f<x->min) f=x->min; 01356 if (x->usemax&&f>x->max) f=x->max; 01357 jit_atom_setfloat(av+i,f); 01358 } else if (x->type==_jit_sym_float64) { 01359 f=jit_atom_getfloat(av+i); 01360 if (x->usescale) f*=x->scale; 01361 if (x->usemin&&f<x->min) f=x->min; 01362 if (x->usemax&&f>x->max) f=x->max; 01363 jit_atom_setfloat(av+i,f); 01364 } 01365 } 01366 return JIT_ERR_NONE; 01367 } 01368 return JIT_ERR_INVALID_PTR; 01369 } 01370 01371 01372 #pragma mark - 01373 // -------------------------------------------------------------------------------- 01374 // 01375 01376 t_jit_err jit_attr_filter_proc_init(void) 01377 { 01378 long attrflags; 01379 void *attr; 01380 01381 _jit_attr_filter_proc_class = jit_class_new("jit_attr_filter_proc",(method)jit_attr_filter_proc_new, 01382 (method)jit_attr_filter_proc_free,sizeof(t_jit_attr_filter_proc),A_CANT,0L); //A_CANT = untyped 01383 01384 jit_class_addmethod(_jit_attr_filter_proc_class, (method)jit_attr_filter_proc_filter, "filter", A_CANT, 0L); 01385 jit_class_addmethod(_jit_attr_filter_proc_class, (method)jit_attr_filter_proc_setproc, "setproc", A_CANT, 0L); 01386 01387 jit_class_register(_jit_attr_filter_proc_class); 01388 01389 return JIT_ERR_NONE; 01390 } 01391 01392 /** 01393 * Constructs instance of t_jit_attr_filter_proc. 01394 * 01395 * @ingroup attrmod 01396 * 01397 * @param proc filter procedure 01398 * 01399 * @return t_jit_attr_filter_clip object pointer 01400 * 01401 * @warning This function is not exported, but is provided 01402 * for reference when calling via jit_object_new. 01403 */ 01404 t_jit_object *jit_attr_filter_proc_new(method proc) 01405 { 01406 t_jit_attr_filter_proc *x; 01407 01408 if (x = (t_jit_attr_filter_proc *)jit_object_alloc(_jit_attr_filter_proc_class)) { 01409 x->proc = proc; 01410 } 01411 01412 return (t_jit_object *)x; 01413 } 01414 01415 t_jit_err jit_attr_filter_proc_free(t_jit_attr_filter_proc *x) 01416 { 01417 return JIT_ERR_NONE; 01418 } 01419 01420 t_jit_err jit_attr_filter_proc_filter(t_jit_attr_filter_proc *x, t_symbol *s, long ac, t_atom *av, void *parent, void *attr) 01421 { 01422 01423 if (x&&x->proc&&parent&&attr) { 01424 return (t_jit_err) (x->proc)(parent,attr,ac,av); 01425 } 01426 return JIT_ERR_INVALID_PTR; 01427 } 01428 01429 t_jit_err jit_attr_filter_proc_setproc(t_jit_attr_filter_proc *x, method proc) 01430 { 01431 x->proc = proc; 01432 01433 return JIT_ERR_NONE; 01434 }
Copyright © 2008, Cycling '74