diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2004-05-18 21:33:33 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2004-05-18 21:33:33 +0000 |
commit | 577ac6e80ff4f436fbd054291ed7dddbc31bd49a (patch) | |
tree | 6ec69b216dda68d7de38a5eba1851b9d4f1431e6 /src/iemlib2/iem_i_route.c |
This commit was generated by cvs2svn to compensate for changes in r1738,svn2git-root
which included commits to RCS files with non-trunk default branches.
svn path=/trunk/externals/iemlib/; revision=1739
Diffstat (limited to 'src/iemlib2/iem_i_route.c')
-rw-r--r-- | src/iemlib2/iem_i_route.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/iemlib2/iem_i_route.c b/src/iemlib2/iem_i_route.c new file mode 100644 index 0000000..48855e6 --- /dev/null +++ b/src/iemlib2/iem_i_route.c @@ -0,0 +1,111 @@ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. + +iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2003 */ + +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#include "m_pd.h" +#include "iemlib.h" +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <math.h> + +/* -------------------------- iem_i_route ------------------------------ */ +/* routes a list beginning with a float to an outlet, which are defined by + first- , last- index and offset-index */ + +static t_class *iem_i_route_class; + +typedef struct _iem_i_route +{ + t_object x_obj; + int x_first_element; + int x_last_element; + t_outlet **x_out; +} t_iem_i_route; + +static void iem_i_route_list(t_iem_i_route *x, t_symbol *sel, int argc, t_atom *argv) +{ + t_outlet **out; + int first, last, i; + + if(!argc) + return; + i = (int)atom_getintarg(0, argc, argv); + first = x->x_first_element; + last = x->x_last_element; + out = x->x_out; + if((i >= first)&&(i <= last)) + { + out += i - first; + if(argc >= 3) + { + if(IS_A_FLOAT(argv,1)) + outlet_list(*out, &s_list, argc-1, argv+1); + else if(IS_A_SYMBOL(argv,1)) + outlet_anything(*out, atom_getsymbolarg(1, argc, argv), argc-2, argv+2); + } + else if(argc >= 2) + { + if(IS_A_FLOAT(argv,1)) + outlet_float(*out, (float)atom_getfloatarg(1, argc, argv)); + else if(IS_A_SYMBOL(argv,1)) + outlet_anything(*out, atom_getsymbolarg(1, argc, argv), 0, argv+2); + } + else + outlet_bang(*out); + } + else + { + out += last - first + 1; + outlet_list(*out, &s_list, argc, argv); + } +} + +static void iem_i_route_free(t_iem_i_route *x) +{ + freebytes(x->x_out, (x->x_last_element-x->x_first_element+2) * sizeof(t_outlet *)); +} + +static void *iem_i_route_new(t_symbol *s, int argc, t_atom *argv) +{ + int n, i; + t_outlet **out; + t_iem_i_route *x = (t_iem_i_route *)pd_new(iem_i_route_class); + + if((argc >= 2)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)) + { + x->x_first_element = (int)atom_getintarg(0, argc, argv); + x->x_last_element = (int)atom_getintarg(1, argc, argv); + if((argc >= 3)&&IS_A_FLOAT(argv,2)) + { + i = (int)atom_getintarg(2, argc, argv); + x->x_first_element += i; + x->x_last_element += i; + } + x->x_out = (t_outlet **)getbytes((x->x_last_element-x->x_first_element+2) * sizeof(t_outlet *)); + n = x->x_last_element - x->x_first_element + 2; + for(i=0, out=x->x_out; i<n; i++, out++) + *out = outlet_new(&x->x_obj, &s_list); + return (x); + } + else + { + post("iem_i_route-ERROR: needs 3 floats!!"); + return(0); + } +} + +void iem_i_route_setup(void) +{ + iem_i_route_class = class_new(gensym("iem_i_route"), (t_newmethod)iem_i_route_new, + (t_method)iem_i_route_free, sizeof(t_iem_i_route), 0, A_GIMME, 0); + class_addcreator((t_newmethod)iem_i_route_new, gensym("iiroute"), A_GIMME, 0); + class_addlist(iem_i_route_class, iem_i_route_list); + class_sethelpsymbol(iem_i_route_class, gensym("iemhelp/help-iem_i_route")); +} |