Max 5 API Reference
00001 /* 00002 * jit.transfer.smoothpulse.c 00003 * 00004 * Copyright 2001-2005 - Cycling '74 00005 * Derek Gerstmann - derek@cycling74.com 00006 * 00007 * functor for a transfer smoothed pulse 00008 * 00009 */ 00010 00011 // -------------------------------------------------------------------------- 00012 00013 #include "jit.common.h" 00014 #include "jit.functor.h" 00015 00016 // -------------------------------------------------------------------------- 00017 00018 typedef struct _jit_functor_transfer_smoothpulse 00019 { 00020 t_jit_object ob; 00021 double startlow; 00022 double starthigh; 00023 double endlow; 00024 double endhigh; 00025 } t_jit_functor_transfer_smoothpulse; 00026 00027 // -------------------------------------------------------------------------- 00028 00029 t_jit_object *jit_functor_transfer_smoothpulse_new(void); 00030 t_jit_err jit_functor_transfer_smoothpulse_free(t_jit_functor_transfer_smoothpulse *x); 00031 t_jit_err jit_functor_transfer_smoothpulse_startlow(t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv); 00032 t_jit_err jit_functor_transfer_smoothpulse_starthigh(t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv); 00033 t_jit_err jit_functor_transfer_smoothpulse_endlow(t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv); 00034 t_jit_err jit_functor_transfer_smoothpulse_endhigh(t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv); 00035 t_jit_err jit_functor_transfer_smoothpulse_recalc(t_jit_functor_transfer_smoothpulse *x); 00036 00037 long jit_functor_transfer_smoothpulse_eval_fixed(t_jit_functor_transfer_smoothpulse *x, long dimcount, long *vals); 00038 float jit_functor_transfer_smoothpulse_eval_float32(t_jit_functor_transfer_smoothpulse *x, long dimcount, float *vals); 00039 double jit_functor_transfer_smoothpulse_eval_float64(t_jit_functor_transfer_smoothpulse *x, long dimcount, double *vals); 00040 00041 long jit_functor_transfer_smoothpulse_eval_fixed_scalar(t_jit_functor_transfer_smoothpulse *x, long val); 00042 float jit_functor_transfer_smoothpulse_eval_float32_scalar(t_jit_functor_transfer_smoothpulse *x, float val); 00043 double jit_functor_transfer_smoothpulse_eval_float64_scalar(t_jit_functor_transfer_smoothpulse *x, double val); 00044 00045 t_class * _jit_functor_transfer_smoothpulse_class; 00046 00047 // -------------------------------------------------------------------------- 00048 00049 t_jit_err jit_functor_transfer_smoothpulse_init(void) 00050 { 00051 t_jit_object *attr; 00052 00053 // create functor class 00054 _jit_functor_transfer_smoothpulse_class = jit_class_new("jit_functor_transfer_smoothpulse", 00055 (method)jit_functor_transfer_smoothpulse_new,(method)jit_functor_transfer_smoothpulse_free, 00056 sizeof(t_jit_functor_transfer_smoothpulse),0L); 00057 00058 // add attribute methods 00059 attr = jit_object_new(_jit_sym_jit_attr_offset,"startlow",_jit_sym_float64,0, 00060 (method)0L,(method)jit_functor_transfer_smoothpulse_startlow, 00061 calcoffset(t_jit_functor_transfer_smoothpulse,startlow)); 00062 jit_class_addattr(_jit_functor_transfer_smoothpulse_class,attr); 00063 attr = jit_object_new(_jit_sym_jit_attr_offset,"starthigh",_jit_sym_float64,0, 00064 (method)0L,(method)jit_functor_transfer_smoothpulse_starthigh, 00065 calcoffset(t_jit_functor_transfer_smoothpulse,starthigh)); 00066 jit_class_addattr(_jit_functor_transfer_smoothpulse_class,attr); 00067 attr = jit_object_new(_jit_sym_jit_attr_offset,"endlow",_jit_sym_float64,0, 00068 (method)0L,(method)jit_functor_transfer_smoothpulse_endlow, 00069 calcoffset(t_jit_functor_transfer_smoothpulse,endlow)); 00070 jit_class_addattr(_jit_functor_transfer_smoothpulse_class,attr); 00071 attr = jit_object_new(_jit_sym_jit_attr_offset,"endhigh",_jit_sym_float64,0, 00072 (method)0L,(method)jit_functor_transfer_smoothpulse_endhigh, 00073 calcoffset(t_jit_functor_transfer_smoothpulse,endhigh)); 00074 jit_class_addattr(_jit_functor_transfer_smoothpulse_class,attr); 00075 00076 // add evaluation methods 00077 jit_class_addmethod(_jit_functor_transfer_smoothpulse_class, 00078 (method)jit_functor_transfer_smoothpulse_eval_fixed, "evalfixed", A_CANT, 0L); 00079 jit_class_addmethod(_jit_functor_transfer_smoothpulse_class, 00080 (method)jit_functor_transfer_smoothpulse_eval_float32, "evalfloat32", A_CANT, 0L); 00081 jit_class_addmethod(_jit_functor_transfer_smoothpulse_class, 00082 (method)jit_functor_transfer_smoothpulse_eval_float64, "evalfloat64", A_CANT, 0L); 00083 00084 // important to add last for subclassing methods 00085 jit_functor_setup_class(_jit_functor_transfer_smoothpulse_class,"transfer","smoothpulse"); 00086 jit_class_register(_jit_functor_transfer_smoothpulse_class); 00087 00088 return JIT_ERR_NONE; 00089 } 00090 00091 t_jit_object *jit_functor_transfer_smoothpulse_new(void) 00092 { 00093 t_jit_functor_transfer_smoothpulse *x; 00094 00095 if (x = (t_jit_functor_transfer_smoothpulse *)jit_object_alloc(_jit_functor_transfer_smoothpulse_class)) { 00096 00097 // initialization 00098 x->startlow = 0.0; 00099 x->starthigh = 0.1; 00100 x->endlow = 0.9; 00101 x->endhigh = 1.0; 00102 jit_functor_transfer_smoothpulse_recalc(x); 00103 } 00104 00105 return (t_jit_object *)x; 00106 } 00107 00108 t_jit_err jit_functor_transfer_smoothpulse_free(t_jit_functor_transfer_smoothpulse *x) 00109 { 00110 return JIT_ERR_NONE; 00111 } 00112 00113 t_jit_err jit_functor_transfer_smoothpulse_startlow( 00114 t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv) 00115 { 00116 double v; 00117 00118 if (x) { 00119 v=jit_atom_getfloat(argv); 00120 if (x->startlow != v) { 00121 x->startlow = v; 00122 jit_functor_transfer_smoothpulse_recalc(x); 00123 } 00124 return JIT_ERR_NONE; 00125 } 00126 return JIT_ERR_INVALID_PTR; 00127 } 00128 00129 t_jit_err jit_functor_transfer_smoothpulse_starthigh( 00130 t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv) 00131 { 00132 double v; 00133 00134 if (x) { 00135 v=jit_atom_getfloat(argv); 00136 if (x->starthigh != v) { 00137 x->starthigh = v; 00138 jit_functor_transfer_smoothpulse_recalc(x); 00139 } 00140 return JIT_ERR_NONE; 00141 } 00142 return JIT_ERR_INVALID_PTR; 00143 } 00144 00145 00146 t_jit_err jit_functor_transfer_smoothpulse_endlow( 00147 t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv) 00148 { 00149 double v; 00150 00151 if (x) { 00152 v=jit_atom_getfloat(argv); 00153 if (x->endlow != v) { 00154 x->endlow = v; 00155 jit_functor_transfer_smoothpulse_recalc(x); 00156 } 00157 return JIT_ERR_NONE; 00158 } 00159 return JIT_ERR_INVALID_PTR; 00160 } 00161 00162 t_jit_err jit_functor_transfer_smoothpulse_endhigh( 00163 t_jit_functor_transfer_smoothpulse *x, void *attr, long argc, t_atom *argv) 00164 { 00165 double v; 00166 00167 if (x) { 00168 v=jit_atom_getfloat(argv); 00169 if (x->endhigh != v) { 00170 x->endhigh = v; 00171 jit_functor_transfer_smoothpulse_recalc(x); 00172 } 00173 return JIT_ERR_NONE; 00174 } 00175 return JIT_ERR_INVALID_PTR; 00176 } 00177 00178 t_jit_err jit_functor_transfer_smoothpulse_recalc( 00179 t_jit_functor_transfer_smoothpulse *x) 00180 { 00181 // calculate intermediary values for efficiency 00182 double t; 00183 if(x->startlow > x->starthigh) 00184 { 00185 t = x->startlow; 00186 x->startlow = x->starthigh; 00187 x->starthigh = t; 00188 } 00189 00190 if(x->endlow > x->endhigh) 00191 { 00192 t = x->endlow; 00193 x->endlow = x->endhigh; 00194 x->endhigh = t; 00195 } 00196 return JIT_ERR_NONE; 00197 } 00198 00199 // -------------------------------------------------------------------------- 00200 // vector evaluation functions (calls scalar functions and generates a product of scalar evaluation for each dimension) 00201 // -------------------------------------------------------------------------- 00202 long jit_functor_transfer_smoothpulse_eval_fixed( 00203 t_jit_functor_transfer_smoothpulse *x, long dimcount, long *vals) 00204 { 00205 return jit_functor_eval_fixed_with_float64((t_jit_object *)x,dimcount,vals, 00206 (t_jit_functor_float64_sig)jit_functor_transfer_smoothpulse_eval_float64); 00207 } 00208 00209 float jit_functor_transfer_smoothpulse_eval_float32( 00210 t_jit_functor_transfer_smoothpulse *x, long dimcount, float *vals) 00211 { 00212 return jit_functor_eval_float32_with_scalar_product((t_jit_object *)x,dimcount,vals, 00213 (t_jit_functor_float32_scalar_sig)jit_functor_transfer_smoothpulse_eval_float32_scalar); 00214 } 00215 00216 double jit_functor_transfer_smoothpulse_eval_float64( 00217 t_jit_functor_transfer_smoothpulse *x, long dimcount, double *vals) 00218 { 00219 return jit_functor_eval_float64_with_scalar_product((t_jit_object *)x,dimcount,vals, 00220 (t_jit_functor_float64_scalar_sig)jit_functor_transfer_smoothpulse_eval_float64_scalar); 00221 } 00222 00223 // -------------------------------------------------------------------------- 00224 // scalar evaluation functions 00225 // -------------------------------------------------------------------------- 00226 long jit_functor_transfer_smoothpulse_eval_fixed_scalar( 00227 t_jit_functor_transfer_smoothpulse *x, long val) 00228 { 00229 return FloatToFixed(jit_functor_transfer_smoothpulse_eval_float32_scalar(x,FixedToFloat(val))); 00230 } 00231 00232 float jit_functor_transfer_smoothpulse_eval_float32_scalar( 00233 t_jit_functor_transfer_smoothpulse *x, float val) 00234 { 00235 if (val < x->startlow || val >= x->endhigh) 00236 return 0.0; 00237 00238 if (val >= x->starthigh) { 00239 00240 if (val < x->endlow) 00241 return 1.0f; 00242 00243 val = (val - x->endlow) / (x->endhigh - x->endlow); 00244 return 1.0f - (val*val * (3.0f - 2.0f*val)); 00245 } 00246 00247 val = (val - x->startlow) / (x->starthigh - x->startlow); 00248 return val*val * (3.0f - 2.0f*val); 00249 } 00250 00251 double jit_functor_transfer_smoothpulse_eval_float64_scalar( 00252 t_jit_functor_transfer_smoothpulse *x, double val) 00253 { 00254 if (val < x->startlow || val >= x->endhigh) 00255 return 0.0; 00256 00257 if (val >= x->starthigh) { 00258 00259 if (val < x->endlow) 00260 return 1.0; 00261 00262 val = (val - x->endlow) / (x->endhigh - x->endlow); 00263 return 1.0 - (val*val * (3.0 - 2.0*val)); 00264 } 00265 00266 val = (val - x->startlow) / (x->starthigh - x->startlow); 00267 return val*val * (3.0 - 2.0*val); 00268 } 00269 // --------------------------------------------------------------------------
Copyright © 2008, Cycling '74