/* --------------------------- k_scale ----------------------------------- */ /* */ /* There probably is a similar object? */ /* */ /* This program is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU General Public License */ /* as published by the Free Software Foundation; either version 2 */ /* of the License, or (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* */ /* ---------------------------------------------------------------------------- */ #include "m_pd.h" #include #ifdef max #undef max #endif #define max(a,b) (((a)>(b))?(a):(b)) #ifdef min #undef min #endif #define min(a,b) (((a)<(b))?(a):(b)) #define boundaries(d,e,f) (min(max((d),(e)),(f))) static char *version = "k_scale v0.2, written by Kjetil S. Matheussen, k.s.matheussen@notam02.no"; typedef struct k_scale { t_object x_ob; t_inlet *x_inlet; /* inlet */ t_inlet *x_inlet1; /* inlet */ t_inlet *x_inlet2; /* inlet */ t_inlet *x_inlet3; /* inlet */ t_inlet *x_inlet4; /* inlet */ t_inlet *x_inlet5; /* inlet */ t_outlet *x_outlet; /* result */ t_outlet *x_outlet2; /* result */ t_float in_minval; t_float in_maxval; t_float out_minval; t_float out_maxval; t_float bound; } t_k_scale; static t_class *k_scale_class; static void k_scale_float(t_k_scale *x, t_floatarg f) { // post("%f %f %f %f\n",x->in_minval,x->in_maxval,x->out_minval,x->out_maxval); float out= x->out_minval + ((f-x->in_minval)*(x->out_maxval-x->out_minval)/(x->in_maxval-x->in_minval)) ; if(x->bound!=0.0f){ out=boundaries(out,x->out_minval,x->out_maxval); } outlet_float(x->x_outlet,out); outlet_float(x->x_outlet2,x->out_maxval+x->out_minval-out); } static void k_scale_ft1(t_k_scale *x, t_floatarg f){x->in_minval=f;} static void k_scale_ft2(t_k_scale *x, t_floatarg f){x->in_maxval=f;} static void k_scale_ft3(t_k_scale *x, t_floatarg f){x->out_minval=f;} static void k_scale_ft4(t_k_scale *x, t_floatarg f){x->out_maxval=f;} static void k_scale_ft5(t_k_scale *x, t_floatarg f){x->bound=f;} static void *k_scale_new(t_symbol *s, t_int argc, t_atom* argv) { int lokke; t_k_scale *x = (t_k_scale *)pd_new(k_scale_class); x->x_inlet1=inlet_new(&x->x_ob,&x->x_ob.ob_pd,gensym("float"),gensym("ft1")); x->x_inlet2=inlet_new(&x->x_ob,&x->x_ob.ob_pd,gensym("float"),gensym("ft2")); x->x_inlet3=inlet_new(&x->x_ob,&x->x_ob.ob_pd,gensym("float"),gensym("ft3")); x->x_inlet4=inlet_new(&x->x_ob,&x->x_ob.ob_pd,gensym("float"),gensym("ft4")); x->x_inlet5=inlet_new(&x->x_ob,&x->x_ob.ob_pd,gensym("float"),gensym("ft5")); x->x_outlet = outlet_new(&x->x_ob, gensym("float")); x->x_outlet2 = outlet_new(&x->x_ob, gensym("float")); x->in_minval=x->out_minval=0.0f; x->in_maxval=x->out_maxval=1.0f; x->bound=0.0f; for(lokke=0;lokkein_minval; break; case 1: goal=&x->in_maxval; break; case 2: goal=&x->out_minval; break; case 3: goal=&x->out_maxval; break; case 4: goal=&x->bound; break; default: goto endfor; } *goal=atom_getfloatarg(lokke,argc,argv); // post("lokke: %d, -1: %f, 0: %f\n",lokke,*goal,atom_getfloatarg(lokke,argc,argv)); } endfor: post(version); return (void *)x; } void k_scale_setup(void) { k_scale_class = class_new(gensym("k_scale"), (t_newmethod)k_scale_new, 0, sizeof(t_k_scale), 0, A_GIMME, 0); class_addfloat(k_scale_class, k_scale_float); class_addmethod(k_scale_class, (t_method)k_scale_ft1, gensym("ft1"), A_FLOAT, 0); class_addmethod(k_scale_class, (t_method)k_scale_ft2, gensym("ft2"), A_FLOAT, 0); class_addmethod(k_scale_class, (t_method)k_scale_ft3, gensym("ft3"), A_FLOAT, 0); class_addmethod(k_scale_class, (t_method)k_scale_ft4, gensym("ft4"), A_FLOAT, 0); class_addmethod(k_scale_class, (t_method)k_scale_ft5, gensym("ft5"), A_FLOAT, 0); class_sethelpsymbol(k_scale_class, gensym("help-k_scale.pd")); }