1
/******************************************************
3
* zexy - implementation file
5
* copyleft (c) IOhannes m zm�lnig
7
* 1999:forum::f�r::uml�ute:2004
9
* institute of electronic music and acoustics (iem)
11
******************************************************
13
* license: GNU General Public License v.2
15
******************************************************/
17
/* hack : 2108:forum::f�r::uml�ute:1999 @ iem */
22
/* =================== tabminmax ====================== */
24
static t_class *tabminmax_class;
26
typedef struct _tabminmax
29
t_outlet*min_out, *max_out;
30
t_symbol *x_arrayname;
31
t_int startindex, stopindex;
34
static void tabminmax_bang(t_tabminmax *x)
40
if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
41
error("%s: no such array", x->x_arrayname->s_name);
42
else if (!zarray_getarray(A, &npoints, &vec))
43
error("%s: bad template for tabminmax", x->x_arrayname->s_name);
51
int start=x->startindex;
52
int stop =x->stopindex;
53
if(start<0||start>stop)start=0;
54
if(stop<start||stop>npoints)stop=npoints;
57
min=zarray_getfloat(vec, start);
63
for (n = 1; n < npoints; n++){
64
t_float val=zarray_getfloat(vec, start+n);
75
SETFLOAT(atombuf, max);
76
SETFLOAT(atombuf+1, maxdex);
77
outlet_list(x->max_out, &s_list, 2, atombuf);
79
SETFLOAT(atombuf, min);
80
SETFLOAT(atombuf+1, mindex);
81
outlet_list(x->min_out, &s_list, 2, atombuf);
85
static void tabminmax_list(t_tabminmax *x, t_symbol*s,int argc, t_atom*argv)
92
b=atom_getint(argv+1);
93
x->startindex=(a<b)?a:b;
94
x->stopindex =(a>b)?a:b;
98
error("tabminmax: list must be 2 floats (is %d atoms)", argc);
102
static void tabminmax_set(t_tabminmax *x, t_symbol *s)
107
static void *tabminmax_new(t_symbol *s)
109
t_tabminmax *x = (t_tabminmax *)pd_new(tabminmax_class);
113
x->min_out=outlet_new(&x->x_obj, &s_list);
114
x->max_out=outlet_new(&x->x_obj, &s_list);
119
static void tabminmax_helper(void)
121
post("\n%c tabminmax - object : dumps a table as a package of floats", HEARTSYMBOL);
122
post("'set <table>'\t: read out another table\n"
123
"'bang'\t\t: get min and max of the table\n"
124
"outlet\t\t: table-data as package of floats");
125
post("creation\t: \"tabminmax <table>\"");
129
void tabminmax_setup(void)
131
tabminmax_class = class_new(gensym("tabminmax"), (t_newmethod)tabminmax_new,
132
0, sizeof(t_tabminmax), 0, A_DEFSYM, 0);
133
class_addbang(tabminmax_class, (t_method)tabminmax_bang);
134
class_addlist(tabminmax_class, (t_method)tabminmax_list);
136
class_addmethod(tabminmax_class, (t_method)tabminmax_set, gensym("set"),
139
class_addmethod(tabminmax_class, (t_method)tabminmax_helper, gensym("help"), 0);
140
zexy_register("tabminmax");