From 4f8c7c28f8ece71d15ed28ae30f253725f1efa39 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 20 Oct 2012 18:32:25 +0000 Subject: update code format to pd-style: astyle --style=ansi --align-pointer=name *.c svn path=/trunk/externals/moonlib/; revision=16427 --- absolutepath.c | 145 ++--- basedir.c | 38 +- char2f.c | 24 +- comma.c | 24 +- dinlet~.c | 46 +- dispatch.c | 180 +++--- dripchar.c | 67 ++- f2char.c | 28 +- gamme.c | 567 ++++++++--------- image.c | 312 +++++----- mknob.c | 645 ++++++++++---------- panvol~.c | 146 ++--- popen.c | 161 ++--- readsfv~.c | 1841 ++++++++++++++++++++++++++++---------------------------- relativepath.c | 160 ++--- s2f.c | 24 +- sarray.c | 213 +++---- sfread2~.c | 542 +++++++++-------- slist.c | 162 ++--- ssaw~.c | 133 ++-- tabdump2.c | 114 ++-- tabenv.c | 185 +++--- tabreadl.c | 39 +- tabsort.c | 70 +-- tabsort2.c | 114 ++-- wac.c | 360 +++++------ 26 files changed, 3239 insertions(+), 3101 deletions(-) diff --git a/absolutepath.c b/absolutepath.c index 0b44dcb..e6d94d7 100644 --- a/absolutepath.c +++ b/absolutepath.c @@ -1,6 +1,6 @@ #ifndef _WIN32 /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -14,7 +14,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -44,9 +44,9 @@ typedef struct _absolutepath { t_object x_obj; t_canvas *x_canvas; - int x_dolzero; - int x_realized; -}t_absolutepath; + int x_dolzero; + int x_realized; +} t_absolutepath; t_class *absolutepath_class; @@ -54,89 +54,94 @@ void absolutepath_setup(void); static t_glist *getcanvas(t_glist *can,int d0) { - t_canvas *retcan=0; - t_gobj *ob; - - if((can->gl_env)&&(can->gl_env->ce_dollarzero==d0)){ - return can; - } - - ob=can->gl_list; - while(ob&&(retcan==0)) { - if (pd_class(&ob->g_pd) == canvas_class) - retcan=getcanvas((t_glist *)ob,d0); - ob=ob->g_next; - } - - if((!retcan)&&(can->gl_next)) retcan=getcanvas((t_glist *)can->gl_next,d0); - return retcan; + t_canvas *retcan=0; + t_gobj *ob; + + if((can->gl_env)&&(can->gl_env->ce_dollarzero==d0)) + { + return can; + } + + ob=can->gl_list; + while(ob&&(retcan==0)) + { + if (pd_class(&ob->g_pd) == canvas_class) + retcan=getcanvas((t_glist *)ob,d0); + ob=ob->g_next; + } + + if((!retcan)&&(can->gl_next)) retcan=getcanvas((t_glist *)can->gl_next,d0); + return retcan; } static void absolutepath_symbol(t_absolutepath *x,t_symbol *sym) { - t_canvas *can=0; + t_canvas *can=0; char buf[MAXPDSTRING], *bufptr, - *instr=sym->s_name, - canname[MAXPDSTRING],totaldir[MAXPDSTRING], - *cnamedir, - *candir; - unsigned int n,i=0; - int fd; - - if(!x->x_realized) can=(t_canvas*)getcanvas(canvas_list,x->x_dolzero); - if(can) { - x->x_canvas = can; - x->x_realized = 1; - //post("found $0 canvas : %x %d ",x->x_canvas, x->x_canvas->gl_env->ce_dollarzero ); - } - - if(!instr) return; - - candir=canvas_getdir(x->x_canvas)->s_name; - if(!candir) candir=""; - - //post("input= %s candir= %s glname=%s",instr,candir,x->x_canvas->gl_name->s_name); - - strcpy(canname,x->x_canvas->gl_name->s_name); - cnamedir=dirname(canname); - - if (strcmp(cnamedir,".")) { - sprintf(totaldir,"%s/%s",candir,cnamedir); - fd=open_via_path(totaldir,instr ,"",buf, &bufptr, MAXPDSTRING, 1); - } - else - fd=open_via_path(candir, instr, "",buf, &bufptr, MAXPDSTRING, 1); - - if (fd>=0) { - close(fd); - buf[strlen(buf)]='/'; - outlet_symbol(x->x_obj.ob_outlet,gensym(buf)); - } - return; + *instr=sym->s_name, + canname[MAXPDSTRING],totaldir[MAXPDSTRING], + *cnamedir, + *candir; + unsigned int n,i=0; + int fd; + + if(!x->x_realized) can=(t_canvas *)getcanvas(canvas_list,x->x_dolzero); + if(can) + { + x->x_canvas = can; + x->x_realized = 1; + //post("found $0 canvas : %x %d ",x->x_canvas, x->x_canvas->gl_env->ce_dollarzero ); + } + + if(!instr) return; + + candir=canvas_getdir(x->x_canvas)->s_name; + if(!candir) candir=""; + + //post("input= %s candir= %s glname=%s",instr,candir,x->x_canvas->gl_name->s_name); + + strcpy(canname,x->x_canvas->gl_name->s_name); + cnamedir=dirname(canname); + + if (strcmp(cnamedir,".")) + { + sprintf(totaldir,"%s/%s",candir,cnamedir); + fd=open_via_path(totaldir,instr ,"",buf, &bufptr, MAXPDSTRING, 1); + } + else + fd=open_via_path(candir, instr, "",buf, &bufptr, MAXPDSTRING, 1); + + if (fd>=0) + { + close(fd); + buf[strlen(buf)]='/'; + outlet_symbol(x->x_obj.ob_outlet,gensym(buf)); + } + return; } static void *absolutepath_new(t_float dolzero) { - t_absolutepath *x = (t_absolutepath *)pd_new(absolutepath_class); - t_canvas *can=canvas_list; - int d0; - - outlet_new(&x->x_obj, 0); + t_absolutepath *x = (t_absolutepath *)pd_new(absolutepath_class); + t_canvas *can=canvas_list; + int d0; + + outlet_new(&x->x_obj, 0); x->x_canvas = canvas_getcurrent(); - x->x_dolzero = dolzero; - x->x_realized=dolzero?0:1; + x->x_dolzero = dolzero; + x->x_realized=dolzero?0:1; - return (void *)x; + return (void *)x; } void absolutepath_setup(void) { - absolutepath_class = class_new(gensym("absolutepath"),(t_newmethod)absolutepath_new, - 0, sizeof(t_absolutepath), 0,A_DEFFLOAT, 0); + absolutepath_class = class_new(gensym("absolutepath"),(t_newmethod)absolutepath_new, + 0, sizeof(t_absolutepath), 0,A_DEFFLOAT, 0); - class_addsymbol(absolutepath_class, absolutepath_symbol); + class_addsymbol(absolutepath_class, absolutepath_symbol); } #endif /* NOT _WIN32 */ diff --git a/basedir.c b/basedir.c index 61ebcf4..e526291 100644 --- a/basedir.c +++ b/basedir.c @@ -1,6 +1,6 @@ #ifndef _WIN32 /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -14,7 +14,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct _basedir { t_object x_obj; -}t_basedir; +} t_basedir; t_class *basedir_class; @@ -39,36 +39,36 @@ void basedir_setup(void); static void basedir_symbol(t_basedir *x,t_symbol *sym) { - static t_binbuf *binbuf=0; - t_atom at[2]; - char *b,*d; - int l; + static t_binbuf *binbuf=0; + t_atom at[2]; + char *b,*d; + int l; - if(!sym->s_name) return; + if(!sym->s_name) return; - b=strdup(sym->s_name); - d=strdup(sym->s_name); + b=strdup(sym->s_name); + d=strdup(sym->s_name); - SETSYMBOL(&at[0],gensym(basename(b))); - SETSYMBOL(&at[1],gensym(dirname(d))); + SETSYMBOL(&at[0],gensym(basename(b))); + SETSYMBOL(&at[1],gensym(dirname(d))); - outlet_list(x->x_obj.ob_outlet,0,2,at); + outlet_list(x->x_obj.ob_outlet,0,2,at); } static void *basedir_new(void) { - t_basedir *x = (t_basedir *)pd_new(basedir_class); - outlet_new(&x->x_obj, 0); - return (void *)x; + t_basedir *x = (t_basedir *)pd_new(basedir_class); + outlet_new(&x->x_obj, 0); + return (void *)x; } void basedir_setup(void) { - basedir_class = class_new(gensym("basedir"),(t_newmethod)basedir_new, - 0, sizeof(t_basedir), 0, 0); + basedir_class = class_new(gensym("basedir"),(t_newmethod)basedir_new, + 0, sizeof(t_basedir), 0, 0); - class_addsymbol(basedir_class, basedir_symbol); + class_addsymbol(basedir_class, basedir_symbol); } diff --git a/char2f.c b/char2f.c index cc5a486..f5df70b 100644 --- a/char2f.c +++ b/char2f.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct _char2f { t_object x_obj; -}t_char2f; +} t_char2f; t_class *char2f_class; @@ -31,23 +31,23 @@ void char2f_setup(void); static void char2f_symbol(t_char2f *x,t_symbol *sym) { - if(!sym->s_name) return; + if(!sym->s_name) return; - outlet_float(x->x_obj.ob_outlet,(t_float)sym->s_name[0]); + outlet_float(x->x_obj.ob_outlet,(t_float)sym->s_name[0]); } static void *char2f_new(void) -{ - t_char2f *x = (t_char2f *)pd_new(char2f_class); - outlet_new(&x->x_obj, &s_float); - return (void *)x; +{ + t_char2f *x = (t_char2f *)pd_new(char2f_class); + outlet_new(&x->x_obj, &s_float); + return (void *)x; } void char2f_setup(void) { - char2f_class = class_new(gensym("char2f"),(t_newmethod)char2f_new, - 0, sizeof(t_char2f), 0, 0); + char2f_class = class_new(gensym("char2f"),(t_newmethod)char2f_new, + 0, sizeof(t_char2f), 0, 0); - class_addsymbol(char2f_class, char2f_symbol); + class_addsymbol(char2f_class, char2f_symbol); } diff --git a/comma.c b/comma.c index 737d2b7..cd2fe85 100644 --- a/comma.c +++ b/comma.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -24,7 +24,7 @@ static t_atom _commaatom_; typedef struct _comma { t_object x_obj; -}t_comma; +} t_comma; t_class *comma_class; @@ -32,22 +32,22 @@ void comma_setup(void); static void comma_bang(t_comma *x) { - outlet_list(x->x_obj.ob_outlet, &s_list, 1, &_commaatom_); + outlet_list(x->x_obj.ob_outlet, &s_list, 1, &_commaatom_); } static void *comma_new(void) -{ - t_comma *x = (t_comma *)pd_new(comma_class); - outlet_new(&x->x_obj,&s_symbol); - return (void *)x; +{ + t_comma *x = (t_comma *)pd_new(comma_class); + outlet_new(&x->x_obj,&s_symbol); + return (void *)x; } void comma_setup(void) { - comma_class = class_new(gensym("comma"),(t_newmethod)comma_new, - 0, sizeof(t_comma), 0, 0); + comma_class = class_new(gensym("comma"),(t_newmethod)comma_new, + 0, sizeof(t_comma), 0, 0); - class_addbang(comma_class, comma_bang); - SETCOMMA(&_commaatom_); + class_addbang(comma_class, comma_bang); + SETCOMMA(&_commaatom_); } diff --git a/dinlet~.c b/dinlet~.c index 7933eac..02a36f7 100644 --- a/dinlet~.c +++ b/dinlet~.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,18 +13,18 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* this file is made from parts of m_object.c and g_io.c * it defines a signal inlet named dinlet~ which is the same as inlet~ -* exepts you can give a default float value for the case none signal +* exepts you can give a default float value for the case none signal * is connected to this inlet~. */ /***********************************************************************/ -/* CAUTION : - You MUST fix a bug pd sources and recompile them in order to have +/* CAUTION : + You MUST fix a bug pd sources and recompile them in order to have dinlet~ working !! this function must be fixed in pd/m_obj.c: */ @@ -33,22 +33,22 @@ t_sample *obj_findsignalscalar(t_object *x, int m) { int n = 0,mbak=m; t_inlet *i; - post("my obj_findsignalscalar"); + post("my obj_findsignalscalar"); if (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin) { - if (!m--) - return (x->ob_pd->c_floatsignalin > 0 ? - (t_sample *)(((char *)x) + x->ob_pd->c_floatsignalin) : 0); - n++; + if (!m--) + return (x->ob_pd->c_floatsignalin > 0 ? + (t_sample *)(((char *)x) + x->ob_pd->c_floatsignalin) : 0); + n++; } for (i = x->ob_inlet; i; i = i->i_next, m--) - if (i->i_symfrom == &s_signal) - { - /*if (m == 0)*/ - if(n==mbak) - return (&i->i_un.iu_floatsignalvalue); - n++; - } + if (i->i_symfrom == &s_signal) + { + /*if (m == 0)*/ + if(n==mbak) + return (&i->i_un.iu_floatsignalvalue); + n++; + } return (0); } #endif @@ -85,11 +85,11 @@ struct _inlet static void dinlet_float(t_inlet *x, t_float f) { if (x->i_symfrom == &s_float) - pd_vmess(x->i_dest, x->i_symto, "f", (t_floatarg)f); + pd_vmess(x->i_dest, x->i_symto, "f", (t_floatarg)f); else if (x->i_symfrom == &s_signal) - x->i_un.iu_floatsignalvalue = f; + x->i_un.iu_floatsignalvalue = f; else if (!x->i_symfrom) - pd_float(x->i_dest, f); + pd_float(x->i_dest, f); /*else inlet_wrong(x, &s_float);*/ } /**************** from g_io.c : *********************************/ @@ -111,8 +111,8 @@ typedef struct _vinlet t_float *x_fill; t_float *x_read; int x_hop; - /* if not reblocking, the next slot communicates the parent's inlet - signal from the prolog to the DSP routine: */ + /* if not reblocking, the next slot communicates the parent's inlet + signal from the prolog to the DSP routine: */ t_signal *x_directsignal; } t_vinlet; @@ -125,7 +125,7 @@ static void *dinlet_newsig(t_floatarg f) x->x_endbuf = x->x_buf = (t_float *)getbytes(0); x->x_bufsize = 0; x->x_directsignal = 0; - x->x_inlet->i_un.iu_floatsignalvalue=f; + x->x_inlet->i_un.iu_floatsignalvalue=f; outlet_new(&x->x_obj, &s_signal); return (x); } diff --git a/dispatch.c b/dispatch.c index f8a937a..a4314e3 100644 --- a/dispatch.c +++ b/dispatch.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2003 Antoine Rousseau +Copyright (C) 2003 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -54,124 +54,130 @@ struct _dispatch static void dispsnd_ff(t_dispsnd *x) { - pd_unbind((t_pd*)x, x->d_eachsnd); + pd_unbind((t_pd *)x, x->d_eachsnd); } static void *dispsnd_new(t_symbol *eachsnd,t_symbol *allsnd,int num) { t_dispsnd *x = (t_dispsnd *)pd_new(dispsnd_class); - - //post("new dispsnd: num=%d rcv=%s snd=%s",num,eachsnd->s_name,allsnd->s_name); - x->d_eachsnd=eachsnd; - x->d_allsnd=allsnd; - x->d_num=num; - - pd_bind((t_pd*)x, x->d_eachsnd); - + + //post("new dispsnd: num=%d rcv=%s snd=%s",num,eachsnd->s_name,allsnd->s_name); + x->d_eachsnd=eachsnd; + x->d_allsnd=allsnd; + x->d_num=num; + + pd_bind((t_pd *)x, x->d_eachsnd); + return (x); } static void dispsnd_float(t_dispsnd *x, t_float f) { - t_atom out[2]; - - if (x->d_allsnd->s_thing) { - SETFLOAT(&out[0],x->d_num); - SETFLOAT(&out[1],f); - - typedmess(x->d_allsnd->s_thing, &s_list, 2, out); - } + t_atom out[2]; + + if (x->d_allsnd->s_thing) + { + SETFLOAT(&out[0],x->d_num); + SETFLOAT(&out[1],f); + + typedmess(x->d_allsnd->s_thing, &s_list, 2, out); + } } static void dispsnd_anything(t_dispsnd *x, t_symbol *s, int argc, t_atom *argv) { - t_atom *out; - - if (x->d_allsnd->s_thing) { - out = (t_atom*)getbytes(sizeof(t_atom)*(argc+2)); - memcpy(&out[2], argv, argc*sizeof(t_atom)); - SETFLOAT(&out[0],x->d_num); - SETSYMBOL(&out[1],s); - - typedmess(x->d_allsnd->s_thing, &s_list, argc+2, out); - - freebytes(out, sizeof(t_atom)*(argc+2)); - } + t_atom *out; + + if (x->d_allsnd->s_thing) + { + out = (t_atom *)getbytes(sizeof(t_atom)*(argc+2)); + memcpy(&out[2], argv, argc*sizeof(t_atom)); + SETFLOAT(&out[0],x->d_num); + SETSYMBOL(&out[1],s); + + typedmess(x->d_allsnd->s_thing, &s_list, argc+2, out); + + freebytes(out, sizeof(t_atom)*(argc+2)); + } } /*--------------------- dispatch ------------------------------------*/ - + static void *dispatch_new(t_symbol *s,t_float from,t_float to) { int i,len; - t_dispatch *x = (t_dispatch *)pd_new(dispatch_class); - char str[512]; - t_symbol *allsnd,*eachsnd; - - x->x_snds=0; + t_dispatch *x = (t_dispatch *)pd_new(dispatch_class); + char str[512]; + t_symbol *allsnd,*eachsnd; + + x->x_snds=0; x->x_sym = s; x->x_from = from; x->x_to = to; - len=x->x_to-x->x_from+1; - - if(len>0){ - sprintf(str,"%s-snd",x->x_sym->s_name); - allsnd=gensym(str); - - sprintf(str,"%s-rcv",x->x_sym->s_name); - x->x_allrcv=gensym(str); - pd_bind((t_pd*)x, x->x_allrcv); - - x->x_snds=getbytes(len*sizeof(t_dispsnd *)); - x->x_eachrcvs=getbytes(len*sizeof(t_symbol *)); - - for(i=0;ix_sym->s_name,i+x->x_from); - eachsnd=gensym(str); - x->x_snds[i]=dispsnd_new(eachsnd,allsnd,i+x->x_from); - - sprintf(str,"%s%d-rcv",x->x_sym->s_name,i+x->x_from); - x->x_eachrcvs[i]=gensym(str); - } - } + len=x->x_to-x->x_from+1; + + if(len>0) + { + sprintf(str,"%s-snd",x->x_sym->s_name); + allsnd=gensym(str); + + sprintf(str,"%s-rcv",x->x_sym->s_name); + x->x_allrcv=gensym(str); + pd_bind((t_pd *)x, x->x_allrcv); + + x->x_snds=getbytes(len*sizeof(t_dispsnd *)); + x->x_eachrcvs=getbytes(len*sizeof(t_symbol *)); + + for(i=0; ix_sym->s_name,i+x->x_from); + eachsnd=gensym(str); + x->x_snds[i]=dispsnd_new(eachsnd,allsnd,i+x->x_from); + + sprintf(str,"%s%d-rcv",x->x_sym->s_name,i+x->x_from); + x->x_eachrcvs[i]=gensym(str); + } + } return (x); } static void dispatch_ff(t_dispatch *x) { - int i,len=x->x_to-x->x_from+1; + int i,len=x->x_to-x->x_from+1; - if(len<=0) return; - - pd_unbind((t_pd*)x, x->x_allrcv); + if(len<=0) return; - for(i=0;ix_snds[i]); + pd_unbind((t_pd *)x, x->x_allrcv); - freebytes(x->x_snds,len*sizeof(t_dispsnd *)); - freebytes(x->x_eachrcvs,len*sizeof(t_symbol *)); + for(i=0; ix_snds[i]); + + freebytes(x->x_snds,len*sizeof(t_dispsnd *)); + freebytes(x->x_eachrcvs,len*sizeof(t_symbol *)); } static void dispatch_list(t_dispatch *x, t_symbol *s, int argc, t_atom *argv) { - int num; - - if((!argc)|(argv[0].a_type!=A_FLOAT)) { - error("dispatch: bad list format"); - return; - } - - num=atom_getint(&argv[0]); - - if((numx_from)|(num>x->x_to)) { - //error("dispatch: bad num"); - return; - } - - if (x->x_eachrcvs[num-x->x_from]->s_thing) - pd_forwardmess(x->x_eachrcvs[num-x->x_from]->s_thing, argc-1, argv+1); + int num; + + if((!argc)|(argv[0].a_type!=A_FLOAT)) + { + error("dispatch: bad list format"); + return; + } + + num=atom_getint(&argv[0]); + + if((numx_from)|(num>x->x_to)) + { + //error("dispatch: bad num"); + return; + } + + if (x->x_eachrcvs[num-x->x_from]->s_thing) + pd_forwardmess(x->x_eachrcvs[num-x->x_from]->s_thing, argc-1, argv+1); } @@ -181,13 +187,13 @@ static void dispatch_list(t_dispatch *x, t_symbol *s, int argc, t_atom *argv) void dispatch_setup(void) { - dispatch_class = class_new(gensym("dispatch"), (t_newmethod)dispatch_new, - (t_method)dispatch_ff, - sizeof(t_dispatch), 0, A_SYMBOL, A_FLOAT, A_FLOAT,0); + dispatch_class = class_new(gensym("dispatch"), (t_newmethod)dispatch_new, + (t_method)dispatch_ff, + sizeof(t_dispatch), 0, A_SYMBOL, A_FLOAT, A_FLOAT,0); class_addlist(dispatch_class, dispatch_list); - dispsnd_class = class_new(gensym("dispatch"), 0, (t_method)dispsnd_ff, - sizeof(t_dispsnd), CLASS_PD, 0); + dispsnd_class = class_new(gensym("dispatch"), 0, (t_method)dispsnd_ff, + sizeof(t_dispsnd), CLASS_PD, 0); class_addanything(dispsnd_class, dispsnd_anything); class_addfloat(dispsnd_class, dispsnd_float); } diff --git a/dripchar.c b/dripchar.c index 184e204..4b6da9e 100644 --- a/dripchar.c +++ b/dripchar.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct _dripchar { t_object x_obj; -}t_dripchar; +} t_dripchar; t_class *dripchar_class; @@ -36,47 +36,48 @@ void dripchar_setup(void); static void dripchar_symbol(t_dripchar *x,t_symbol *sym) { - static t_binbuf *binbuf=0; - t_atom at; - char *c,s[2]={0}; - int l; - - if(!binbuf) binbuf=binbuf_new(); - /*post("dripchar_symbol");*/ - if(!sym->s_name) return; - - c=sym->s_name; - while(*c) { - s[0]=*c++; - SETSYMBOL(&at,gensym(s)); - binbuf_add(binbuf,1,&at); - } - - - outlet_list(x->x_obj.ob_outlet,0, - binbuf_getnatom(binbuf),binbuf_getvec(binbuf)); - binbuf_clear(binbuf); + static t_binbuf *binbuf=0; + t_atom at; + char *c,s[2]= {0}; + int l; + + if(!binbuf) binbuf=binbuf_new(); + /*post("dripchar_symbol");*/ + if(!sym->s_name) return; + + c=sym->s_name; + while(*c) + { + s[0]=*c++; + SETSYMBOL(&at,gensym(s)); + binbuf_add(binbuf,1,&at); + } + + + outlet_list(x->x_obj.ob_outlet,0, + binbuf_getnatom(binbuf),binbuf_getvec(binbuf)); + binbuf_clear(binbuf); } static void dripchar_float(t_dripchar *x,t_floatarg f) { - post("dripchar_float"); - /*outlet_symbol(x->x_obj.ob_outlet,*/ + post("dripchar_float"); + /*outlet_symbol(x->x_obj.ob_outlet,*/ } static void *dripchar_new(void) -{ - t_dripchar *x = (t_dripchar *)pd_new(dripchar_class); - outlet_new(&x->x_obj, 0); - return (void *)x; +{ + t_dripchar *x = (t_dripchar *)pd_new(dripchar_class); + outlet_new(&x->x_obj, 0); + return (void *)x; } void dripchar_setup(void) { - dripchar_class = class_new(gensym("dripchar"),(t_newmethod)dripchar_new, - 0, sizeof(t_dripchar), 0, 0); + dripchar_class = class_new(gensym("dripchar"),(t_newmethod)dripchar_new, + 0, sizeof(t_dripchar), 0, 0); - class_addsymbol(dripchar_class, dripchar_symbol); - class_addfloat(dripchar_class, dripchar_float); + class_addsymbol(dripchar_class, dripchar_symbol); + class_addfloat(dripchar_class, dripchar_float); } diff --git a/f2char.c b/f2char.c index e14c5cf..ed51465 100644 --- a/f2char.c +++ b/f2char.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct _f2char { t_object x_obj; -}t_f2char; +} t_f2char; t_class *f2char_class; @@ -30,24 +30,24 @@ void f2char_setup(void); static void f2char_float(t_f2char *x,t_floatarg f) { - char s[2]={0}; - - s[0]=(char)f; - outlet_symbol(x->x_obj.ob_outlet,gensym(s)); + char s[2]= {0}; + + s[0]=(char)f; + outlet_symbol(x->x_obj.ob_outlet,gensym(s)); } static void *f2char_new(void) -{ - t_f2char *x = (t_f2char *)pd_new(f2char_class); - outlet_new(&x->x_obj,&s_symbol); - return (void *)x; +{ + t_f2char *x = (t_f2char *)pd_new(f2char_class); + outlet_new(&x->x_obj,&s_symbol); + return (void *)x; } void f2char_setup(void) { - f2char_class = class_new(gensym("f2char"),(t_newmethod)f2char_new, - 0, sizeof(t_f2char), 0, 0); + f2char_class = class_new(gensym("f2char"),(t_newmethod)f2char_new, + 0, sizeof(t_f2char), 0, 0); - class_addfloat(f2char_class, f2char_float); + class_addfloat(f2char_class, f2char_float); } diff --git a/gamme.c b/gamme.c index 81583c3..3df8d52 100644 --- a/gamme.c +++ b/gamme.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include @@ -53,13 +53,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static t_class *gamme_class; static char *NoteNames[]= - { "C","C#","D","D#","E","F","F#","G","G#","A","A#","B" }; +{ "C","C#","D","D#","E","F","F#","G","G#","A","A#","B" }; static char NoteColPos[]= - { 1,-1,2,-2,3,4,-4,5,-5,6,-6,7 }; -static char Whites[]={0,2,4,5,7,9,11}; -static char Blacks[]={1,3,6,8,10}; -static char BlacksWhites[]={1,3,6,8,10,0,2,4,5,7,9,11}; -static char WhitesBlacks[]={0,2,4,5,7,9,11,1,3,6,8,10}; +{ 1,-1,2,-2,3,4,-4,5,-5,6,-6,7 }; +static char Whites[]= {0,2,4,5,7,9,11}; +static char Blacks[]= {1,3,6,8,10}; +static char BlacksWhites[]= {1,3,6,8,10,0,2,4,5,7,9,11}; +static char WhitesBlacks[]= {0,2,4,5,7,9,11,1,3,6,8,10}; #define ISWHITE(x) (NoteColPos[x]>0) #define ISBLACK(x) (!ISWHITE(x)) @@ -69,15 +69,15 @@ static char WhitesBlacks[]={0,2,4,5,7,9,11,1,3,6,8,10}; typedef struct _gamme { - t_object x_obj; - t_outlet *x_out_n; /*gives the number of selected notes when change occurs*/ - t_outlet *x_out_note; /*gives the number and new value of the changed notes when change occurs*/ - t_glist * x_glist; - int x_width; - int x_height; - char x_n; - char x_notes[12]; - char x_on_notes[12]; + t_object x_obj; + t_outlet *x_out_n; /*gives the number of selected notes when change occurs*/ + t_outlet *x_out_note; /*gives the number and new value of the changed notes when change occurs*/ + t_glist *x_glist; + int x_width; + int x_height; + char x_n; + char x_notes[12]; + char x_on_notes[12]; } t_gamme; /* widget helper functions */ @@ -89,157 +89,165 @@ typedef struct _gamme #define BLACKH 0.6 static void note_get_rel_rect(int x, float *xp1, float *yp1, float *xp2, float *yp2) { - int cp=NoteColPos[x]; - - *xp1=(abs(cp)-1)*(NOTEWIDTH+INTERSPACE) + (cp<0)*BLACK1st; - *xp2=*xp1+NOTEWIDTH; - - *yp1=0; - *yp2=cp<0?BLACKH:1; + int cp=NoteColPos[x]; + + *xp1=(abs(cp)-1)*(NOTEWIDTH+INTERSPACE) + (cp<0)*BLACK1st; + *xp2=*xp1+NOTEWIDTH; + + *yp1=0; + *yp2=cp<0?BLACKH:1; } static int get_touched_note(float x, float y) { - int i,j; - float xp1,xp2,yp1,yp2; - - for(j=0;j<12;j++) { - i=BlacksWhites[j]; - note_get_rel_rect(i,&xp1,&yp1,&xp2,&yp2); - if((x>=xp1)&&(x<=xp2)&&(y>=yp1)&&(y<=yp2)) - return i; - } - /*post("gamme::get_touched_note note not found: x=%f y=%f",x,y);*/ - return -1; + int i,j; + float xp1,xp2,yp1,yp2; + + for(j=0; j<12; j++) + { + i=BlacksWhites[j]; + note_get_rel_rect(i,&xp1,&yp1,&xp2,&yp2); + if((x>=xp1)&&(x<=xp2)&&(y>=yp1)&&(y<=yp2)) + return i; + } + /*post("gamme::get_touched_note note not found: x=%f y=%f",x,y);*/ + return -1; } static void draw_inlets(t_gamme *x, t_glist *glist, int firsttime, int nin, int nout) { - int n = nout; - int nplus, i; + int n = nout; + int nplus, i; int xpos=text_xpix(&x->x_obj, glist); int ypos=text_ypix(&x->x_obj, glist); - nplus = (n == 1 ? 1 : n-1); - for (i = 0; i < n; i++) - { - int onset = xpos + (x->x_width - IOWIDTH) * i / nplus; - if (firsttime) - sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xo%d\n", - glist_getcanvas(glist), - onset, ypos + x->x_height - 1, - onset + IOWIDTH, ypos + x->x_height, - x, i); - else - sys_vgui(".x%lx.c coords %xo%d %d %d %d %d\n", - glist_getcanvas(glist), x, i, - onset, ypos + x->x_height - 1, - onset + IOWIDTH, ypos + x->x_height); - } - n = nin; - nplus = (n == 1 ? 1 : n-1); - for (i = 0; i < n; i++) - { - int onset = xpos + (x->x_width - IOWIDTH) * i / nplus; - if (firsttime) - sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xi%d\n", - glist_getcanvas(glist), - onset, ypos, - onset + IOWIDTH, ypos + 1, - x, i); - else - sys_vgui(".x%lx.c coords %xi%d %d %d %d %d\n", - glist_getcanvas(glist), x, i, - onset, ypos, - onset + IOWIDTH, ypos + 1); - - } + nplus = (n == 1 ? 1 : n-1); + for (i = 0; i < n; i++) + { + int onset = xpos + (x->x_width - IOWIDTH) * i / nplus; + if (firsttime) + sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xo%d\n", + glist_getcanvas(glist), + onset, ypos + x->x_height - 1, + onset + IOWIDTH, ypos + x->x_height, + x, i); + else + sys_vgui(".x%lx.c coords %xo%d %d %d %d %d\n", + glist_getcanvas(glist), x, i, + onset, ypos + x->x_height - 1, + onset + IOWIDTH, ypos + x->x_height); + } + n = nin; + nplus = (n == 1 ? 1 : n-1); + for (i = 0; i < n; i++) + { + int onset = xpos + (x->x_width - IOWIDTH) * i / nplus; + if (firsttime) + sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xi%d\n", + glist_getcanvas(glist), + onset, ypos, + onset + IOWIDTH, ypos + 1, + x, i); + else + sys_vgui(".x%lx.c coords %xi%d %d %d %d %d\n", + glist_getcanvas(glist), x, i, + onset, ypos, + onset + IOWIDTH, ypos + 1); + + } } void gamme_drawme(t_gamme *x, t_glist *glist, int firsttime) { - int i,j; - float x1,y1,x2,y2; - int xi1,yi1,xi2,yi2; - char *color; + int i,j; + float x1,y1,x2,y2; + int xi1,yi1,xi2,yi2; + char *color; int xpos=text_xpix(&x->x_obj, glist); int ypos=text_ypix(&x->x_obj, glist); - - if (firsttime) { - sys_vgui(".x%lx.c create rectangle \ + + if (firsttime) + { + sys_vgui(".x%lx.c create rectangle \ %d %d %d %d -tags %xS "BACKGROUND"\n", - glist_getcanvas(glist), - xpos, ypos, - xpos + x->x_width, ypos + x->x_height, - x); - - } - else { - sys_vgui(".x%lx.c coords %xS \ + glist_getcanvas(glist), + xpos, ypos, + xpos + x->x_width, ypos + x->x_height, + x); + + } + else + { + sys_vgui(".x%lx.c coords %xS \ %d %d %d %d\n", - glist_getcanvas(glist), x, - xpos, ypos, - xpos + x->x_width, ypos + x->x_height); - } - - for(j=0;j<12;j++){ - i=WhitesBlacks[j]; - note_get_rel_rect(i,&x1,&y1,&x2,&y2); - xi1=xpos + x->x_width*x1; - xi2=xpos + x->x_width*x2; - yi1=ypos + x->x_height*y1; - yi2=ypos + x->x_height*y2; - - if (firsttime) { - color=x->x_notes[i]? (ISWHITE(i)?SELWHITECOLOR:SELBLACKCOLOR): - (ISWHITE(i)?WHITECOLOR:BLACKCOLOR); - sys_vgui(".x%lx.c create rectangle \ + glist_getcanvas(glist), x, + xpos, ypos, + xpos + x->x_width, ypos + x->x_height); + } + + for(j=0; j<12; j++) + { + i=WhitesBlacks[j]; + note_get_rel_rect(i,&x1,&y1,&x2,&y2); + xi1=xpos + x->x_width*x1; + xi2=xpos + x->x_width*x2; + yi1=ypos + x->x_height*y1; + yi2=ypos + x->x_height*y2; + + if (firsttime) + { + color=x->x_notes[i]? (ISWHITE(i)?SELWHITECOLOR:SELBLACKCOLOR): + (ISWHITE(i)?WHITECOLOR:BLACKCOLOR); + sys_vgui(".x%lx.c create rectangle \ %d %d %d %d -tags %x%s -fill %s\n", - glist_getcanvas(glist),xi1,yi1,xi2,yi2, - x,NoteNames[i],color); - } - else { - sys_vgui(".x%lx.c coords %x%s \ + glist_getcanvas(glist),xi1,yi1,xi2,yi2, + x,NoteNames[i],color); + } + else + { + sys_vgui(".x%lx.c coords %x%s \ %d %d %d %d\n", - glist_getcanvas(glist),x,NoteNames[i],xi1,yi1,xi2,yi2); - } - } - - draw_inlets(x, glist, firsttime, 1,3); + glist_getcanvas(glist),x,NoteNames[i],xi1,yi1,xi2,yi2); + } + } + + draw_inlets(x, glist, firsttime, 1,3); } -void gamme_erase(t_gamme* x,t_glist* glist) +void gamme_erase(t_gamme *x,t_glist *glist) { - int n; + int n; t_canvas *canvas=glist_getcanvas(glist); - sys_vgui(".x%lx.c delete %xS\n",canvas, x); + sys_vgui(".x%lx.c delete %xS\n",canvas, x); - for(n=0;n<12;n++) - sys_vgui(".x%lx.c delete %x%s\n",canvas,x,NoteNames[n]); + for(n=0; n<12; n++) + sys_vgui(".x%lx.c delete %x%s\n",canvas,x,NoteNames[n]); - n = 1; - while (n--) { - sys_vgui(".x%lx.c delete %xi%d\n",canvas,x,n); - } - n = 3; - while (n--) { - sys_vgui(".x%lx.c delete %xo%d\n",canvas,x,n); - } + n = 1; + while (n--) + { + sys_vgui(".x%lx.c delete %xi%d\n",canvas,x,n); + } + n = 3; + while (n--) + { + sys_vgui(".x%lx.c delete %xo%d\n",canvas,x,n); + } } - + /* ------------------------ gamme widgetbehaviour----------------------------- */ static void gamme_getrect(t_gobj *z, t_glist *glist, - int *xp1, int *yp1, int *xp2, int *yp2) + int *xp1, int *yp1, int *xp2, int *yp2) { t_gamme *x = (t_gamme *)z; int width, height; - t_gamme* s = (t_gamme*)z; + t_gamme *s = (t_gamme *)z; width = s->x_width; @@ -251,28 +259,28 @@ static void gamme_getrect(t_gobj *z, t_glist *glist, } static void gamme_displace(t_gobj *z, t_glist *glist, - int dx, int dy) + int dx, int dy) { t_gamme *x = (t_gamme *)z; x->x_obj.te_xpos += dx; x->x_obj.te_ypos += dy; gamme_drawme(x, glist, 0); - canvas_fixlinesfor(glist,(t_text*) x); + canvas_fixlinesfor(glist,(t_text *) x); } static void gamme_select(t_gobj *z, t_glist *glist, int state) { - t_gamme *x = (t_gamme *)z; - sys_vgui(".x%lx.c itemconfigure %xS -fill %s\n", glist, - x, (state? "blue" : BACKGROUNDCOLOR)); + t_gamme *x = (t_gamme *)z; + sys_vgui(".x%lx.c itemconfigure %xS -fill %s\n", glist, + x, (state? "blue" : BACKGROUNDCOLOR)); } static void gamme_activate(t_gobj *z, t_glist *glist, int state) { -/* t_text *x = (t_text *)z; - t_rtext *y = glist_findrtext(glist, x); - if (z->g_pd != gatom_class) rtext_activate(y, state);*/ + /* t_text *x = (t_text *)z; + t_rtext *y = glist_findrtext(glist, x); + if (z->g_pd != gatom_class) rtext_activate(y, state);*/ } static void gamme_delete(t_gobj *z, t_glist *glist) @@ -281,14 +289,14 @@ static void gamme_delete(t_gobj *z, t_glist *glist) canvas_deletelinesfor(glist, x); } - + static void gamme_vis(t_gobj *z, t_glist *glist, int vis) { - t_gamme* s = (t_gamme*)z; + t_gamme *s = (t_gamme *)z; if (vis) - gamme_drawme(s, glist, 1); + gamme_drawme(s, glist, 1); else - gamme_erase(s,glist); + gamme_erase(s,glist); } /* can we use the normal text save function ?? */ @@ -296,34 +304,34 @@ static void gamme_vis(t_gobj *z, t_glist *glist, int vis) static void gamme_save(t_gobj *z, t_binbuf *b) { t_gamme *x = (t_gamme *)z; - char *c=x->x_notes; - + char *c=x->x_notes; + binbuf_addv(b, "ssiisiiiiiiiiiiiiii", gensym("#X"),gensym("obj"), - (t_int)x->x_obj.te_xpos, (t_int)x->x_obj.te_ypos, - atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), - x->x_width,x->x_height, - c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7],c[8],c[9],c[10],c[11]); + (t_int)x->x_obj.te_xpos, (t_int)x->x_obj.te_ypos, + atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), + x->x_width,x->x_height, + c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7],c[8],c[9],c[10],c[11]); binbuf_addv(b, ";"); } void gamme_getn(t_gamme *x) { - outlet_float(x->x_out_n,x->x_n); + outlet_float(x->x_out_n,x->x_n); } void gamme_out_changed(t_gamme *x,int note) { - t_atom ats[2]; - SETFLOAT(&ats[0],note); - SETFLOAT(&ats[1],x->x_notes[note]); + t_atom ats[2]; + SETFLOAT(&ats[0],note); + SETFLOAT(&ats[1],x->x_notes[note]); - outlet_list(x->x_out_note,0,2,ats); + outlet_list(x->x_out_note,0,2,ats); } inline float my_mod(float x,int n) { - float y=fmod(x,n); - return y<0?y+n:y; + float y=fmod(x,n); + return y<0?y+n:y; } #define my_div(x,y) (floor(x/y)) @@ -331,136 +339,138 @@ inline float my_mod(float x,int n) void gamme_set(t_gamme *x,t_floatarg note,t_floatarg on) { - unsigned int i,notei=tonotei(note),changed=0; - char *color; + unsigned int i,notei=tonotei(note),changed=0; + char *color; t_canvas *canvas=glist_getcanvas(x->x_glist); - - - if(x->x_notes[notei]!=on) changed=1; - if(on<0) x->x_notes[notei]=!(x->x_notes[notei]); - else x->x_notes[notei]=on; - if(changed) gamme_out_changed(x,notei); - - color=x->x_notes[notei]?(ISWHITE(notei)?SELWHITECOLOR:SELBLACKCOLOR): - (ISWHITE(notei)?WHITECOLOR:BLACKCOLOR); - - if(glist_isvisible(x->x_glist)) - sys_vgui(".x%lx.c itemconfigure %x%s -fill %s\n", canvas, - x, NoteNames[notei],color); - - x->x_n=0; - for(i=0;i<12;i++) if(x->x_notes[i]) x->x_on_notes[(int)(x->x_n++)]=i; - gamme_getn(x); + + + if(x->x_notes[notei]!=on) changed=1; + if(on<0) x->x_notes[notei]=!(x->x_notes[notei]); + else x->x_notes[notei]=on; + if(changed) gamme_out_changed(x,notei); + + color=x->x_notes[notei]?(ISWHITE(notei)?SELWHITECOLOR:SELBLACKCOLOR): + (ISWHITE(notei)?WHITECOLOR:BLACKCOLOR); + + if(glist_isvisible(x->x_glist)) + sys_vgui(".x%lx.c itemconfigure %x%s -fill %s\n", canvas, + x, NoteNames[notei],color); + + x->x_n=0; + for(i=0; i<12; i++) if(x->x_notes[i]) x->x_on_notes[(int)(x->x_n++)]=i; + gamme_getn(x); } #define getnote(n) \ (my_div(n,(int)x->x_n)*12+x->x_on_notes[(int)my_mod(n,x->x_n)]) void gamme_get(t_gamme *x,t_floatarg ref_octave,t_floatarg note) { - int no0,no1,ni0,ni1,n0,n1,n; - float xn,xx,nn; + int no0,no1,ni0,ni1,n0,n1,n; + float xn,xx,nn; - if(!x->x_n) return; - no0=floor(note); - no1=ceil(note); - xx=note-no0; + if(!x->x_n) return; + no0=floor(note); + no1=ceil(note); + xx=note-no0; - nn=getnote((float)no0)*(1-xx)+getnote((float)(no0+1))*xx+ref_octave*12; - n=getnote((float)no0)+ref_octave*12; - outlet_float(x->x_obj.ob_outlet,nn); + nn=getnote((float)no0)*(1-xx)+getnote((float)(no0+1))*xx+ref_octave*12; + n=getnote((float)no0)+ref_octave*12; + outlet_float(x->x_obj.ob_outlet,nn); } static void gamme_click(t_gamme *x, t_floatarg xpos, t_floatarg ypos, - t_floatarg shift, t_floatarg ctrl, t_floatarg alt) + t_floatarg shift, t_floatarg ctrl, t_floatarg alt) { - int note; + int note; int x0=text_xpix(&x->x_obj, x->x_glist); int y0=text_ypix(&x->x_obj, x->x_glist); - - note=get_touched_note( - (xpos-x0)/x->x_width, - (ypos-y0)/x->x_height); - - if(note>=0) gamme_set(x,note,!x->x_notes[note]); + + note=get_touched_note( + (xpos-x0)/x->x_width, + (ypos-y0)/x->x_height); + + if(note>=0) gamme_set(x,note,!x->x_notes[note]); } static int gamme_newclick(t_gobj *z, struct _glist *glist, - int xpix, int ypix, int shift, int alt, int dbl, int doit) + int xpix, int ypix, int shift, int alt, int dbl, int doit) { - t_gamme* x = (t_gamme *)z; + t_gamme *x = (t_gamme *)z; if(doit) { - gamme_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, - 0, (t_floatarg)alt); + gamme_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, + 0, (t_floatarg)alt); } return (1); } void gamme_float(t_gamme *x,t_floatarg f) { - unsigned int notei=tonotei(f); + unsigned int notei=tonotei(f); - /*post("notei=%d",notei);*/ - if(x->x_notes[notei]) - outlet_float(x->x_obj.ob_outlet,f); + /*post("notei=%d",notei);*/ + if(x->x_notes[notei]) + outlet_float(x->x_obj.ob_outlet,f); } void gamme_round(t_gamme *x,t_floatarg f,t_floatarg round) { - unsigned int notei=tonotei(f); - int imin=floor(f),imax=ceil(f); - float norm; - - if(!x->x_n) return; - - while(!x->x_notes[(int)my_mod((imin),12U)]) imin--; - while(!x->x_notes[(int)my_mod((imax),12U)]) imax++; - - /*post("min: %d max: %d",imin,imax);*/ - - if((imin!=imax)&&round) { - round*=round; - norm=(f-imin)/(imax-imin)*2-1; - norm=norm/sqrt(1+round*norm*norm)*sqrt(1+round)/2+.5; - f=norm*(imax-imin)+imin; - } - outlet_float(x->x_obj.ob_outlet,f); + unsigned int notei=tonotei(f); + int imin=floor(f),imax=ceil(f); + float norm; + + if(!x->x_n) return; + + while(!x->x_notes[(int)my_mod((imin),12U)]) imin--; + while(!x->x_notes[(int)my_mod((imax),12U)]) imax++; + + /*post("min: %d max: %d",imin,imax);*/ + + if((imin!=imax)&&round) + { + round*=round; + norm=(f-imin)/(imax-imin)*2-1; + norm=norm/sqrt(1+round*norm*norm)*sqrt(1+round)/2+.5; + f=norm*(imax-imin)+imin; + } + outlet_float(x->x_obj.ob_outlet,f); } void gamme_setall(t_gamme *x,t_symbol *s, int argc, t_atom *argv) { - int i=0,err=0; - - if(argc==12) - { - for(i=0;i<12;i++) err+=!IS_A_FLOAT(argv,i); - if(!err) for(i=0;i<12;i++) gamme_set(x,i,atom_getfloat(&argv[i])); - } + int i=0,err=0; + + if(argc==12) + { + for(i=0; i<12; i++) err+=!IS_A_FLOAT(argv,i); + if(!err) for(i=0; i<12; i++) gamme_set(x,i,atom_getfloat(&argv[i])); + } } void gamme_getall(t_gamme *x) { - int i=0; + int i=0; - for(i=0;i<12;i++) gamme_out_changed(x,i); - gamme_getn(x); + for(i=0; i<12; i++) gamme_out_changed(x,i); + gamme_getn(x); } extern int sys_noloadbang; static void gamme_loadbang(t_gamme *x) { - int i; - - if(sys_noloadbang) return; - for(i=0;i<12;i++) gamme_out_changed(x,i); - gamme_getn(x); + int i; + + if(sys_noloadbang) return; + for(i=0; i<12; i++) gamme_out_changed(x,i); + gamme_getn(x); } -void gamme_size(t_gamme* x,t_floatarg w,t_floatarg h) { - x->x_width = w; - x->x_height = h; - gamme_drawme(x, x->x_glist, 0); +void gamme_size(t_gamme *x,t_floatarg w,t_floatarg h) +{ + x->x_width = w; + x->x_height = h; + gamme_drawme(x, x->x_glist, 0); } t_widgetbehavior gamme_widgetbehavior; @@ -474,73 +484,74 @@ static void gamme_setwidget(void) gamme_widgetbehavior.w_deletefn = gamme_delete; gamme_widgetbehavior.w_visfn = gamme_vis; gamme_widgetbehavior.w_clickfn = gamme_newclick; - //gamme_widgetbehavior.w_propertiesfn = NULL; + //gamme_widgetbehavior.w_propertiesfn = NULL; //gamme_widgetbehavior.w_savefn = gamme_save; } static void *gamme_new(t_symbol *s, int argc, t_atom *argv) { - int i=0,err=0; - - t_gamme *x = (t_gamme *)pd_new(gamme_class); - - x->x_glist = (t_glist*) canvas_getcurrent(); - x->x_width = DEFAULTWIDTH; - x->x_height = DEFAULTHEIGHT; - outlet_new(&x->x_obj, &s_float); - x->x_out_n=outlet_new(&x->x_obj, &s_float); - x->x_out_note=outlet_new(&x->x_obj, &s_float); - - x->x_n=0; - for(i=0;i<12;i++) x->x_notes[i]=0; - for(i=0;i<12;i++) x->x_on_notes[i]=0; - - if((argc>1)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)) - { - if(atom_getfloat(&argv[0])) x->x_width = atom_getfloat(&argv[0]); - if(atom_getfloat(&argv[1])) x->x_height = atom_getfloat(&argv[1]); - - if(argc==14) - { - for(i=0;i<12;i++) err+=(!IS_A_FLOAT(argv,i+2)); - if(!err) { - for(i=0;i<12;i++) if(x->x_notes[i]=atom_getfloat(&argv[i+2])) - x->x_on_notes[(int)(x->x_n++)]=i; - /*gamme_set(x,i,atom_getfloat(&argv[i+2]));gamme_getn(x);*/ - } - else post("gamme_new : error in creation arguments"); - } - /*if(argc==14) gamme_setall(x,s,argc-2,&argv[2]);*/ - } - - return (x); + int i=0,err=0; + + t_gamme *x = (t_gamme *)pd_new(gamme_class); + + x->x_glist = (t_glist *) canvas_getcurrent(); + x->x_width = DEFAULTWIDTH; + x->x_height = DEFAULTHEIGHT; + outlet_new(&x->x_obj, &s_float); + x->x_out_n=outlet_new(&x->x_obj, &s_float); + x->x_out_note=outlet_new(&x->x_obj, &s_float); + + x->x_n=0; + for(i=0; i<12; i++) x->x_notes[i]=0; + for(i=0; i<12; i++) x->x_on_notes[i]=0; + + if((argc>1)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)) + { + if(atom_getfloat(&argv[0])) x->x_width = atom_getfloat(&argv[0]); + if(atom_getfloat(&argv[1])) x->x_height = atom_getfloat(&argv[1]); + + if(argc==14) + { + for(i=0; i<12; i++) err+=(!IS_A_FLOAT(argv,i+2)); + if(!err) + { + for(i=0; i<12; i++) if(x->x_notes[i]=atom_getfloat(&argv[i+2])) + x->x_on_notes[(int)(x->x_n++)]=i; + /*gamme_set(x,i,atom_getfloat(&argv[i+2]));gamme_getn(x);*/ + } + else post("gamme_new : error in creation arguments"); + } + /*if(argc==14) gamme_setall(x,s,argc-2,&argv[2]);*/ + } + + return (x); } void gamme_setup(void) { - gamme_class = class_new(gensym("gamme"), (t_newmethod)gamme_new, 0, - sizeof(t_gamme),0, A_GIMME,0); + gamme_class = class_new(gensym("gamme"), (t_newmethod)gamme_new, 0, + sizeof(t_gamme),0, A_GIMME,0); class_addfloat(gamme_class,gamme_float); class_addmethod(gamme_class, (t_method)gamme_click, gensym("click"), - A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); class_addmethod(gamme_class, (t_method)gamme_size, gensym("size"), - A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, 0); class_addmethod(gamme_class, (t_method)gamme_set, gensym("set"), - A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, 0); class_addmethod(gamme_class, (t_method)gamme_get, gensym("get"), - A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, 0); class_addmethod(gamme_class, (t_method)gamme_round, gensym("round"), - A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, 0); class_addmethod(gamme_class, (t_method)gamme_setall, gensym("setall"), - A_GIMME, 0); + A_GIMME, 0); class_addmethod(gamme_class, (t_method)gamme_getall, gensym("getall"), 0); diff --git a/image.c b/image.c index 9f320e1..fa20732 100644 --- a/image.c +++ b/image.c @@ -15,87 +15,93 @@ static t_class *image_class; typedef struct _image { - t_object x_obj; - t_glist * x_glist; - int x_width; - int x_height; - t_symbol* x_image; - int x_type; //0=file 1=tk_image - t_int x_localimage; //localimage "img%x" done + t_object x_obj; + t_glist *x_glist; + int x_width; + int x_height; + t_symbol *x_image; + int x_type; //0=file 1=tk_image + t_int x_localimage; //localimage "img%x" done } t_image; /* widget helper functions */ -const char* image_get_filename(t_image *x,char *file) +const char *image_get_filename(t_image *x,char *file) { - static char fname[MAXPDSTRING]; - char *bufptr; - int fd; - - fd=open_via_path(canvas_getdir(glist_getcanvas(x->x_glist))->s_name, - file, "",fname, &bufptr, MAXPDSTRING, 1); - if(fd>0){ - fname[strlen(fname)]='/'; - //post("image file: %s",fname); - close(fd); - return fname; - } - else return 0; + static char fname[MAXPDSTRING]; + char *bufptr; + int fd; + + fd=open_via_path(canvas_getdir(glist_getcanvas(x->x_glist))->s_name, + file, "",fname, &bufptr, MAXPDSTRING, 1); + if(fd>0) + { + fname[strlen(fname)]='/'; + //post("image file: %s",fname); + close(fd); + return fname; + } + else return 0; } void image_drawme(t_image *x, t_glist *glist, int firsttime) { - if (firsttime) { - if(x->x_type) { - sys_vgui(".x%lx.c create image %d %d -tags %xS\n", - glist_getcanvas(glist), - text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x); - sys_vgui(".x%lx.c itemconfigure %xS -image %s\n", - glist_getcanvas(glist),x,x->x_image->s_name); - } - else { - const char *fname=image_get_filename(x,x->x_image->s_name); - if(!x->x_localimage) { - sys_vgui("image create photo img%x\n",x); - x->x_localimage=1; - } - if(fname) sys_vgui("img%x configure -file %s\n",x,fname); - sys_vgui(".x%lx.c create image %d %d -image img%x -tags %xS\n", - glist_getcanvas(glist), - text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x); - } - /* TODO callback from gui - sys_vgui("image_size logo"); - */ - } - else { - sys_vgui(".x%lx.c coords %xS \ + if (firsttime) + { + if(x->x_type) + { + sys_vgui(".x%lx.c create image %d %d -tags %xS\n", + glist_getcanvas(glist), + text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x); + sys_vgui(".x%lx.c itemconfigure %xS -image %s\n", + glist_getcanvas(glist),x,x->x_image->s_name); + } + else + { + const char *fname=image_get_filename(x,x->x_image->s_name); + if(!x->x_localimage) + { + sys_vgui("image create photo img%x\n",x); + x->x_localimage=1; + } + if(fname) sys_vgui("img%x configure -file %s\n",x,fname); + sys_vgui(".x%lx.c create image %d %d -image img%x -tags %xS\n", + glist_getcanvas(glist), + text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),x,x); + } + /* TODO callback from gui + sys_vgui("image_size logo"); + */ + } + else + { + sys_vgui(".x%lx.c coords %xS \ %d %d\n", - glist_getcanvas(glist), x, - text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)); - } + glist_getcanvas(glist), x, + text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist)); + } } -void image_erase(t_image* x,t_glist* glist) +void image_erase(t_image *x,t_glist *glist) { - int n; - sys_vgui(".x%lx.c delete %xS\n", - glist_getcanvas(glist), x); + int n; + sys_vgui(".x%lx.c delete %xS\n", + glist_getcanvas(glist), x); } - + /* ------------------------ image widgetbehaviour----------------------------- */ static void image_getrect(t_gobj *z, t_glist *glist, - int *xp1, int *yp1, int *xp2, int *yp2) + int *xp1, int *yp1, int *xp2, int *yp2) { int width, height; - t_image* x = (t_image*)z; + t_image *x = (t_image *)z; width = x->x_width; @@ -107,35 +113,37 @@ static void image_getrect(t_gobj *z, t_glist *glist, } static void image_displace(t_gobj *z, t_glist *glist, - int dx, int dy) + int dx, int dy) { t_image *x = (t_image *)z; x->x_obj.te_xpix += dx; x->x_obj.te_ypix += dy; sys_vgui(".x%lx.c coords %xSEL %d %d %d %d\n", - glist_getcanvas(glist), x, - text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), - text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height); + glist_getcanvas(glist), x, + text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), + text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height); image_drawme(x, glist, 0); - canvas_fixlinesfor(glist,(t_text*) x); + canvas_fixlinesfor(glist,(t_text *) x); } static void image_select(t_gobj *z, t_glist *glist, int state) { - t_image *x = (t_image *)z; - if (state) { - sys_vgui(".x%lx.c create rectangle \ + t_image *x = (t_image *)z; + if (state) + { + sys_vgui(".x%lx.c create rectangle \ %d %d %d %d -tags %xSEL -outline blue\n", - glist_getcanvas(glist), - text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), - text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height, - x); - } - else { - sys_vgui(".x%lx.c delete %xSEL\n", - glist_getcanvas(glist), x); - } + glist_getcanvas(glist), + text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), + text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height, + x); + } + else + { + sys_vgui(".x%lx.c delete %xSEL\n", + glist_getcanvas(glist), x); + } @@ -144,9 +152,9 @@ static void image_select(t_gobj *z, t_glist *glist, int state) static void image_activate(t_gobj *z, t_glist *glist, int state) { -/* t_text *x = (t_text *)z; - t_rtext *y = glist_findrtext(glist, x); - if (z->g_pd != gatom_class) rtext_activate(y, state);*/ + /* t_text *x = (t_text *)z; + t_rtext *y = glist_findrtext(glist, x); + if (z->g_pd != gatom_class) rtext_activate(y, state);*/ } static void image_delete(t_gobj *z, t_glist *glist) @@ -155,14 +163,14 @@ static void image_delete(t_gobj *z, t_glist *glist) canvas_deletelinesfor(glist, x); } - + static void image_vis(t_gobj *z, t_glist *glist, int vis) { - t_image* s = (t_image*)z; + t_image *s = (t_image *)z; if (vis) - image_drawme(s, glist, 1); + image_drawme(s, glist, 1); else - image_erase(s,glist); + image_erase(s,glist); } /* can we use the normal text save function ?? */ @@ -171,75 +179,81 @@ static void image_save(t_gobj *z, t_binbuf *b) { t_image *x = (t_image *)z; binbuf_addv(b, "ssiissi", gensym("#X"),gensym("obj"), - x->x_obj.te_xpix, x->x_obj.te_ypix, - atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), - x->x_image,x->x_type); + x->x_obj.te_xpix, x->x_obj.te_ypix, + atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), + x->x_image,x->x_type); binbuf_addv(b, ";"); } t_widgetbehavior image_widgetbehavior; -void image_size(t_image* x,t_floatarg w,t_floatarg h) { - x->x_width = w; - x->x_height = h; +void image_size(t_image *x,t_floatarg w,t_floatarg h) +{ + x->x_width = w; + x->x_height = h; } -void image_color(t_image* x,t_symbol* col) +void image_color(t_image *x,t_symbol *col) { -/* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang .. - so color black does the same as bang, but doesn't forward the bang -*/ + /* outlet_bang(x->x_obj.ob_outlet); only bang if there was a bang .. + so color black does the same as bang, but doesn't forward the bang + */ } -void image_open(t_gobj *z,t_symbol* file) +void image_open(t_gobj *z,t_symbol *file) { - t_image* x = (t_image*)z; - const char *fname; - int oldtype=x->x_type; - - - fname=image_get_filename(x,file->s_name); - if(fname){ - x->x_image=file; - x->x_type=0; - if(glist_isvisible(x->x_glist)) { - if(!x->x_localimage) { - sys_vgui("image create photo img%x\n",x); - x->x_localimage=1; - } - sys_vgui("img%x blank\n",x); - sys_vgui("img%x configure -file %s\n",x,fname); - if(oldtype) sys_vgui(".x%lx.c itemconfigure %xS -image img%x\n", - glist_getcanvas(x->x_glist),x,x); - } - } + t_image *x = (t_image *)z; + const char *fname; + int oldtype=x->x_type; + + + fname=image_get_filename(x,file->s_name); + if(fname) + { + x->x_image=file; + x->x_type=0; + if(glist_isvisible(x->x_glist)) + { + if(!x->x_localimage) + { + sys_vgui("image create photo img%x\n",x); + x->x_localimage=1; + } + sys_vgui("img%x blank\n",x); + sys_vgui("img%x configure -file %s\n",x,fname); + if(oldtype) sys_vgui(".x%lx.c itemconfigure %xS -image img%x\n", + glist_getcanvas(x->x_glist),x,x); + } + } } - -void image_load(t_gobj *z,t_symbol* image,t_symbol* file) + +void image_load(t_gobj *z,t_symbol *image,t_symbol *file) { - t_image* x = (t_image*)z; - const char *fname; + t_image *x = (t_image *)z; + const char *fname; - fname=image_get_filename(x,file->s_name); - if(fname){ - sys_vgui("image create photo %s -file %s\n",image->s_name,fname); - } + fname=image_get_filename(x,file->s_name); + if(fname) + { + sys_vgui("image create photo %s -file %s\n",image->s_name,fname); + } } - -void image_set(t_gobj *z,t_symbol* image) + +void image_set(t_gobj *z,t_symbol *image) { - t_image* x = (t_image*)z; - - x->x_image=image; - x->x_type=1; - - if(glist_isvisible(x->x_glist)) { - sys_vgui(".x%lx.c itemconfigure %xS -image %s\n", - glist_getcanvas(x->x_glist),x,x->x_image->s_name); - } + t_image *x = (t_image *)z; + + x->x_image=image; + x->x_type=1; + + if(glist_isvisible(x->x_glist)) + { + sys_vgui(".x%lx.c itemconfigure %xS -image %s\n", + glist_getcanvas(x->x_glist),x,x->x_image->s_name); + } } - + static void image_setwidget(void) { @@ -249,9 +263,9 @@ static void image_setwidget(void) image_widgetbehavior.w_activatefn = image_activate; image_widgetbehavior.w_deletefn = image_delete; image_widgetbehavior.w_visfn = image_vis; -#if (PD_VERSION_MINOR > 31) +#if (PD_VERSION_MINOR > 31) image_widgetbehavior.w_clickfn = NULL; - image_widgetbehavior.w_propertiesfn = NULL; + image_widgetbehavior.w_propertiesfn = NULL; #endif #if PD_MINOR_VERSION < 37 image_widgetbehavior.w_savefn = image_save; @@ -259,41 +273,41 @@ static void image_setwidget(void) } -static void *image_new(t_symbol* image,int type) +static void *image_new(t_symbol *image,int type) { t_image *x = (t_image *)pd_new(image_class); - x->x_glist = (t_glist*) canvas_getcurrent(); + x->x_glist = (t_glist *) canvas_getcurrent(); x->x_width = 15; x->x_height = 15; - x->x_type=type; - x->x_localimage=0; - x->x_image = image; + x->x_type=type; + x->x_localimage=0; + x->x_image = image; - outlet_new(&x->x_obj, &s_float); + outlet_new(&x->x_obj, &s_float); return (x); } void image_setup(void) { image_class = class_new(gensym("image"), (t_newmethod)image_new, 0, - sizeof(t_image),0, A_DEFSYM,A_DEFFLOAT,0); + sizeof(t_image),0, A_DEFSYM,A_DEFFLOAT,0); -/* - class_addmethod(image_class, (t_method)image_size, gensym("size"), - A_FLOAT, A_FLOAT, 0); + /* + class_addmethod(image_class, (t_method)image_size, gensym("size"), + A_FLOAT, A_FLOAT, 0); - class_addmethod(image_class, (t_method)image_color, gensym("color"), - A_SYMBOL, 0); -*/ + class_addmethod(image_class, (t_method)image_color, gensym("color"), + A_SYMBOL, 0); + */ class_addmethod(image_class, (t_method)image_open, gensym("open"), - A_SYMBOL, 0); + A_SYMBOL, 0); class_addmethod(image_class, (t_method)image_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); class_addmethod(image_class, (t_method)image_load, gensym("load"), - A_SYMBOL, A_SYMBOL, 0); + A_SYMBOL, A_SYMBOL, 0); image_setwidget(); class_setwidget(image_class,&image_widgetbehavior); diff --git a/mknob.c b/mknob.c index f96f028..ee924ee 100644 --- a/mknob.c +++ b/mknob.c @@ -53,54 +53,54 @@ static void mknob_update_knob(t_mknob *x, t_glist *glist) { t_canvas *canvas=glist_getcanvas(glist); // float val=(x->x_val + 50.0)/100.0/MKNOB_TANGLE; - float val=(x->x_val + 50.0)/100.0/x->x_H; - float angle, - radius=x->x_gui.x_w/2.0, - miniradius=MKNOB_THICK; - int x0,y0,x1,y1,xc,yc,xp,yp,xpc,ypc; + float val=(x->x_val + 50.0)/100.0/x->x_H; + float angle, + radius=x->x_gui.x_w/2.0, + miniradius=MKNOB_THICK; + int x0,y0,x1,y1,xc,yc,xp,yp,xpc,ypc; x0=text_xpix(&x->x_gui.x_obj, glist); y0=text_ypix(&x->x_gui.x_obj, glist); - x1=x0+x->x_gui.x_w; - y1=y0+x->x_gui.x_w; - xc=(x0+x1)/2; - yc=(y0+y1)/2; - - if(x->x_gui.x_h<0) - angle=val*(M_PI*2)+M_PI/2.0; - else - angle=val*(M_PI*1.5)+3.0*M_PI/4.0; - - xp=xc+radius*cos(angle); - yp=yc+radius*sin(angle); - xpc=miniradius*cos(angle-M_PI/2); - ypc=miniradius*sin(angle-M_PI/2); - - sys_vgui(".x%lx.c coords %xKNOB %d %d %d %d %d %d\n", - canvas,x,xp,yp,xc+xpc,yc+ypc,xc-xpc,yc-ypc); + x1=x0+x->x_gui.x_w; + y1=y0+x->x_gui.x_w; + xc=(x0+x1)/2; + yc=(y0+y1)/2; + + if(x->x_gui.x_h<0) + angle=val*(M_PI*2)+M_PI/2.0; + else + angle=val*(M_PI*1.5)+3.0*M_PI/4.0; + + xp=xc+radius*cos(angle); + yp=yc+radius*sin(angle); + xpc=miniradius*cos(angle-M_PI/2); + ypc=miniradius*sin(angle-M_PI/2); + + sys_vgui(".x%lx.c coords %xKNOB %d %d %d %d %d %d\n", + canvas,x,xp,yp,xc+xpc,yc+ypc,xc-xpc,yc-ypc); } static void mknob_draw_update(t_mknob *x, t_glist *glist) { if (glist_isvisible(glist)) { - mknob_update_knob(x,glist); - - /*if(x->x_val == x->x_center) - { - if(!x->x_thick) - { - sys_vgui(".x%lx.c itemconfigure %xKNOB -width 7\n", canvas, x); - x->x_thick = 1; - } - } - else - { - if(x->x_thick) - { - sys_vgui(".x%lx.c itemconfigure %xKNOB -width 3\n", canvas, x); - x->x_thick = 0; - } - }*/ + mknob_update_knob(x,glist); + + /*if(x->x_val == x->x_center) + { + if(!x->x_thick) + { + sys_vgui(".x%lx.c itemconfigure %xKNOB -width 7\n", canvas, x); + x->x_thick = 1; + } + } + else + { + if(x->x_thick) + { + sys_vgui(".x%lx.c itemconfigure %xKNOB -width 3\n", canvas, x); + x->x_thick = 0; + } + }*/ } } @@ -109,31 +109,31 @@ static void mknob_draw_new(t_mknob *x, t_glist *glist) int xpos=text_xpix(&x->x_gui.x_obj, glist); int ypos=text_ypix(&x->x_gui.x_obj, glist); int r = xpos + (x->x_val + 50)/100; - int xc=xpos+x->x_gui.x_w/2; - int yc=ypos+x->x_gui.x_w/2; + int xc=xpos+x->x_gui.x_w/2; + int yc=ypos+x->x_gui.x_w/2; t_canvas *canvas=glist_getcanvas(glist); - sys_vgui(".x%lx.c create oval %d %d %d %d -fill #%6.6x -tags %xBASE\n", - canvas,xpos,ypos,xpos + x->x_gui.x_w, ypos + x->x_gui.x_w, - x->x_gui.x_bcol,x); - sys_vgui(".x%lx.c create polygon %d %d %d %d %d %d -fill #%6.6x -tags %xKNOB\n", - glist_getcanvas(glist), - xc,ypos,xc-4,yc,xc+4,yc,x->x_gui.x_fcol,x); - mknob_update_knob(x,glist); + sys_vgui(".x%lx.c create oval %d %d %d %d -fill #%6.6x -tags %xBASE\n", + canvas,xpos,ypos,xpos + x->x_gui.x_w, ypos + x->x_gui.x_w, + x->x_gui.x_bcol,x); + sys_vgui(".x%lx.c create polygon %d %d %d %d %d %d -fill #%6.6x -tags %xKNOB\n", + glist_getcanvas(glist), + xc,ypos,xc-4,yc,xc+4,yc,x->x_gui.x_fcol,x); + mknob_update_knob(x,glist); sys_vgui(".x%lx.c create text %d %d -text {%s} -anchor w \ -font {{%s} %d bold} -fill #%6.6x -tags %xLABEL\n", - canvas, xpos+x->x_gui.x_ldx, - ypos+x->x_gui.x_ldy, - strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"", - x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x); + canvas, xpos+x->x_gui.x_ldx, + ypos+x->x_gui.x_ldy, + strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"", + x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x); /*if(!x->x_gui.x_fsf.x_snd_able) sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xOUT%d\n", - canvas, xpos+ x->x_gui.x_w/2-3, ypos + x->x_gui.x_w-1, - xpos+ x->x_gui.x_w/2+4, ypos + x->x_gui.x_w, x, 0); + canvas, xpos+ x->x_gui.x_w/2-3, ypos + x->x_gui.x_w-1, + xpos+ x->x_gui.x_w/2+4, ypos + x->x_gui.x_w, x, 0); if(!x->x_gui.x_fsf.x_rcv_able) - sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xIN%d\n", - canvas, xpos+ x->x_gui.x_w/2-3, ypos, - xpos+ x->x_gui.x_w/2+4, ypos+1, x, 0);*/ + sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xIN%d\n", + canvas, xpos+ x->x_gui.x_w/2-3, ypos, + xpos+ x->x_gui.x_w/2+4, ypos+1, x, 0);*/ } static void mknob_draw_move(t_mknob *x, t_glist *glist) @@ -144,25 +144,25 @@ static void mknob_draw_move(t_mknob *x, t_glist *glist) t_canvas *canvas=glist_getcanvas(glist); sys_vgui(".x%lx.c coords %xBASE %d %d %d %d\n", - canvas, x, - xpos, ypos, - xpos + x->x_gui.x_w, ypos + x->x_gui.x_w); + canvas, x, + xpos, ypos, + xpos + x->x_gui.x_w, ypos + x->x_gui.x_w); mknob_update_knob(x,glist); sys_vgui(".x%lx.c coords %xLABEL %d %d\n", - canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy); + canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy); /*if(!x->x_gui.x_fsf.x_snd_able) sys_vgui(".x%lx.c coords %xOUT%d %d %d %d %d\n", - canvas, x, 0, - xpos+ x->x_gui.x_w/2-3, ypos + x->x_gui.x_w-1, - xpos+ x->x_gui.x_w/2+4, ypos + x->x_gui.x_w); + canvas, x, 0, + xpos+ x->x_gui.x_w/2-3, ypos + x->x_gui.x_w-1, + xpos+ x->x_gui.x_w/2+4, ypos + x->x_gui.x_w); if(!x->x_gui.x_fsf.x_rcv_able) - sys_vgui(".x%lx.c coords %xIN%d %d %d %d %d\n", - canvas, x, 0, - xpos+ x->x_gui.x_w/2-3, ypos, - xpos+ x->x_gui.x_w/2+4, ypos+1);*/ + sys_vgui(".x%lx.c coords %xIN%d %d %d %d %d\n", + canvas, x, 0, + xpos+ x->x_gui.x_w/2-3, ypos, + xpos+ x->x_gui.x_w/2+4, ypos+1);*/ } -static void mknob_draw_erase(t_mknob* x,t_glist* glist) +static void mknob_draw_erase(t_mknob *x,t_glist *glist) { t_canvas *canvas=glist_getcanvas(glist); @@ -175,19 +175,19 @@ static void mknob_draw_erase(t_mknob* x,t_glist* glist) sys_vgui(".x%lx.c delete %xIN%d\n", canvas, x, 0);*/ } -static void mknob_draw_config(t_mknob* x,t_glist* glist) +static void mknob_draw_config(t_mknob *x,t_glist *glist) { t_canvas *canvas=glist_getcanvas(glist); sys_vgui(".x%lx.c itemconfigure %xLABEL -font {{%s} %d bold} -fill #%6.6x -text {%s} \n", - canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, - x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol, - strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:""); + canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, + x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol, + strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:""); sys_vgui(".x%lx.c itemconfigure %xKNOB -fill #%6.6x\n", canvas, x, x->x_gui.x_fcol); sys_vgui(".x%lx.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol); } -static void mknob_draw_io(t_mknob* x,t_glist* glist, int old_snd_rcv_flags) +static void mknob_draw_io(t_mknob *x,t_glist *glist, int old_snd_rcv_flags) { int xpos=text_xpix(&x->x_gui.x_obj, glist); int ypos=text_ypix(&x->x_gui.x_obj, glist); @@ -195,61 +195,61 @@ static void mknob_draw_io(t_mknob* x,t_glist* glist, int old_snd_rcv_flags) /*if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able) sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xOUT%d\n", - canvas, xpos+ x->x_gui.x_w/2-3, ypos + x->x_gui.x_w-1, - xpos+ x->x_gui.x_w/2+4, ypos + x->x_gui.x_w, x, 0); + canvas, xpos+ x->x_gui.x_w/2-3, ypos + x->x_gui.x_w-1, + xpos+ x->x_gui.x_w/2+4, ypos + x->x_gui.x_w, x, 0); if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able) sys_vgui(".x%lx.c delete %xOUT%d\n", canvas, x, 0); if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able) sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %xIN%d\n", - canvas, xpos+ x->x_gui.x_w/2-3, ypos, - xpos+ x->x_gui.x_w/2+4, ypos+1, x, 0); + canvas, xpos+ x->x_gui.x_w/2-3, ypos, + xpos+ x->x_gui.x_w/2+4, ypos+1, x, 0); if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able) - sys_vgui(".x%lx.c delete %xIN%d\n", canvas, x, 0);*/ + sys_vgui(".x%lx.c delete %xIN%d\n", canvas, x, 0);*/ } -static void mknob_draw_select(t_mknob* x,t_glist* glist) +static void mknob_draw_select(t_mknob *x,t_glist *glist) { t_canvas *canvas=glist_getcanvas(glist); if(x->x_gui.x_fsf.x_selected) { - //pd_bind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym); - sys_vgui(".x%lx.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); - sys_vgui(".x%lx.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); + //pd_bind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym); + sys_vgui(".x%lx.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); + sys_vgui(".x%lx.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); } else { - //pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym); - sys_vgui(".x%lx.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL); - sys_vgui(".x%lx.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol); + //pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym); + sys_vgui(".x%lx.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL); + sys_vgui(".x%lx.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol); } } void mknob_draw(t_mknob *x, t_glist *glist, int mode) { if(mode == IEM_GUI_DRAW_MODE_UPDATE) - mknob_draw_update(x, glist); + mknob_draw_update(x, glist); else if(mode == IEM_GUI_DRAW_MODE_MOVE) - mknob_draw_move(x, glist); + mknob_draw_move(x, glist); else if(mode == IEM_GUI_DRAW_MODE_NEW) - mknob_draw_new(x, glist); + mknob_draw_new(x, glist); else if(mode == IEM_GUI_DRAW_MODE_SELECT) - mknob_draw_select(x, glist); + mknob_draw_select(x, glist); else if(mode == IEM_GUI_DRAW_MODE_ERASE) - mknob_draw_erase(x, glist); + mknob_draw_erase(x, glist); else if(mode == IEM_GUI_DRAW_MODE_CONFIG) - mknob_draw_config(x, glist); + mknob_draw_config(x, glist); /*else if(mode >= IEM_GUI_DRAW_MODE_IO) - mknob_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);*/ + mknob_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);*/ } /* ------------------------ mknob widgetbehaviour----------------------------- */ static void mknob_getrect(t_gobj *z, t_glist *glist, - int *xp1, int *yp1, int *xp2, int *yp2) + int *xp1, int *yp1, int *xp2, int *yp2) { - t_mknob* x = (t_mknob*)z; + t_mknob *x = (t_mknob *)z; *xp1 = text_xpix(&x->x_gui.x_obj, glist); *yp1 = text_ypix(&x->x_gui.x_obj, glist); @@ -265,86 +265,86 @@ static void mknob_save(t_gobj *z, t_binbuf *b) iemgui_save(&x->x_gui, srl, bflcol); binbuf_addv(b, "ssiisiiffiisssiiiiiiiii", gensym("#X"),gensym("obj"), - (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, - atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), - x->x_gui.x_w, x->x_gui.x_h, - (float)x->x_min, (float)x->x_max, - x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa), - srl[0], srl[1], srl[2], - x->x_gui.x_ldx, x->x_gui.x_ldy, - iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize, - bflcol[0], bflcol[1], bflcol[2], - x->x_val, x->x_steady); + (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, + atom_getsymbol(binbuf_getvec(x->x_gui.x_obj.te_binbuf)), + x->x_gui.x_w, x->x_gui.x_h, + (float)x->x_min, (float)x->x_max, + x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa), + srl[0], srl[1], srl[2], + x->x_gui.x_ldx, x->x_gui.x_ldy, + iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize, + bflcol[0], bflcol[1], bflcol[2], + x->x_val, x->x_steady); binbuf_addv(b, ";"); } void mknob_check_wh(t_mknob *x, int w, int h) { int H; - - if(w < MKNOB_MINSIZE) w = MKNOB_MINSIZE; + + if(w < MKNOB_MINSIZE) w = MKNOB_MINSIZE; x->x_gui.x_w = w; - + if(h < -1) h=-1; if((h>0)&&(h<20)) h=20; x->x_gui.x_h = h; - - H=x->x_gui.x_h; - if(H<0) H=360; - if(H==0) H=270; - x->x_H=H; - + + H=x->x_gui.x_h; + if(H<0) H=360; + if(H==0) H=270; + x->x_H=H; + if(x->x_lin0_log1) - x->x_k = log(x->x_max/x->x_min)/(double)(x->x_H - 1); + x->x_k = log(x->x_max/x->x_min)/(double)(x->x_H - 1); else - x->x_k = (x->x_max - x->x_min)/(double)(x->x_H - 1); + x->x_k = (x->x_max - x->x_min)/(double)(x->x_H - 1); /*x->x_center = (x->x_gui.x_w-1)*50; if(x->x_val > (x->x_gui.x_w*100 - 100)) { - x->x_pos = x->x_gui.x_w*100 - 100; - x->x_val = x->x_pos; + x->x_pos = x->x_gui.x_w*100 - 100; + x->x_val = x->x_pos; } if(x->x_lin0_log1) - x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_w - 1); + x->x_k = log(x->x_max/x->x_min)/(double)(x->x_gui.x_w - 1); else - x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_w - 1);*/ + x->x_k = (x->x_max - x->x_min)/(double)(x->x_gui.x_w - 1);*/ } void mknob_check_minmax(t_mknob *x, double min, double max) { int H; - - if(x->x_lin0_log1) + + if(x->x_lin0_log1) { - if((min == 0.0)&&(max == 0.0)) - max = 1.0; - if(max > 0.0) - { - if(min <= 0.0) - min = 0.01*max; - } - else - { - if(min > 0.0) - max = 0.01*min; - } + if((min == 0.0)&&(max == 0.0)) + max = 1.0; + if(max > 0.0) + { + if(min <= 0.0) + min = 0.01*max; + } + else + { + if(min > 0.0) + max = 0.01*min; + } } x->x_min = min; x->x_max = max; if(x->x_min > x->x_max) /* bugfix */ - x->x_gui.x_isa.x_reverse = 1; + x->x_gui.x_isa.x_reverse = 1; else x->x_gui.x_isa.x_reverse = 0; if(x->x_lin0_log1) - x->x_k = log(x->x_max/x->x_min)/(double)(x->x_H - 1); + x->x_k = log(x->x_max/x->x_min)/(double)(x->x_H - 1); else - x->x_k = (x->x_max - x->x_min)/(double)(x->x_H - 1); + x->x_k = (x->x_max - x->x_min)/(double)(x->x_H - 1); /*if(x->x_lin0_log1) - x->x_k = log(x->x_max/x->x_min)/(double)(MKNOB_TANGLE - 1); + x->x_k = log(x->x_max/x->x_min)/(double)(MKNOB_TANGLE - 1); else - x->x_k = (x->x_max - x->x_min)/(double)(MKNOB_TANGLE - 1);*/ + x->x_k = (x->x_max - x->x_min)/(double)(MKNOB_TANGLE - 1);*/ } static void mknob_properties(t_gobj *z, t_glist *owner) @@ -362,13 +362,13 @@ static void mknob_properties(t_gobj *z, t_glist *owner) %s %d %d \ %d %d \ %d %d %d\n", - x->x_gui.x_w, MKNOB_MINSIZE, x->x_gui.x_h, -1, - x->x_min, x->x_max, 0.0,/*no_schedule*/ - x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/ - srl[0]->s_name, srl[1]->s_name, - srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy, - x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize, - 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol); + x->x_gui.x_w, MKNOB_MINSIZE, x->x_gui.x_h, -1, + x->x_min, x->x_max, 0.0,/*no_schedule*/ + x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, x->x_steady, -1,/*no multi, but iem-characteristic*/ + srl[0]->s_name, srl[1]->s_name, + srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy, + x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize, + 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol); gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf); } @@ -378,22 +378,22 @@ static void mknob_set(t_mknob *x, t_floatarg f) /* bugfix */ if(x->x_gui.x_isa.x_reverse) /* bugfix */ { - if(f > x->x_min) - f = x->x_min; - if(f < x->x_max) - f = x->x_max; + if(f > x->x_min) + f = x->x_min; + if(f < x->x_max) + f = x->x_max; } else { - if(f > x->x_max) - f = x->x_max; - if(f < x->x_min) - f = x->x_min; + if(f > x->x_max) + f = x->x_max; + if(f < x->x_min) + f = x->x_min; } if(x->x_lin0_log1) - g = log(f/x->x_min)/x->x_k; + g = log(f/x->x_min)/x->x_k; else - g = (f - x->x_min) / x->x_k; + g = (f - x->x_min) / x->x_k; x->x_val = (int)(100.0*g + 0.49999); x->x_pos = x->x_val; (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); @@ -404,11 +404,11 @@ static void mknob_bang(t_mknob *x) double out; if(x->x_lin0_log1) - out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01); + out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01); else - out = (double)(x->x_val)*0.01*x->x_k + x->x_min; + out = (double)(x->x_val)*0.01*x->x_k + x->x_min; if((out < 1.0e-10)&&(out > -1.0e-10)) - out = 0.0; + out = 0.0; outlet_float(x->x_gui.x_obj.ob_outlet, out); if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) pd_float(x->x_gui.x_snd->s_thing, out); @@ -428,9 +428,9 @@ static void mknob_dialog(t_mknob *x, t_symbol *s, int argc, t_atom *argv) if(lilo != 0) lilo = 1; x->x_lin0_log1 = lilo; if(steady) - x->x_steady = 1; + x->x_steady = 1; else - x->x_steady = 0; + x->x_steady = 0; sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv); //x->x_gui.x_h = iemgui_clip_size(h); //x->x_gui.x_w = iemgui_clip_size(w); @@ -439,7 +439,7 @@ static void mknob_dialog(t_mknob *x, t_symbol *s, int argc, t_atom *argv) (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG); (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags); (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE); - canvas_fixlinesfor(x->x_gui.x_glist, (t_text*)x); + canvas_fixlinesfor(x->x_gui.x_glist, (t_text *)x); } static int xm0,ym0,xm,ym; @@ -447,31 +447,31 @@ static int xm0,ym0,xm,ym; static void mknob_motion(t_mknob *x, t_floatarg dx, t_floatarg dy) { int old = x->x_val; - float d=-dy; - - if (abs(dx)>abs(dy)) d=dx; + float d=-dy; + + if (abs(dx)>abs(dy)) d=dx; if(x->x_gui.x_fsf.x_finemoved) - x->x_pos += (int)d; + x->x_pos += (int)d; else - x->x_pos += 100*(int)d; + x->x_pos += 100*(int)d; x->x_val = x->x_pos; if(x->x_val > (100*x->x_H - 100)) { - x->x_val = 100*x->x_H - 100; - x->x_pos += 50; - x->x_pos -= x->x_pos%100; + x->x_val = 100*x->x_H - 100; + x->x_pos += 50; + x->x_pos -= x->x_pos%100; } if(x->x_val < 0) { - x->x_val = 0; - x->x_pos -= 50; - x->x_pos -= x->x_pos%100; + x->x_val = 0; + x->x_pos -= 50; + x->x_pos -= x->x_pos%100; } if(old != x->x_val) { - (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); - mknob_bang(x); + (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); + mknob_bang(x); } } @@ -480,23 +480,23 @@ static void mknob_motion_circular(t_mknob *x, t_floatarg dx, t_floatarg dy) int xc=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w/2; int yc=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w/2; int old = x->x_val; - float alpha; - - xm+=dx; - ym+=dy; - - alpha=atan2(xm-xc,ym-yc)*180.0/M_PI; - - x->x_pos=(int)(31500-alpha*100.0)%36000; - if(x->x_pos>31500) x->x_pos=0; - else if(x->x_pos>(27000-100)) x->x_pos=(27000-100); + float alpha; + + xm+=dx; + ym+=dy; + + alpha=atan2(xm-xc,ym-yc)*180.0/M_PI; + + x->x_pos=(int)(31500-alpha*100.0)%36000; + if(x->x_pos>31500) x->x_pos=0; + else if(x->x_pos>(27000-100)) x->x_pos=(27000-100); x->x_val=x->x_pos; - - if(old != x->x_val) + + if(old != x->x_val) { - (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); - mknob_bang(x); + (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); + mknob_bang(x); } } @@ -505,111 +505,127 @@ static void mknob_motion_fullcircular(t_mknob *x, t_floatarg dx, t_floatarg dy) int xc=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w/2; int yc=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w/2; int old = x->x_val; - float alpha; - - xm+=dx; - ym+=dy; - - alpha=atan2(xm-xc,ym-yc)*180.0/M_PI; - - x->x_pos=(int)(36000-alpha*100.0)%36000; - /*if(x->x_pos>31500) x->x_pos=0; - else if(x->x_pos>(27000-100)) x->x_pos=(27000-100);*/ - - if(x->x_pos>(36000-100)) x->x_pos=(36000-100); + float alpha; + + xm+=dx; + ym+=dy; + + alpha=atan2(xm-xc,ym-yc)*180.0/M_PI; + + x->x_pos=(int)(36000-alpha*100.0)%36000; + /*if(x->x_pos>31500) x->x_pos=0; + else if(x->x_pos>(27000-100)) x->x_pos=(27000-100);*/ + + if(x->x_pos>(36000-100)) x->x_pos=(36000-100); x->x_val=x->x_pos; - - if(old != x->x_val) + + if(old != x->x_val) { - (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); - mknob_bang(x); + (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); + mknob_bang(x); } } static void mknob_click(t_mknob *x, t_floatarg xpos, t_floatarg ypos, - t_floatarg shift, t_floatarg ctrl, t_floatarg alt) + t_floatarg shift, t_floatarg ctrl, t_floatarg alt) { xm0=xm=xpos; ym0=ym=ypos; - //if(!x->x_steady) - //x->x_val = (int)(100.0 * (xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist))); + //if(!x->x_steady) + //x->x_val = (int)(100.0 * (xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist))); if(x->x_val > (100*x->x_H - 100)) - x->x_val = 100*x->x_H - 100; + x->x_val = 100*x->x_H - 100; if(x->x_val < 0) - x->x_val = 0; + x->x_val = 0; x->x_pos = x->x_val; (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); mknob_bang(x); - if(x->x_gui.x_h<0) - glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, - (t_glistmotionfn)mknob_motion_fullcircular, 0, xpos, ypos); - else if(x->x_gui.x_h==0) - glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, - (t_glistmotionfn)mknob_motion_circular, 0, xpos, ypos); - else - glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, - (t_glistmotionfn)mknob_motion, 0, xpos, ypos); + if(x->x_gui.x_h<0) + glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, + (t_glistmotionfn)mknob_motion_fullcircular, 0, xpos, ypos); + else if(x->x_gui.x_h==0) + glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, + (t_glistmotionfn)mknob_motion_circular, 0, xpos, ypos); + else + glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, + (t_glistmotionfn)mknob_motion, 0, xpos, ypos); } static int mknob_newclick(t_gobj *z, struct _glist *glist, - int xpix, int ypix, int shift, int alt, int dbl, int doit) + int xpix, int ypix, int shift, int alt, int dbl, int doit) { - t_mknob* x = (t_mknob *)z; + t_mknob *x = (t_mknob *)z; if(doit) { - mknob_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, - 0, (t_floatarg)alt); - if(shift) - x->x_gui.x_fsf.x_finemoved = 1; - else - x->x_gui.x_fsf.x_finemoved = 0; + mknob_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, + 0, (t_floatarg)alt); + if(shift) + x->x_gui.x_fsf.x_finemoved = 1; + else + x->x_gui.x_fsf.x_finemoved = 0; } return (1); } static void mknob_size(t_mknob *x, t_symbol *s, int ac, t_atom *av) { - int w=(int)atom_getintarg(0, ac, av), - h=x->x_gui.x_h; + int w=(int)atom_getintarg(0, ac, av), + h=x->x_gui.x_h; if(ac > 1) h=(int)atom_getintarg(1, ac, av); - - mknob_check_wh(x, w, h); + + mknob_check_wh(x, w, h); iemgui_size((void *)x, &x->x_gui); } static void mknob_delta(t_mknob *x, t_symbol *s, int ac, t_atom *av) -{iemgui_delta((void *)x, &x->x_gui, s, ac, av);} +{ + iemgui_delta((void *)x, &x->x_gui, s, ac, av); +} static void mknob_pos(t_mknob *x, t_symbol *s, int ac, t_atom *av) -{iemgui_pos((void *)x, &x->x_gui, s, ac, av);} +{ + iemgui_pos((void *)x, &x->x_gui, s, ac, av); +} static void mknob_range(t_mknob *x, t_symbol *s, int ac, t_atom *av) { mknob_check_minmax(x, (double)atom_getfloatarg(0, ac, av), - (double)atom_getfloatarg(1, ac, av)); + (double)atom_getfloatarg(1, ac, av)); } static void mknob_color(t_mknob *x, t_symbol *s, int ac, t_atom *av) -{iemgui_color((void *)x, &x->x_gui, s, ac, av);} +{ + iemgui_color((void *)x, &x->x_gui, s, ac, av); +} static void mknob_send(t_mknob *x, t_symbol *s) -{iemgui_send(x, &x->x_gui, s);} +{ + iemgui_send(x, &x->x_gui, s); +} static void mknob_receive(t_mknob *x, t_symbol *s) -{iemgui_receive(x, &x->x_gui, s);} +{ + iemgui_receive(x, &x->x_gui, s); +} static void mknob_label(t_mknob *x, t_symbol *s) -{iemgui_label((void *)x, &x->x_gui, s);} +{ + iemgui_label((void *)x, &x->x_gui, s); +} static void mknob_label_pos(t_mknob *x, t_symbol *s, int ac, t_atom *av) -{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);} +{ + iemgui_label_pos((void *)x, &x->x_gui, s, ac, av); +} static void mknob_label_font(t_mknob *x, t_symbol *s, int ac, t_atom *av) -{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);} +{ + iemgui_label_font((void *)x, &x->x_gui, s, ac, av); +} static void mknob_log(t_mknob *x) { @@ -639,16 +655,16 @@ static void mknob_float(t_mknob *x, t_floatarg f) mknob_set(x, f); if(x->x_lin0_log1) - out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01); + out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01); else - out = (double)(x->x_val)*0.01*x->x_k + x->x_min; + out = (double)(x->x_val)*0.01*x->x_k + x->x_min; if((out < 1.0e-10)&&(out > -1.0e-10)) - out = 0.0; + out = 0.0; if(x->x_gui.x_fsf.x_put_in2out) { - outlet_float(x->x_gui.x_obj.ob_outlet, out); - if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) - pd_float(x->x_gui.x_snd->s_thing, out); + outlet_float(x->x_gui.x_obj.ob_outlet, out); + if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing) + pd_float(x->x_gui.x_snd->s_thing, out); } } @@ -656,8 +672,8 @@ static void mknob_loadbang(t_mknob *x) { if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit) { - (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); - mknob_bang(x); + (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE); + mknob_bang(x); } } @@ -680,7 +696,7 @@ static void mknob_loadbang(t_mknob *x) static void *mknob_new(t_symbol *s, int argc, t_atom *argv) { t_mknob *x = (t_mknob *)pd_new(mknob_class); - int bflcol[]={-262144, -1, -1}; + int bflcol[]= {-262144, -1, -1}; //t_symbol *srl[3]; int w=MKNOB_DEFAULTSIZE, h=MKNOB_DEFAULTH; int fs=8 ,lilo=0, ldx=-2, ldy=-6, f=0, v=0, steady=1; @@ -695,58 +711,58 @@ static void *mknob_new(t_symbol *s, int argc, t_atom *argv) srl[2] = gensym("empty");*/ if(((argc == 17)||(argc == 18))&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1) - &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3) - &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5) - &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6)) - &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7)) - &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8)) - &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10) - &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13) - &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16)) + &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3) + &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5) + &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6)) + &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7)) + &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8)) + &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10) + &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13) + &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16)) { - w = (int)atom_getintarg(0, argc, argv); - h = (int)atom_getintarg(1, argc, argv); - min = (double)atom_getfloatarg(2, argc, argv); - max = (double)atom_getfloatarg(3, argc, argv); - lilo = (int)atom_getintarg(4, argc, argv); - iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv)); - iemgui_new_getnames(&x->x_gui, 6, argv); - ldx = (int)atom_getintarg(9, argc, argv); - ldy = (int)atom_getintarg(10, argc, argv); - iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv)); - fs = (int)atom_getintarg(12, argc, argv); - bflcol[0] = (int)atom_getintarg(13, argc, argv); - bflcol[1] = (int)atom_getintarg(14, argc, argv); - bflcol[2] = (int)atom_getintarg(15, argc, argv); - v = (int)atom_getintarg(16, argc, argv); - /*iinit = (int)atom_getintarg(5, argc, argv); - if(IS_A_SYMBOL(argv,6)) - srl[0] = atom_getsymbolarg(6, argc, argv); - else if(IS_A_FLOAT(argv,6)) - { - sprintf(str, "%d", (int)atom_getintarg(6, argc, argv)); - srl[0] = gensym(str); - } - if(IS_A_SYMBOL(argv,7)) - srl[1] = atom_getsymbolarg(7, argc, argv); - else if(IS_A_FLOAT(argv,7)) - { - sprintf(str, "%d", (int)atom_getintarg(7, argc, argv)); - srl[1] = gensym(str); - } - if(IS_A_SYMBOL(argv,8)) - srl[2] = atom_getsymbolarg(8, argc, argv); - else if(IS_A_FLOAT(argv,8)) - { - sprintf(str, "%d", (int)atom_getintarg(8, argc, argv)); - srl[2] = gensym(str); - }*/ - //ifstyle = (int)atom_getintarg(11, argc, argv); + w = (int)atom_getintarg(0, argc, argv); + h = (int)atom_getintarg(1, argc, argv); + min = (double)atom_getfloatarg(2, argc, argv); + max = (double)atom_getfloatarg(3, argc, argv); + lilo = (int)atom_getintarg(4, argc, argv); + iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv)); + iemgui_new_getnames(&x->x_gui, 6, argv); + ldx = (int)atom_getintarg(9, argc, argv); + ldy = (int)atom_getintarg(10, argc, argv); + iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv)); + fs = (int)atom_getintarg(12, argc, argv); + bflcol[0] = (int)atom_getintarg(13, argc, argv); + bflcol[1] = (int)atom_getintarg(14, argc, argv); + bflcol[2] = (int)atom_getintarg(15, argc, argv); + v = (int)atom_getintarg(16, argc, argv); + /*iinit = (int)atom_getintarg(5, argc, argv); + if(IS_A_SYMBOL(argv,6)) + srl[0] = atom_getsymbolarg(6, argc, argv); + else if(IS_A_FLOAT(argv,6)) + { + sprintf(str, "%d", (int)atom_getintarg(6, argc, argv)); + srl[0] = gensym(str); + } + if(IS_A_SYMBOL(argv,7)) + srl[1] = atom_getsymbolarg(7, argc, argv); + else if(IS_A_FLOAT(argv,7)) + { + sprintf(str, "%d", (int)atom_getintarg(7, argc, argv)); + srl[1] = gensym(str); + } + if(IS_A_SYMBOL(argv,8)) + srl[2] = atom_getsymbolarg(8, argc, argv); + else if(IS_A_FLOAT(argv,8)) + { + sprintf(str, "%d", (int)atom_getintarg(8, argc, argv)); + srl[2] = gensym(str); + }*/ + //ifstyle = (int)atom_getintarg(11, argc, argv); } else iemgui_new_getnames(&x->x_gui, 6, 0); if((argc == 18)&&IS_A_FLOAT(argv,17)) - steady = (int)atom_getintarg(17, argc, argv); + steady = (int)atom_getintarg(17, argc, argv); /*iinit &= IEM_INIT_ARGS_ALL; ifstyle &= IEM_FSTYLE_FLAGS_ALL; @@ -758,26 +774,29 @@ static void *mknob_new(t_symbol *s, int argc, t_atom *argv) x->x_gui.x_glist = (t_glist *)canvas_getcurrent(); //x->x_gui.x_isa = *init; if(x->x_gui.x_isa.x_loadinit) - x->x_val = v; + x->x_val = v; else - x->x_val = 0; + x->x_val = 0; x->x_pos = x->x_val; if(lilo != 0) lilo = 1; x->x_lin0_log1 = lilo; if(steady != 0) steady = 1; x->x_steady = steady; - if(!strcmp(x->x_gui.x_snd->s_name, "empty")) x->x_gui.x_fsf.x_snd_able = 0; + if(!strcmp(x->x_gui.x_snd->s_name, "empty")) x->x_gui.x_fsf.x_snd_able = 0; if(!strcmp(x->x_gui.x_rcv->s_name, "empty")) x->x_gui.x_fsf.x_rcv_able = 0; //if(!strcmp(srl[0]->s_name, "empty")) fstyle->x_snd_able = 0; //if(!strcmp(srl[1]->s_name, "empty")) fstyle->x_rcv_able = 0; //x->x_gui.x_unique_num = 0; if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica"); else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times"); - else { x->x_gui.x_fsf.x_font_style = 0; - /*if(fstyle->x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica"); - else if(fstyle->x_font_style == 2) strcpy(x->x_gui.x_font, "times"); - else { fstyle->x_font_style = 0;*/ - strcpy(x->x_gui.x_font, "courier"); } + else + { + x->x_gui.x_fsf.x_font_style = 0; + /*if(fstyle->x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica"); + else if(fstyle->x_font_style == 2) strcpy(x->x_gui.x_font, "times"); + else { fstyle->x_font_style = 0;*/ + strcpy(x->x_gui.x_font, "courier"); + } //x->x_gui.x_fsf = *fstyle; //iemgui_first_dollararg2sym(&x->x_gui, srl); //if(x->x_gui.x_fsf.x_rcv_able) pd_bind(&x->x_gui.x_obj.ob_pd, srl[1]); @@ -788,7 +807,7 @@ static void *mknob_new(t_symbol *s, int argc, t_atom *argv) x->x_gui.x_ldx = ldx; x->x_gui.x_ldy = ldy; if(fs < 4) - fs = 4; + fs = 4; x->x_gui.x_fontsize = fs; //x->x_gui.x_h = iemgui_clip_size(h); //x->x_gui.x_w = iemgui_clip_size(w); @@ -805,9 +824,9 @@ static void *mknob_new(t_symbol *s, int argc, t_atom *argv) static void mknob_free(t_mknob *x) { /*if(x->x_gui.x_fsf.x_selected) - pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym);*/ + pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym);*/ if(x->x_gui.x_fsf.x_rcv_able) - pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); + pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); gfxstub_deleteforkey(x); } @@ -821,7 +840,7 @@ void canvas_mknob(t_glist *gl, t_symbol *s, int argc, t_atom *argv) void mknob_setup(void) { mknob_class = class_new(gensym("mknob"), (t_newmethod)mknob_new, - (t_method)mknob_free, sizeof(t_mknob), 0, A_GIMME, 0); + (t_method)mknob_free, sizeof(t_mknob), 0, A_GIMME, 0); #ifndef GGEE_mknob_COMPATIBLE // class_addcreator((t_newmethod)mknob_new, gensym("mknob"), A_GIMME, 0); #endif @@ -829,9 +848,9 @@ void mknob_setup(void) class_addfloat(mknob_class,mknob_float); //class_addlist(mknob_class, mknob_list); class_addmethod(mknob_class, (t_method)mknob_click, gensym("click"), - A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); class_addmethod(mknob_class, (t_method)mknob_motion, gensym("motion"), - A_FLOAT, A_FLOAT, 0); + A_FLOAT, A_FLOAT, 0); class_addmethod(mknob_class, (t_method)mknob_dialog, gensym("dialog"), A_GIMME, 0); class_addmethod(mknob_class, (t_method)mknob_loadbang, gensym("loadbang"), 0); class_addmethod(mknob_class, (t_method)mknob_set, gensym("set"), A_FLOAT, 0); @@ -850,7 +869,7 @@ void mknob_setup(void) class_addmethod(mknob_class, (t_method)mknob_init, gensym("init"), A_FLOAT, 0); class_addmethod(mknob_class, (t_method)mknob_steady, gensym("steady"), A_FLOAT, 0); /*if(!iemgui_key_sym) - iemgui_key_sym = gensym("#keyname");*/ + iemgui_key_sym = gensym("#keyname");*/ mknob_widgetbehavior.w_getrectfn = mknob_getrect; mknob_widgetbehavior.w_displacefn = iemgui_displace; mknob_widgetbehavior.w_selectfn = iemgui_select; @@ -865,5 +884,5 @@ void mknob_setup(void) class_setsavefn(mknob_class, mknob_save); class_setpropertiesfn(mknob_class, mknob_properties); class_addmethod(canvas_class, (t_method)canvas_mknob, gensym("mknob"), - A_GIMME, A_NULL); + A_GIMME, A_NULL); } diff --git a/panvol~.c b/panvol~.c index 2e302c6..05709ff 100644 --- a/panvol~.c +++ b/panvol~.c @@ -1,28 +1,28 @@ -/*************************************************************************** - * File: pan~.c - * Auth: Iain Mott [iain.mott@bigpond.com] - * Maintainer: Iain Mott [iain.mott@bigpond.com] - * Version: Part of motex_1.1.2 +/*************************************************************************** + * File: pan~.c + * Auth: Iain Mott [iain.mott@bigpond.com] + * Maintainer: Iain Mott [iain.mott@bigpond.com] + * Version: Part of motex_1.1.2 * Date: January 2001 - * + * * Description: Pd signal external. Equal-power stereo panning - * Angle input specified in degrees. -45 left, 0 centre, 45 right. + * Angle input specified in degrees. -45 left, 0 centre, 45 right. * See supporting Pd patch: pan~.pd - * - * Copyright (C) 2001 by Iain Mott [iain.mott@bigpond.com] - * - * 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, 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, which should be included with this - * program, for more details. - * - ****************************************************************************/ + * + * Copyright (C) 2001 by Iain Mott [iain.mott@bigpond.com] + * + * 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, 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, which should be included with this + * program, for more details. + * + ****************************************************************************/ /* I've only add a global volume... Antoine Rousseau 2003*/ @@ -35,85 +35,85 @@ static t_class *pan_class; typedef struct _pan { - t_object x_obj; - float x_f; - float pan; - float left; - float right; - float vol; + t_object x_obj; + float x_f; + float pan; + float left; + float right; + float vol; } t_pan; static void *pan_new(t_symbol *s, int argc, t_atom *argv) { - t_pan *x = (t_pan *)pd_new(pan_class); - outlet_new(&x->x_obj, gensym("signal")); - outlet_new(&x->x_obj, gensym("signal")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("panf")); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("volf")); + t_pan *x = (t_pan *)pd_new(pan_class); + outlet_new(&x->x_obj, gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("panf")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("volf")); - x->x_f = 0; - x->left = ROOT2DIV2; - x->right = ROOT2DIV2; - x->vol = 1; - return (x); + x->x_f = 0; + x->left = ROOT2DIV2; + x->right = ROOT2DIV2; + x->vol = 1; + return (x); } static t_int *pan_perform(t_int *w) { - float *in1 = (t_float *)(w[1]); - float *out1 = (t_float *)(w[2]); - float *out2 = (t_float *)(w[3]); - int n = (int)(w[4]); - t_pan *x = (t_pan *)(w[5]); - float left=x->left*x->vol; - float right=x->right*x->vol; - float value; - - while (n--) + float *in1 = (t_float *)(w[1]); + float *out1 = (t_float *)(w[2]); + float *out2 = (t_float *)(w[3]); + int n = (int)(w[4]); + t_pan *x = (t_pan *)(w[5]); + float left=x->left*x->vol; + float right=x->right*x->vol; + float value; + + while (n--) { - value = *in1++; - *out1++ = value * left; - *out2++ = value * right; + value = *in1++; + *out1++ = value * left; + *out2++ = value * right; } - return (w+6); + return (w+6); } static void pan_dsp(t_pan *x, t_signal **sp) { - int n = sp[0]->s_n; - float *in1 = sp[0]->s_vec; - float *out1 = sp[1]->s_vec; - float *out2 = sp[2]->s_vec; + int n = sp[0]->s_n; + float *in1 = sp[0]->s_vec; + float *out1 = sp[1]->s_vec; + float *out2 = sp[2]->s_vec; - dsp_add(pan_perform, 5, - in1, out1, out2, n, x); + dsp_add(pan_perform, 5, + in1, out1, out2, n, x); } static void pan_f(t_pan *x, t_floatarg f) { - double angle; - f = f < -45 ? -45 : f; - f = f > 45 ? 45 : f; - angle = f * RADCONST; // convert degrees to radians - x->right = ROOT2DIV2 * (cos(angle) + sin(angle)); - x->left = ROOT2DIV2 * (cos(angle) - sin(angle)); -/* post("left = %f : right = %f", x->left, x->right); */ + double angle; + f = f < -45 ? -45 : f; + f = f > 45 ? 45 : f; + angle = f * RADCONST; // convert degrees to radians + x->right = ROOT2DIV2 * (cos(angle) + sin(angle)); + x->left = ROOT2DIV2 * (cos(angle) - sin(angle)); + /* post("left = %f : right = %f", x->left, x->right); */ } static void vol_f(t_pan *x, t_floatarg f) { - f = f < 0 ? 0 : f; - x->vol=f; + f = f < 0 ? 0 : f; + x->vol=f; } void panvol_tilde_setup(void) { - pan_class = class_new(gensym("panvol~"), (t_newmethod)pan_new, 0, - sizeof(t_pan), 0, A_GIMME, 0); + pan_class = class_new(gensym("panvol~"), (t_newmethod)pan_new, 0, + sizeof(t_pan), 0, A_GIMME, 0); - class_addmethod(pan_class, nullfn, gensym("signal"), 0); + class_addmethod(pan_class, nullfn, gensym("signal"), 0); - class_addmethod(pan_class, (t_method)pan_dsp, gensym("dsp"), 0); - class_addmethod(pan_class, (t_method)pan_f, gensym("panf"), A_FLOAT, 0); - class_addmethod(pan_class, (t_method)vol_f, gensym("volf"), A_FLOAT, 0); + class_addmethod(pan_class, (t_method)pan_dsp, gensym("dsp"), 0); + class_addmethod(pan_class, (t_method)pan_f, gensym("panf"), A_FLOAT, 0); + class_addmethod(pan_class, (t_method)vol_f, gensym("volf"), A_FLOAT, 0); } diff --git a/popen.c b/popen.c index c97a17c..2e82cd4 100644 --- a/popen.c +++ b/popen.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -29,9 +29,9 @@ typedef struct popen { t_object x_obj; FILE *x_file; - char x_data[BUFSIZE]; - int x_count; - int x_ropened; + char x_data[BUFSIZE]; + int x_count; + int x_ropened; t_outlet *x_msgout; } t_popen; @@ -45,22 +45,23 @@ static void *popen_new(t_symbol *s, int argc, t_atom *argv) x = (t_popen *)pd_new(popen_class); - x->x_file = NULL; - x->x_count=0; - x->x_msgout = outlet_new(&x->x_obj, &s_anything); - x->x_ropened=0; + x->x_file = NULL; + x->x_count=0; + x->x_msgout = outlet_new(&x->x_obj, &s_anything); + x->x_ropened=0; return (x); } static void popen_close(t_popen *x) { - if(x->x_ropened) { - sys_rmpollfn(fileno(x->x_file)); - //fflush(x->x_file); - } - if(x->x_file) pclose(x->x_file); - x->x_file=0; - x->x_ropened=0; + if(x->x_ropened) + { + sys_rmpollfn(fileno(x->x_file)); + //fflush(x->x_file); + } + if(x->x_file) pclose(x->x_file); + x->x_file=0; + x->x_ropened=0; } static void popen_ff(t_popen *x) @@ -93,25 +94,26 @@ static void popen_open(t_popen *x, t_symbol *s,int argc, t_atom *argv) } static void popen_list(t_popen *x, t_symbol *s, - int argc, t_atom *argv) + int argc, t_atom *argv) { - t_binbuf *bb; - char *buf; - int l; + t_binbuf *bb; + char *buf; + int l; - if(!x->x_file) return; + if(!x->x_file) return; - bb=binbuf_new(); - binbuf_add(bb,argc,argv); - //binbuf_print(bb); - binbuf_gettext(bb, &buf,&l); - buf[l]=0; + bb=binbuf_new(); + binbuf_add(bb,argc,argv); + //binbuf_print(bb); + binbuf_gettext(bb, &buf,&l); + buf[l]=0; - //printf("popen list: %s\n",buf); - fprintf(x->x_file,"%s\n",buf);fflush(x->x_file); + //printf("popen list: %s\n",buf); + fprintf(x->x_file,"%s\n",buf); + fflush(x->x_file); - freebytes(buf,l); - binbuf_free(bb); + freebytes(buf,l); + binbuf_free(bb); } static void popen_out(t_popen *x, t_binbuf *b) @@ -121,52 +123,55 @@ static void popen_out(t_popen *x, t_binbuf *b) t_atom *at = binbuf_getvec(b); for (msg = 0; msg < natom;) { - int emsg; - for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA - && at[emsg].a_type != A_SEMI; emsg++) - ; - if (emsg > msg) - { - int i; - for (i = msg; i < emsg; i++) - if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) - { - pd_error(x, "popen: got dollar sign in message"); - goto nodice; - } - if (at[msg].a_type == A_FLOAT) - { - if (emsg > msg + 1) - outlet_list(x->x_msgout, 0, emsg-msg, at + msg); - else outlet_float(x->x_msgout, at[msg].a_w.w_float); - } - else if (at[msg].a_type == A_SYMBOL) - outlet_anything(x->x_msgout, at[msg].a_w.w_symbol, - emsg-msg-1, at + msg + 1); - } - nodice: - msg = emsg + 1; + int emsg; + for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA + && at[emsg].a_type != A_SEMI; emsg++) + ; + if (emsg > msg) + { + int i; + for (i = msg; i < emsg; i++) + if (at[i].a_type == A_DOLLAR || at[i].a_type == A_DOLLSYM) + { + pd_error(x, "popen: got dollar sign in message"); + goto nodice; + } + if (at[msg].a_type == A_FLOAT) + { + if (emsg > msg + 1) + outlet_list(x->x_msgout, 0, emsg-msg, at + msg); + else outlet_float(x->x_msgout, at[msg].a_w.w_float); + } + else if (at[msg].a_type == A_SYMBOL) + outlet_anything(x->x_msgout, at[msg].a_w.w_symbol, + emsg-msg-1, at + msg + 1); + } +nodice: + msg = emsg + 1; } } static void popen_read(t_popen *x,int fd) { - int len,i=0; - unsigned char b; - unsigned char buffer[BUFSIZE]; - - if((len=read(fd,buffer,BUFSIZE))> 0){ - - for(i=0;ix_count>=BUFSIZE) x->x_count=0; - x->x_data[x->x_count++]=buffer[i]; - if(buffer[i]==';') { - binbuf_text(inbinbuf, x->x_data, x->x_count); - x->x_count=0; - popen_out(x,inbinbuf); - } - } - } + int len,i=0; + unsigned char b; + unsigned char buffer[BUFSIZE]; + + if((len=read(fd,buffer,BUFSIZE))> 0) + { + + for(i=0; ix_count>=BUFSIZE) x->x_count=0; + x->x_data[x->x_count++]=buffer[i]; + if(buffer[i]==';') + { + binbuf_text(inbinbuf, x->x_data, x->x_count); + x->x_count=0; + popen_out(x,inbinbuf); + } + } + } } static void popen_ropen(t_popen *x, t_symbol *s,int argc, t_atom *argv) @@ -190,21 +195,21 @@ static void popen_ropen(t_popen *x, t_symbol *s,int argc, t_atom *argv) //post("cmd=%s",cmd); x->x_file=popen(cmd,"r"); - sys_addpollfn(fileno(x->x_file),(t_fdpollfn)popen_read,(void*)x); - x->x_ropened=1; + sys_addpollfn(fileno(x->x_file),(t_fdpollfn)popen_read,(void *)x); + x->x_ropened=1; } void popen_setup(void ) { - inbinbuf = binbuf_new(); + inbinbuf = binbuf_new(); popen_class = class_new(gensym("popen"), (t_newmethod)popen_new, - (t_method)popen_close,sizeof(t_popen), 0, A_GIMME, 0); + (t_method)popen_close,sizeof(t_popen), 0, A_GIMME, 0); class_addmethod(popen_class, (t_method)popen_close, - gensym("close"), 0); + gensym("close"), 0); class_addmethod(popen_class, (t_method)popen_open, - gensym("open"), A_GIMME, 0); + gensym("open"), A_GIMME, 0); class_addmethod(popen_class, (t_method)popen_ropen, - gensym("ropen"), A_GIMME, 0); + gensym("ropen"), A_GIMME, 0); class_addlist(popen_class, popen_list); } diff --git a/readsfv~.c b/readsfv~.c index fc9c54f..e3248ac 100644 --- a/readsfv~.c +++ b/readsfv~.c @@ -14,10 +14,10 @@ objects are available for linux only so far, although they could be compiled for Windows if someone were willing to find a Pthreads package for it. */ /* this is a partial copy of d_soundfile, with some hacking: - 1: a fix in soundfiler to compute the normalization factor only on + 1: a fix in soundfiler to compute the normalization factor only on the samples we want to write on the disk... 2: a version of readsf~ that works with a (positive) speed parameter. - + Antoine Rousseau */ @@ -124,7 +124,7 @@ typedef struct _comm unsigned char c_samprate[10]; /* sample rate, 80-bit float! */ } t_comm; - /* this version is more convenient for writing them out: */ +/* this version is more convenient for writing them out: */ typedef struct _aiff { char a_fileid[4]; /* chunk id 'FORM' */ @@ -170,15 +170,15 @@ extern int garray_ambigendian(void); static uint32 swap4(uint32 n, int doit) { if (doit) - return (((n & 0xff) << 24) | ((n & 0xff00) << 8) | - ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24)); + return (((n & 0xff) << 24) | ((n & 0xff00) << 8) | + ((n & 0xff0000) >> 8) | ((n & 0xff000000) >> 24)); else return (n); } static uint16 swap2(uint32 n, int doit) { if (doit) - return (((n & 0xff) << 8) | ((n & 0xff00) >> 8)); + return (((n & 0xff) << 8) | ((n & 0xff00) >> 8)); else return (n); } @@ -186,8 +186,11 @@ static void swapstring(char *foo, int doit) { if (doit) { - char a = foo[0], b = foo[1], c = foo[2], d = foo[3]; - foo[0] = d; foo[1] = c; foo[2] = b; foo[3] = a; + char a = foo[0], b = foo[1], c = foo[2], d = foo[3]; + foo[0] = d; + foo[1] = c; + foo[2] = b; + foo[3] = a; } } @@ -205,13 +208,13 @@ void readsf_banana( void); /* debugging */ */ extern int open_soundfile(const char *dirname, const char *filename, int headersize, - int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, - long skipframes); + int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, + long skipframes); static void soundfile_xferin(int sfchannels, int nvecs, float **vecs, - long itemsread, unsigned char *buf, int nitems, int bytespersamp, - int bigendian) + long itemsread, unsigned char *buf, int nitems, int bytespersamp, + int bigendian) { int i, j; unsigned char *sp, *sp2; @@ -220,202 +223,213 @@ static void soundfile_xferin(int sfchannels, int nvecs, float **vecs, int bytesperframe = bytespersamp * sfchannels; for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp) { - if (bytespersamp == 2) - { - if (bigendian) - { - for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; - j < nitems; j++, sp2 += bytesperframe, fp++) - *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16)); - } - else - { - for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; - j < nitems; j++, sp2 += bytesperframe, fp++) - *fp = SCALE * ((sp2[1] << 24) | (sp2[0] << 16)); - } - } - else if (bytespersamp == 3) - { - if (bigendian) - { - for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; - j < nitems; j++, sp2 += bytesperframe, fp++) - *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16) - | (sp2[2] << 8)); - } - else - { - for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; - j < nitems; j++, sp2 += bytesperframe, fp++) - *fp = SCALE * ((sp2[2] << 24) | (sp2[1] << 16) - | (sp2[0] << 8)); - } - } - else if (bytespersamp == 4) - { - if (bigendian) - { - for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; - j < nitems; j++, sp2 += bytesperframe, fp++) - *(long *)fp = ((sp2[0] << 24) | (sp2[1] << 16) - | (sp2[2] << 8) | sp2[3]); - } - else - { - for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; - j < nitems; j++, sp2 += bytesperframe, fp++) - *(long *)fp = ((sp2[3] << 24) | (sp2[2] << 16) - | (sp2[1] << 8) | sp2[0]); - } - } + if (bytespersamp == 2) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; + j < nitems; j++, sp2 += bytesperframe, fp++) + *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16)); + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; + j < nitems; j++, sp2 += bytesperframe, fp++) + *fp = SCALE * ((sp2[1] << 24) | (sp2[0] << 16)); + } + } + else if (bytespersamp == 3) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; + j < nitems; j++, sp2 += bytesperframe, fp++) + *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16) + | (sp2[2] << 8)); + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; + j < nitems; j++, sp2 += bytesperframe, fp++) + *fp = SCALE * ((sp2[2] << 24) | (sp2[1] << 16) + | (sp2[0] << 8)); + } + } + else if (bytespersamp == 4) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; + j < nitems; j++, sp2 += bytesperframe, fp++) + *(long *)fp = ((sp2[0] << 24) | (sp2[1] << 16) + | (sp2[2] << 8) | sp2[3]); + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + itemsread; + j < nitems; j++, sp2 += bytesperframe, fp++) + *(long *)fp = ((sp2[3] << 24) | (sp2[2] << 16) + | (sp2[1] << 8) | sp2[0]); + } + } } - /* zero out other outputs */ + /* zero out other outputs */ for (i = sfchannels; i < nvecs; i++) - for (j = nitems, fp = vecs[i]; j--; ) - *fp++ = 0; + for (j = nitems, fp = vecs[i]; j--; ) + *fp++ = 0; } static void interpolate(int nvec,float **invec,int nin, - float **outvec,int nout) + float **outvec,int nout) { - float r=nin/(float)nout; - int i,j; + float r=nin/(float)nout; + int i,j; - for(i=0;i - -skip - -bytes - -normalize - -nextstep - -wave - -big - -little - */ +/* soundfiler2_write ... + +usage: write [flags] filename table ... +flags: +-nframes +-skip +-bytes +-normalize +-nextstep +-wave +-big +-little +*/ - /* the routine which actually does the work should LATER also be called - from garray_write16. */ +/* the routine which actually does the work should LATER also be called +from garray_write16. */ - /* Parse arguments for writing. The "obj" argument is only for flagging - errors. For streaming to a file the "normalize", "onset" and "nframes" - arguments shouldn't be set but the calling routine flags this. */ +/* Parse arguments for writing. The "obj" argument is only for flagging +errors. For streaming to a file the "normalize", "onset" and "nframes" +arguments shouldn't be set but the calling routine flags this. */ static int soundfiler2_writeargparse(void *obj, int *p_argc, t_atom **p_argv, - t_symbol **p_filesym, - int *p_filetype, int *p_bytespersamp, int *p_swap, int *p_bigendian, - int *p_normalize, long *p_onset, long *p_nframes,float *p_amp) + t_symbol **p_filesym, + int *p_filetype, int *p_bytespersamp, int *p_swap, int *p_bigendian, + int *p_normalize, long *p_onset, long *p_nframes,float *p_amp) { int argc = *p_argc; t_atom *argv = *p_argv; int bytespersamp = 2, bigendian = 0, - endianness = -1, swap, filetype = FORMAT_WAVE, normalize = 0; + endianness = -1, swap, filetype = FORMAT_WAVE, normalize = 0; long onset = 0, nframes = 0x7fffffff; - float amp=1; + float amp=1; t_symbol *filesym; while (argc > 0 && argv->a_type == A_SYMBOL && - *argv->a_w.w_symbol->s_name == '-') + *argv->a_w.w_symbol->s_name == '-') { - char *flag = argv->a_w.w_symbol->s_name + 1; - if (!strcmp(flag, "skip")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((onset = argv[1].a_w.w_float) < 0)) - goto usage; - argc -= 2; argv += 2; - } - else if (!strcmp(flag, "nframes")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((nframes = argv[1].a_w.w_float) < 0)) - goto usage; - argc -= 2; argv += 2; - } - else if (!strcmp(flag, "bytes")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((bytespersamp = argv[1].a_w.w_float) < 2) || - bytespersamp > 4) - goto usage; - argc -= 2; argv += 2; - } - else if (!strcmp(flag, "normalize")) - { - normalize = 1; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "amp")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT) - goto usage; - amp = argv[1].a_w.w_float; - argc -= 2; argv += 2; - } - else if (!strcmp(flag, "wave")) - { - filetype = FORMAT_WAVE; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "nextstep")) - { - filetype = FORMAT_NEXT; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "aiff")) - { - filetype = FORMAT_AIFF; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "big")) - { - endianness = 1; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "little")) - { - endianness = 1; - argc -= 1; argv += 1; - } - else goto usage; + char *flag = argv->a_w.w_symbol->s_name + 1; + if (!strcmp(flag, "skip")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((onset = argv[1].a_w.w_float) < 0)) + goto usage; + argc -= 2; + argv += 2; + } + else if (!strcmp(flag, "nframes")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((nframes = argv[1].a_w.w_float) < 0)) + goto usage; + argc -= 2; + argv += 2; + } + else if (!strcmp(flag, "bytes")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((bytespersamp = argv[1].a_w.w_float) < 2) || + bytespersamp > 4) + goto usage; + argc -= 2; + argv += 2; + } + else if (!strcmp(flag, "normalize")) + { + normalize = 1; + argc -= 1; + argv += 1; + } + else if (!strcmp(flag, "amp")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT) + goto usage; + amp = argv[1].a_w.w_float; + argc -= 2; + argv += 2; + } + else if (!strcmp(flag, "wave")) + { + filetype = FORMAT_WAVE; + argc -= 1; + argv += 1; + } + else if (!strcmp(flag, "nextstep")) + { + filetype = FORMAT_NEXT; + argc -= 1; + argv += 1; + } + else if (!strcmp(flag, "aiff")) + { + filetype = FORMAT_AIFF; + argc -= 1; + argv += 1; + } + else if (!strcmp(flag, "big")) + { + endianness = 1; + argc -= 1; + argv += 1; + } + else if (!strcmp(flag, "little")) + { + endianness = 1; + argc -= 1; + argv += 1; + } + else goto usage; } - /* only NextStep handles floating point samples */ + /* only NextStep handles floating point samples */ if (bytespersamp == 4) - filetype = FORMAT_NEXT; + filetype = FORMAT_NEXT; - /* for WAVE force little endian; for nextstep use machine native */ + /* for WAVE force little endian; for nextstep use machine native */ if (filetype == FORMAT_WAVE) { - bigendian = 0; - if (endianness == 1) - pd_error(obj, "WAVE file forced to little endian"); + bigendian = 0; + if (endianness == 1) + pd_error(obj, "WAVE file forced to little endian"); } else if (filetype == FORMAT_AIFF) { - bigendian = 1; - if (endianness == 0) - pd_error(obj, "AIFF file forced to big endian"); + bigendian = 1; + if (endianness == 0) + pd_error(obj, "AIFF file forced to big endian"); } else if (endianness == -1) { - bigendian = garray_ambigendian(); + bigendian = garray_ambigendian(); } swap = (bigendian != garray_ambigendian()); if (!argc || argv->a_type != A_SYMBOL) - goto usage; + goto usage; filesym = argv->a_w.w_symbol; - argc--; argv++; - + argc--; + argv++; + *p_argc = argc; *p_argv = argv; *p_filesym = filesym; @@ -433,8 +447,8 @@ usage: } static int create_soundfile2(t_canvas *canvas, const char *filename, - int filetype, int nframes, int bytespersamp, - int bigendian, int nchannels, int swap) + int filetype, int nframes, int bytespersamp, + int bigendian, int nchannels, int swap) { char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING]; char headerbuf[WRITEHDRSIZE]; @@ -442,123 +456,123 @@ static int create_soundfile2(t_canvas *canvas, const char *filename, t_nextstep *nexthdr = (t_nextstep *)headerbuf; t_aiff *aiffhdr = (t_aiff *)headerbuf; int fd, headersize = 0; - + strncpy(filenamebuf, filename, MAXPDSTRING-10); filenamebuf[MAXPDSTRING-10] = 0; if (filetype == FORMAT_NEXT) { - if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".snd")) - strcat(filenamebuf, ".snd"); - if (bigendian) - strncpy(nexthdr->ns_fileid, ".snd", 4); - else strncpy(nexthdr->ns_fileid, "dns.", 4); - nexthdr->ns_onset = swap4(sizeof(*nexthdr), swap); - nexthdr->ns_length = 0; - nexthdr->ns_format = swap4((bytespersamp == 3 ? NS_FORMAT_LINEAR_24 : - (bytespersamp == 4 ? NS_FORMAT_FLOAT : NS_FORMAT_LINEAR_16)), swap);; - nexthdr->ns_sr = swap4(44100, swap); /* lie */ - nexthdr->ns_nchans = swap4(nchannels, swap); - strcpy(nexthdr->ns_info, "Pd "); - swapstring(nexthdr->ns_info, swap); - headersize = sizeof(t_nextstep); + if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".snd")) + strcat(filenamebuf, ".snd"); + if (bigendian) + strncpy(nexthdr->ns_fileid, ".snd", 4); + else strncpy(nexthdr->ns_fileid, "dns.", 4); + nexthdr->ns_onset = swap4(sizeof(*nexthdr), swap); + nexthdr->ns_length = 0; + nexthdr->ns_format = swap4((bytespersamp == 3 ? NS_FORMAT_LINEAR_24 : + (bytespersamp == 4 ? NS_FORMAT_FLOAT : NS_FORMAT_LINEAR_16)), swap);; + nexthdr->ns_sr = swap4(44100, swap); /* lie */ + nexthdr->ns_nchans = swap4(nchannels, swap); + strcpy(nexthdr->ns_info, "Pd "); + swapstring(nexthdr->ns_info, swap); + headersize = sizeof(t_nextstep); } else if (filetype == FORMAT_AIFF) { - long datasize = nframes * nchannels * bytespersamp; - long longtmp; - static unsigned char dogdoo[] = - {0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0, 'S', 'S', 'N', 'D'}; - if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".aif") && - strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff")) - strcat(filenamebuf, ".aif"); - strncpy(aiffhdr->a_fileid, "FORM", 4); - aiffhdr->a_chunksize = swap4(datasize + sizeof(*aiffhdr) + 4, swap); - strncpy(aiffhdr->a_aiffid, "AIFF", 4); - strncpy(aiffhdr->a_fmtid, "COMM", 4); - aiffhdr->a_fmtchunksize = swap4(18, swap); - aiffhdr->a_nchannels = swap2(nchannels, swap); - longtmp = swap4(nframes, swap); - memcpy(&aiffhdr->a_nframeshi, &longtmp, 4); - aiffhdr->a_bitspersamp = swap2(8 * bytespersamp, swap); - memcpy(aiffhdr->a_samprate, dogdoo, sizeof(dogdoo)); - longtmp = swap4(datasize, swap); - memcpy(aiffhdr->a_samprate + sizeof(dogdoo), &longtmp, 4); - headersize = AIFFPLUS; + long datasize = nframes * nchannels * bytespersamp; + long longtmp; + static unsigned char dogdoo[] = + {0x40, 0x0e, 0xac, 0x44, 0, 0, 0, 0, 0, 0, 'S', 'S', 'N', 'D'}; + if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".aif") && + strcmp(filenamebuf + strlen(filenamebuf)-5, ".aiff")) + strcat(filenamebuf, ".aif"); + strncpy(aiffhdr->a_fileid, "FORM", 4); + aiffhdr->a_chunksize = swap4(datasize + sizeof(*aiffhdr) + 4, swap); + strncpy(aiffhdr->a_aiffid, "AIFF", 4); + strncpy(aiffhdr->a_fmtid, "COMM", 4); + aiffhdr->a_fmtchunksize = swap4(18, swap); + aiffhdr->a_nchannels = swap2(nchannels, swap); + longtmp = swap4(nframes, swap); + memcpy(&aiffhdr->a_nframeshi, &longtmp, 4); + aiffhdr->a_bitspersamp = swap2(8 * bytespersamp, swap); + memcpy(aiffhdr->a_samprate, dogdoo, sizeof(dogdoo)); + longtmp = swap4(datasize, swap); + memcpy(aiffhdr->a_samprate + sizeof(dogdoo), &longtmp, 4); + headersize = AIFFPLUS; } else /* WAVE format */ { - long datasize = nframes * nchannels * bytespersamp; - if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".wav")) - strcat(filenamebuf, ".wav"); - strncpy(wavehdr->w_fileid, "RIFF", 4); - wavehdr->w_chunksize = swap4(datasize + sizeof(*wavehdr) - 8, swap); - strncpy(wavehdr->w_waveid, "WAVE", 4); - strncpy(wavehdr->w_fmtid, "fmt ", 4); - wavehdr->w_fmtchunksize = swap4(16, swap); - wavehdr->w_fmttag = swap2(1, swap); - wavehdr->w_nchannels = swap2(nchannels, swap); - wavehdr->w_samplespersec = swap4(44100, swap); - wavehdr->w_navgbytespersec = swap4(44100 * nchannels * bytespersamp, swap); - wavehdr->w_nblockalign = swap2(bytespersamp, swap); - wavehdr->w_nbitspersample = swap2(8 * bytespersamp, swap); - strncpy(wavehdr->w_datachunkid, "data", 4); - wavehdr->w_datachunksize = swap4(datasize, swap); - headersize = sizeof(t_wave); + long datasize = nframes * nchannels * bytespersamp; + if (strcmp(filenamebuf + strlen(filenamebuf)-4, ".wav")) + strcat(filenamebuf, ".wav"); + strncpy(wavehdr->w_fileid, "RIFF", 4); + wavehdr->w_chunksize = swap4(datasize + sizeof(*wavehdr) - 8, swap); + strncpy(wavehdr->w_waveid, "WAVE", 4); + strncpy(wavehdr->w_fmtid, "fmt ", 4); + wavehdr->w_fmtchunksize = swap4(16, swap); + wavehdr->w_fmttag = swap2(1, swap); + wavehdr->w_nchannels = swap2(nchannels, swap); + wavehdr->w_samplespersec = swap4(44100, swap); + wavehdr->w_navgbytespersec = swap4(44100 * nchannels * bytespersamp, swap); + wavehdr->w_nblockalign = swap2(bytespersamp, swap); + wavehdr->w_nbitspersample = swap2(8 * bytespersamp, swap); + strncpy(wavehdr->w_datachunkid, "data", 4); + wavehdr->w_datachunksize = swap4(datasize, swap); + headersize = sizeof(t_wave); } canvas_makefilename(canvas, filenamebuf, buf2, MAXPDSTRING); sys_bashfilename(buf2, buf2); if ((fd = open(buf2, BINCREATE, 0666)) < 0) - return (-1); + return (-1); if (write(fd, headerbuf, headersize) < headersize) { - close (fd); - return (-1); + close (fd); + return (-1); } return (fd); } static void soundfile_finishwrite(void *obj, char *filename, int fd, - int filetype, long nframes, long itemswritten, int bytesperframe, int swap) + int filetype, long nframes, long itemswritten, int bytesperframe, int swap) { if (itemswritten < nframes) { - if (nframes < 0x7fffffff) - pd_error(obj, "soundfiler2_write: %d out of %d bytes written", - itemswritten, nframes); - /* try to fix size fields in header */ - if (filetype == FORMAT_WAVE) - { - long datasize = itemswritten * bytesperframe, mofo; - - if (lseek(fd, - ((char *)(&((t_wave *)0)->w_chunksize)) - (char *)0, - SEEK_SET) == 0) - goto baddonewrite; - mofo = swap4(datasize + sizeof(t_wave) - 8, swap); - if (write(fd, (char *)(&mofo), 4) < 4) - goto baddonewrite; - if (lseek(fd, - ((char *)(&((t_wave *)0)->w_datachunksize)) - (char *)0, - SEEK_SET) == 0) - goto baddonewrite; - mofo = swap4(datasize, swap); - if (write(fd, (char *)(&mofo), 4) < 4) - goto baddonewrite; - } - if (filetype == FORMAT_AIFF) - { - long mofo; - if (lseek(fd, - ((char *)(&((t_aiff *)0)->a_nframeshi)) - (char *)0, - SEEK_SET) == 0) - goto baddonewrite; - mofo = swap4(nframes, swap); - if (write(fd, (char *)(&mofo), 4) < 4) - goto baddonewrite; - } + if (nframes < 0x7fffffff) + pd_error(obj, "soundfiler2_write: %d out of %d bytes written", + itemswritten, nframes); + /* try to fix size fields in header */ + if (filetype == FORMAT_WAVE) + { + long datasize = itemswritten * bytesperframe, mofo; + + if (lseek(fd, + ((char *)(&((t_wave *)0)->w_chunksize)) - (char *)0, + SEEK_SET) == 0) + goto baddonewrite; + mofo = swap4(datasize + sizeof(t_wave) - 8, swap); + if (write(fd, (char *)(&mofo), 4) < 4) + goto baddonewrite; + if (lseek(fd, + ((char *)(&((t_wave *)0)->w_datachunksize)) - (char *)0, + SEEK_SET) == 0) + goto baddonewrite; + mofo = swap4(datasize, swap); + if (write(fd, (char *)(&mofo), 4) < 4) + goto baddonewrite; + } + if (filetype == FORMAT_AIFF) + { + long mofo; + if (lseek(fd, + ((char *)(&((t_aiff *)0)->a_nframeshi)) - (char *)0, + SEEK_SET) == 0) + goto baddonewrite; + mofo = swap4(nframes, swap); + if (write(fd, (char *)(&mofo), 4) < 4) + goto baddonewrite; + } } return; baddonewrite: @@ -566,8 +580,8 @@ baddonewrite: } static void soundfile_xferout(int nchannels, float **vecs, - unsigned char *buf, int nitems, long onset, int bytespersamp, - int bigendian, float normalfactor) + unsigned char *buf, int nitems, long onset, int bytespersamp, + int bigendian, float normalfactor) { int i, j; unsigned char *sp, *sp2; @@ -576,101 +590,105 @@ static void soundfile_xferout(int nchannels, float **vecs, long xx; for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp) { - if (bytespersamp == 2) - { - float ff = normalfactor * 32768.; - if (bigendian) - { - for (j = 0, sp2 = sp, fp = vecs[i] + onset; - j < nitems; j++, sp2 += bytesperframe, fp++) - { - int xx = 32768. + (*fp * ff); - xx -= 32768; - if (xx < -32767) - xx = -32767; - if (xx > 32767) - xx = 32767; - sp2[0] = (xx >> 8); - sp2[1] = xx; - } - } - else - { - for (j = 0, sp2 = sp, fp=vecs[i] + onset; - j < nitems; j++, sp2 += bytesperframe, fp++) - { - int xx = 32768. + (*fp * ff); - xx -= 32768; - if (xx < -32767) - xx = -32767; - if (xx > 32767) - xx = 32767; - sp2[1] = (xx >> 8); - sp2[0] = xx; - } - } - } - else if (bytespersamp == 3) - { - float ff = normalfactor * 8388608.; - if (bigendian) - { - for (j = 0, sp2 = sp, fp=vecs[i] + onset; - j < nitems; j++, sp2 += bytesperframe, fp++) - { - int xx = 8388608. + (*fp * ff); - xx -= 8388608; - if (xx < -8388607) - xx = -8388607; - if (xx > 8388607) - xx = 8388607; - sp2[0] = (xx >> 16); - sp2[1] = (xx >> 8); - sp2[2] = xx; - } - } - else - { - for (j = 0, sp2 = sp, fp=vecs[i] + onset; - j < nitems; j++, sp2 += bytesperframe, fp++) - { - int xx = 8388608. + (*fp * ff); - xx -= 8388608; - if (xx < -8388607) - xx = -8388607; - if (xx > 8388607) - xx = 8388607; - sp2[2] = (xx >> 16); - sp2[1] = (xx >> 8); - sp2[0] = xx; - } - } - } - else if (bytespersamp == 4) - { - if (bigendian) - { - for (j = 0, sp2 = sp, fp=vecs[i] + onset; - j < nitems; j++, sp2 += bytesperframe, fp++) - { - float f2 = *fp * normalfactor; - xx = *(long *)&f2; - sp2[0] = (xx >> 24); sp2[1] = (xx >> 24); - sp2[2] = (xx >> 24); sp2[3] = xx; - } - } - else - { - for (j = 0, sp2 = sp, fp=vecs[i] + onset; - j < nitems; j++, sp2 += bytesperframe, fp++) - { - float f2 = *fp * normalfactor; - xx = *(long *)&f2; - sp2[3] = (xx >> 24); sp2[2] = (xx >> 24); - sp2[1] = (xx >> 24); sp2[0] = xx; - } - } - } + if (bytespersamp == 2) + { + float ff = normalfactor * 32768.; + if (bigendian) + { + for (j = 0, sp2 = sp, fp = vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp++) + { + int xx = 32768. + (*fp * ff); + xx -= 32768; + if (xx < -32767) + xx = -32767; + if (xx > 32767) + xx = 32767; + sp2[0] = (xx >> 8); + sp2[1] = xx; + } + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp++) + { + int xx = 32768. + (*fp * ff); + xx -= 32768; + if (xx < -32767) + xx = -32767; + if (xx > 32767) + xx = 32767; + sp2[1] = (xx >> 8); + sp2[0] = xx; + } + } + } + else if (bytespersamp == 3) + { + float ff = normalfactor * 8388608.; + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp++) + { + int xx = 8388608. + (*fp * ff); + xx -= 8388608; + if (xx < -8388607) + xx = -8388607; + if (xx > 8388607) + xx = 8388607; + sp2[0] = (xx >> 16); + sp2[1] = (xx >> 8); + sp2[2] = xx; + } + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp++) + { + int xx = 8388608. + (*fp * ff); + xx -= 8388608; + if (xx < -8388607) + xx = -8388607; + if (xx > 8388607) + xx = 8388607; + sp2[2] = (xx >> 16); + sp2[1] = (xx >> 8); + sp2[0] = xx; + } + } + } + else if (bytespersamp == 4) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp++) + { + float f2 = *fp * normalfactor; + xx = *(long *)&f2; + sp2[0] = (xx >> 24); + sp2[1] = (xx >> 24); + sp2[2] = (xx >> 24); + sp2[3] = xx; + } + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp++) + { + float f2 = *fp * normalfactor; + xx = *(long *)&f2; + sp2[3] = (xx >> 24); + sp2[2] = (xx >> 24); + sp2[1] = (xx >> 24); + sp2[0] = xx; + } + } + } } } @@ -696,25 +714,25 @@ static t_soundfiler2 *soundfiler2_new(void) return (x); } - /* soundfiler2_read ... +/* soundfiler2_read ... - usage: read [flags] filename table ... - flags: - -skip ... frames to skip in file - -nframes - -onset ... onset in table to read into (NOT DONE YET) - -raw - -resize - -maxsize - */ +usage: read [flags] filename table ... +flags: + -skip ... frames to skip in file +-nframes +-onset ... onset in table to read into (NOT DONE YET) +-raw +-resize +-maxsize +*/ static void soundfiler2_read(t_soundfiler2 *x, t_symbol *s, - int argc, t_atom *argv) + int argc, t_atom *argv) { int headersize = -1, channels = 0, bytespersamp = 0, bigendian = 0, - resize = 0, i, j; + resize = 0, i, j; long skipframes = 0, nframes = 0, finalsize = 0, itemsleft, - maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff; + maxsize = DEFMAXSIZE, itemsread = 0, bytelimit = 0x7fffffff; int fd = -1; char endianness, *filename; t_garray *garrays[MAXSFCHANS]; @@ -723,173 +741,179 @@ static void soundfiler2_read(t_soundfiler2 *x, t_symbol *s, int bufframes, nitems; FILE *fp; while (argc > 0 && argv->a_type == A_SYMBOL && - *argv->a_w.w_symbol->s_name == '-') + *argv->a_w.w_symbol->s_name == '-') { - char *flag = argv->a_w.w_symbol->s_name + 1; - if (!strcmp(flag, "skip")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((skipframes = argv[1].a_w.w_float) < 0)) - goto usage; - argc -= 2; argv += 2; - } - else if (!strcmp(flag, "nframes")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((nframes = argv[1].a_w.w_float) < 0)) - goto usage; - argc -= 2; argv += 2; - } - else if (!strcmp(flag, "raw")) - { - if (argc < 5 || - argv[1].a_type != A_FLOAT || - ((headersize = argv[1].a_w.w_float) < 0) || - argv[2].a_type != A_FLOAT || - ((channels = argv[2].a_w.w_float) < 1) || - (channels > MAXSFCHANS) || - argv[3].a_type != A_FLOAT || - ((bytespersamp = argv[3].a_w.w_float) < 2) || - (bytespersamp > 4) || - argv[4].a_type != A_SYMBOL || - ((endianness = argv[4].a_w.w_symbol->s_name[0]) != 'b' - && endianness != 'l' && endianness != 'n')) - goto usage; - if (endianness == 'b') - bigendian = 1; - else if (endianness == 'l') - bigendian = 0; - else - bigendian = garray_ambigendian(); - argc -= 5; argv += 5; - } - else if (!strcmp(flag, "resize")) - { - resize = 1; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "maxsize")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((maxsize = argv[1].a_w.w_float) < 0)) - goto usage; - resize = 1; /* maxsize implies resize. */ - argc -= 2; argv += 2; - } - else goto usage; + char *flag = argv->a_w.w_symbol->s_name + 1; + if (!strcmp(flag, "skip")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((skipframes = argv[1].a_w.w_float) < 0)) + goto usage; + argc -= 2; + argv += 2; + } + else if (!strcmp(flag, "nframes")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((nframes = argv[1].a_w.w_float) < 0)) + goto usage; + argc -= 2; + argv += 2; + } + else if (!strcmp(flag, "raw")) + { + if (argc < 5 || + argv[1].a_type != A_FLOAT || + ((headersize = argv[1].a_w.w_float) < 0) || + argv[2].a_type != A_FLOAT || + ((channels = argv[2].a_w.w_float) < 1) || + (channels > MAXSFCHANS) || + argv[3].a_type != A_FLOAT || + ((bytespersamp = argv[3].a_w.w_float) < 2) || + (bytespersamp > 4) || + argv[4].a_type != A_SYMBOL || + ((endianness = argv[4].a_w.w_symbol->s_name[0]) != 'b' + && endianness != 'l' && endianness != 'n')) + goto usage; + if (endianness == 'b') + bigendian = 1; + else if (endianness == 'l') + bigendian = 0; + else + bigendian = garray_ambigendian(); + argc -= 5; + argv += 5; + } + else if (!strcmp(flag, "resize")) + { + resize = 1; + argc -= 1; + argv += 1; + } + else if (!strcmp(flag, "maxsize")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((maxsize = argv[1].a_w.w_float) < 0)) + goto usage; + resize = 1; /* maxsize implies resize. */ + argc -= 2; + argv += 2; + } + else goto usage; } if (argc < 2 || argc > MAXSFCHANS + 1 || argv[0].a_type != A_SYMBOL) - goto usage; + goto usage; filename = argv[0].a_w.w_symbol->s_name; - argc--; argv++; - + argc--; + argv++; + for (i = 0; i < argc; i++) { - int vecsize; - if (argv[i].a_type != A_SYMBOL) - goto usage; - if (!(garrays[i] = - (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) - { - pd_error(x, "%s: no such table", argv[i].a_w.w_symbol->s_name); - goto done; - } - else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i])) - error("%s: bad template for tabwrite", - argv[i].a_w.w_symbol->s_name); - if (finalsize && finalsize != vecsize && !resize) - { - post("soundfiler2_read: arrays have different lengths; resizing..."); - resize = 1; - } - finalsize = vecsize; + int vecsize; + if (argv[i].a_type != A_SYMBOL) + goto usage; + if (!(garrays[i] = + (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) + { + pd_error(x, "%s: no such table", argv[i].a_w.w_symbol->s_name); + goto done; + } + else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i])) + error("%s: bad template for tabwrite", + argv[i].a_w.w_symbol->s_name); + if (finalsize && finalsize != vecsize && !resize) + { + post("soundfiler2_read: arrays have different lengths; resizing..."); + resize = 1; + } + finalsize = vecsize; } fd = open_soundfile(canvas_getdir(x->x_canvas)->s_name, filename, - headersize, &bytespersamp, &bigendian, &channels, &bytelimit, - skipframes); + headersize, &bytespersamp, &bigendian, &channels, &bytelimit, + skipframes); if (fd < 0) { - pd_error(x, "soundfiler2_read: %s: %s", filename, (errno == EIO ? - "unknown or bad header format" : strerror(errno))); - goto done; + pd_error(x, "soundfiler2_read: %s: %s", filename, (errno == EIO ? + "unknown or bad header format" : strerror(errno))); + goto done; } if (resize) { - /* figure out what to resize to */ - long poswas, eofis, framesinfile; - - poswas = lseek(fd, 0, SEEK_CUR); - eofis = lseek(fd, 0, SEEK_END); - if (poswas < 0 || eofis < 0) - { - pd_error(x, "lseek failed"); - goto done; - } - lseek(fd, poswas, SEEK_SET); - framesinfile = (eofis - poswas) / (channels * bytespersamp); - if (framesinfile > maxsize) - { - pd_error(x, "soundfiler2_read: truncated to %d elements", maxsize); - framesinfile = maxsize; - } - if (framesinfile > bytelimit / bytespersamp) - framesinfile = bytelimit / bytespersamp; - finalsize = framesinfile; - for (i = 0; i < argc; i++) - { - int vecsize; - - garray_resize(garrays[i], finalsize); - /* for sanity's sake let's clear the save-in-patch flag here */ - garray_setsaveit(garrays[i], 0); - garray_getfloatarray(garrays[i], &vecsize, &vecs[i]); - /* if the resize failed, garray_resize reported the error */ - if (vecsize != framesinfile) - { - pd_error(x, "resize failed"); - goto done; - } - } + /* figure out what to resize to */ + long poswas, eofis, framesinfile; + + poswas = lseek(fd, 0, SEEK_CUR); + eofis = lseek(fd, 0, SEEK_END); + if (poswas < 0 || eofis < 0) + { + pd_error(x, "lseek failed"); + goto done; + } + lseek(fd, poswas, SEEK_SET); + framesinfile = (eofis - poswas) / (channels * bytespersamp); + if (framesinfile > maxsize) + { + pd_error(x, "soundfiler2_read: truncated to %d elements", maxsize); + framesinfile = maxsize; + } + if (framesinfile > bytelimit / bytespersamp) + framesinfile = bytelimit / bytespersamp; + finalsize = framesinfile; + for (i = 0; i < argc; i++) + { + int vecsize; + + garray_resize(garrays[i], finalsize); + /* for sanity's sake let's clear the save-in-patch flag here */ + garray_setsaveit(garrays[i], 0); + garray_getfloatarray(garrays[i], &vecsize, &vecs[i]); + /* if the resize failed, garray_resize reported the error */ + if (vecsize != framesinfile) + { + pd_error(x, "resize failed"); + goto done; + } + } } if (!finalsize) finalsize = 0x7fffffff; if (finalsize > bytelimit / bytespersamp) - finalsize = bytelimit / bytespersamp; + finalsize = bytelimit / bytespersamp; fp = fdopen(fd, "rb"); bufframes = SAMPBUFSIZE / (channels * bytespersamp); for (itemsread = 0; itemsread < finalsize; ) { - int thisread = finalsize - itemsread; - thisread = (thisread > bufframes ? bufframes : thisread); - nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); - if (nitems <= 0) break; - soundfile_xferin(channels, argc, vecs, itemsread, - (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); - itemsread += nitems; + int thisread = finalsize - itemsread; + thisread = (thisread > bufframes ? bufframes : thisread); + nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); + if (nitems <= 0) break; + soundfile_xferin(channels, argc, vecs, itemsread, + (unsigned char *)sampbuf, nitems, bytespersamp, bigendian); + itemsread += nitems; } - /* zero out remaining elements of vectors */ - + /* zero out remaining elements of vectors */ + for (i = 0; i < argc; i++) { - int nzero, vecsize; - garray_getfloatarray(garrays[i], &vecsize, &vecs[i]); - for (j = itemsread; j < vecsize; j++) - vecs[i][j] = 0; + int nzero, vecsize; + garray_getfloatarray(garrays[i], &vecsize, &vecs[i]); + for (j = itemsread; j < vecsize; j++) + vecs[i][j] = 0; } - /* zero out vectors in excess of number of channels */ + /* zero out vectors in excess of number of channels */ for (i = channels; i < argc; i++) { - int vecsize; - float *foo; - garray_getfloatarray(garrays[i], &vecsize, &foo); - for (j = 0; j < vecsize; j++) - foo[j] = 0; + int vecsize; + float *foo; + garray_getfloatarray(garrays[i], &vecsize, &foo); + for (j = 0; j < vecsize; j++) + foo[j] = 0; } - /* do all graphics updates */ + /* do all graphics updates */ for (i = 0; i < argc; i++) - garray_redraw(garrays[i]); + garray_redraw(garrays[i]); fclose(fp); fd = -1; goto done; @@ -899,20 +923,20 @@ usage: post("-raw ."); done: if (fd >= 0) - close (fd); - outlet_float(x->x_obj.ob_outlet, (float)itemsread); + close (fd); + outlet_float(x->x_obj.ob_outlet, (float)itemsread); } - /* this is broken out from soundfiler2_write below so garray_write can - call it too... not done yet though. */ +/* this is broken out from soundfiler2_write below so garray_write can +call it too... not done yet though. */ static long soundfiler2_dowrite(void *obj, t_canvas *canvas, - int argc, t_atom *argv) + int argc, t_atom *argv) { int headersize, bytespersamp, bigendian, - endianness, swap, filetype, normalize, i, j, nchannels; + endianness, swap, filetype, normalize, i, j, nchannels; long onset, nframes, itemsleft, - maxsize = DEFMAXSIZE, itemswritten = 0; + maxsize = DEFMAXSIZE, itemswritten = 0; t_garray *garrays[MAXSFCHANS]; t_float *vecs[MAXSFCHANS]; char sampbuf[SAMPBUFSIZE]; @@ -922,92 +946,92 @@ static long soundfiler2_dowrite(void *obj, t_canvas *canvas, t_symbol *filesym; if (soundfiler2_writeargparse(obj, &argc, &argv, &filesym, &filetype, - &bytespersamp, &swap, &bigendian, &normalize, &onset, &nframes,&)) - goto usage; + &bytespersamp, &swap, &bigendian, &normalize, &onset, &nframes,&)) + goto usage; nchannels = argc; if (nchannels < 1 || nchannels > MAXSFCHANS) - goto usage; + goto usage; for (i = 0; i < nchannels; i++) { - int vecsize; - - if (argv[i].a_type != A_SYMBOL) goto usage; - - if (!(garrays[i] = - (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) - { - pd_error(obj, "%s: no such table", argv[i].a_w.w_symbol->s_name); - goto fail; - } - else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i])) - error("%s: bad template for tabwrite",argv[i].a_w.w_symbol->s_name); - if (nframes > vecsize - onset) - nframes = vecsize - onset; - - for (j = 0; j < nframes; j++) /* FIXED (Antoine Rousseau)*/ - { - ftmp=vecs[i][j+onset]; - if (ftmp > biggest) biggest = ftmp; - else if (-ftmp > biggest) biggest = -ftmp; - } + int vecsize; + + if (argv[i].a_type != A_SYMBOL) goto usage; + + if (!(garrays[i] = + (t_garray *)pd_findbyclass(argv[i].a_w.w_symbol, garray_class))) + { + pd_error(obj, "%s: no such table", argv[i].a_w.w_symbol->s_name); + goto fail; + } + else if (!garray_getfloatarray(garrays[i], &vecsize, &vecs[i])) + error("%s: bad template for tabwrite",argv[i].a_w.w_symbol->s_name); + if (nframes > vecsize - onset) + nframes = vecsize - onset; + + for (j = 0; j < nframes; j++) /* FIXED (Antoine Rousseau)*/ + { + ftmp=vecs[i][j+onset]; + if (ftmp > biggest) biggest = ftmp; + else if (-ftmp > biggest) biggest = -ftmp; + } } - + if (nframes <= 0) { - pd_error(obj, "soundfiler2_write: no samples at onset %ld", onset); - goto fail; + pd_error(obj, "soundfiler2_write: no samples at onset %ld", onset); + goto fail; } if ((fd = create_soundfile2(canvas, filesym->s_name, filetype, - nframes, bytespersamp, bigendian, nchannels, - swap)) < 0) + nframes, bytespersamp, bigendian, nchannels, + swap)) < 0) { - post("%s: %s\n", filesym->s_name, strerror(errno)); - goto fail; + post("%s: %s\n", filesym->s_name, strerror(errno)); + goto fail; } if (!normalize) { - if ((bytespersamp != 4) && (biggest > 1)) - { - //post("%s: normalizing max amplitude %f to 1", filesym->s_name, biggest); - normalize = 1; - } - //else post("%s: biggest amplitude = %f", filesym->s_name, biggest); + if ((bytespersamp != 4) && (biggest > 1)) + { + //post("%s: normalizing max amplitude %f to 1", filesym->s_name, biggest); + normalize = 1; + } + //else post("%s: biggest amplitude = %f", filesym->s_name, biggest); } if (normalize) - normfactor = (biggest > 0 ? 32767./(32768. * biggest) : 1); + normfactor = (biggest > 0 ? 32767./(32768. * biggest) : 1); else normfactor = amp; - /*post("%s: biggest amplitude = %f , normfactor = %f", - filesym->s_name, biggest,normfactor);*/ + /*post("%s: biggest amplitude = %f , normfactor = %f", + filesym->s_name, biggest,normfactor);*/ bufframes = SAMPBUFSIZE / (nchannels * bytespersamp); for (itemswritten = 0; itemswritten < nframes; ) { - int thiswrite = nframes - itemswritten, nitems, nbytes; - thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); - soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, - onset, bytespersamp, bigendian, normfactor); - nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); - if (nbytes < nchannels * bytespersamp * thiswrite) - { - post("%s: %s", filesym->s_name, strerror(errno)); - if (nbytes > 0) - itemswritten += nbytes / (nchannels * bytespersamp); - break; - } - itemswritten += thiswrite; - onset += thiswrite; + int thiswrite = nframes - itemswritten, nitems, nbytes; + thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); + soundfile_xferout(argc, vecs, (unsigned char *)sampbuf, thiswrite, + onset, bytespersamp, bigendian, normfactor); + nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); + if (nbytes < nchannels * bytespersamp * thiswrite) + { + post("%s: %s", filesym->s_name, strerror(errno)); + if (nbytes > 0) + itemswritten += nbytes / (nchannels * bytespersamp); + break; + } + itemswritten += thiswrite; + onset += thiswrite; } if (fd >= 0) { - soundfile_finishwrite(obj, filesym->s_name, fd, - filetype, nframes, itemswritten, nchannels * bytespersamp, swap); - close (fd); + soundfile_finishwrite(obj, filesym->s_name, fd, + filetype, nframes, itemswritten, nchannels * bytespersamp, swap); + close (fd); } - return ((float)itemswritten); + return ((float)itemswritten); usage: pd_error(obj, "usage: write [flags] filename tablename..."); post("flags: -skip -nframes -bytes -wave -aiff -nextstep ..."); @@ -1015,26 +1039,26 @@ usage: post("(defaults to a 16-bit wave file)."); fail: if (fd >= 0) - close (fd); + close (fd); return (0); } static void soundfiler2_write(t_soundfiler2 *x, t_symbol *s, - int argc, t_atom *argv) + int argc, t_atom *argv) { long bozo = soundfiler2_dowrite(x, x->x_canvas, - argc, argv); + argc, argv); outlet_float(x->x_obj.ob_outlet, (float)bozo); } void soundfiler2_setup(void) { - soundfiler2_class = class_new(gensym("soundfiler2"), (t_newmethod)soundfiler2_new, - 0, sizeof(t_soundfiler2), 0, 0); - class_addmethod(soundfiler2_class, (t_method)soundfiler2_read, gensym("read"), - A_GIMME, 0); + soundfiler2_class = class_new(gensym("soundfiler2"), (t_newmethod)soundfiler2_new, + 0, sizeof(t_soundfiler2), 0, 0); + class_addmethod(soundfiler2_class, (t_method)soundfiler2_read, gensym("read"), + A_GIMME, 0); class_addmethod(soundfiler2_class, (t_method)soundfiler2_write, - gensym("write"), A_GIMME, 0); + gensym("write"), A_GIMME, 0); } /************************* readsf object ******************************/ @@ -1089,7 +1113,7 @@ typedef struct _readsf int x_vecsize; /* vector size for transfers */ t_outlet *x_bangout; /* bang-on-done outlet */ int x_state; /* opened, running, or idle */ - /* parameters to communicate with subthread */ + /* parameters to communicate with subthread */ int x_requestcode; /* pending request from parent to I/O thread */ char *x_filename; /* file to open (string is permanently allocated) */ int x_fileerror; /* slot for "errno" return */ @@ -1100,7 +1124,7 @@ typedef struct _readsf long x_onsetframes; /* number of sample frames to skip */ long x_bytelimit; /* max number of data bytes to read */ int x_fd; /* filedesc */ - int x_fifosize; /* buffer size appropriately rounded down */ + int x_fifosize; /* buffer size appropriately rounded down */ int x_fifohead; /* index of next byte to get from file */ int x_fifotail; /* index of next byte the ugen will read */ int x_eof; /* true if fifohead has stopped changing */ @@ -1110,7 +1134,7 @@ typedef struct _readsf int x_itemswritten; /* writesf~ only; items writen */ int x_swap; /* writesf~ only; true if byte swapping */ float x_f; /* writesf~ only; scalar for signal inlet */ - /*----HACK------*/ + /*----HACK------*/ float x_speed; /*speed of reading*/ float x_frac; /*fractionnal part of sample to play next buffer*/ @@ -1160,7 +1184,7 @@ static void readsf_banana( void) #define sfread_cond_wait(a,b) readsf_fakewait(b) -#define sfread_cond_signal(a) +#define sfread_cond_signal(a) #endif static void *readsf_child_main(void *zz) @@ -1170,234 +1194,234 @@ static void *readsf_child_main(void *zz) pthread_mutex_lock(&x->x_mutex); while (1) { - int fd, fifohead; - char *buf; - pute("0\n"); - if (x->x_requestcode == REQUEST_NOTHING) - { - pute("wait 2\n"); - sfread_cond_signal(&x->x_answercondition); - sfread_cond_wait(&x->x_requestcondition, &x->x_mutex); - pute("3\n"); - } - else if (x->x_requestcode == REQUEST_OPEN) - { - char boo[80]; - int sysrtn, wantbytes; - - /* copy file stuff out of the data structure so we can - relinquish the mutex while we're in open_soundfile(). */ - long onsetframes = x->x_onsetframes; - long bytelimit = 0x7fffffff; - int skipheaderbytes = x->x_skipheaderbytes; - int bytespersample = x->x_bytespersample; - int sfchannels = x->x_sfchannels; - int bigendian = x->x_bigendian; - char *filename = x->x_filename; - char *dirname = canvas_getdir(x->x_canvas)->s_name; - /* alter the request code so that an ensuing "open" will get - noticed. */ - pute("4\n"); - x->x_requestcode = REQUEST_BUSY; - x->x_fileerror = 0; - - /* if there's already a file open, close it */ - if (x->x_fd >= 0) - { - fd = x->x_fd; - pthread_mutex_unlock(&x->x_mutex); - close (fd); - pthread_mutex_lock(&x->x_mutex); - x->x_fd = -1; - if (x->x_requestcode != REQUEST_BUSY) - goto lost; - } - /* open the soundfile with the mutex unlocked */ - pthread_mutex_unlock(&x->x_mutex); - fd = open_soundfile(dirname, filename, - skipheaderbytes, &bytespersample, &bigendian, - &sfchannels, &bytelimit, onsetframes); - pthread_mutex_lock(&x->x_mutex); - - pute("5\n"); - /* copy back into the instance structure. */ - x->x_bytespersample = bytespersample; - x->x_sfchannels = sfchannels; - x->x_bigendian = bigendian; - x->x_fd = fd; - x->x_bytelimit = bytelimit; - if (fd < 0) - { - x->x_fileerror = errno; - x->x_eof = 1; - pute("open failed\n"); - pute(filename); - pute(dirname); - goto lost; - } - /* check if another request has been made; if so, field it */ - if (x->x_requestcode != REQUEST_BUSY) - goto lost; - pute("6\n"); - x->x_fifohead = 0; - /* set fifosize from bufsize. fifosize must be a - multiple of the number of bytes eaten for each DSP - tick. We pessimistically assume MAXVECSIZE samples - per tick since that could change. There could be a - problem here if the vector size increases while a - soundfile is being played... */ - x->x_fifosize = x->x_bufsize - (x->x_bufsize % - (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE)); - /* arrange for the "request" condition to be signalled 16 - times per buffer */ - sprintf(boo, "fifosize %d\n", - x->x_fifosize); - pute(boo); - x->x_sigcountdown = x->x_sigperiod = - (x->x_fifosize / - (16 * x->x_bytespersample * x->x_sfchannels * - x->x_vecsize)); - /* in a loop, wait for the fifo to get hungry and feed it */ - - while (x->x_requestcode == REQUEST_BUSY) - { - int fifosize = x->x_fifosize; - pute("77\n"); - if (x->x_eof) - break; - if (x->x_fifohead >= x->x_fifotail) - { - /* if the head is >= the tail, we can immediately read - to the end of the fifo. Unless, that is, we would - read all the way to the end of the buffer and the - "tail" is zero; this would fill the buffer completely - which isn't allowed because you can't tell a completely - full buffer from an empty one. */ - if (x->x_fifotail || (fifosize - x->x_fifohead > READSIZE)) - { - wantbytes = fifosize - x->x_fifohead; - if (wantbytes > READSIZE) - wantbytes = READSIZE; - if (wantbytes > x->x_bytelimit) - wantbytes = x->x_bytelimit; - sprintf(boo, "head %d, tail %d, size %d\n", - x->x_fifohead, x->x_fifotail, wantbytes); - pute(boo); - } - else - { - pute("wait 7a ...\n"); - sfread_cond_signal(&x->x_answercondition); - pute("signalled\n"); - sfread_cond_wait(&x->x_requestcondition, - &x->x_mutex); - pute("7a done\n"); - continue; - } - } - else - { - /* otherwise check if there are at least READSIZE - bytes to read. If not, wait and loop back. */ - wantbytes = x->x_fifotail - x->x_fifohead - 1; - if (wantbytes < READSIZE) - { - pute("wait 7...\n"); - sfread_cond_signal(&x->x_answercondition); - sfread_cond_wait(&x->x_requestcondition, - &x->x_mutex); - pute("7 done\n"); - continue; - } - else wantbytes = READSIZE; - } - pute("8\n"); - fd = x->x_fd; - buf = x->x_buf; - fifohead = x->x_fifohead; - pthread_mutex_unlock(&x->x_mutex); - sysrtn = read(fd, buf + fifohead, wantbytes); - pthread_mutex_lock(&x->x_mutex); - if (x->x_requestcode != REQUEST_BUSY) - break; - if (sysrtn < 0) - { - pute("fileerror\n"); - x->x_fileerror = errno; - break; - } - else if (sysrtn == 0) - { - x->x_eof = 1; - break; - } - else - { - x->x_fifohead += sysrtn; - x->x_bytelimit -= sysrtn; - if (x->x_bytelimit <= 0) - { - x->x_eof = 1; - break; - } - if (x->x_fifohead == fifosize) - x->x_fifohead = 0; - } - sprintf(boo, "after: head %d, tail %d\n", - x->x_fifohead, x->x_fifotail); - pute(boo); - /* signal parent in case it's waiting for data */ - sfread_cond_signal(&x->x_answercondition); - } - lost: - - if (x->x_requestcode == REQUEST_BUSY) - x->x_requestcode = REQUEST_NOTHING; - /* fell out of read loop: close file if necessary, - set EOF and signal once more */ - if (x->x_fd >= 0) - { - fd = x->x_fd; - pthread_mutex_unlock(&x->x_mutex); - close (fd); - pthread_mutex_lock(&x->x_mutex); - x->x_fd = -1; - } - sfread_cond_signal(&x->x_answercondition); - - } - else if (x->x_requestcode == REQUEST_CLOSE) - { - if (x->x_fd >= 0) - { - fd = x->x_fd; - pthread_mutex_unlock(&x->x_mutex); - close (fd); - pthread_mutex_lock(&x->x_mutex); - x->x_fd = -1; - } - if (x->x_requestcode == REQUEST_CLOSE) - x->x_requestcode = REQUEST_NOTHING; - sfread_cond_signal(&x->x_answercondition); - } - else if (x->x_requestcode == REQUEST_QUIT) - { - if (x->x_fd >= 0) - { - fd = x->x_fd; - pthread_mutex_unlock(&x->x_mutex); - close (fd); - pthread_mutex_lock(&x->x_mutex); - x->x_fd = -1; - } - x->x_requestcode = REQUEST_NOTHING; - sfread_cond_signal(&x->x_answercondition); - break; - } - else - { - pute("13\n"); - } + int fd, fifohead; + char *buf; + pute("0\n"); + if (x->x_requestcode == REQUEST_NOTHING) + { + pute("wait 2\n"); + sfread_cond_signal(&x->x_answercondition); + sfread_cond_wait(&x->x_requestcondition, &x->x_mutex); + pute("3\n"); + } + else if (x->x_requestcode == REQUEST_OPEN) + { + char boo[80]; + int sysrtn, wantbytes; + + /* copy file stuff out of the data structure so we can + relinquish the mutex while we're in open_soundfile(). */ + long onsetframes = x->x_onsetframes; + long bytelimit = 0x7fffffff; + int skipheaderbytes = x->x_skipheaderbytes; + int bytespersample = x->x_bytespersample; + int sfchannels = x->x_sfchannels; + int bigendian = x->x_bigendian; + char *filename = x->x_filename; + char *dirname = canvas_getdir(x->x_canvas)->s_name; + /* alter the request code so that an ensuing "open" will get + noticed. */ + pute("4\n"); + x->x_requestcode = REQUEST_BUSY; + x->x_fileerror = 0; + + /* if there's already a file open, close it */ + if (x->x_fd >= 0) + { + fd = x->x_fd; + pthread_mutex_unlock(&x->x_mutex); + close (fd); + pthread_mutex_lock(&x->x_mutex); + x->x_fd = -1; + if (x->x_requestcode != REQUEST_BUSY) + goto lost; + } + /* open the soundfile with the mutex unlocked */ + pthread_mutex_unlock(&x->x_mutex); + fd = open_soundfile(dirname, filename, + skipheaderbytes, &bytespersample, &bigendian, + &sfchannels, &bytelimit, onsetframes); + pthread_mutex_lock(&x->x_mutex); + + pute("5\n"); + /* copy back into the instance structure. */ + x->x_bytespersample = bytespersample; + x->x_sfchannels = sfchannels; + x->x_bigendian = bigendian; + x->x_fd = fd; + x->x_bytelimit = bytelimit; + if (fd < 0) + { + x->x_fileerror = errno; + x->x_eof = 1; + pute("open failed\n"); + pute(filename); + pute(dirname); + goto lost; + } + /* check if another request has been made; if so, field it */ + if (x->x_requestcode != REQUEST_BUSY) + goto lost; + pute("6\n"); + x->x_fifohead = 0; + /* set fifosize from bufsize. fifosize must be a + multiple of the number of bytes eaten for each DSP + tick. We pessimistically assume MAXVECSIZE samples + per tick since that could change. There could be a + problem here if the vector size increases while a + soundfile is being played... */ + x->x_fifosize = x->x_bufsize - (x->x_bufsize % + (x->x_bytespersample * x->x_sfchannels * MAXVECSIZE)); + /* arrange for the "request" condition to be signalled 16 + times per buffer */ + sprintf(boo, "fifosize %d\n", + x->x_fifosize); + pute(boo); + x->x_sigcountdown = x->x_sigperiod = + (x->x_fifosize / + (16 * x->x_bytespersample * x->x_sfchannels * + x->x_vecsize)); + /* in a loop, wait for the fifo to get hungry and feed it */ + + while (x->x_requestcode == REQUEST_BUSY) + { + int fifosize = x->x_fifosize; + pute("77\n"); + if (x->x_eof) + break; + if (x->x_fifohead >= x->x_fifotail) + { + /* if the head is >= the tail, we can immediately read + to the end of the fifo. Unless, that is, we would + read all the way to the end of the buffer and the + "tail" is zero; this would fill the buffer completely + which isn't allowed because you can't tell a completely + full buffer from an empty one. */ + if (x->x_fifotail || (fifosize - x->x_fifohead > READSIZE)) + { + wantbytes = fifosize - x->x_fifohead; + if (wantbytes > READSIZE) + wantbytes = READSIZE; + if (wantbytes > x->x_bytelimit) + wantbytes = x->x_bytelimit; + sprintf(boo, "head %d, tail %d, size %d\n", + x->x_fifohead, x->x_fifotail, wantbytes); + pute(boo); + } + else + { + pute("wait 7a ...\n"); + sfread_cond_signal(&x->x_answercondition); + pute("signalled\n"); + sfread_cond_wait(&x->x_requestcondition, + &x->x_mutex); + pute("7a done\n"); + continue; + } + } + else + { + /* otherwise check if there are at least READSIZE + bytes to read. If not, wait and loop back. */ + wantbytes = x->x_fifotail - x->x_fifohead - 1; + if (wantbytes < READSIZE) + { + pute("wait 7...\n"); + sfread_cond_signal(&x->x_answercondition); + sfread_cond_wait(&x->x_requestcondition, + &x->x_mutex); + pute("7 done\n"); + continue; + } + else wantbytes = READSIZE; + } + pute("8\n"); + fd = x->x_fd; + buf = x->x_buf; + fifohead = x->x_fifohead; + pthread_mutex_unlock(&x->x_mutex); + sysrtn = read(fd, buf + fifohead, wantbytes); + pthread_mutex_lock(&x->x_mutex); + if (x->x_requestcode != REQUEST_BUSY) + break; + if (sysrtn < 0) + { + pute("fileerror\n"); + x->x_fileerror = errno; + break; + } + else if (sysrtn == 0) + { + x->x_eof = 1; + break; + } + else + { + x->x_fifohead += sysrtn; + x->x_bytelimit -= sysrtn; + if (x->x_bytelimit <= 0) + { + x->x_eof = 1; + break; + } + if (x->x_fifohead == fifosize) + x->x_fifohead = 0; + } + sprintf(boo, "after: head %d, tail %d\n", + x->x_fifohead, x->x_fifotail); + pute(boo); + /* signal parent in case it's waiting for data */ + sfread_cond_signal(&x->x_answercondition); + } +lost: + + if (x->x_requestcode == REQUEST_BUSY) + x->x_requestcode = REQUEST_NOTHING; + /* fell out of read loop: close file if necessary, + set EOF and signal once more */ + if (x->x_fd >= 0) + { + fd = x->x_fd; + pthread_mutex_unlock(&x->x_mutex); + close (fd); + pthread_mutex_lock(&x->x_mutex); + x->x_fd = -1; + } + sfread_cond_signal(&x->x_answercondition); + + } + else if (x->x_requestcode == REQUEST_CLOSE) + { + if (x->x_fd >= 0) + { + fd = x->x_fd; + pthread_mutex_unlock(&x->x_mutex); + close (fd); + pthread_mutex_lock(&x->x_mutex); + x->x_fd = -1; + } + if (x->x_requestcode == REQUEST_CLOSE) + x->x_requestcode = REQUEST_NOTHING; + sfread_cond_signal(&x->x_answercondition); + } + else if (x->x_requestcode == REQUEST_QUIT) + { + if (x->x_fd >= 0) + { + fd = x->x_fd; + pthread_mutex_unlock(&x->x_mutex); + close (fd); + pthread_mutex_lock(&x->x_mutex); + x->x_fd = -1; + } + x->x_requestcode = REQUEST_NOTHING; + sfread_cond_signal(&x->x_answercondition); + break; + } + else + { + pute("13\n"); + } } pute("thread exit\n"); pthread_mutex_unlock(&x->x_mutex); @@ -1413,23 +1437,23 @@ static void *readsf_new(t_floatarg fnchannels, t_floatarg fbufsize) t_readsf *x; int nchannels = fnchannels, bufsize = fbufsize, i; char *buf; - + if (nchannels < 1) - nchannels = 1; + nchannels = 1; else if (nchannels > MAXSFCHANS) - nchannels = MAXSFCHANS; + nchannels = MAXSFCHANS; if (bufsize <= 0) bufsize = DEFBUFPERCHAN * nchannels; else if (bufsize < MINBUFSIZE) - bufsize = MINBUFSIZE; + bufsize = MINBUFSIZE; else if (bufsize > MAXBUFSIZE) - bufsize = MAXBUFSIZE; + bufsize = MAXBUFSIZE; buf = getbytes(bufsize); if (!buf) return (0); - + x = (t_readsf *)pd_new(readsfv_class); for (i = 0; i < nchannels; i++) - outlet_new(&x->x_obj, gensym("signal")); + outlet_new(&x->x_obj, gensym("signal")); x->x_noutlets = nchannels; x->x_bangout = outlet_new(&x->x_obj, &s_bang); pthread_mutex_init(&x->x_mutex, 0); @@ -1458,74 +1482,75 @@ static t_int *readsf_perform(t_int *w) { t_readsf *x = (t_readsf *)(w[1]); int vecsize = x->x_vecsize, noutlets = x->x_noutlets, i, j, - bytespersample = x->x_bytespersample, - bigendian = x->x_bigendian,wantsamples; + bytespersample = x->x_bytespersample, + bigendian = x->x_bigendian,wantsamples; float *fp,tmp,speed=x->x_speed; if (x->x_state == STATE_STREAM) { - int wantbytes, nchannels, sfchannels = x->x_sfchannels; - pthread_mutex_lock(&x->x_mutex); - tmp=vecsize *speed+x->x_frac; - wantsamples=(int)tmp; - x->x_frac=tmp-wantsamples; - - if(!speed) goto idle; - - wantbytes = sfchannels * wantsamples * bytespersample; - - while ( - !x->x_eof && x->x_fifohead >= x->x_fifotail && - x->x_fifohead < x->x_fifotail + wantbytes-1) - { - pute("wait...\n"); - sfread_cond_signal(&x->x_requestcondition); - sfread_cond_wait(&x->x_answercondition, &x->x_mutex); - pute("done\n"); - } - if (x->x_eof && x->x_fifohead >= x->x_fifotail && - x->x_fifohead < x->x_fifotail + wantbytes-1) - { - if (x->x_fileerror) - { - pd_error(x, "dsp: %s: %s", x->x_filename, - (x->x_fileerror == EIO ? - "unknown or bad header format" : - strerror(x->x_fileerror))); - } - clock_delay(x->x_clock, 0); - x->x_state = STATE_IDLE; - sfread_cond_signal(&x->x_requestcondition); - pthread_mutex_unlock(&x->x_mutex); - goto idle; - } - - if(speed==1) - soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0, - (unsigned char *)(x->x_buf + x->x_fifotail), vecsize, - bytespersample, bigendian); - else { - soundfile_xferin(sfchannels, noutlets, tmpvec, 0, - (unsigned char *)(x->x_buf + x->x_fifotail), wantsamples, - bytespersample, bigendian); - interpolate(noutlets,tmpvec,wantsamples,x->x_outvec,vecsize); - } - - x->x_fifotail += wantbytes; - if (x->x_fifotail >= x->x_fifosize) - x->x_fifotail = 0; - if ((--x->x_sigcountdown) <= 0) - { - sfread_cond_signal(&x->x_requestcondition); - x->x_sigcountdown = x->x_sigperiod; - } - pthread_mutex_unlock(&x->x_mutex); + int wantbytes, nchannels, sfchannels = x->x_sfchannels; + pthread_mutex_lock(&x->x_mutex); + tmp=vecsize *speed+x->x_frac; + wantsamples=(int)tmp; + x->x_frac=tmp-wantsamples; + + if(!speed) goto idle; + + wantbytes = sfchannels * wantsamples * bytespersample; + + while ( + !x->x_eof && x->x_fifohead >= x->x_fifotail && + x->x_fifohead < x->x_fifotail + wantbytes-1) + { + pute("wait...\n"); + sfread_cond_signal(&x->x_requestcondition); + sfread_cond_wait(&x->x_answercondition, &x->x_mutex); + pute("done\n"); + } + if (x->x_eof && x->x_fifohead >= x->x_fifotail && + x->x_fifohead < x->x_fifotail + wantbytes-1) + { + if (x->x_fileerror) + { + pd_error(x, "dsp: %s: %s", x->x_filename, + (x->x_fileerror == EIO ? + "unknown or bad header format" : + strerror(x->x_fileerror))); + } + clock_delay(x->x_clock, 0); + x->x_state = STATE_IDLE; + sfread_cond_signal(&x->x_requestcondition); + pthread_mutex_unlock(&x->x_mutex); + goto idle; + } + + if(speed==1) + soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0, + (unsigned char *)(x->x_buf + x->x_fifotail), vecsize, + bytespersample, bigendian); + else + { + soundfile_xferin(sfchannels, noutlets, tmpvec, 0, + (unsigned char *)(x->x_buf + x->x_fifotail), wantsamples, + bytespersample, bigendian); + interpolate(noutlets,tmpvec,wantsamples,x->x_outvec,vecsize); + } + + x->x_fifotail += wantbytes; + if (x->x_fifotail >= x->x_fifosize) + x->x_fifotail = 0; + if ((--x->x_sigcountdown) <= 0) + { + sfread_cond_signal(&x->x_requestcondition); + x->x_sigcountdown = x->x_sigperiod; + } + pthread_mutex_unlock(&x->x_mutex); } else { - idle: - for (i = 0; i < noutlets; i++) - for (j = vecsize, fp = x->x_outvec[i]; j--; ) - *fp++ = 0; +idle: + for (i = 0; i < noutlets; i++) + for (j = vecsize, fp = x->x_outvec[i]; j--; ) + *fp++ = 0; } return (w+2); } @@ -1535,13 +1560,13 @@ static void readsf_start(t_readsf *x) /* start making output. If we're in the "startup" state change to the "running" state. */ if (x->x_state == STATE_STARTUP) - x->x_state = STATE_STREAM; + x->x_state = STATE_STREAM; else pd_error(x, "readsf: start requested with no prior 'open'"); } static void readsf_stop(t_readsf *x) { - /* LATER rethink whether you need the mutex just to set a variable? */ + /* LATER rethink whether you need the mutex just to set a variable? */ pthread_mutex_lock(&x->x_mutex); x->x_state = STATE_IDLE; x->x_requestcode = REQUEST_CLOSE; @@ -1552,21 +1577,21 @@ static void readsf_stop(t_readsf *x) static void readsf_float(t_readsf *x, t_floatarg f) { if (f != 0) - readsf_start(x); + readsf_start(x); else readsf_stop(x); } static void readsf_speed(t_readsf *x, t_floatarg f) { if((f>=0)&&(f<=8)) - x->x_speed=f; + x->x_speed=f; } - /* open method. Called as: - open filename [skipframes headersize channels bytespersamp endianness] - (if headersize is zero, header is taken to be automatically - detected; thus, use the special "-1" to mean a truly headerless file.) - */ +/* open method. Called as: +open filename [skipframes headersize channels bytespersamp endianness] + (if headersize is zero, header is taken to be automatically +detected; thus, use the special "-1" to mean a truly headerless file.) +*/ static void readsf_open(t_readsf *x, t_symbol *s, int argc, t_atom *argv) { @@ -1577,22 +1602,22 @@ static void readsf_open(t_readsf *x, t_symbol *s, int argc, t_atom *argv) t_float bytespersamp = atom_getfloatarg(4, argc, argv); t_symbol *endian = atom_getsymbolarg(5, argc, argv); if (!*filesym->s_name) - return; + return; pthread_mutex_lock(&x->x_mutex); x->x_requestcode = REQUEST_OPEN; x->x_filename = filesym->s_name; x->x_fifotail = 0; x->x_fifohead = 0; if (*endian->s_name == 'b') - x->x_bigendian = 1; + x->x_bigendian = 1; else if (*endian->s_name == 'l') - x->x_bigendian = 0; + x->x_bigendian = 0; else if (*endian->s_name) - pd_error(x, "endianness neither 'b' nor 'l'"); + pd_error(x, "endianness neither 'b' nor 'l'"); else x->x_bigendian = garray_ambigendian(); x->x_onsetframes = (onsetframes > 0 ? onsetframes : 0); - x->x_skipheaderbytes = (headerbytes > 0 ? headerbytes : - (headerbytes == 0 ? -1 : 0)); + x->x_skipheaderbytes = (headerbytes > 0 ? headerbytes : + (headerbytes == 0 ? -1 : 0)); x->x_sfchannels = (channels >= 1 ? channels : 1); x->x_bytespersample = (bytespersamp > 2 ? bytespersamp : 2); x->x_eof = 0; @@ -1609,11 +1634,11 @@ static void readsf_dsp(t_readsf *x, t_signal **sp) int i, noutlets = x->x_noutlets; pthread_mutex_lock(&x->x_mutex); x->x_vecsize = sp[0]->s_n; - + x->x_sigperiod = (x->x_fifosize / - (x->x_bytespersample * x->x_sfchannels * x->x_vecsize)); + (x->x_bytespersample * x->x_sfchannels * x->x_vecsize)); for (i = 0; i < noutlets; i++) - x->x_outvec[i] = sp[i]->s_vec; + x->x_outvec[i] = sp[i]->s_vec; pthread_mutex_unlock(&x->x_mutex); dsp_add(readsf_perform, 1, x); } @@ -1630,7 +1655,7 @@ static void readsf_print(t_readsf *x) static void readsf_free(t_readsf *x) { - /* request QUIT and wait for acknowledge */ + /* request QUIT and wait for acknowledge */ void *threadrtn; pthread_mutex_lock(&x->x_mutex); x->x_requestcode = REQUEST_QUIT; @@ -1638,15 +1663,15 @@ static void readsf_free(t_readsf *x) sfread_cond_signal(&x->x_requestcondition); while (x->x_requestcode != REQUEST_NOTHING) { - post("signalling..."); - sfread_cond_signal(&x->x_requestcondition); - sfread_cond_wait(&x->x_answercondition, &x->x_mutex); + post("signalling..."); + sfread_cond_signal(&x->x_requestcondition); + sfread_cond_wait(&x->x_answercondition, &x->x_mutex); } pthread_mutex_unlock(&x->x_mutex); if (pthread_join(x->x_childthread, &threadrtn)) - error("readsf_free: join failed"); + error("readsf_free: join failed"); post("... done."); - + pthread_cond_destroy(&x->x_requestcondition); pthread_cond_destroy(&x->x_answercondition); pthread_mutex_destroy(&x->x_mutex); @@ -1662,7 +1687,7 @@ void readsfv_tilde_setup(void) int i; readsfv_class = class_new(gensym("readsfv~"), (t_newmethod)readsf_new, - (t_method)readsf_free, sizeof(t_readsf), 0, A_DEFFLOAT, A_DEFFLOAT, 0); + (t_method)readsf_free, sizeof(t_readsf), 0, A_DEFFLOAT, A_DEFFLOAT, 0); class_addfloat(readsfv_class, (t_method)readsf_float); class_addmethod(readsfv_class, (t_method)readsf_speed, gensym("speed"), A_FLOAT,0); @@ -1670,11 +1695,11 @@ void readsfv_tilde_setup(void) class_addmethod(readsfv_class, (t_method)readsf_stop, gensym("stop"), 0); class_addmethod(readsfv_class, (t_method)readsf_dsp, gensym("dsp"), 0); class_addmethod(readsfv_class, (t_method)readsf_open, gensym("open"), - A_GIMME, 0); + A_GIMME, 0); class_addmethod(readsfv_class, (t_method)readsf_print, gensym("print"), 0); - for(i=0;igl_env)&&(can->gl_env->ce_dollarzero==d0)){ - return can; - } - - ob=can->gl_list; - while(ob&&(retcan==0)) { - if (pd_class(&ob->g_pd) == canvas_class) - retcan=getcanvas((t_glist *)ob,d0); - ob=ob->g_next; - } - - if((!retcan)&&(can->gl_next)) retcan=getcanvas((t_glist *)can->gl_next,d0); - return retcan; + t_canvas *retcan=0; + t_gobj *ob; + + if((can->gl_env)&&(can->gl_env->ce_dollarzero==d0)) + { + return can; + } + + ob=can->gl_list; + while(ob&&(retcan==0)) + { + if (pd_class(&ob->g_pd) == canvas_class) + retcan=getcanvas((t_glist *)ob,d0); + ob=ob->g_next; + } + + if((!retcan)&&(can->gl_next)) retcan=getcanvas((t_glist *)can->gl_next,d0); + return retcan; } static void relativepath_symbol(t_relativepath *x,t_symbol *sym) { - t_canvas *can=0; - t_symbol *s=sym; - char *instr=sym->s_name,*outstr=instr, - *candir, - canname[MAXPDSTRING],totaldir[MAXPDSTRING], - *cnamedir; - unsigned int n,i=0; - - if(!x->x_realized) can=(t_canvas*)getcanvas(canvas_list,x->x_dolzero); - if(can) { - x->x_canvas = can; - x->x_realized = 1; - //post("found $0 canvas : %x %d ",x->x_canvas, x->x_canvas->gl_env->ce_dollarzero ); - } - - if(!instr) return; - - candir=canvas_getdir(x->x_canvas)->s_name; - if(!candir) candir=""; - - strcpy(canname,x->x_canvas->gl_name->s_name); - //post("canname=%s",canname); - cnamedir=dirname(canname); - - if (strcmp(cnamedir,".")) { - sprintf(totaldir,"%s/%s",candir,cnamedir); - } - else - strcpy(totaldir,candir); - - //post("dir=%s",totaldir); - - n=strlen(totaldir); - if(strlen(instr)<=n) goto end; - - while(is_name,*outstr=instr, + *candir, + canname[MAXPDSTRING],totaldir[MAXPDSTRING], + *cnamedir; + unsigned int n,i=0; + + if(!x->x_realized) can=(t_canvas *)getcanvas(canvas_list,x->x_dolzero); + if(can) + { + x->x_canvas = can; + x->x_realized = 1; + //post("found $0 canvas : %x %d ",x->x_canvas, x->x_canvas->gl_env->ce_dollarzero ); + } + + if(!instr) return; + + candir=canvas_getdir(x->x_canvas)->s_name; + if(!candir) candir=""; + + strcpy(canname,x->x_canvas->gl_name->s_name); + //post("canname=%s",canname); + cnamedir=dirname(canname); + + if (strcmp(cnamedir,".")) + { + sprintf(totaldir,"%s/%s",candir,cnamedir); + } + else + strcpy(totaldir,candir); + + //post("dir=%s",totaldir); + + n=strlen(totaldir); + if(strlen(instr)<=n) goto end; + + while(ix_obj.ob_outlet,s); + outlet_symbol(x->x_obj.ob_outlet,s); } static void *relativepath_new(t_float dolzero) { - t_relativepath *x = (t_relativepath *)pd_new(relativepath_class); - int d0; + t_relativepath *x = (t_relativepath *)pd_new(relativepath_class); + int d0; - outlet_new(&x->x_obj, 0); - x->x_canvas = canvas_getcurrent(); - x->x_dolzero = dolzero; - x->x_realized=dolzero?0:1; + outlet_new(&x->x_obj, 0); + x->x_canvas = canvas_getcurrent(); + x->x_dolzero = dolzero; + x->x_realized=dolzero?0:1; - return (void *)x; + return (void *)x; } void relativepath_setup(void) { - relativepath_class = class_new(gensym("relativepath"),(t_newmethod)relativepath_new, - 0, sizeof(t_relativepath), 0,A_DEFFLOAT,0); + relativepath_class = class_new(gensym("relativepath"),(t_newmethod)relativepath_new, + 0, sizeof(t_relativepath), 0,A_DEFFLOAT,0); - class_addsymbol(relativepath_class, relativepath_symbol); + class_addsymbol(relativepath_class, relativepath_symbol); } #endif /* NOT _WIN32 */ diff --git a/s2f.c b/s2f.c index 9af9035..ac0ef89 100644 --- a/s2f.c +++ b/s2f.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct _s2f { t_object x_obj; -}t_s2f; +} t_s2f; t_class *s2f_class; @@ -31,23 +31,23 @@ void s2f_setup(void); static void s2f_symbol(t_s2f *x,t_symbol *sym) { - if(!sym->s_name) return; + if(!sym->s_name) return; - outlet_float(x->x_obj.ob_outlet,(t_float)strtod(sym->s_name,0)); + outlet_float(x->x_obj.ob_outlet,(t_float)strtod(sym->s_name,0)); } static void *s2f_new(void) -{ - t_s2f *x = (t_s2f *)pd_new(s2f_class); - outlet_new(&x->x_obj, &s_float); - return (void *)x; +{ + t_s2f *x = (t_s2f *)pd_new(s2f_class); + outlet_new(&x->x_obj, &s_float); + return (void *)x; } void s2f_setup(void) { - s2f_class = class_new(gensym("s2f"),(t_newmethod)s2f_new, - 0, sizeof(t_s2f), 0, 0); + s2f_class = class_new(gensym("s2f"),(t_newmethod)s2f_new, + 0, sizeof(t_s2f), 0, 0); - class_addsymbol(s2f_class, s2f_symbol); + class_addsymbol(s2f_class, s2f_symbol); } diff --git a/sarray.c b/sarray.c index d44f7ce..def0a51 100644 --- a/sarray.c +++ b/sarray.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2003 Antoine Rousseau +Copyright (C) 2003 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -31,8 +31,8 @@ typedef struct scommon t_pd c_pd; t_symbol *c_sym; int c_refcount; - int c_len; - t_symbol **c_array; + int c_len; + t_symbol **c_array; } t_scommon; typedef struct _sarray @@ -40,100 +40,101 @@ typedef struct _sarray t_object x_obj; t_symbol *x_sym; t_scommon *x_c; - //t_outlet *x_symout; - //t_outlet *x_lenout; + //t_outlet *x_symout; + //t_outlet *x_lenout; } t_sarray; /*static int scommon_find(t_scommon *x, t_symbol *s) { t_sitem *si=x->first; t_int i=1; - + while(si) { - if(!strcmp(si->s->s_name,s->s_name)) return i; + if(!strcmp(si->s->s_name,s->s_name)) return i; si=si->next; i++; } return 0; }*/ - + static t_symbol *scommon_get(t_scommon *x, t_float f) { - int i=(int)f; + int i=(int)f; - if(i<0) i=0; - if(i>=x->c_len) i=x->c_len-1; - return x->c_array[i]; + if(i<0) i=0; + if(i>=x->c_len) i=x->c_len-1; + return x->c_array[i]; } static void scommon_set(t_scommon *x, t_float f, t_symbol *s) { - int i=(int)f; - - if((i<0)||(i>=x->c_len)) return; - x->c_array[i]=s; - //x->c_array[i]=gensym(strdup(s->s_name)); - //x->c_array[i]=gensym("ok"); + int i=(int)f; + + if((i<0)||(i>=x->c_len)) return; + x->c_array[i]=s; + //x->c_array[i]=gensym(strdup(s->s_name)); + //x->c_array[i]=gensym("ok"); } static void scommon_setlen(t_scommon *x, t_float flen) { int i,oldlen=x->c_len,len=flen; - - if(len<1) len=1; - x->c_len=len; - - x->c_array=realloc(x->c_array,sizeof(t_symbol *)*len); - - if(len>oldlen) for(i=oldlen;ic_array[i]=&s_; + + if(len<1) len=1; + x->c_len=len; + + x->c_array=realloc(x->c_array,sizeof(t_symbol *)*len); + + if(len>oldlen) for(i=oldlen; ic_array[i]=&s_; } static void scommon_reset(t_scommon *x) { - int i; - - for(i=0;ic_len;i++) x->c_array[i]=&s_; + int i; + + for(i=0; ic_len; i++) x->c_array[i]=&s_; } static t_atom *scommon_dump(t_scommon *x,t_symbol *s) { - int i; - t_atom *atombuf; - - atombuf = (t_atom *)getbytes(sizeof(t_atom)*x->c_len); - - for(i=0;ic_len;i++) { - if(x->c_array[i]==&s_) SETSYMBOL(&atombuf[i],s); - else SETSYMBOL(&atombuf[i],x->c_array[i]); - } - - return atombuf; + int i; + t_atom *atombuf; + + atombuf = (t_atom *)getbytes(sizeof(t_atom)*x->c_len); + + for(i=0; ic_len; i++) + { + if(x->c_array[i]==&s_) SETSYMBOL(&atombuf[i],s); + else SETSYMBOL(&atombuf[i],x->c_array[i]); + } + + return atombuf; } static void scommon_ff(t_scommon *x) { - //scommon_reset(x); - pd_unbind((t_pd*)x, x->c_sym); + //scommon_reset(x); + pd_unbind((t_pd *)x, x->c_sym); } static void *scommon_new(t_symbol *s) { t_scommon *x = (t_scommon *)pd_new(scommon_class); - x->c_refcount = 0; - x->c_sym=s; - pd_bind((t_pd*)x, s); - - x->c_len=1; - x->c_array=malloc(sizeof(t_symbol *)*1); - scommon_reset(x); + x->c_refcount = 0; + x->c_sym=s; + pd_bind((t_pd *)x, s); + + x->c_len=1; + x->c_array=malloc(sizeof(t_symbol *)*1); + scommon_reset(x); return (x); } - /* get a pointer to a named symbol list (a "scommon" object), - which is created if necessary. */ +/* get a pointer to a named symbol list (a "scommon" object), +which is created if necessary. */ t_scommon *sarray_scget(t_symbol *s) { t_scommon *c = (t_scommon *)pd_findbyclass(s, scommon_class); @@ -143,21 +144,21 @@ t_scommon *sarray_scget(t_symbol *s) return (c); } - /* release a variable. This only frees the "scommon" resource when the - last interested party releases it. */ +/* release a variable. This only frees the "scommon" resource when the +last interested party releases it. */ void sarray_release(t_scommon *c) { - if (!--c->c_refcount) scommon_ff(c); + if (!--c->c_refcount) scommon_ff(c); } - + static void *sarray_new(t_symbol *s,t_float len) { t_sarray *x = (t_sarray *)pd_new(sarray_class); - + x->x_sym = s; x->x_c = sarray_scget(s); - if(len) scommon_setlen(x->x_c,len); + if(len) scommon_setlen(x->x_c,len); outlet_new(&x->x_obj, &s_anything); //x->x_symout=outlet_new(&x->x_obj, &s_anything); @@ -172,82 +173,86 @@ static void sarray_ff(t_sarray *x) static void sarray_print(t_sarray *x) { - int i; - - for(i=0;ix_c->c_len;i++){ - post("item %d: %s",i,x->x_c->c_array[i]->s_name); - } + int i; + + for(i=0; ix_c->c_len; i++) + { + post("item %d: %s",i,x->x_c->c_array[i]->s_name); + } } static void sarray_reset(t_sarray *x) { - scommon_reset(x->x_c); + scommon_reset(x->x_c); } static void sarray_set(t_sarray *x, t_symbol *sfoo,int argc, t_atom *argv) { - int i,j=0; - t_symbol *snull=&s_,*s; - - /*if((argc<2)||(argv[0].a_type!=A_FLOAT)) - { - error("Bad arguments for message 'set' to object 'sarray'"); - return ; - }*/ - if(argv[0].a_type==A_SYMBOL) { - snull=atom_getsymbol(&argv[0]); - j=1; - } - - if(argv[j].a_type!=A_FLOAT){ - error("Bad arguments for message 'set' to object 'sarray'"); - return ; - } - - i=atom_getfloat(&argv[j++]); - - while((jx_c,i++,s); - } + int i,j=0; + t_symbol *snull=&s_,*s; + + /*if((argc<2)||(argv[0].a_type!=A_FLOAT)) + { + error("Bad arguments for message 'set' to object 'sarray'"); + return ; + }*/ + if(argv[0].a_type==A_SYMBOL) + { + snull=atom_getsymbol(&argv[0]); + j=1; + } + + if(argv[j].a_type!=A_FLOAT) + { + error("Bad arguments for message 'set' to object 'sarray'"); + return ; + } + + i=atom_getfloat(&argv[j++]); + + while((jx_c,i++,s); + } } static void sarray_get(t_sarray *x,t_float i) { - t_symbol *s=scommon_get(x->x_c,i); - - if(s==&s_) outlet_bang(x->x_obj.ob_outlet); - else outlet_symbol(x->x_obj.ob_outlet,scommon_get(x->x_c,i)); + t_symbol *s=scommon_get(x->x_c,i); + + if(s==&s_) outlet_bang(x->x_obj.ob_outlet); + else outlet_symbol(x->x_obj.ob_outlet,scommon_get(x->x_c,i)); } static void sarray_dump(t_sarray *x,t_symbol *s) { - t_atom *l=scommon_dump(x->x_c,s); + t_atom *l=scommon_dump(x->x_c,s); - outlet_list(x->x_obj.ob_outlet, &s_list, x->x_c->c_len, l); - free(l); + outlet_list(x->x_obj.ob_outlet, &s_list, x->x_c->c_len, l); + free(l); } static void sarray_setarray(t_sarray *x,t_symbol *s) { - sarray_release(x->x_c); - x->x_c = sarray_scget(s); - x->x_sym = s; + sarray_release(x->x_c); + x->x_c = sarray_scget(s); + x->x_sym = s; } static void sarray_setlen(t_sarray *x,t_float len) { - scommon_setlen(x->x_c,len); + scommon_setlen(x->x_c,len); } void sarray_setup(void) { s__=gensym("_"); - sarray_class = class_new(gensym("sarray"), (t_newmethod)sarray_new, - (t_method)sarray_ff, - sizeof(t_sarray), 0, A_DEFSYM, A_DEFFLOAT,0); + sarray_class = class_new(gensym("sarray"), (t_newmethod)sarray_new, + (t_method)sarray_ff, + sizeof(t_sarray), 0, A_DEFSYM, A_DEFFLOAT,0); //class_addbang(sarray_class, sarray_bang); //class_addfloat(sarray_class, sarray_float); @@ -258,7 +263,7 @@ void sarray_setup(void) class_addmethod(sarray_class,(t_method)sarray_setlen, gensym("setlen"),A_FLOAT,0); class_addmethod(sarray_class,(t_method)sarray_dump, gensym("dump"),A_DEFSYM,0); class_addmethod(sarray_class,(t_method)sarray_setarray, gensym("setarray"),A_SYMBOL,0); - scommon_class = class_new(gensym("sarray"), 0, 0, - sizeof(t_scommon), CLASS_PD, 0); + scommon_class = class_new(gensym("sarray"), 0, 0, + sizeof(t_scommon), CLASS_PD, 0); } diff --git a/sfread2~.c b/sfread2~.c index c4d7653..f32494d 100644 --- a/sfread2~.c +++ b/sfread2~.c @@ -34,27 +34,27 @@ static t_class *sfread_class; typedef struct _sfread { - t_object x_obj; - void* x_mapaddr; - int x_fd; - - t_int x_play; - t_int x_outchannels; - t_int x_loop; - double x_index; //samples - t_float x_speed; //1=sample rate - t_int x_interp; - - t_int x_size; // bytes - t_int x_fchannels; // file channels - t_int x_len; // samples - t_int x_skip; //bytes - t_clock *x_clock; - - - t_glist * x_glist; - t_outlet *x_stateout; - t_outlet *x_sizeout; + t_object x_obj; + void *x_mapaddr; + int x_fd; + + t_int x_play; + t_int x_outchannels; + t_int x_loop; + double x_index; //samples + t_float x_speed; //1=sample rate + t_int x_interp; + + t_int x_size; // bytes + t_int x_fchannels; // file channels + t_int x_len; // samples + t_int x_skip; //bytes + t_clock *x_clock; + + + t_glist *x_glist; + t_outlet *x_stateout; + t_outlet *x_sizeout; } t_sfread; #define MAX_CHANS 4 @@ -70,271 +70,296 @@ typedef struct _sfread static t_int *sfread_perform(t_int *w) { - t_sfread* x = (t_sfread*)(w[1]); - short *fp, *buf = x->x_mapaddr+x->x_skip; -/* t_float *in = (t_float *)(w[2]); will we need this (indexing) ?*/ - int c = x->x_outchannels; - int fc = x->x_fchannels,fc2=2*fc; - double findex = x->x_index; - t_float speed = x->x_speed; - float frac, a, b, cc, d, cminusb; - int i,n,index,rindex; - int end = x->x_len -3;/* -3 is for safe interpolation*/ - t_float* out[MAX_CHANS]; - t_int in_off[MAX_CHANS]; - t_int loground=(fc==1?0:fc==2?1:2); - - if(!x->x_mapaddr) return(w+c+4); - - for (i=0;i end) - findex = end; - - if (findex + n*speed > end) { // playing forward end - if (!x->x_loop) { - x->x_play=0; - findex = 0; - clock_delay(x->x_clock, 0); - } - } - - if (findex + n*speed < 1) { // playing backwards end - if (!x->x_loop) { - x->x_play=0; - findex = end; - clock_delay(x->x_clock, 0); - } - - } - - - if (x->x_play && x->x_mapaddr) { - - if (speed != 1) { /* different speed */ - if (x->x_interp) while (n--) { - index=findex; - rindex=index< end) { - if (x->x_loop) findex = 1; - else break; - } - if (findex < 1) { - if (x->x_loop) findex = end; - else break; - } - } - else while (n--) { - rindex=((int)findex)< end) { - if (x->x_loop) findex = 1; - else break; - } - if (findex < 1) { - if (x->x_loop) findex = end; - else break; - } - } - /* Fill with zero in case of end */ - n++; - while (n--) - for (i=0;i end2) { - if (x->x_loop) rindex = 1; - else break; - } - } - - /* Fill with zero in case of end */ - n++; - while (n--) - for (i=0;i>loground; - } - - } - else { - while (n--) { - for (i=0;ix_index = findex; - return (w+c+4); + t_sfread *x = (t_sfread *)(w[1]); + short *fp, *buf = x->x_mapaddr+x->x_skip; + /* t_float *in = (t_float *)(w[2]); will we need this (indexing) ?*/ + int c = x->x_outchannels; + int fc = x->x_fchannels,fc2=2*fc; + double findex = x->x_index; + t_float speed = x->x_speed; + float frac, a, b, cc, d, cminusb; + int i,n,index,rindex; + int end = x->x_len -3;/* -3 is for safe interpolation*/ + t_float *out[MAX_CHANS]; + t_int in_off[MAX_CHANS]; + t_int loground=(fc==1?0:fc==2?1:2); + + if(!x->x_mapaddr) return(w+c+4); + + for (i=0; i end) + findex = end; + + if (findex + n*speed > end) // playing forward end + { + if (!x->x_loop) + { + x->x_play=0; + findex = 0; + clock_delay(x->x_clock, 0); + } + } + + if (findex + n*speed < 1) // playing backwards end + { + if (!x->x_loop) + { + x->x_play=0; + findex = end; + clock_delay(x->x_clock, 0); + } + + } + + + if (x->x_play && x->x_mapaddr) + { + + if (speed != 1) /* different speed */ + { + if (x->x_interp) while (n--) + { + index=findex; + rindex=index< end) + { + if (x->x_loop) findex = 1; + else break; + } + if (findex < 1) + { + if (x->x_loop) findex = end; + else break; + } + } + else while (n--) + { + rindex=((int)findex)< end) + { + if (x->x_loop) findex = 1; + else break; + } + if (findex < 1) + { + if (x->x_loop) findex = end; + else break; + } + } + /* Fill with zero in case of end */ + n++; + while (n--) + for (i=0; i end2) + { + if (x->x_loop) rindex = 1; + else break; + } + } + + /* Fill with zero in case of end */ + n++; + while (n--) + for (i=0; i>loground; + } + + } + else + { + while (n--) + { + for (i=0; ix_index = findex; + return (w+c+4); } static void sfread_loop(t_sfread *x, t_floatarg f) { - x->x_loop = f; + x->x_loop = f; } static void sfread_interp(t_sfread *x, t_floatarg f) { - x->x_interp = (f!=0); + x->x_interp = (f!=0); } static void sfread_index(t_sfread *x, t_floatarg f) { - x->x_index = f; + x->x_index = f; } -static void sfread_size(t_sfread* x) +static void sfread_size(t_sfread *x) { - outlet_float(x->x_sizeout,x->x_len); + outlet_float(x->x_sizeout,x->x_len); } -static void sfread_state(t_sfread* x) +static void sfread_state(t_sfread *x) { outlet_float(x->x_stateout, x->x_play); } static void sfread_float(t_sfread *x, t_floatarg f) { - int t = f; - if (t && x->x_mapaddr) { - x->x_play=1; - } - else { - x->x_play=0; - } - sfread_state(x); + int t = f; + if (t && x->x_mapaddr) + { + x->x_play=1; + } + else + { + x->x_play=0; + } + sfread_state(x); } -static void sfread_bang(t_sfread* x) +static void sfread_bang(t_sfread *x) { - x->x_index = x->x_speed>0?1:x->x_len-3; - sfread_float(x,1.0); + x->x_index = x->x_speed>0?1:x->x_len-3; + sfread_float(x,1.0); } static void sfread_dsp(t_sfread *x, t_signal **sp) { -/* post("sfread: dsp"); */ - switch (x->x_outchannels) { - case 1: - dsp_add(sfread_perform, 4, x, sp[0]->s_vec, - sp[1]->s_vec, sp[0]->s_n); - break; - case 2: - dsp_add(sfread_perform, 5, x, sp[0]->s_vec, - sp[1]->s_vec,sp[2]->s_vec, sp[0]->s_n); - break; - case 4: - dsp_add(sfread_perform, 6, x, sp[0]->s_vec, - sp[1]->s_vec,sp[2]->s_vec, - sp[3]->s_vec,sp[4]->s_vec, - sp[0]->s_n); - break; - } + /* post("sfread: dsp"); */ + switch (x->x_outchannels) + { + case 1: + dsp_add(sfread_perform, 4, x, sp[0]->s_vec, + sp[1]->s_vec, sp[0]->s_n); + break; + case 2: + dsp_add(sfread_perform, 5, x, sp[0]->s_vec, + sp[1]->s_vec,sp[2]->s_vec, sp[0]->s_n); + break; + case 4: + dsp_add(sfread_perform, 6, x, sp[0]->s_vec, + sp[1]->s_vec,sp[2]->s_vec, + sp[3]->s_vec,sp[4]->s_vec, + sp[0]->s_n); + break; + } } extern int open_soundfile(const char *dirname, const char *filename, int headersize, - int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, - long skipframes); /* in pd/src/d_soundfile.c */ + int *p_bytespersamp, int *p_bigendian, int *p_nchannels, long *p_bytelimit, + long skipframes); /* in pd/src/d_soundfile.c */ static void sfread_open(t_sfread *x,t_symbol *filename) { - struct stat fstate; - char fname[MAXPDSTRING]; - int bytespersamp=0,bigendian=0,channels=0; - long bytelimit= 0x7fffffff,skipframes = 0; - - if (filename == &s_) { - post("sfread: open without filename"); - return; - } - - canvas_makefilename(glist_getcanvas(x->x_glist), filename->s_name, - fname, MAXPDSTRING); - - - /* close the old file */ - - if (x->x_mapaddr) munmap(x->x_mapaddr,x->x_size); - if (x->x_fd >= 0) close(x->x_fd); - - /*if ((x->x_fd = open(fname,O_RDONLY)) < 0)*/ - //post("fname: %s",fname); - - if ((x->x_fd = open_soundfile("",fname, -1,&bytespersamp,&bigendian, - &channels, &bytelimit,0)) < 0) - { - error("can't open %s",fname); - x->x_play = 0; - x->x_mapaddr = NULL; - return; - } - - if( ((x->x_fchannels!=1)&&(x->x_fchannels!=2)&&(x->x_fchannels!=4)) || - (bytespersamp!=2) ) - { - error("file %s error: not a 1 or 2 or 4 channels soundfile, or not a 16 bits soundfile",fname); - post("channels:%d bytes:%d ",x->x_fchannels,bytespersamp); - x->x_play = 0; - x->x_mapaddr = NULL; - return; - } - - x->x_fchannels=channels; - - /* get the size */ - - fstat(x->x_fd,&fstate); - x->x_size = (int)fstate.st_size; - x->x_skip=x->x_size-bytelimit; - x->x_len = (bytelimit)/(bytespersamp*x->x_fchannels); - - //post("bytelimit=%d x->x_size-x->x_skip=%d x->x_size=%d x->x_skip=%d",bytelimit,x->x_size-x->x_skip,x->x_size,x->x_skip); - - /* map the file into memory */ - - if (!(x->x_mapaddr = mmap(NULL,x->x_size,PROT_READ,MAP_PRIVATE,x->x_fd,0))) - { - error("can't mmap %s",fname); - return; - } - sfread_size(x); + struct stat fstate; + char fname[MAXPDSTRING]; + int bytespersamp=0,bigendian=0,channels=0; + long bytelimit= 0x7fffffff,skipframes = 0; + + if (filename == &s_) + { + post("sfread: open without filename"); + return; + } + + canvas_makefilename(glist_getcanvas(x->x_glist), filename->s_name, + fname, MAXPDSTRING); + + + /* close the old file */ + + if (x->x_mapaddr) munmap(x->x_mapaddr,x->x_size); + if (x->x_fd >= 0) close(x->x_fd); + + /*if ((x->x_fd = open(fname,O_RDONLY)) < 0)*/ + //post("fname: %s",fname); + + if ((x->x_fd = open_soundfile("",fname, -1,&bytespersamp,&bigendian, + &channels, &bytelimit,0)) < 0) + { + error("can't open %s",fname); + x->x_play = 0; + x->x_mapaddr = NULL; + return; + } + + if( ((x->x_fchannels!=1)&&(x->x_fchannels!=2)&&(x->x_fchannels!=4)) || + (bytespersamp!=2) ) + { + error("file %s error: not a 1 or 2 or 4 channels soundfile, or not a 16 bits soundfile",fname); + post("channels:%d bytes:%d ",x->x_fchannels,bytespersamp); + x->x_play = 0; + x->x_mapaddr = NULL; + return; + } + + x->x_fchannels=channels; + + /* get the size */ + + fstat(x->x_fd,&fstate); + x->x_size = (int)fstate.st_size; + x->x_skip=x->x_size-bytelimit; + x->x_len = (bytelimit)/(bytespersamp*x->x_fchannels); + + //post("bytelimit=%d x->x_size-x->x_skip=%d x->x_size=%d x->x_skip=%d",bytelimit,x->x_size-x->x_skip,x->x_size,x->x_skip); + + /* map the file into memory */ + + if (!(x->x_mapaddr = mmap(NULL,x->x_size,PROT_READ,MAP_PRIVATE,x->x_fd,0))) + { + error("can't mmap %s",fname); + return; + } + sfread_size(x); } static void *sfread_new(t_floatarg chan,t_floatarg interp) @@ -342,7 +367,7 @@ static void *sfread_new(t_floatarg chan,t_floatarg interp) t_sfread *x = (t_sfread *)pd_new(sfread_class); t_int c = chan; - x->x_glist = (t_glist*) canvas_getcurrent(); + x->x_glist = (t_glist *) canvas_getcurrent(); if (c<1 || c > MAX_CHANS) c = 1; floatinlet_new(&x->x_obj, &x->x_speed); @@ -362,31 +387,32 @@ static void *sfread_new(t_floatarg chan,t_floatarg interp) x->x_speed = 1.0; x->x_play = 0; x->x_interp = (interp!=0); - x->x_clock = clock_new(x, (t_method)sfread_state); - - while (c--) { - outlet_new(&x->x_obj, gensym("signal")); + x->x_clock = clock_new(x, (t_method)sfread_state); + + while (c--) + { + outlet_new(&x->x_obj, gensym("signal")); } - x->x_stateout = outlet_new(&x->x_obj, &s_float); - x->x_sizeout = outlet_new(&x->x_obj, &s_float); + x->x_stateout = outlet_new(&x->x_obj, &s_float); + x->x_sizeout = outlet_new(&x->x_obj, &s_float); -/* post("sfread: x_channels = %d, x_speed = %f",x->x_channels,x->x_speed);*/ + /* post("sfread: x_channels = %d, x_speed = %f",x->x_channels,x->x_speed);*/ return (x); } - + static void sfread_free(t_sfread *x) { - clock_free(x->x_clock); + clock_free(x->x_clock); } void sfread2_tilde_setup(void) { - /* sfread */ + /* sfread */ - sfread_class = class_new(gensym("sfread2~"), (t_newmethod)sfread_new, - (t_method)sfread_free,sizeof(t_sfread), 0,A_DEFFLOAT,A_DEFFLOAT,0); + sfread_class = class_new(gensym("sfread2~"), (t_newmethod)sfread_new, + (t_method)sfread_free,sizeof(t_sfread), 0,A_DEFFLOAT,A_DEFFLOAT,0); class_addmethod(sfread_class, nullfn, gensym("signal"), 0); class_addmethod(sfread_class, (t_method) sfread_dsp, gensym("dsp"), 0); @@ -400,7 +426,7 @@ void sfread2_tilde_setup(void) class_addmethod(sfread_class,(t_method)sfread_index,gensym("index"),A_FLOAT,A_NULL); - // Impossible with pd-0.35 because it leaves super-user mode. + // Impossible with pd-0.35 because it leaves super-user mode. //if(munlockall()) perror("munlockall()"); //if(mlockall(MCL_CURRENT)) perror("mlockall(MCL_CURRENT)"); } diff --git a/slist.c b/slist.c index 6af28c6..fa0c350 100644 --- a/slist.c +++ b/slist.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2003 Antoine Rousseau +Copyright (C) 2003 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -29,8 +29,8 @@ typedef struct _sitem t_sitem; struct _sitem { - t_sitem *next; - t_symbol *s; + t_sitem *next; + t_symbol *s; }; typedef struct scommon @@ -38,7 +38,7 @@ typedef struct scommon t_pd c_pd; t_symbol *c_sym; int c_refcount; - t_sitem *first; + t_sitem *first; } t_scommon; typedef struct _slist @@ -46,43 +46,43 @@ typedef struct _slist t_object x_obj; t_symbol *x_sym; t_scommon *x_c; - t_outlet *x_symout; - t_outlet *x_lenout; + t_outlet *x_symout; + t_outlet *x_lenout; } t_slist; static void sitem_delete(t_sitem **x) { - t_sitem *next=(*x)->next; - - //freebytes((*x)->name,strlen((*x)->name)+1); - freebytes(*x,sizeof(t_sitem)); - (*x)=next; + t_sitem *next=(*x)->next; + + //freebytes((*x)->name,strlen((*x)->name)+1); + freebytes(*x,sizeof(t_sitem)); + (*x)=next; } static void sitem_add(t_sitem **x,t_symbol *s) { - t_int l; - t_sitem *newone=getbytes(sizeof(t_sitem)); - - //newone->name=getbytes(l=(strlen(s->s_name)+1)); - //strncpy(newone->name,s->s_name,l); - newone->s=s; - newone->next=0; - - while(*x) x=&((*x)->next); - - *x=newone; + t_int l; + t_sitem *newone=getbytes(sizeof(t_sitem)); + + //newone->name=getbytes(l=(strlen(s->s_name)+1)); + //strncpy(newone->name,s->s_name,l); + newone->s=s; + newone->next=0; + + while(*x) x=&((*x)->next); + + *x=newone; } static void *scommon_new(t_symbol *s) { t_scommon *x = (t_scommon *)pd_new(scommon_class); - x->c_refcount = 0; - x->c_sym=s; - pd_bind((t_pd*)x, s); - + x->c_refcount = 0; + x->c_sym=s; + pd_bind((t_pd *)x, s); + x->first=0; return (x); @@ -90,36 +90,37 @@ static void *scommon_new(t_symbol *s) static int scommon_find(t_scommon *x, t_symbol *s) { - t_sitem *si=x->first; - t_int i=1; - - while(si) { - if(!strcmp(si->s->s_name,s->s_name)) return i; - si=si->next; - i++; - } - return 0; -} - + t_sitem *si=x->first; + t_int i=1; + + while(si) + { + if(!strcmp(si->s->s_name,s->s_name)) return i; + si=si->next; + i++; + } + return 0; +} + static void scommon_add(t_scommon *x, t_symbol *s) { - sitem_add(&x->first,s); + sitem_add(&x->first,s); } static void scommon_reset(t_scommon *x) { - while(x->first) sitem_delete(&x->first); + while(x->first) sitem_delete(&x->first); } static void scommon_ff(t_scommon *x) { - scommon_reset(x); - pd_unbind((t_pd*)x, x->c_sym); + scommon_reset(x); + pd_unbind((t_pd *)x, x->c_sym); } - /* get a pointer to a named symbol list (a "scommon" object), - which is created if necessary. */ +/* get a pointer to a named symbol list (a "scommon" object), +which is created if necessary. */ t_scommon *slist_get(t_symbol *s) { t_scommon *c = (t_scommon *)pd_findbyclass(s, scommon_class); @@ -129,14 +130,14 @@ t_scommon *slist_get(t_symbol *s) return (c); } - /* release a variable. This only frees the "scommon" resource when the - last interested party releases it. */ +/* release a variable. This only frees the "scommon" resource when the +last interested party releases it. */ void slist_release(t_scommon *c) { - if (!--c->c_refcount) scommon_ff(c); + if (!--c->c_refcount) scommon_ff(c); } - + static void *slist_new(t_symbol *s) { t_slist *x = (t_slist *)pd_new(slist_class); @@ -155,69 +156,72 @@ static void slist_ff(t_slist *x) static void slist_print(t_slist *x) { - t_sitem *t=x->x_c->first; - int i=0; - - while(t){ - post("item %d: %s",++i,t->s->s_name); - t=t->next; - } + t_sitem *t=x->x_c->first; + int i=0; + + while(t) + { + post("item %d: %s",++i,t->s->s_name); + t=t->next; + } } static void slist_reset(t_slist *x) { - scommon_reset(x->x_c); + scommon_reset(x->x_c); } static void slist_add(t_slist *x,t_symbol *s) { - scommon_add(x->x_c,s); + scommon_add(x->x_c,s); } static void slist_find(t_slist *x,t_symbol *s) { - outlet_float(x->x_obj.ob_outlet,scommon_find(x->x_c,s)); + outlet_float(x->x_obj.ob_outlet,scommon_find(x->x_c,s)); } static void slist_setlist(t_slist *x,t_symbol *s) { - slist_release(x->x_c); - x->x_c = slist_get(s); + slist_release(x->x_c); + x->x_c = slist_get(s); } static void slist_float(t_slist *x, t_float f) { - t_sitem *t=x->x_c->first; - int i=0; + t_sitem *t=x->x_c->first; + int i=0; + + if(!f) return; - if(!f) return; - - while(t&&((++i)!=f)){ - t=t->next; - } + while(t&&((++i)!=f)) + { + t=t->next; + } - if(t) outlet_symbol(x->x_symout,t->s); + if(t) outlet_symbol(x->x_symout,t->s); } static void slist_len(t_slist *x) { - t_sitem *t=x->x_c->first; - int i=0; + t_sitem *t=x->x_c->first; + int i=0; - while(t){ - t=t->next; - i++; - } + while(t) + { + t=t->next; + i++; + } - outlet_float(x->x_lenout,i); + outlet_float(x->x_lenout,i); } void slist_setup(void) { slist_class = class_new(gensym("slist"), (t_newmethod)slist_new, - (t_method)slist_ff, - sizeof(t_slist), 0, A_DEFSYM, 0); + (t_method)slist_ff, + sizeof(t_slist), 0, A_DEFSYM, 0); //class_addbang(slist_class, slist_bang); class_addfloat(slist_class, slist_float); @@ -227,7 +231,7 @@ void slist_setup(void) class_addmethod(slist_class,(t_method)slist_reset, gensym("reset"),0); class_addmethod(slist_class,(t_method)slist_print, gensym("print"),0); class_addmethod(slist_class,(t_method)slist_len, gensym("len"),0); - scommon_class = class_new(gensym("slist"), 0, 0, - sizeof(t_scommon), CLASS_PD, 0); + scommon_class = class_new(gensym("slist"), 0, 0, + sizeof(t_scommon), CLASS_PD, 0); } diff --git a/ssaw~.c b/ssaw~.c index c91b0f1..c57015e 100644 --- a/ssaw~.c +++ b/ssaw~.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004 Antoine Rousseau +Copyright (C) 2004 Antoine Rousseau all material Copyright (c) 1997-1999 Miller Puckette. This library is free software; you can redistribute it and/or @@ -14,7 +14,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -26,16 +26,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */ - /* machine-dependent definitions. These ifdefs really - should have been by CPU type and not by operating system! */ +/* machine-dependent definitions. These ifdefs really +should have been by CPU type and not by operating system! */ #ifdef IRIX - /* big-endian. Most significant byte is at low address in memory */ +/* big-endian. Most significant byte is at low address in memory */ #define HIOFFSET 0 /* word offset to find MSB */ #define LOWOFFSET 1 /* word offset to find LSB */ #define int32 long /* a data type that has 32 bits */ #else #ifdef _WIN32 - /* little-endian; most significant byte is at highest address */ +/* little-endian; most significant byte is at highest address */ #define HIOFFSET 1 #define LOWOFFSET 0 #define int32 long @@ -56,17 +56,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include -#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN) +#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN) #error No byte order defined -#endif - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define HIOFFSET 1 -#define LOWOFFSET 0 -#else -#define HIOFFSET 0 /* word offset to find MSB */ -#define LOWOFFSET 1 /* word offset to find LSB */ -#endif /* __BYTE_ORDER */ +#endif + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define HIOFFSET 1 +#define LOWOFFSET 0 +#else +#define HIOFFSET 0 /* word offset to find MSB */ +#define LOWOFFSET 1 /* word offset to find LSB */ +#endif /* __BYTE_ORDER */ #include #define int32 int32_t @@ -96,9 +96,9 @@ static float ssaw_array[1002]; typedef struct _ssaw { - t_object x_obj; + t_object x_obj; //from phasor~: - double x_phase; + double x_phase; float x_conv; float x_f; /* scalar frequency */ float x_band; /* band limit (Hertz)*/ @@ -126,7 +126,7 @@ static t_int *ssaw_perform(t_int *w) union tabfudge tf; int normhipart; float conv = x->x_conv; - float band=x->x_band*.33; + float band=x->x_band*.33; float *buf = ssaw_array; tf.tf_d = UNITBIT32; @@ -134,41 +134,45 @@ static t_int *ssaw_perform(t_int *w) tf.tf_d = dphase; for (i = 0; i < n; i++) - //while (n--) + //while (n--) { - float phase,band2,findex /*= *in++*/; - int index /*= findex*/; - float frac, a, b, c, d, cminusb, *fp; - - tf.tf_i[HIOFFSET] = normhipart; - band2=abs(*in); - if(band2>999999) band2=999999; else if(band2<1) band2=1; - band2=band/band2; - dphase += *in++ * conv; - /**out++*/phase = (tf.tf_d - UNITBIT32)-0.5; - tf.tf_d = dphase; - - findex=phase*band2; - if(findex>0.5) findex=0.5; else if(findex<-0.5) findex=-0.5; - - /*findex=findex*1000+501; - index=findex;*/ - /*if (index < 1) - index = 1, frac = 0; - else if (index > maxindex) - index = maxindex, frac = 1; - else*/ frac = findex - index; - /*fp = buf + index; - a = fp[-1]; - b = fp[0]; - c = fp[1]; - d = fp[2]; - cminusb = c-b; - *out++ = 0.5+ phase - ( - b + frac * ( cminusb - 0.1666667f * (1.-frac) * ( - (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b))) - );*/ - *out++ = 0.5+ phase - buf[(int)(findex*1000+501)]; + float phase,band2,findex /*= *in++*/; + int index /*= findex*/; + float frac, a, b, c, d, cminusb, *fp; + + tf.tf_i[HIOFFSET] = normhipart; + band2=abs(*in); + if(band2>999999) band2=999999; + else if(band2<1) band2=1; + band2=band/band2; + dphase += *in++ * conv; + /**out++*/ + phase = (tf.tf_d - UNITBIT32)-0.5; + tf.tf_d = dphase; + + findex=phase*band2; + if(findex>0.5) findex=0.5; + else if(findex<-0.5) findex=-0.5; + + /*findex=findex*1000+501; + index=findex;*/ + /*if (index < 1) + index = 1, frac = 0; + else if (index > maxindex) + index = maxindex, frac = 1; + else*/ + frac = findex - index; + /*fp = buf + index; + a = fp[-1]; + b = fp[0]; + c = fp[1]; + d = fp[2]; + cminusb = c-b; + *out++ = 0.5+ phase - ( + b + frac * ( cminusb - 0.1666667f * (1.-frac) * ( + (d - a - 3.0f * cminusb) * frac + (d + 2.0f*a - 3.0f*b))) + );*/ + *out++ = 0.5+ phase - buf[(int)(findex*1000+501)]; } tf.tf_i[HIOFFSET] = normhipart; @@ -189,25 +193,26 @@ static void ssaw_ft1(t_ssaw *x, t_float f) static void ssaw_initarray(void) { - int i; - float j; - - for(i=0;i<1002;i++){ - j=(i-1)*M_PI/1000.0; //period 2000 sample, 1 sample back phase - ssaw_array[i]= 0.57692* - (-1*cos(j) + 0.333333*cos(j*3.0) -0.2* cos(j*5.0)); - } + int i; + float j; + + for(i=0; i<1002; i++) + { + j=(i-1)*M_PI/1000.0; //period 2000 sample, 1 sample back phase + ssaw_array[i]= 0.57692* + (-1*cos(j) + 0.333333*cos(j*3.0) -0.2* cos(j*5.0)); + } } void ssaw_tilde_setup(void) { ssaw_class = class_new(gensym("ssaw~"), (t_newmethod)ssaw_new, 0, - sizeof(t_ssaw), 0, A_DEFFLOAT, 0); + sizeof(t_ssaw), 0, A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(ssaw_class, t_ssaw, x_f); class_addmethod(ssaw_class, (t_method)ssaw_dsp, gensym("dsp"), 0); class_addmethod(ssaw_class, (t_method)ssaw_ft1, - gensym("ft1"), A_FLOAT, 0); - ssaw_initarray(); + gensym("ft1"), A_FLOAT, 0); + ssaw_initarray(); } diff --git a/tabdump2.c b/tabdump2.c index 98dac2c..deb8e16 100644 --- a/tabdump2.c +++ b/tabdump2.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2004 Antoine Rousseau +Copyright (C) 2004 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -27,94 +27,94 @@ static t_class *tabdump_class; typedef struct _tabdump { - t_object x_obj; - t_symbol *x_arrayname; + t_object x_obj; + t_symbol *x_arrayname; } t_tabdump; static void tabdump_bang(t_tabdump *x, t_float findex) { - t_garray *A; - int npoints; - t_float *vec; - - if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) - error("%s: no such array", x->x_arrayname->s_name); - else if (!garray_getfloatarray(A, &npoints, &vec)) - error("%s: bad template for tabdump", x->x_arrayname->s_name); - else + t_garray *A; + int npoints; + t_float *vec; + + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + error("%s: no such array", x->x_arrayname->s_name); + else if (!garray_getfloatarray(A, &npoints, &vec)) + error("%s: bad template for tabdump", x->x_arrayname->s_name); + else { - int n; - t_atom *atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); + int n; + t_atom *atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); - for (n = 0; n < npoints; n++) SETFLOAT(&atombuf[n], vec[n]); - outlet_list(x->x_obj.ob_outlet, &s_list, npoints, atombuf); + for (n = 0; n < npoints; n++) SETFLOAT(&atombuf[n], vec[n]); + outlet_list(x->x_obj.ob_outlet, &s_list, npoints, atombuf); } } static void tabdump_dump(t_tabdump *x, t_float min, t_float max) { - t_garray *A; - int npoints,nmin=(int)min,nmax=(int)max; - t_float *vec; - - if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) - error("%s: no such array", x->x_arrayname->s_name); - else if (!garray_getfloatarray(A, &npoints, &vec)) - error("%s: bad template for tabdump", x->x_arrayname->s_name); - else if ((min<0)||(max<=min)||(max>npoints)) - error("tabdump: bad arguments min=%d max=%d for %s (%d elements)", - nmin,nmax,x->x_arrayname->s_name,npoints); - else + t_garray *A; + int npoints,nmin=(int)min,nmax=(int)max; + t_float *vec; + + if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) + error("%s: no such array", x->x_arrayname->s_name); + else if (!garray_getfloatarray(A, &npoints, &vec)) + error("%s: bad template for tabdump", x->x_arrayname->s_name); + else if ((min<0)||(max<=min)||(max>npoints)) + error("tabdump: bad arguments min=%d max=%d for %s (%d elements)", + nmin,nmax,x->x_arrayname->s_name,npoints); + else { - int n; - t_atom *atombuf; - - npoints=nmax-nmin; - atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); - - for (n = 0; n < npoints; n++) SETFLOAT(&atombuf[n], vec[n+nmin]); - outlet_list(x->x_obj.ob_outlet, &s_list, npoints, atombuf); + int n; + t_atom *atombuf; + + npoints=nmax-nmin; + atombuf = (t_atom *)getbytes(sizeof(t_atom)*npoints); + + for (n = 0; n < npoints; n++) SETFLOAT(&atombuf[n], vec[n+nmin]); + outlet_list(x->x_obj.ob_outlet, &s_list, npoints, atombuf); } } static void tabdump_set(t_tabdump *x, t_symbol *s) { - x->x_arrayname = s; + x->x_arrayname = s; } static void *tabdump_new(t_symbol *s) { - t_tabdump *x = (t_tabdump *)pd_new(tabdump_class); - x->x_arrayname = s; - outlet_new(&x->x_obj, &s_list); + t_tabdump *x = (t_tabdump *)pd_new(tabdump_class); + x->x_arrayname = s; + outlet_new(&x->x_obj, &s_list); - return (x); + return (x); } static void tabdump_helper(void) { - post("\n tabdump2 - object : dumps a table as a package of floats"); - post("'set '\t: read out another table\n" - "'bang'\t\t: dump the table\n" - "'dump '\t\t: dump the table from to (without )\n" - "outlet\t\t: table-data as package of floats"); - post("creation\t: \"tabdump2
\""); + post("\n tabdump2 - object : dumps a table as a package of floats"); + post("'set
'\t: read out another table\n" + "'bang'\t\t: dump the table\n" + "'dump '\t\t: dump the table from to (without )\n" + "outlet\t\t: table-data as package of floats"); + post("creation\t: \"tabdump2
\""); } void tabdump2_setup(void) { - tabdump_class = class_new(gensym("tabdump2"), (t_newmethod)tabdump_new, - 0, sizeof(t_tabdump), 0, A_DEFSYM, 0); - class_addbang(tabdump_class, (t_method)tabdump_bang); - class_addmethod(tabdump_class, (t_method)tabdump_dump,gensym("dump"), - A_FLOAT,A_FLOAT,0); - class_addmethod(tabdump_class, (t_method)tabdump_set, gensym("set"), - A_SYMBOL, 0); - - class_addmethod(tabdump_class, (t_method)tabdump_helper, gensym("help"), 0); + tabdump_class = class_new(gensym("tabdump2"), (t_newmethod)tabdump_new, + 0, sizeof(t_tabdump), 0, A_DEFSYM, 0); + class_addbang(tabdump_class, (t_method)tabdump_bang); + class_addmethod(tabdump_class, (t_method)tabdump_dump,gensym("dump"), + A_FLOAT,A_FLOAT,0); + class_addmethod(tabdump_class, (t_method)tabdump_set, gensym("set"), + A_SYMBOL, 0); + + class_addmethod(tabdump_class, (t_method)tabdump_helper, gensym("help"), 0); } diff --git a/tabenv.c b/tabenv.c index 9b52fbe..b499e22 100644 --- a/tabenv.c +++ b/tabenv.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct tabenv { - /*env part*/ + /*env part*/ t_object x_obj; /* header */ t_outlet *x_outlet; /* a "float" outlet */ t_clock *x_clock; /* a "clock" object */ @@ -40,9 +40,9 @@ typedef struct tabenv int x_npoints; /* analysis window size in samples */ float x_result; /* result to output */ float x_sumbuf[MAXOVERLAP]; /* summing buffer */ - float x_f; - - /*tabplay part*/ + float x_f; + + /*tabplay part*/ int x_tabphase; int x_nsampsintab; int x_limit; @@ -64,11 +64,11 @@ static void *tabenv_new(t_symbol *s,t_floatarg fnpoints, t_floatarg fperiod) if (npoints < 1) npoints = 1024; if (period < 1) period = npoints/2; if (period < npoints / MAXOVERLAP + 1) - period = npoints / MAXOVERLAP + 1; + period = npoints / MAXOVERLAP + 1; if (!(buf = getbytes(sizeof(float) * (npoints + MAXVSTAKEN)))) { - error("env: couldn't allocate buffer"); - return (0); + error("env: couldn't allocate buffer"); + return (0); } x = (t_tabenv *)pd_new(tabenv_class); x->x_buf = buf; @@ -77,17 +77,17 @@ static void *tabenv_new(t_symbol *s,t_floatarg fnpoints, t_floatarg fperiod) x->x_period = period; for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; for (i = 0; i < npoints; i++) - buf[i] = (1. - cos((2 * 3.14159 * i) / npoints))/npoints; + buf[i] = (1. - cos((2 * 3.14159 * i) / npoints))/npoints; for (; i < npoints+MAXVSTAKEN; i++) buf[i] = 0; x->x_clock = clock_new(x, (t_method)tabenv_tick); x->x_outlet = outlet_new(&x->x_obj, gensym("float")); x->x_f = 0; - /* tabplay */ + /* tabplay */ x->x_tabphase = 0x7fffffff; x->x_limit = 0; x->x_arrayname = s; - + return (x); } @@ -97,34 +97,34 @@ static t_int *sigenv_perform(t_int *w) t_float *in = (t_float *)(w[2]); int n = (int)(w[3]); int count; - float *sump; + float *sump; in += n; for (count = x->x_phase, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) + count < x->x_npoints; count += x->x_realperiod, sump++) { - float *hp = x->x_buf + count; - float *fp = in; - float sum = *sump; - int i; - - for (i = 0; i < n; i++) - { - fp--; - sum += *hp++ * (*fp * *fp); - } - *sump = sum; + float *hp = x->x_buf + count; + float *fp = in; + float sum = *sump; + int i; + + for (i = 0; i < n; i++) + { + fp--; + sum += *hp++ * (*fp * *fp); + } + *sump = sum; } sump[0] = 0; x->x_phase -= n; if (x->x_phase < 0) { - x->x_result = x->x_sumbuf[0]; - for (count = x->x_realperiod, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) - sump[0] = sump[1]; - sump[0] = 0; - x->x_phase = x->x_realperiod - n; - clock_delay(x->x_clock, 0L); + x->x_result = x->x_sumbuf[0]; + for (count = x->x_realperiod, sump = x->x_sumbuf; + count < x->x_npoints; count += x->x_realperiod, sump++) + sump[0] = sump[1]; + sump[0] = 0; + x->x_phase = x->x_realperiod - n; + clock_delay(x->x_clock, 0L); } return (w+4); } @@ -134,28 +134,28 @@ static t_int *tabplay_tilde_perform(t_int *w) t_tabenv *x = (t_tabenv *)(w[1]); t_float *out = (t_float *)(w[2]), *fp; int n = (int)(w[3]), phase = x->x_phase, - endphase = (x->x_nsampsintab < x->x_limit ? - x->x_nsampsintab : x->x_limit), nxfer, n3; + endphase = (x->x_nsampsintab < x->x_limit ? + x->x_nsampsintab : x->x_limit), nxfer, n3; if (!x->x_vec || phase >= endphase) - goto zero; - + goto zero; + nxfer = endphase - phase; fp = x->x_vec + phase; if (nxfer > n) - nxfer = n; + nxfer = n; n3 = n - nxfer; phase += nxfer; while (nxfer--) - *out++ = *fp++; + *out++ = *fp++; if (phase >= endphase) { - clock_delay(x->x_clock, 0); - x->x_phase = 0x7fffffff; - while (n3--) - *out++ = 0; + clock_delay(x->x_clock, 0); + x->x_phase = 0x7fffffff; + while (n3--) + *out++ = 0; } else x->x_phase = phase; - + return (w+4); zero: while (n--) *out++ = 0; @@ -167,35 +167,35 @@ static void tabenv_perform_64(t_tabenv *x,t_float *in) { int n = 64; int count; - float *sump; + float *sump; in += n; for (count = x->x_phase, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) + count < x->x_npoints; count += x->x_realperiod, sump++) { - float *hp = x->x_buf + count; - float *fp = in; - float sum = *sump; - int i; - - for (i = 0; i < n; i++) - { - fp--; - sum += *hp++ * (*fp * *fp); - } - *sump = sum; + float *hp = x->x_buf + count; + float *fp = in; + float sum = *sump; + int i; + + for (i = 0; i < n; i++) + { + fp--; + sum += *hp++ * (*fp * *fp); + } + *sump = sum; } sump[0] = 0; x->x_phase -= n; if (x->x_phase < 0) { - x->x_result = x->x_sumbuf[0]; - for (count = x->x_realperiod, sump = x->x_sumbuf; - count < x->x_npoints; count += x->x_realperiod, sump++) - sump[0] = sump[1]; - sump[0] = 0; - x->x_phase = x->x_realperiod - n; - /*clock_delay(x->x_clock, 0L);*/ - outlet_float(x->x_outlet, powtodb(x->x_result)); + x->x_result = x->x_sumbuf[0]; + for (count = x->x_realperiod, sump = x->x_sumbuf; + count < x->x_npoints; count += x->x_realperiod, sump++) + sump[0] = sump[1]; + sump[0] = 0; + x->x_phase = x->x_realperiod - n; + /*clock_delay(x->x_clock, 0L);*/ + outlet_float(x->x_outlet, powtodb(x->x_result)); } } @@ -207,14 +207,14 @@ static void tabenv_set(t_tabenv *x, t_symbol *s) x->x_arrayname = s; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { - if (*s->s_name) pd_error(x, "tabenv: %s: no such array", - x->x_arrayname->s_name); - x->x_vec = 0; + if (*s->s_name) pd_error(x, "tabenv: %s: no such array", + x->x_arrayname->s_name); + x->x_vec = 0; } else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec)) { - error("%s: bad template for tabenv", x->x_arrayname->s_name); - x->x_vec = 0; + error("%s: bad template for tabenv", x->x_arrayname->s_name); + x->x_vec = 0; } else garray_usedindsp(a); } @@ -222,48 +222,49 @@ static void tabenv_set(t_tabenv *x, t_symbol *s) static void sigenv_dsp(t_tabenv *x, t_signal **sp) { if (x->x_period % sp[0]->s_n) x->x_realperiod = - x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n); + x->x_period + sp[0]->s_n - (x->x_period % sp[0]->s_n); else x->x_realperiod = x->x_period; dsp_add(sigenv_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); if (sp[0]->s_n > MAXVSTAKEN) bug("sigenv_dsp"); } static void tabenv_list(t_tabenv *x, t_symbol *s, - int argc, t_atom *argv) + int argc, t_atom *argv) { long start = atom_getfloatarg(0, argc, argv); long length = atom_getfloatarg(1, argc, argv); - float *limitp,*p; - int i; + float *limitp,*p; + int i; - tabenv_set(x, x->x_arrayname); + tabenv_set(x, x->x_arrayname); - if (start < 0) start = 0; + if (start < 0) start = 0; if (length <= 0) - x->x_limit = 0x7fffffff; + x->x_limit = 0x7fffffff; else - x->x_limit = start + length; + x->x_limit = start + length; x->x_tabphase = start; - if(length <= 0) length = x->x_nsampsintab - 1; - if(start >= x->x_nsampsintab) start = x->x_nsampsintab - 1; - if((start + length) >= x->x_nsampsintab) - length = x->x_nsampsintab - 1 - start; - - limitp = x->x_vec + start + length - 63; - /*limitp = x->x_vec + 2048;*/ + if(length <= 0) length = x->x_nsampsintab - 1; + if(start >= x->x_nsampsintab) start = x->x_nsampsintab - 1; + if((start + length) >= x->x_nsampsintab) + length = x->x_nsampsintab - 1 - start; + + limitp = x->x_vec + start + length - 63; + /*limitp = x->x_vec + 2048;*/ /*if (x->x_period % length) x->x_realperiod = - x->x_period + length - (x->x_period % length); - else*/ x->x_realperiod = x->x_period; + x->x_period + length - (x->x_period % length); + else*/ + x->x_realperiod = x->x_period; - for(p = x->x_vec + start; p < limitp ; p += 64) - tabenv_perform_64( x , p ); + for(p = x->x_vec + start; p < limitp ; p += 64) + tabenv_perform_64( x , p ); } static void tabenv_reset(t_tabenv *x) { int i; - x->x_phase = 0; + x->x_phase = 0; for (i = 0; i < MAXOVERLAP; i++) x->x_sumbuf[i] = 0; } @@ -282,12 +283,12 @@ static void tabenv_ff(t_tabenv *x) /* cleanup on free */ void tabenv_setup(void ) { tabenv_class = class_new(gensym("tabenv"), (t_newmethod)tabenv_new, - (t_method)tabenv_ff, sizeof(t_tabenv), 0, A_DEFSYM, A_DEFFLOAT, A_DEFFLOAT, 0); + (t_method)tabenv_ff, sizeof(t_tabenv), 0, A_DEFSYM, A_DEFFLOAT, A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(tabenv_class, t_tabenv, x_f); class_addmethod(tabenv_class, (t_method)tabenv_reset, - gensym("reset"), 0); + gensym("reset"), 0); class_addmethod(tabenv_class, (t_method)tabenv_set, - gensym("set"), A_DEFSYM, 0); + gensym("set"), A_DEFSYM, 0); class_addlist(tabenv_class, tabenv_list); } diff --git a/tabreadl.c b/tabreadl.c index e669bd8..ef660ac 100644 --- a/tabreadl.c +++ b/tabreadl.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -37,24 +37,25 @@ static void tabreadl_float(t_tabreadl *x, t_float f) t_float *vec; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) - error("%s: no such array", x->x_arrayname->s_name); + error("%s: no such array", x->x_arrayname->s_name); else if (!garray_getfloatarray(a, &npoints, &vec)) - error("%s: bad template for tabreadl", x->x_arrayname->s_name); + error("%s: bad template for tabreadl", x->x_arrayname->s_name); else { - int n ; - float r,v; - - if (f < 0) f = 0; - else if (f >= npoints) f = npoints - 1; - n=f; - if(npoints>1){ - r=f-n; - v=vec[n]*(1-r)+vec[n+1]*r; - outlet_float(x->x_obj.ob_outlet, v ); - } - else - outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0)); + int n ; + float r,v; + + if (f < 0) f = 0; + else if (f >= npoints) f = npoints - 1; + n=f; + if(npoints>1) + { + r=f-n; + v=vec[n]*(1-r)+vec[n+1]*r; + outlet_float(x->x_obj.ob_outlet, v ); + } + else + outlet_float(x->x_obj.ob_outlet, (npoints ? vec[n] : 0)); } } @@ -74,10 +75,10 @@ static void *tabreadl_new(t_symbol *s) void tabreadl_setup(void) { tabreadl_class = class_new(gensym("tabreadl"), (t_newmethod)tabreadl_new, - 0, sizeof(t_tabreadl), 0, A_DEFSYM, 0); + 0, sizeof(t_tabreadl), 0, A_DEFSYM, 0); class_addfloat(tabreadl_class, (t_method)tabreadl_float); class_addmethod(tabreadl_class, (t_method)tabreadl_set, gensym("set"), - A_SYMBOL, 0); + A_SYMBOL, 0); } diff --git a/tabsort.c b/tabsort.c index 53956a1..1658426 100644 --- a/tabsort.c +++ b/tabsort.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA typedef struct tabsort { - /*env part*/ + /*env part*/ t_object x_obj; /* header */ t_symbol *x_arrayname1; t_symbol *x_arrayname2; @@ -41,67 +41,67 @@ static void *tabsort_new(t_symbol *tab1,t_symbol *tab2) x->x_arrayname1 = tab1; x->x_arrayname2 = tab2; - outlet_new((t_object*)x, &s_bang); + outlet_new((t_object *)x, &s_bang); return (x); } static void tabsort_set1(t_tabsort *x, t_symbol *s) { - x->x_arrayname1 = s; + x->x_arrayname1 = s; } static void tabsort_set2(t_tabsort *x, t_symbol *s) { - x->x_arrayname2 = s; + x->x_arrayname2 = s; } static void tabsort_float(t_tabsort *x, t_floatarg n) { - t_garray *a; - int n1,n2,i,j; - t_float *vec1,*vec2,tmp; + t_garray *a; + int n1,n2,i,j; + t_float *vec1,*vec2,tmp; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname1, garray_class))) { - if (*x->x_arrayname1->s_name) pd_error(x, "tabsort: %s: no such array", - x->x_arrayname1->s_name); - return; + if (*x->x_arrayname1->s_name) pd_error(x, "tabsort: %s: no such array", + x->x_arrayname1->s_name); + return; } else if (!garray_getfloatarray(a, &n1, &vec1)) { - error("%s: bad template for tabsort", x->x_arrayname1->s_name); - return; + error("%s: bad template for tabsort", x->x_arrayname1->s_name); + return; } if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname2, garray_class))) { - if (*x->x_arrayname2->s_name) pd_error(x, "tabsort: %s: no such array", - x->x_arrayname2->s_name); - return; + if (*x->x_arrayname2->s_name) pd_error(x, "tabsort: %s: no such array", + x->x_arrayname2->s_name); + return; } else if (!garray_getfloatarray(a, &n2, &vec2)) { - error("%s: bad template for tabsort", x->x_arrayname2->s_name); - return; + error("%s: bad template for tabsort", x->x_arrayname2->s_name); + return; } - if(n>n1) n=n1; - if(n>n2) n=n2; + if(n>n1) n=n1; + if(n>n2) n=n2; - for(i=0;ii;j--) - if(vec1[(int)vec2[j-1]]i; j--) + if(vec1[(int)vec2[j-1]]ob_outlet); + garray_redraw(a); + outlet_bang(((t_object *)x)->ob_outlet); } @@ -113,11 +113,11 @@ static void tabsort_ff(t_tabsort *x) /* cleanup on free */ void tabsort_setup(void ) { tabsort_class = class_new(gensym("tabsort"), (t_newmethod)tabsort_new, - (t_method)tabsort_ff, sizeof(t_tabsort), 0, A_DEFSYM, A_DEFSYM, 0); + (t_method)tabsort_ff, sizeof(t_tabsort), 0, A_DEFSYM, A_DEFSYM, 0); class_addmethod(tabsort_class, (t_method)tabsort_set1, - gensym("set1"), A_DEFSYM, 0); + gensym("set1"), A_DEFSYM, 0); class_addmethod(tabsort_class, (t_method)tabsort_set2, - gensym("set2"), A_DEFSYM, 0); + gensym("set2"), A_DEFSYM, 0); class_addfloat(tabsort_class, tabsort_float); } diff --git a/tabsort2.c b/tabsort2.c index b447bf2..67232de 100644 --- a/tabsort2.c +++ b/tabsort2.c @@ -1,5 +1,5 @@ /* -Copyright (C) 2002 Antoine Rousseau +Copyright (C) 2002 Antoine Rousseau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -46,102 +46,102 @@ static void *tabsort2_new(t_symbol *tab1,t_symbol *tab2,t_symbol *tab3) x->x_arrayname2 = tab2; x->x_arrayname3 = tab3; x->x_clock = clock_new(x, (t_method)tabsort2_tick); - outlet_new((t_object*)x, &s_float); + outlet_new((t_object *)x, &s_float); return (x); } static void tabsort2_set1(t_tabsort2 *x, t_symbol *s) { - x->x_arrayname1 = s; + x->x_arrayname1 = s; } static void tabsort2_set2(t_tabsort2 *x, t_symbol *s) { - x->x_arrayname2 = s; + x->x_arrayname2 = s; } static void tabsort2_set3(t_tabsort2 *x, t_symbol *s) { - x->x_arrayname3 = s; + x->x_arrayname3 = s; } static void tabsort2_float(t_tabsort2 *x, t_floatarg n) { - t_garray *a; - int n1,n2,n3,i,j,h,sqn; - t_float *vec1,*vec2,*vec3,tmp; + t_garray *a; + int n1,n2,n3,i,j,h,sqn; + t_float *vec1,*vec2,*vec3,tmp; if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname1, garray_class))) { - if (*x->x_arrayname1->s_name) pd_error(x, "tabsort2: %s: no such array", - x->x_arrayname1->s_name); - return; + if (*x->x_arrayname1->s_name) pd_error(x, "tabsort2: %s: no such array", + x->x_arrayname1->s_name); + return; } else if (!garray_getfloatarray(a, &n1, &vec1)) { - error("%s: bad template for tabsort2", x->x_arrayname1->s_name); - return; + error("%s: bad template for tabsort2", x->x_arrayname1->s_name); + return; } if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname2, garray_class))) { - if (*x->x_arrayname2->s_name) pd_error(x, "tabsort2: %s: no such array", - x->x_arrayname2->s_name); - return; + if (*x->x_arrayname2->s_name) pd_error(x, "tabsort2: %s: no such array", + x->x_arrayname2->s_name); + return; } else if (!garray_getfloatarray(a, &n2, &vec2)) { - error("%s: bad template for tabsort2", x->x_arrayname2->s_name); - return; + error("%s: bad template for tabsort2", x->x_arrayname2->s_name); + return; } if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname3, garray_class))) { - if (*x->x_arrayname3->s_name) pd_error(x, "tabsort2: %s: no such array", - x->x_arrayname3->s_name); - return; + if (*x->x_arrayname3->s_name) pd_error(x, "tabsort2: %s: no such array", + x->x_arrayname3->s_name); + return; } else if (!garray_getfloatarray(a, &n3, &vec3)) { - error("%s: bad template for tabsort2", x->x_arrayname3->s_name); - return; + error("%s: bad template for tabsort2", x->x_arrayname3->s_name); + return; } - if(n>n1) n=n1; - if(n>n2) n=n2; - if(n>n3) n=n3; - - for(i=0;ii;j--) - if(vec1[(int)vec3[j-1]]i;j--) - if(vec2[(int)vec3[h*sqn+j-1]]ob_outlet,(t_float)sqn); + if(n>n1) n=n1; + if(n>n2) n=n2; + if(n>n3) n=n3; + + for(i=0; ii; j--) + if(vec1[(int)vec3[j-1]]i; j--) + if(vec2[(int)vec3[h*sqn+j-1]]ob_outlet,(t_float)sqn); } static void tabsort2_tick(t_tabsort2 *x) /* callback function for the env clock */ { - //clock_delay(x->x_clock, 0L); + //clock_delay(x->x_clock, 0L); } static void tabsort2_ff(t_tabsort2 *x) /* cleanup on free */ @@ -153,11 +153,11 @@ static void tabsort2_ff(t_tabsort2 *x) /* cleanup on free */ void tabsort2_setup(void ) { tabsort2_class = class_new(gensym("tabsort2"), (t_newmethod)tabsort2_new, - (t_method)tabsort2_ff, sizeof(t_tabsort2), 0, A_DEFSYM, A_DEFSYM, A_DEFSYM, 0); + (t_method)tabsort2_ff, sizeof(t_tabsort2), 0, A_DEFSYM, A_DEFSYM, A_DEFSYM, 0); class_addmethod(tabsort2_class, (t_method)tabsort2_set1, - gensym("set1"), A_DEFSYM, 0); + gensym("set1"), A_DEFSYM, 0); class_addmethod(tabsort2_class, (t_method)tabsort2_set2, - gensym("set2"), A_DEFSYM, 0); + gensym("set2"), A_DEFSYM, 0); class_addfloat(tabsort2_class, tabsort2_float); } diff --git a/wac.c b/wac.c index 736194e..fa84017 100644 --- a/wac.c +++ b/wac.c @@ -1,5 +1,5 @@ - /* - wacom graphire on serial port only... +/* + wacom graphire on serial port only... */ #include @@ -38,10 +38,10 @@ typedef struct _wac t_outlet *button_out; t_symbol *file; int fd; - int count; - int oldbuttons; - unsigned char data[BUFSIZE]; -}t_wac; + int count; + int oldbuttons; + unsigned char data[BUFSIZE]; +} t_wac; t_class *wac_class; @@ -51,204 +51,208 @@ static void wac_process(t_wac *x); static void wac_open(t_wac *x) { - if(x->fd>=0) return; - - x->fd = open (x->file->s_name, O_RDONLY | O_NONBLOCK); - if(x->fd<0){ - post("open (%s, O_RDONLY | O_NONBLOCK)",x->file->s_name); - perror("open"); - return; - } - sys_addpollfn(x->fd,(t_fdpollfn)wac_read,(void*)x); + if(x->fd>=0) return; + + x->fd = open (x->file->s_name, O_RDONLY | O_NONBLOCK); + if(x->fd<0) + { + post("open (%s, O_RDONLY | O_NONBLOCK)",x->file->s_name); + perror("open"); + return; + } + sys_addpollfn(x->fd,(t_fdpollfn)wac_read,(void *)x); } static void wac_close(t_wac *x) { - if(x->fd<0) return; + if(x->fd<0) return; - sys_rmpollfn(x->fd); - close(x->fd); - x->fd=-1; + sys_rmpollfn(x->fd); + close(x->fd); + x->fd=-1; } static void wac_float(t_wac *x,t_floatarg connect) { - if(connect!=0) wac_open(x); - else wac_close(x); + if(connect!=0) wac_open(x); + else wac_close(x); } static void *wac_new(t_symbol *file) -{ - t_wac *x = (t_wac *)pd_new(wac_class); - - //if(file->s_name) - if(file!=&s_) - x->file=file; - else x->file=gensym("/dev/ttyS0"); - - post("wac_new file=%s",x->file->s_name); - x->axis_out = outlet_new(&x->t_ob, &s_list); - x->button_out = outlet_new(&x->t_ob, &s_list); - - x->fd=-1; - - return (void *)x; +{ + t_wac *x = (t_wac *)pd_new(wac_class); + + //if(file->s_name) + if(file!=&s_) + x->file=file; + else x->file=gensym("/dev/ttyS0"); + + post("wac_new file=%s",x->file->s_name); + x->axis_out = outlet_new(&x->t_ob, &s_list); + x->button_out = outlet_new(&x->t_ob, &s_list); + + x->fd=-1; + + return (void *)x; } void wac_setup(void) { - wac_class = class_new(gensym("wac"),(t_newmethod)wac_new, - (t_method)wac_close, sizeof(t_wac), 0, A_DEFSYM, 0); - class_addfloat(wac_class, wac_float); - + wac_class = class_new(gensym("wac"),(t_newmethod)wac_new, + (t_method)wac_close, sizeof(t_wac), 0, A_DEFSYM, 0); + class_addfloat(wac_class, wac_float); + } static void wac_read(t_wac *x,int fd) { - int len,i=0; - unsigned char b; - unsigned char buffer[BUFSIZE]; - - while((len=read(fd,buffer,BUFSIZE))> -1){ - - for(i=0;icount=0; - x->data[x->count++]=buffer[i]; - if(x->count==7) wac_process(x); - } - } + int len,i=0; + unsigned char b; + unsigned char buffer[BUFSIZE]; + + while((len=read(fd,buffer,BUFSIZE))> -1) + { + + for(i=0; icount=0; + x->data[x->count++]=buffer[i]; + if(x->count==7) wac_process(x); + } + } } static void wac_process(t_wac *X) { int is_stylus = 1, is_button, is_proximity, wheel=0; int x, y, z, buttons, tx = 0, ty = 0; - unsigned char *data=X->data; - t_atom ats[3]; - - is_stylus = (data[0] & POINTER_BIT); - - if(!is_stylus) return; - - x = (((data[0] & 0x3) << 14) + - (data[1] << 7) + - data[2]); - y = (((data[3] & 0x3) << 14) + - (data[4] << 7) + - data[5]); - - - z = ((data[6] & ZAXIS_BITS) * 2) + - ((data[3] & ZAXIS_BIT) >> 2); - - //z = z*4 + ((data[0] & ZAXIS_BIT) >> 1); - - if (!(data[6] & ZAXIS_SIGN_BIT)) { - z += 128; - } - - is_proximity = (data[0] & PROXIMITY_BIT); - - buttons = ((data[3] & 0x38) >> 3); - /*if (is_stylus) { - buttons = ((data[3] & 0x30) >> 3) | - (z >= Threshold ? 1 : 0); - } - else { - buttons = (data[3] & 0x38) >> 3; - - wheel = (data[6] & 0x30) >> 4; - - if (data[6] & 0x40) { - wheel = -wheel; - } - }*/ - //is_button = (buttons != 0); - if(buttons!=X->oldbuttons) - { - X->oldbuttons=buttons; - - SETFLOAT(&ats[0],buttons&1); - SETFLOAT(&ats[1],(buttons&2)!=0); - SETFLOAT(&ats[2],(buttons&4)!=0); - outlet_list(X->button_out,0,3,ats); - } - SETFLOAT(&ats[0],x/5103.0); - SETFLOAT(&ats[1],y/3711.0); - SETFLOAT(&ats[2],z/256.0); - outlet_list(X->axis_out,0,3,ats); + unsigned char *data=X->data; + t_atom ats[3]; + + is_stylus = (data[0] & POINTER_BIT); + + if(!is_stylus) return; + + x = (((data[0] & 0x3) << 14) + + (data[1] << 7) + + data[2]); + y = (((data[3] & 0x3) << 14) + + (data[4] << 7) + + data[5]); + + + z = ((data[6] & ZAXIS_BITS) * 2) + + ((data[3] & ZAXIS_BIT) >> 2); + + //z = z*4 + ((data[0] & ZAXIS_BIT) >> 1); + + if (!(data[6] & ZAXIS_SIGN_BIT)) + { + z += 128; + } + + is_proximity = (data[0] & PROXIMITY_BIT); + + buttons = ((data[3] & 0x38) >> 3); + /*if (is_stylus) { + buttons = ((data[3] & 0x30) >> 3) | + (z >= Threshold ? 1 : 0); + } + else { + buttons = (data[3] & 0x38) >> 3; + + wheel = (data[6] & 0x30) >> 4; + + if (data[6] & 0x40) { + wheel = -wheel; + } + }*/ + //is_button = (buttons != 0); + if(buttons!=X->oldbuttons) + { + X->oldbuttons=buttons; + + SETFLOAT(&ats[0],buttons&1); + SETFLOAT(&ats[1],(buttons&2)!=0); + SETFLOAT(&ats[2],(buttons&4)!=0); + outlet_list(X->button_out,0,3,ats); + } + SETFLOAT(&ats[0],x/5103.0); + SETFLOAT(&ats[1],y/3711.0); + SETFLOAT(&ats[2],z/256.0); + outlet_list(X->axis_out,0,3,ats); } - /* Format of 7 bytes data packet for Wacom Tablets - Byte 1 - bit 7 Sync bit always 1 - bit 6 Pointing device detected - bit 5 Cursor = 0 / Stylus = 1 - bit 4 Reserved - bit 3 1 if a button on the pointing device has been pressed - bit 2 Reserved - bit 1 X15 - bit 0 X14 - - Byte 2 - bit 7 Always 0 - bits 6-0 = X13 - X7 - - Byte 3 - bit 7 Always 0 - bits 6-0 = X6 - X0 - - Byte 4 - bit 7 Always 0 - bit 6 B3 - bit 5 B2 - bit 4 B1 - bit 3 B0 - bit 2 P0 - bit 1 Y15 - bit 0 Y14 - - Byte 5 - bit 7 Always 0 - bits 6-0 = Y13 - Y7 - - Byte 6 - bit 7 Always 0 - bits 6-0 = Y6 - Y0 - - Byte 7 - bit 7 Always 0 - bit 6 Sign of pressure data - bit 5 P6 - bit 4 P5 - bit 3 P4 - bit 2 P3 - bit 1 P2 - bit 0 P1 - - byte 8 and 9 are optional and present only - in tilt mode. - - Byte 8 - bit 7 Always 0 - bit 6 Sign of tilt X - bit 5 Xt6 - bit 4 Xt5 - bit 3 Xt4 - bit 2 Xt3 - bit 1 Xt2 - bit 0 Xt1 - - Byte 9 - bit 7 Always 0 - bit 6 Sign of tilt Y - bit 5 Yt6 - bit 4 Yt5 - bit 3 Yt4 - bit 2 Yt3 - bit 1 Yt2 - bit 0 Yt1 - - */ - +/* Format of 7 bytes data packet for Wacom Tablets +Byte 1 +bit 7 Sync bit always 1 +bit 6 Pointing device detected +bit 5 Cursor = 0 / Stylus = 1 +bit 4 Reserved +bit 3 1 if a button on the pointing device has been pressed +bit 2 Reserved +bit 1 X15 +bit 0 X14 + +Byte 2 +bit 7 Always 0 +bits 6-0 = X13 - X7 + +Byte 3 +bit 7 Always 0 +bits 6-0 = X6 - X0 + +Byte 4 +bit 7 Always 0 +bit 6 B3 +bit 5 B2 +bit 4 B1 +bit 3 B0 +bit 2 P0 +bit 1 Y15 +bit 0 Y14 + +Byte 5 +bit 7 Always 0 +bits 6-0 = Y13 - Y7 + +Byte 6 +bit 7 Always 0 +bits 6-0 = Y6 - Y0 + +Byte 7 +bit 7 Always 0 +bit 6 Sign of pressure data +bit 5 P6 +bit 4 P5 +bit 3 P4 +bit 2 P3 +bit 1 P2 +bit 0 P1 + +byte 8 and 9 are optional and present only +in tilt mode. + +Byte 8 +bit 7 Always 0 +bit 6 Sign of tilt X +bit 5 Xt6 +bit 4 Xt5 +bit 3 Xt4 +bit 2 Xt3 +bit 1 Xt2 +bit 0 Xt1 + +Byte 9 +bit 7 Always 0 +bit 6 Sign of tilt Y +bit 5 Yt6 +bit 4 Yt5 +bit 3 Yt4 +bit 2 Yt3 +bit 1 Yt2 +bit 0 Yt1 + +*/ + -- cgit v1.2.1