Max 5 API Reference
00001 /* 00002 * jit.transfer.smoothstep.c 00003 * 00004 * Copyright 2001-2005 - Cycling '74 00005 * Derek Gerstmann - derek@cycling74.com 00006 * 00007 * functor for a transfer smoothed step 00008 * 00009 */ 00010 00011 // -------------------------------------------------------------------------- 00012 00013 #include "jit.common.h" 00014 #include "jit.functor.h" 00015 00016 // -------------------------------------------------------------------------- 00017 00018 typedef struct _jit_functor_transfer_smoothstep 00019 { 00020 t_jit_object ob; 00021 double low; 00022 double high; 00023 } t_jit_functor_transfer_smoothstep; 00024 00025 // -------------------------------------------------------------------------- 00026 00027 t_jit_object *jit_functor_transfer_smoothstep_new(void); 00028 t_jit_err jit_functor_transfer_smoothstep_free(t_jit_functor_transfer_smoothstep *x); 00029 t_jit_err jit_functor_transfer_smoothstep_low(t_jit_functor_transfer_smoothstep *x, void *attr, long argc, t_atom *argv); 00030 t_jit_err jit_functor_transfer_smoothstep_high(t_jit_functor_transfer_smoothstep *x, void *attr, long argc, t_atom *argv); 00031 t_jit_err jit_functor_transfer_smoothstep_recalc(t_jit_functor_transfer_smoothstep *x); 00032 00033 long jit_functor_transfer_smoothstep_eval_fixed(t_jit_functor_transfer_smoothstep *x, long dimcount, long *vals); 00034 float jit_functor_transfer_smoothstep_eval_float32(t_jit_functor_transfer_smoothstep *x, long dimcount, float *vals); 00035 double jit_functor_transfer_smoothstep_eval_float64(t_jit_functor_transfer_smoothstep *x, long dimcount, double *vals); 00036 00037 long jit_functor_transfer_smoothstep_eval_fixed_scalar(t_jit_functor_transfer_smoothstep *x, long val); 00038 float jit_functor_transfer_smoothstep_eval_float32_scalar(t_jit_functor_transfer_smoothstep *x, float val); 00039 double jit_functor_transfer_smoothstep_eval_float64_scalar(t_jit_functor_transfer_smoothstep *x, double val); 00040 00041 t_class * _jit_functor_transfer_smoothstep_class; 00042 00043 // -------------------------------------------------------------------------- 00044 00045 t_jit_err jit_functor_transfer_smoothstep_init(void) 00046 { 00047 t_jit_object *attr; 00048 00049 // create functor class 00050 _jit_functor_transfer_smoothstep_class = jit_class_new("jit_functor_transfer_smoothstep", 00051 (method)jit_functor_transfer_smoothstep_new,(method)jit_functor_transfer_smoothstep_free, 00052 sizeof(t_jit_functor_transfer_smoothstep),0L); 00053 00054 // add attribute methods 00055 attr = jit_object_new(_jit_sym_jit_attr_offset,"low",_jit_sym_float64,0, 00056 (method)0L,(method)jit_functor_transfer_smoothstep_low, 00057 calcoffset(t_jit_functor_transfer_smoothstep,low)); 00058 jit_class_addattr(_jit_functor_transfer_smoothstep_class,attr); 00059 attr = jit_object_new(_jit_sym_jit_attr_offset,"high",_jit_sym_float64,0, 00060 (method)0L,(method)jit_functor_transfer_smoothstep_high, 00061 calcoffset(t_jit_functor_transfer_smoothstep,high)); 00062 jit_class_addattr(_jit_functor_transfer_smoothstep_class,attr); 00063 00064 // add evaluation methods 00065 jit_class_addmethod(_jit_functor_transfer_smoothstep_class, 00066 (method)jit_functor_transfer_smoothstep_eval_fixed, "evalfixed", A_CANT, 0L); 00067 jit_class_addmethod(_jit_functor_transfer_smoothstep_class, 00068 (method)jit_functor_transfer_smoothstep_eval_float32, "evalfloat32", A_CANT, 0L); 00069 jit_class_addmethod(_jit_functor_transfer_smoothstep_class, 00070 (method)jit_functor_transfer_smoothstep_eval_float64, "evalfloat64", A_CANT, 0L); 00071 00072 // important to add last for subclassing methods 00073 jit_functor_setup_class(_jit_functor_transfer_smoothstep_class,"transfer","smoothstep"); 00074 jit_class_register(_jit_functor_transfer_smoothstep_class); 00075 00076 return JIT_ERR_NONE; 00077 } 00078 00079 t_jit_object *jit_functor_transfer_smoothstep_new(void) 00080 { 00081 t_jit_functor_transfer_smoothstep *x; 00082 00083 if (x = (t_jit_functor_transfer_smoothstep *)jit_object_alloc(_jit_functor_transfer_smoothstep_class)) { 00084 00085 // initialization 00086 x->low = 0.0; 00087 x->high = 1.0; 00088 jit_functor_transfer_smoothstep_recalc(x); 00089 } 00090 00091 return (t_jit_object *)x; 00092 } 00093 00094 t_jit_err jit_functor_transfer_smoothstep_free(t_jit_functor_transfer_smoothstep *x) 00095 { 00096 return JIT_ERR_NONE; 00097 } 00098 00099 t_jit_err jit_functor_transfer_smoothstep_low( 00100 t_jit_functor_transfer_smoothstep *x, void *attr, long argc, t_atom *argv) 00101 { 00102 double v; 00103 00104 if (x) { 00105 v=jit_atom_getfloat(argv); 00106 if (x->low != v) { 00107 x->low = v; 00108 jit_functor_transfer_smoothstep_recalc(x); 00109 } 00110 return JIT_ERR_NONE; 00111 } 00112 return JIT_ERR_INVALID_PTR; 00113 } 00114 00115 t_jit_err jit_functor_transfer_smoothstep_high( 00116 t_jit_functor_transfer_smoothstep *x, void *attr, long argc, t_atom *argv) 00117 { 00118 double v; 00119 00120 if (x) { 00121 v=jit_atom_getfloat(argv); 00122 if (x->high != v) { 00123 x->high = v; 00124 jit_functor_transfer_smoothstep_recalc(x); 00125 } 00126 return JIT_ERR_NONE; 00127 } 00128 return JIT_ERR_INVALID_PTR; 00129 } 00130 00131 t_jit_err jit_functor_transfer_smoothstep_recalc(t_jit_functor_transfer_smoothstep *x) 00132 { 00133 // calculate intermediary values for efficiency 00134 double t; 00135 if(x->low > x->high) 00136 { 00137 t = x->low; 00138 x->low = x->high; 00139 x->high = t; 00140 } 00141 return JIT_ERR_NONE; 00142 } 00143 00144 // -------------------------------------------------------------------------- 00145 // vector evaluation functions (calls scalar functions and generates a product of scalar evaluation for each dimension) 00146 // -------------------------------------------------------------------------- 00147 long jit_functor_transfer_smoothstep_eval_fixed( 00148 t_jit_functor_transfer_smoothstep *x, long dimcount, long *vals) 00149 { 00150 return jit_functor_eval_fixed_with_float64((t_jit_object *)x,dimcount,vals, 00151 (t_jit_functor_float64_sig)jit_functor_transfer_smoothstep_eval_float64); 00152 } 00153 00154 float jit_functor_transfer_smoothstep_eval_float32( 00155 t_jit_functor_transfer_smoothstep *x, long dimcount, float *vals) 00156 { 00157 return jit_functor_eval_float32_with_scalar_product((t_jit_object *)x,dimcount,vals, 00158 (t_jit_functor_float32_scalar_sig)jit_functor_transfer_smoothstep_eval_float32_scalar); 00159 } 00160 00161 double jit_functor_transfer_smoothstep_eval_float64( 00162 t_jit_functor_transfer_smoothstep *x, long dimcount, double *vals) 00163 { 00164 return jit_functor_eval_float64_with_scalar_product((t_jit_object *)x,dimcount,vals, 00165 (t_jit_functor_float64_scalar_sig)jit_functor_transfer_smoothstep_eval_float64_scalar); 00166 } 00167 00168 // -------------------------------------------------------------------------- 00169 // scalar evaluation functions 00170 // -------------------------------------------------------------------------- 00171 long jit_functor_transfer_smoothstep_eval_fixed_scalar( 00172 t_jit_functor_transfer_smoothstep *x, long val) 00173 { 00174 return FloatToFixed(jit_functor_transfer_smoothstep_eval_float32_scalar(x,FixedToFloat(val))); 00175 } 00176 00177 float jit_functor_transfer_smoothstep_eval_float32_scalar( 00178 t_jit_functor_transfer_smoothstep *x, float val) 00179 { 00180 if (val < x->low) 00181 return 0; 00182 if (val >= x->high) 00183 return 1; 00184 00185 val = (val - x->low) / (x->high - x->low); 00186 return val*val * (3 - 2*val); 00187 } 00188 00189 double jit_functor_transfer_smoothstep_eval_float64_scalar( 00190 t_jit_functor_transfer_smoothstep *x, double val) 00191 { 00192 if (val < x->low) 00193 return 0; 00194 if (val >= x->high) 00195 return 1; 00196 00197 val = (val - x->low) / (x->high - x->low); 00198 return val*val * (3 - 2*val); 00199 } 00200 // --------------------------------------------------------------------------
Copyright © 2008, Cycling '74