Max 5 API Reference
00001 /* 00002 jit.mop.c 00003 00004 Copyright 2001-2005 - Cycling '74 00005 Joshua Kit Clayton jkc@cycling74.com 00006 00007 */ 00008 00009 #include "jit.common.h" 00010 00011 /** 00012 * @defgroup mopmod MOP Module 00013 @ingroup jitter 00014 */ 00015 00016 #define JIT_MATRIX_MAX_TYPES 16 //for future use 00017 #define JIT_MOP_SIZE_VARIABLE -1 00018 #define JIT_MOP_INPUT_RESAMP 0 00019 #define JIT_MOP_INPUT_RESIZE 1 00020 #define JIT_MOP_INPUT_TRUNC 2 00021 00022 void *_jit_mop_io_class; 00023 void *_jit_mop_class; 00024 00025 /** 00026 * t_jit_mop_io object struct. 00027 * 00028 * @ingroup mopmod 00029 * 00030 * @warning This struct should not be accessed directly, 00031 * but is provided for reference when calling 00032 * Jitter attribute functions. 00033 */ 00034 typedef struct _jit_mop_io 00035 { 00036 t_jit_object ob; ///< standard object header 00037 void *special; ///< special data pointer for use by wrappers of various kinds (e.g. max wrapper) 00038 t_symbol *ioname; ///< "ioname" attribute 00039 t_symbol *matrixname; ///< "matrixname" attribute 00040 void *matrix; ///< internal matrix, accessed via methods (unused in class template MOP) 00041 t_symbol *types[JIT_MATRIX_MAX_TYPES]; ///< "types" attribute 00042 long mindim[JIT_MATRIX_MAX_DIMCOUNT]; ///< "mindim" attribute 00043 long maxdim[JIT_MATRIX_MAX_DIMCOUNT]; ///< "maxdim" attribute 00044 long typescount; ///< relevant to "types" attribute 00045 long mindimcount; ///< "mindimcount" attribute 00046 long maxdimcount; ///< "maxdimcount" attribute 00047 long minplanecount; ///< "minplanecount" attribute 00048 long maxplanecount; ///< "maxplanecount" attribute 00049 //flags 00050 char typelink; ///< "typelink" attribute 00051 char dimlink; ///< "dimlink" attribute 00052 char planelink; ///< "planelink" attribute 00053 method ioproc; ///< I/O procedure, accessed via methods 00054 } t_jit_mop_io; 00055 00056 /** 00057 * t_jit_mop object struct. 00058 * 00059 * @ingroup mopmod 00060 * 00061 * @warning This struct should not be accessed directly, 00062 * but is provided for reference when calling 00063 * Jitter attribute functions. 00064 */ 00065 typedef struct _jit_mop 00066 { 00067 t_jit_object ob; ///< standard object header 00068 void *special; ///< special data pointer for use by wrappers of various kinds (e.g. max wrapper) 00069 long inputcount; ///< "inputcount" attribute 00070 long outputcount; ///< "inputcount" attribute 00071 t_jit_linklist *inputlist; ///< linked list of inputs, accessed via methods 00072 t_jit_linklist *outputlist; ///< linked list of inputs, accessed via methods 00073 //flags 00074 char caninplace; ///< deprecated 00075 char adapt; ///< "adapt" attribute 00076 char outputmode; ///< "outputmode" attribute 00077 } t_jit_mop; 00078 00079 //the first input is different than other inputs since 00080 //it doesn't store matrices, only processes them 00081 00082 t_jit_object *jit_mop_io_new(void); 00083 t_jit_object *jit_mop_io_newcopy(t_jit_mop_io *x); 00084 t_jit_err jit_mop_io_free(t_jit_mop *x); 00085 t_jit_err jit_mop_io_restrict_type(t_jit_mop_io *x, t_jit_matrix_info *info); 00086 t_jit_err jit_mop_io_restrict_planecount(t_jit_mop_io *x, t_jit_matrix_info *info); 00087 t_jit_err jit_mop_io_restrict_dim(t_jit_mop_io *x, t_jit_matrix_info *info); 00088 t_jit_err jit_mop_io_special(t_jit_mop_io *x, void *special); 00089 void *jit_mop_io_getspecial(t_jit_mop_io *x); 00090 t_jit_err jit_mop_io_matrix(t_jit_mop_io *x, void *m); 00091 void *jit_mop_io_getmatrix(t_jit_mop_io *x); 00092 t_jit_err jit_mop_io_ioproc(t_jit_mop_io *x, method ioproc); 00093 method jit_mop_io_getioproc(t_jit_mop_io *x); 00094 void *jit_mop_io_decorator(t_jit_mop_io *x, t_symbol *s); 00095 00096 t_jit_object *jit_mop_new(long inputcount, long outputcount); 00097 t_jit_object *jit_mop_newcopy(t_jit_mop *x); 00098 void *jit_mop_getinput(t_jit_mop *x, long i); 00099 void *jit_mop_getoutput(t_jit_mop *x, long i); 00100 void *jit_mop_getinputlist(t_jit_mop *x); 00101 void *jit_mop_getoutputlist(t_jit_mop *x); 00102 t_jit_err jit_mop_free(t_jit_mop *x); 00103 t_jit_err jit_mop_matrix_calc(t_jit_mop *x, void *o); 00104 t_jit_err jit_mop_special(t_jit_mop *x, void *special); 00105 void *jit_mop_getspecial(t_jit_mop *x); 00106 t_jit_err jit_mop_addinputs(t_jit_mop *x, long c); 00107 t_jit_err jit_mop_addoutputs(t_jit_mop *x, long c); 00108 00109 static t_symbol *ps_resamp,*ps_adapt,*ps_trunc,*ps_trunc_zero,*ps_custom; 00110 00111 t_jit_err jit_mop_init(void) 00112 { 00113 long attrflags; 00114 void *attr; 00115 00116 //_jit_mop_io_class 00117 _jit_mop_io_class = jit_class_new("jit_mop_io",(method)jit_mop_io_new,(method)jit_mop_io_free, 00118 sizeof(t_jit_mop_io),A_CANT,0L); //A_CANT = untyped 00119 00120 //add methods 00121 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_newcopy, "newcopy", A_CANT, 0L); 00122 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_restrict_type, "restrict_type", A_CANT, 0L); 00123 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_restrict_planecount, "restrict_planecount", A_CANT, 0L); 00124 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_restrict_dim, "restrict_dim", A_CANT, 0L); 00125 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_special, "special", A_CANT, 0L); 00126 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_getspecial, "getspecial", A_CANT, 0L); 00127 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_decorator, "decorator", A_CANT, 0L); 00128 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_matrix, "matrix", A_CANT, 0L); 00129 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_getmatrix, "getmatrix", A_CANT, 0L); 00130 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_ioproc, "ioproc", A_CANT, 0L); 00131 jit_class_addmethod(_jit_mop_io_class, (method)jit_mop_io_getioproc, "getioproc", A_CANT, 0L); 00132 00133 //add attributes 00134 attrflags = 0; 00135 attr = jit_object_new(_jit_sym_jit_attr_offset_array,"types",_jit_sym_symbol,JIT_MATRIX_MAX_TYPES,attrflags, 00136 (method)0L,(method)0L,calcoffset(t_jit_mop_io,typescount),calcoffset(t_jit_mop_io,types)); 00137 jit_class_addattr(_jit_mop_io_class,attr); 00138 attr = jit_object_new(_jit_sym_jit_attr_offset_array,"mindim",_jit_sym_long,JIT_MATRIX_MAX_DIMCOUNT,attrflags, 00139 (method)0L,(method)0L,calcoffset(t_jit_mop_io,mindimcount),calcoffset(t_jit_mop_io,mindim)); 00140 jit_class_addattr(_jit_mop_io_class,attr); 00141 attr = jit_object_new(_jit_sym_jit_attr_offset_array,"maxdim",_jit_sym_long,JIT_MATRIX_MAX_DIMCOUNT,attrflags, 00142 (method)0L,(method)0L,calcoffset(t_jit_mop_io,maxdimcount),calcoffset(t_jit_mop_io,maxdim)); 00143 jit_class_addattr(_jit_mop_io_class,attr); 00144 attr = jit_object_new(_jit_sym_jit_attr_offset,"mindimcount",_jit_sym_long,attrflags, 00145 (method)0L,(method)0L,calcoffset(t_jit_mop_io,mindimcount)); 00146 jit_class_addattr(_jit_mop_io_class,attr); 00147 attr = jit_object_new(_jit_sym_jit_attr_offset,"maxdimcount",_jit_sym_long,attrflags, 00148 (method)0L,(method)0L,calcoffset(t_jit_mop_io,maxdimcount)); 00149 jit_class_addattr(_jit_mop_io_class,attr); 00150 attr = jit_object_new(_jit_sym_jit_attr_offset,"minplanecount",_jit_sym_long,attrflags, 00151 (method)0L,(method)0L,calcoffset(t_jit_mop_io,minplanecount)); 00152 jit_class_addattr(_jit_mop_io_class,attr); 00153 attr = jit_object_new(_jit_sym_jit_attr_offset,"maxplanecount",_jit_sym_long,attrflags, 00154 (method)0L,(method)0L,calcoffset(t_jit_mop_io,maxplanecount)); 00155 jit_class_addattr(_jit_mop_io_class,attr); 00156 attr = jit_object_new(_jit_sym_jit_attr_offset,"typelink",_jit_sym_char,attrflags, 00157 (method)0L,(method)0L,calcoffset(t_jit_mop_io,typelink)); 00158 jit_class_addattr(_jit_mop_io_class,attr); 00159 attr = jit_object_new(_jit_sym_jit_attr_offset,"dimlink",_jit_sym_char,attrflags, 00160 (method)0L,(method)0L,calcoffset(t_jit_mop_io,dimlink)); 00161 jit_class_addattr(_jit_mop_io_class,attr); 00162 attr = jit_object_new(_jit_sym_jit_attr_offset,"planelink",_jit_sym_char,attrflags, 00163 (method)0L,(method)0L,calcoffset(t_jit_mop_io,planelink)); 00164 jit_class_addattr(_jit_mop_io_class,attr); 00165 attr = jit_object_new(_jit_sym_jit_attr_offset,"ioname",_jit_sym_symbol,attrflags, 00166 (method)0L,(method)0L,calcoffset(t_jit_mop_io,ioname)); 00167 jit_class_addattr(_jit_mop_io_class,attr); 00168 attr = jit_object_new(_jit_sym_jit_attr_offset,"matrixname",_jit_sym_symbol,attrflags, 00169 (method)0L,(method)0L,calcoffset(t_jit_mop_io,matrixname)); 00170 jit_class_addattr(_jit_mop_io_class,attr); 00171 00172 jit_class_register(_jit_mop_io_class); 00173 00174 //_jit_mop_class 00175 _jit_mop_class = jit_class_new("jit_mop",(method)jit_mop_new,(method)jit_mop_free, 00176 sizeof(t_jit_mop),A_CANT,0L); //A_CANT = untyped 00177 00178 jit_class_addmethod(_jit_mop_class, (method)jit_mop_matrix_calc, "matrix_calc", A_CANT, 0L); 00179 jit_class_addmethod(_jit_mop_class, (method)jit_mop_getinput, "getinput", A_CANT, 0L); 00180 jit_class_addmethod(_jit_mop_class, (method)jit_mop_getoutput, "getoutput", A_CANT, 0L); 00181 jit_class_addmethod(_jit_mop_class, (method)jit_mop_getinputlist, "getinputlist", A_CANT, 0L); 00182 jit_class_addmethod(_jit_mop_class, (method)jit_mop_getoutputlist, "getoutputlist", A_CANT, 0L); 00183 jit_class_addmethod(_jit_mop_class, (method)jit_mop_special, "special", A_CANT, 0L); 00184 jit_class_addmethod(_jit_mop_class, (method)jit_mop_getspecial, "getspecial", A_CANT, 0L); 00185 jit_class_addmethod(_jit_mop_class, (method)jit_mop_newcopy, "newcopy", A_CANT, 0L); 00186 jit_class_addmethod(_jit_mop_class, (method)jit_mop_addinputs, "addinputs", A_CANT, 0L); 00187 jit_class_addmethod(_jit_mop_class, (method)jit_mop_addoutputs, "addoutputs", A_CANT, 0L); 00188 //add attribute s 00189 attrflags = 0; 00190 attr = jit_object_new(_jit_sym_jit_attr_offset,"inputcount",_jit_sym_long,attrflags, 00191 (method)0L,(method)0L,calcoffset(t_jit_mop,inputcount)); 00192 jit_class_addattr(_jit_mop_class,attr); 00193 attr = jit_object_new(_jit_sym_jit_attr_offset,"outputcount",_jit_sym_long,attrflags, 00194 (method)0L,(method)0L,calcoffset(t_jit_mop,outputcount)); 00195 jit_class_addattr(_jit_mop_class,attr); 00196 attr = jit_object_new(_jit_sym_jit_attr_offset,"caninplace",_jit_sym_char,attrflags, 00197 (method)0L,(method)0L,calcoffset(t_jit_mop,caninplace)); 00198 jit_class_addattr(_jit_mop_class,attr); 00199 attr = jit_object_new(_jit_sym_jit_attr_offset,"adapt",_jit_sym_char,attrflags, 00200 (method)0L,(method)0L,calcoffset(t_jit_mop,adapt)); 00201 jit_class_addattr(_jit_mop_class,attr); 00202 attr = jit_object_new(_jit_sym_jit_attr_offset,"outputmode",_jit_sym_char,attrflags, 00203 (method)0L,(method)0L,calcoffset(t_jit_mop,outputmode)); 00204 jit_class_addattr(_jit_mop_class,attr); 00205 00206 jit_class_register(_jit_mop_class); 00207 ps_resamp = gensym("resamp"); 00208 ps_adapt = gensym("adapt"); 00209 00210 ps_trunc = gensym("trunc"); 00211 ps_trunc_zero = gensym("trunc_zero"); 00212 ps_custom = gensym("custom"); 00213 00214 return JIT_ERR_NONE; 00215 } 00216 00217 /** 00218 * Constructs instance of t_jit_mop_io. 00219 * 00220 * @ingroup mopmod 00221 * 00222 * @return t_jit_mop_io object pointer 00223 * 00224 * @warning This function is not exported, but is provided 00225 * for reference when calling via jit_object_new. 00226 */ 00227 t_jit_object *jit_mop_io_new(void) 00228 { 00229 t_jit_mop_io *x; 00230 long i=0; 00231 00232 if (x = (t_jit_mop_io *)jit_object_alloc(_jit_mop_io_class)) { 00233 x->special = NULL; 00234 x->ioname = gensym("io"); 00235 x->matrixname = NULL; 00236 x->matrix = NULL; 00237 x->types[0] = _jit_sym_char; 00238 x->types[1] = _jit_sym_long; 00239 x->types[2] = _jit_sym_float32; 00240 x->types[3] = _jit_sym_float64; 00241 for (i=4;i<JIT_MATRIX_MAX_TYPES;i++) { 00242 x->types[i] = NULL; 00243 } 00244 for (i=0;i<JIT_MATRIX_MAX_DIMCOUNT;i++) { 00245 x->mindim[i] = 0; 00246 x->maxdim[i] = 0; 00247 } 00248 x->minplanecount = 1; 00249 x->maxplanecount = JIT_MATRIX_MAX_PLANECOUNT; 00250 x->mindimcount = 1; 00251 x->maxdimcount = JIT_MATRIX_MAX_DIMCOUNT; 00252 x->typescount = 4; 00253 x->typelink = 1; 00254 x->dimlink = 1; 00255 x->planelink = 1; 00256 x->ioproc = NULL; 00257 } 00258 00259 return (t_jit_object *)x; 00260 } 00261 00262 /** 00263 * Constructs instance of t_jit_mop_io, copying settings of input. 00264 * 00265 * @ingroup mopmod 00266 * 00267 * @param x t_jit_mop_io object pointer 00268 * @return t_jit_mop_io object pointer 00269 * 00270 * @warning This function is not exported, but is provided 00271 * for reference when calling via jit_object_method 00272 * on an intance of t_jit_mop_io. 00273 */ 00274 t_jit_object *jit_mop_io_newcopy(t_jit_mop_io *x) 00275 { 00276 t_jit_mop_io *y; 00277 long i=0; 00278 00279 if (y = (t_jit_mop_io *)jit_object_alloc(_jit_mop_io_class)) { 00280 *y = *x; //should be fine in this instance 00281 } 00282 00283 return (t_jit_object *)y; 00284 } 00285 00286 /** 00287 * Frees instance of t_jit_mop_io. 00288 * 00289 * @ingroup mopmod 00290 * 00291 * @param x t_jit_mop_io object pointer 00292 * @return t_jit_err error code 00293 * 00294 * @warning Use jit_object_free instead. 00295 */ 00296 t_jit_err jit_mop_io_free(t_jit_mop *x) 00297 { 00298 //nada 00299 return JIT_ERR_NONE; 00300 } 00301 00302 /** 00303 * Restricts the type specified in t_jit_matrix_info struct to those permitted by 00304 * t_jit_mop_io instance, overwriting value in t_jit_matrix_info struct. 00305 * 00306 * @ingroup mopmod 00307 * 00308 * @param x t_jit_mop_io object pointer 00309 * @param info t_jit_matrix_info pointer 00310 * 00311 * @return t_jit_err error code 00312 * 00313 * @warning This function is not exported, but is provided 00314 * for reference when calling via jit_object_method 00315 * on an intance of t_jit_mop_io. 00316 */ 00317 t_jit_err jit_mop_io_restrict_type(t_jit_mop_io *x, t_jit_matrix_info *info) 00318 { 00319 long i; 00320 00321 if (x&&info) { 00322 for (i=0;i<x->typescount;i++) { 00323 if (info->type==x->types[i]) 00324 return JIT_ERR_NONE; 00325 } 00326 if (x->matrix) 00327 info->type = jit_attr_getsym(x->matrix,_jit_sym_type); 00328 else 00329 info->type = x->types[0]; 00330 00331 return JIT_ERR_GENERIC; 00332 } 00333 return JIT_ERR_INVALID_PTR; 00334 } 00335 00336 /** 00337 * Restricts the planecount specified in t_jit_matrix_info struct to those permitted by 00338 * t_jit_mop_io instance, overwriting value in t_jit_matrix_info struct. 00339 * 00340 * @ingroup mopmod 00341 * 00342 * @param x t_jit_mop_io object pointer 00343 * @param info t_jit_matrix_info pointer 00344 * 00345 * @return t_jit_err error code 00346 * 00347 * @warning This function is not exported, but is provided 00348 * for reference when calling via jit_object_method 00349 * on an intance of t_jit_mop_io. 00350 */ 00351 t_jit_err jit_mop_io_restrict_planecount(t_jit_mop_io *x, t_jit_matrix_info *info) 00352 { 00353 00354 if (x&&info) { 00355 if ((info->planecount>=x->minplanecount) && 00356 (info->planecount<=x->maxplanecount)) 00357 { 00358 return JIT_ERR_NONE; 00359 } 00360 CLIP(info->planecount,x->minplanecount,x->maxplanecount); 00361 return JIT_ERR_GENERIC; 00362 } 00363 return JIT_ERR_INVALID_PTR; 00364 } 00365 00366 /** 00367 * Restricts the dimension sizes specified in t_jit_matrix_info struct to those permitted by 00368 * t_jit_mop_io instance, overwriting value in t_jit_matrix_info struct. 00369 * 00370 * @ingroup mopmod 00371 * 00372 * @param x t_jit_mop_io object pointer 00373 * @param info t_jit_matrix_info pointer 00374 * 00375 * @return t_jit_err error code 00376 * 00377 * @warning This function is not exported, but is provided 00378 * for reference when calling via jit_object_method 00379 * on an intance of t_jit_mop_io. 00380 */ 00381 t_jit_err jit_mop_io_restrict_dim(t_jit_mop_io *x, t_jit_matrix_info *info) 00382 { 00383 long i; 00384 t_jit_err err=JIT_ERR_NONE; 00385 00386 if (x&&info) { 00387 if (x->mindimcount&&(info->dimcount<x->mindimcount)) { 00388 for (i=MAX(info->dimcount,0);i<x->mindimcount;i++) 00389 info->dim[i] = 1; 00390 info->dimcount = x->mindimcount; 00391 err=JIT_ERR_GENERIC; 00392 } else if (x->maxdimcount&&(info->dimcount>x->maxdimcount)) { 00393 info->dimcount = x->maxdimcount; 00394 err=JIT_ERR_GENERIC; 00395 } 00396 for (i=0;i<JIT_MATRIX_MAX_DIMCOUNT;i++) { 00397 if (x->mindim[i]&&(info->dim[i]<x->mindim[i])) { 00398 info->dim[i] = x->mindim[i]; 00399 err=JIT_ERR_GENERIC; 00400 } else if (x->maxdim[i]&&(info->dim[i]>x->maxdim[i])) { 00401 info->dim[i] = x->maxdim[i]; 00402 err=JIT_ERR_GENERIC; 00403 } 00404 } 00405 return err; 00406 } 00407 return JIT_ERR_INVALID_PTR; 00408 } 00409 00410 t_jit_err jit_mop_io_special(t_jit_mop_io *x, void *special) 00411 { 00412 x->special = special; 00413 return JIT_ERR_NONE; 00414 } 00415 00416 void *jit_mop_io_getspecial(t_jit_mop_io *x) 00417 { 00418 return x->special; 00419 } 00420 00421 /** 00422 * Sets the internal matrix reference. 00423 * 00424 * @ingroup mopmod 00425 * 00426 * @param x t_jit_mop_io object pointer 00427 * @param m t_jit_matrix object pointer 00428 * 00429 * @return t_jit_err error code 00430 * 00431 * @warning This function is not exported, but is provided 00432 * for reference when calling via jit_object_method 00433 * on an intance of t_jit_mop_io. 00434 */ 00435 t_jit_err jit_mop_io_matrix(t_jit_mop_io *x, void *m) 00436 { 00437 x->matrix = m; 00438 return JIT_ERR_NONE; 00439 } 00440 00441 /** 00442 * Retrieves the internal matrix reference. 00443 * 00444 * @ingroup mopmod 00445 * 00446 * @param x t_jit_mop_io object pointer 00447 * 00448 * @return t_jit_matrix object pointer 00449 * 00450 * @warning This function is not exported, but is provided 00451 * for reference when calling via jit_object_method 00452 * on an intance of t_jit_mop_io. 00453 */ 00454 void *jit_mop_io_getmatrix(t_jit_mop_io *x) 00455 { 00456 return x->matrix; 00457 } 00458 00459 /** 00460 * Sets the I/O procedure used when handling incoming matrices. 00461 * 00462 * @ingroup mopmod 00463 * 00464 * @param x t_jit_mop_io object pointer 00465 * @param ioproc I/O procedure 00466 * 00467 * @return t_jit_err error code 00468 * 00469 * @warning This function is not exported, but is provided 00470 * for reference when calling via jit_object_method 00471 * on an intance of t_jit_mop_io. 00472 */ 00473 t_jit_err jit_mop_io_ioproc(t_jit_mop_io *x, method ioproc) 00474 { 00475 x->ioproc = ioproc; 00476 return JIT_ERR_NONE; 00477 } 00478 00479 /** 00480 * Retrieves the I/O procedure used when handling incoming matrices. 00481 * 00482 * @ingroup mopmod 00483 * 00484 * @param x t_jit_mop_io object pointer 00485 * 00486 * @return I/O procedure 00487 * 00488 * @warning This function is not exported, but is provided 00489 * for reference when calling via jit_object_method 00490 * on an intance of t_jit_mop_io. 00491 */ 00492 method jit_mop_io_getioproc(t_jit_mop_io *x) 00493 { 00494 return x->ioproc; 00495 } 00496 00497 void *jit_mop_io_decorator(t_jit_mop_io *x, t_symbol *s) 00498 { 00499 return (x)?x->matrix:NULL; 00500 } 00501 00502 #pragma mark - 00503 // -------------------------------------------------------------------------------- 00504 // 00505 00506 /** 00507 * Constructs instance of t_jit_mop. 00508 * 00509 * @ingroup mopmod 00510 * 00511 * @return t_jit_mop object pointer 00512 * 00513 * @warning This function is not exported, but is provided 00514 * for reference when calling via jit_object_new. 00515 */ 00516 t_jit_object *jit_mop_new(long inputcount, long outputcount) 00517 { 00518 t_jit_mop *x; 00519 void *o; 00520 long i; 00521 char tmpstr[64]; 00522 00523 if (x = (t_jit_mop *)jit_object_alloc(_jit_mop_class)) { 00524 x->special = NULL; 00525 x->inputcount = inputcount; 00526 x->outputcount = outputcount; 00527 x->inputlist = jit_object_new(gensym("jit_linklist")); 00528 x->outputlist = jit_object_new(gensym("jit_linklist")); 00529 x->caninplace = 1; 00530 x->adapt = 1; 00531 x->outputmode = 1; 00532 if ((!x->inputlist)||(!x->outputlist)) { 00533 jit_object_free(x); 00534 x=NULL; 00535 goto out; 00536 } 00537 i=1; 00538 while (inputcount-- > 0) { 00539 if (o = jit_object_new(gensym("jit_mop_io"))) { 00540 jit_object_method(x->inputlist,_jit_sym_append,o); 00541 if (i==1) { sprintf(tmpstr,"in"); i++; } 00542 else { sprintf(tmpstr,"in%d",i++); } 00543 jit_attr_setsym(o,gensym("ioname"),gensym(tmpstr)); 00544 } else { 00545 jit_object_free(x); 00546 x=NULL; 00547 goto out; 00548 } 00549 } 00550 i=1; 00551 while (outputcount-- > 0) { 00552 if (o = jit_object_new(gensym("jit_mop_io"))) { 00553 jit_object_method(x->outputlist,_jit_sym_append,o); 00554 if (i==1) { sprintf(tmpstr,"out"); i++; } 00555 else { sprintf(tmpstr,"out%d",i++); } 00556 jit_attr_setsym(o,gensym("ioname"),gensym(tmpstr)); 00557 } else { 00558 jit_object_free(x); 00559 x=NULL; 00560 goto out; 00561 } 00562 } 00563 } 00564 out: 00565 return (t_jit_object *)x; 00566 } 00567 00568 /** 00569 * Constructs instance of t_jit_mop, copying settings of input. 00570 * 00571 * @ingroup mopmod 00572 * 00573 * @param x t_jit_mop object pointer 00574 * @return t_jit_mop object pointer 00575 * 00576 * @warning This function is not exported, but is provided 00577 * for reference when calling via jit_object_method 00578 * on an intance of t_jit_mop. 00579 */ 00580 t_jit_object *jit_mop_newcopy(t_jit_mop *x) 00581 { 00582 t_jit_mop *y; 00583 void *o,*p; 00584 long inputcount,outputcount; 00585 long i=0; 00586 00587 if (y = (t_jit_mop *)jit_object_alloc(_jit_mop_class)) { 00588 *y = *x; 00589 y->inputlist = jit_object_new(gensym("jit_linklist")); 00590 y->outputlist = jit_object_new(gensym("jit_linklist")); 00591 inputcount = x->inputcount; 00592 outputcount = x->outputcount; 00593 i=1; 00594 while (inputcount-- > 0) { 00595 if (o=jit_object_method(x->inputlist,_jit_sym_getindex,i-1)) { 00596 p = jit_object_method(o,_jit_sym_newcopy); 00597 jit_object_method(y->inputlist,_jit_sym_append,p); 00598 } else { 00599 jit_object_free(y); 00600 y=NULL; 00601 goto out; 00602 } 00603 i++; 00604 } 00605 i=1; 00606 while (outputcount-- > 0) { 00607 if (o=jit_object_method(x->outputlist,_jit_sym_getindex,i-1)) { 00608 p = jit_object_method(o,_jit_sym_newcopy); 00609 jit_object_method(y->outputlist,_jit_sym_append,p); 00610 } else { 00611 jit_object_free(y); 00612 y=NULL; 00613 goto out; 00614 } 00615 i++; 00616 } 00617 } 00618 out: 00619 return (t_jit_object *)y; 00620 } 00621 00622 00623 /** 00624 * Retrieves input at input list index specified. 00625 * 00626 * @ingroup mopmod 00627 * 00628 * @param x t_jit_mop object pointer 00629 * @param i index 00630 * 00631 * @return t_jit_mop_io object pointer 00632 * 00633 * @warning This function is not exported, but is provided 00634 * for reference when calling via jit_object_method 00635 * on an intance of t_jit_mop. 00636 */ 00637 void *jit_mop_getinput(t_jit_mop *x, long i) 00638 { 00639 if (x&&x->inputlist&&i>=1) 00640 return jit_object_method(x->inputlist,_jit_sym_getindex,i-1); 00641 else 00642 return NULL; 00643 } 00644 00645 /** 00646 * Retrieves output at output list index specified. 00647 * 00648 * @ingroup mopmod 00649 * 00650 * @param x t_jit_mop object pointer 00651 * @param i index 00652 * 00653 * @return t_jit_mop_io object pointer 00654 * 00655 * @warning This function is not exported, but is provided 00656 * for reference when calling via jit_object_method 00657 * on an intance of t_jit_mop. 00658 */ 00659 void *jit_mop_getoutput(t_jit_mop *x, long i) 00660 { 00661 if (x&&x->outputlist&&i>=1) 00662 return jit_object_method(x->outputlist,_jit_sym_getindex,i-1); 00663 else 00664 return NULL; 00665 } 00666 00667 /** 00668 * Retrieves input list. 00669 * 00670 * @ingroup mopmod 00671 * 00672 * @param x t_jit_mop object pointer 00673 * 00674 * @return t_jit_linklist object pointer 00675 * 00676 * @warning This function is not exported, but is provided 00677 * for reference when calling via jit_object_method 00678 * on an intance of t_jit_mop. 00679 */ 00680 void *jit_mop_getinputlist(t_jit_mop *x) 00681 { 00682 if (x) 00683 return x->inputlist; 00684 else 00685 return NULL; 00686 } 00687 00688 /** 00689 * Retrieves output list. 00690 * 00691 * @ingroup mopmod 00692 * 00693 * @param x t_jit_mop object pointer 00694 * 00695 * @return t_jit_linklist object pointer 00696 * 00697 * @warning This function is not exported, but is provided 00698 * for reference when calling via jit_object_method 00699 * on an intance of t_jit_mop. 00700 */ 00701 void *jit_mop_getoutputlist(t_jit_mop *x) 00702 { 00703 if (x) 00704 return x->outputlist; 00705 else 00706 return NULL; 00707 } 00708 00709 00710 /** 00711 * Frees instance of t_jit_mop. 00712 * 00713 * @ingroup mopmod 00714 * 00715 * @param x t_jit_mop object pointer 00716 * @return t_jit_err error code 00717 * 00718 * @warning Use jit_object_free instead. 00719 */ 00720 t_jit_err jit_mop_free(t_jit_mop *x) 00721 { 00722 if (x->inputlist) jit_object_free(x->inputlist); 00723 if (x->outputlist) jit_object_free(x->outputlist); 00724 return JIT_ERR_NONE; 00725 } 00726 00727 t_jit_err jit_mop_special(t_jit_mop *x, void *special) 00728 { 00729 x->special = special; 00730 return JIT_ERR_NONE; 00731 } 00732 00733 void *jit_mop_getspecial(t_jit_mop *x) 00734 { 00735 return x->special; 00736 } 00737 00738 t_jit_err jit_mop_matrix_calc(t_jit_mop *x, void *o) 00739 { 00740 return (t_jit_err) jit_object_method(o,_jit_sym_matrix_calc,x->inputlist,x->outputlist); 00741 } 00742 00743 t_jit_err jit_mop_addinputs(t_jit_mop *x, long c) 00744 { 00745 long i; 00746 void *o; 00747 char tmpstr[256]; 00748 00749 if (x&&x->inputlist) { 00750 if (x->inputcount<0) { 00751 x->inputcount = c; 00752 i = 1; 00753 } else { 00754 x->inputcount += c; 00755 i = x->inputcount+1; 00756 } 00757 while (c-- > 0) { 00758 if (o = jit_object_new(gensym("jit_mop_io"))) { 00759 jit_object_method(x->inputlist,_jit_sym_append,o); 00760 if (i==1) { sprintf(tmpstr,"in"); i++; } 00761 else { sprintf(tmpstr,"in%d",i++); } 00762 jit_attr_setsym(o,gensym("ioname"),gensym(tmpstr)); 00763 } else { 00764 return JIT_ERR_OUT_OF_MEM; 00765 } 00766 } 00767 } 00768 return JIT_ERR_NONE; 00769 } 00770 00771 t_jit_err jit_mop_addoutputs(t_jit_mop *x, long c) 00772 { 00773 long i; 00774 void *o; 00775 char tmpstr[256]; 00776 00777 if (x&&x->outputlist) { 00778 if (x->outputcount<0) { 00779 x->outputcount = c; 00780 i = 1; 00781 } else { 00782 x->outputcount += c; 00783 i = x->outputcount+1; 00784 } 00785 while (c-- > 0) { 00786 if (o = jit_object_new(gensym("jit_mop_io"))) { 00787 jit_object_method(x->outputlist,_jit_sym_append,o); 00788 if (i==1) { sprintf(tmpstr,"out"); i++; } 00789 else { sprintf(tmpstr,"out%d",i++); } 00790 jit_attr_setsym(o,gensym("ioname"),gensym(tmpstr)); 00791 } else { 00792 return JIT_ERR_OUT_OF_MEM; 00793 } 00794 } 00795 } 00796 return JIT_ERR_NONE; 00797 } 00798 00799 #pragma mark - 00800 // -------------------------------------------------------------------------------- 00801 // utils 00802 00803 /** 00804 * Utility function to set the type attribute for all MOP inputs and outputs. 00805 * 00806 * @ingroup mopmod 00807 * 00808 * @param mop t_jit_mop object pointer 00809 * @param s type symbol 00810 * 00811 * @return t_jit_err error code 00812 * 00813 */ 00814 t_jit_err jit_mop_single_type(void *mop, t_symbol *s) 00815 { 00816 void *o; 00817 long i; 00818 t_atom a; 00819 t_jit_mop *x=mop; 00820 00821 if (x&&s) { 00822 jit_atom_setsym(&a,s); 00823 for (i=1;i<=x->inputcount;i++) { 00824 if (o=jit_object_method(x->inputlist,_jit_sym_getindex,i-1)) { 00825 jit_object_method(o,gensym("types"),1,&a); 00826 } 00827 } 00828 for (i=1;i<=x->outputcount;i++) { 00829 if (o=jit_object_method(x->outputlist,_jit_sym_getindex,i-1)) { 00830 jit_object_method(o,gensym("types"),1,&a); 00831 } 00832 } 00833 } 00834 return JIT_ERR_NONE; 00835 } 00836 00837 /** 00838 * Utility function to set the planecount attribute for all MOP inputs and outputs. 00839 * 00840 * @ingroup mopmod 00841 * 00842 * @param mop t_jit_mop object pointer 00843 * @param c planecount 00844 * 00845 * @return t_jit_err error code 00846 * 00847 */ 00848 t_jit_err jit_mop_single_planecount(void *mop, long c) 00849 { 00850 void *o; 00851 long i; 00852 t_jit_mop *x=mop; 00853 00854 if (x) { 00855 for (i=1;i<=x->inputcount;i++) { 00856 if (o=jit_object_method(x->inputlist,_jit_sym_getindex,i-1)) { 00857 jit_attr_setlong(o,gensym("minplanecount"),c); 00858 jit_attr_setlong(o,gensym("maxplanecount"),c); 00859 } 00860 } 00861 for (i=1;i<=x->outputcount;i++) { 00862 if (o=jit_object_method(x->outputlist,_jit_sym_getindex,i-1)) { 00863 jit_attr_setlong(o,gensym("minplanecount"),c); 00864 jit_attr_setlong(o,gensym("maxplanecount"),c); 00865 } 00866 } 00867 } 00868 return JIT_ERR_NONE; 00869 } 00870 00871 /** 00872 * Utility function to send the same method to all MOP inputs and outputs. 00873 * 00874 * @ingroup mopmod 00875 * 00876 * @param mop t_jit_mop object pointer 00877 * @param s method symbol 00878 * @param ... untyped arguments 00879 * 00880 * @return t_jit_err error code 00881 * 00882 */ 00883 t_jit_err jit_mop_methodall(void *mop, t_symbol *s, ...) 00884 { 00885 void *o; 00886 long i; 00887 t_jit_mop *x=mop; 00888 00889 if (x) { 00890 for (i=1;i<=x->inputcount;i++) { 00891 if (o=jit_object_method(x->inputlist,_jit_sym_getindex,i-1)) { 00892 jit_object_method(o,s,*((t_stack_splat *)(((char *)(&s))+4))); 00893 } 00894 } 00895 for (i=1;i<=x->outputcount;i++) { 00896 if (o=jit_object_method(x->outputlist,_jit_sym_getindex,i-1)) { 00897 jit_object_method(o,s,*((t_stack_splat *)(((char *)(&s))+4))); 00898 } 00899 } 00900 } 00901 return JIT_ERR_NONE; 00902 } 00903 00904 /** 00905 * Utility function to disable all linking attributes for a MOP input. 00906 * 00907 * @ingroup mopmod 00908 * 00909 * @param mop t_jit_mop object pointer 00910 * @param c input index 00911 * 00912 * @return t_jit_err error code 00913 * 00914 */ 00915 t_jit_err jit_mop_input_nolink(void *mop, long c) 00916 { 00917 void *o; 00918 t_jit_mop *x=mop; 00919 00920 if (x) { 00921 if (o=jit_object_method(x->inputlist,_jit_sym_getindex,c-1)) { 00922 jit_attr_setlong(o,gensym("typelink"),0); 00923 jit_attr_setlong(o,gensym("planelink"),0); 00924 jit_attr_setlong(o,gensym("dimlink"),0); 00925 } 00926 } 00927 return JIT_ERR_NONE; 00928 } 00929 00930 /** 00931 * Utility function to disable all linking attributes for a MOP output. 00932 * 00933 * @ingroup mopmod 00934 * 00935 * @param mop t_jit_mop object pointer 00936 * @param c output index 00937 * 00938 * @return t_jit_err error code 00939 * 00940 */ 00941 t_jit_err jit_mop_output_nolink(void *mop, long c) 00942 { 00943 void *o; 00944 t_jit_mop *x=mop; 00945 00946 if (x) { 00947 if (o=jit_object_method(x->outputlist,_jit_sym_getindex,c-1)) { 00948 jit_attr_setlong(o,gensym("typelink"),0); 00949 jit_attr_setlong(o,gensym("planelink"),0); 00950 jit_attr_setlong(o,gensym("dimlink"),0); 00951 } 00952 } 00953 return JIT_ERR_NONE; 00954 } 00955 00956 /** 00957 * MOP I/O procedure to copy and adapt to input. 00958 * 00959 * @ingroup mopmod 00960 * 00961 * @param mop t_jit_mop object pointer 00962 * @param mop_io t_jit_mop_io object pointer 00963 * @param matrix t_jit_matrix object pointer 00964 * 00965 * @return t_jit_err error code 00966 * 00967 * @code 00968 void *m; 00969 t_jit_matrix_info info; 00970 00971 if (matrix&&(m=jit_object_method(mop_io,_jit_sym_getmatrix))) { 00972 jit_object_method(matrix,_jit_sym_getinfo,&info); 00973 jit_object_method(mop_io,_jit_sym_restrict_type,&info); 00974 jit_object_method(mop_io,_jit_sym_restrict_dim,&info); 00975 jit_object_method(mop_io,_jit_sym_restrict_planecount,&info); 00976 jit_object_method(m,_jit_sym_setinfo,&info); 00977 jit_object_method(m,_jit_sym_frommatrix,matrix,NULL); 00978 } 00979 00980 return JIT_ERR_NONE; 00981 * @endcode 00982 * 00983 */ 00984 t_jit_err jit_mop_ioproc_copy_adapt(void *mop, void *mop_io, void *matrix) 00985 { 00986 void *m; 00987 t_jit_matrix_info info; 00988 00989 if (matrix&&(m=jit_object_method(mop_io,_jit_sym_getmatrix))) { 00990 jit_object_method(matrix,_jit_sym_getinfo,&info); 00991 jit_object_method(mop_io,_jit_sym_restrict_type,&info); 00992 jit_object_method(mop_io,_jit_sym_restrict_dim,&info); 00993 jit_object_method(mop_io,_jit_sym_restrict_planecount,&info); 00994 jit_object_method(m,_jit_sym_setinfo,&info); 00995 jit_object_method(m,_jit_sym_frommatrix,matrix,NULL); 00996 } 00997 00998 return JIT_ERR_NONE; 00999 } 01000 01001 /** 01002 * MOP I/O procedure to copy, but truncate input. 01003 * 01004 * @ingroup mopmod 01005 * 01006 * @param mop t_jit_mop object pointer 01007 * @param mop_io t_jit_mop_io object pointer 01008 * @param matrix t_jit_matrix object pointer 01009 * 01010 * @return t_jit_err error code 01011 * 01012 * @code 01013 void *m; 01014 t_jit_matrix_info info; 01015 01016 if (matrix&&(m=jit_object_method(mop_io,_jit_sym_getmatrix))) { 01017 jit_object_method(m,_jit_sym_frommatrix_trunc,matrix); 01018 } 01019 01020 return JIT_ERR_NONE; 01021 * @endcode 01022 * 01023 */ 01024 t_jit_err jit_mop_ioproc_copy_trunc(void *mop, void *mop_io, void *matrix) 01025 { 01026 void *m; 01027 01028 if (matrix&&(m=jit_object_method(mop_io,_jit_sym_getmatrix))) { 01029 jit_object_method(m,_jit_sym_frommatrix_trunc,matrix); 01030 } 01031 01032 return JIT_ERR_NONE; 01033 } 01034 01035 /** 01036 * MOP I/O procedure to copy, but truncate input. Zero elsewhere. 01037 * 01038 * @ingroup mopmod 01039 * 01040 * @param mop t_jit_mop object pointer 01041 * @param mop_io t_jit_mop_io object pointer 01042 * @param matrix t_jit_matrix object pointer 01043 * 01044 * @return t_jit_err error code 01045 * 01046 * @code 01047 void *m; 01048 t_jit_matrix_info info; 01049 01050 if (matrix&&(m=jit_object_method(mop_io,_jit_sym_getmatrix))) { 01051 jit_object_method(m,_jit_sym_clear); 01052 jit_object_method(m,_jit_sym_frommatrix_trunc,matrix); 01053 } 01054 01055 return JIT_ERR_NONE; 01056 * @endcode 01057 * 01058 */ 01059 t_jit_err jit_mop_ioproc_copy_trunc_zero(void *mop, void *mop_io, void *matrix) 01060 { 01061 void *m; 01062 01063 if (matrix&&(m=jit_object_method(mop_io,_jit_sym_getmatrix))) { 01064 //could be faster without the full clear 01065 jit_object_method(m,_jit_sym_clear); 01066 jit_object_method(m,_jit_sym_frommatrix_trunc,matrix); 01067 } 01068 01069 return JIT_ERR_NONE; 01070 } 01071 01072 01073 /** 01074 * Utility to convert MOP I/O procedure function to a human-readable type name. 01075 * 01076 * @ingroup mopmod 01077 * 01078 * @param ioproc t_jit_mop_io procedure pointer 01079 * 01080 * @return t_symbol pointer 01081 * 01082 * @code 01083 if (ioproc==NULL) { 01084 return ps_resamp; 01085 } else if (ioproc==jit_mop_ioproc_copy_adapt) { 01086 return ps_adapt; 01087 } else if (ioproc==jit_mop_ioproc_copy_trunc) { 01088 return ps_trunc; 01089 } else if (ioproc==jit_mop_ioproc_copy_trunc_zero) { 01090 return ps_trunc_zero; 01091 } else { 01092 return ps_custom; 01093 } 01094 return ps_resamp; 01095 * @endcode 01096 * 01097 */ 01098 t_symbol *jit_mop_ioproc_tosym(void *ioproc) 01099 { 01100 if (ioproc==NULL) { 01101 return ps_resamp; 01102 } else if (ioproc==jit_mop_ioproc_copy_adapt) { 01103 return ps_adapt; 01104 } else if (ioproc==jit_mop_ioproc_copy_trunc) { 01105 return ps_trunc; 01106 } else if (ioproc==jit_mop_ioproc_copy_trunc_zero) { 01107 return ps_trunc_zero; 01108 } else { 01109 return ps_custom; 01110 } 01111 return ps_resamp; 01112 }
Copyright © 2008, Cycling '74