aboutsummaryrefslogtreecommitdiff
path: root/src/tabminmax.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tabminmax.c')
-rw-r--r--src/tabminmax.c105
1 files changed, 55 insertions, 50 deletions
diff --git a/src/tabminmax.c b/src/tabminmax.c
index 8353ae3..796d8f7 100644
--- a/src/tabminmax.c
+++ b/src/tabminmax.c
@@ -1,4 +1,4 @@
-/*
+/*
* tabminmax: get minimum and maximum of a table
*
* (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem)
@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -24,8 +24,7 @@
static t_class *tabminmax_class;
-typedef struct _tabminmax
-{
+typedef struct _tabminmax {
t_object x_obj;
t_outlet*min_out, *max_out;
t_symbol *x_arrayname;
@@ -38,55 +37,59 @@ static void tabminmax_bang(t_tabminmax *x)
int npoints;
zarray_t *vec;
- if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
+ if (!(A = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) {
error("%s: no such array", x->x_arrayname->s_name);
- else if (!zarray_getarray(A, &npoints, &vec))
+ } else if (!zarray_getarray(A, &npoints, &vec)) {
error("%s: bad template for tabminmax", x->x_arrayname->s_name);
- else
- {
- int n;
- t_atom atombuf[2];
- t_float min, max;
- int mindex, maxdex;
-
- int start=x->startindex;
- int stop =x->stopindex;
- if(start<0||start>stop)start=0;
- if(stop<start||stop>npoints)stop=npoints;
- npoints=stop-start;
-
- min=zarray_getfloat(vec, start);
- max=min;
-
- mindex=start;
- maxdex=start;
-
- for (n = 1; n < npoints; n++){
- t_float val=zarray_getfloat(vec, start+n);
- if(val<min){
- mindex=start+n;
- min=val;
- }
- if(val>max){
- maxdex=start+n;
- max=val;
- }
+ } else {
+ int n;
+ t_atom atombuf[2];
+ t_float min, max;
+ int mindex, maxdex;
+
+ int start=x->startindex;
+ int stop =x->stopindex;
+ if(start<0||start>stop) {
+ start=0;
+ }
+ if(stop<start||stop>npoints) {
+ stop=npoints;
+ }
+ npoints=stop-start;
+
+ min=zarray_getfloat(vec, start);
+ max=min;
+
+ mindex=start;
+ maxdex=start;
+
+ for (n = 1; n < npoints; n++) {
+ t_float val=zarray_getfloat(vec, start+n);
+ if(val<min) {
+ mindex=start+n;
+ min=val;
+ }
+ if(val>max) {
+ maxdex=start+n;
+ max=val;
}
-
- SETFLOAT(atombuf, max);
- SETFLOAT(atombuf+1, maxdex);
- outlet_list(x->max_out, gensym("list"), 2, atombuf);
-
- SETFLOAT(atombuf, min);
- SETFLOAT(atombuf+1, mindex);
- outlet_list(x->min_out, gensym("list"), 2, atombuf);
}
+
+ SETFLOAT(atombuf, max);
+ SETFLOAT(atombuf+1, maxdex);
+ outlet_list(x->max_out, gensym("list"), 2, atombuf);
+
+ SETFLOAT(atombuf, min);
+ SETFLOAT(atombuf+1, mindex);
+ outlet_list(x->min_out, gensym("list"), 2, atombuf);
+ }
}
-static void tabminmax_list(t_tabminmax *x, t_symbol* UNUSED(s),int argc, t_atom*argv)
+static void tabminmax_list(t_tabminmax *x, t_symbol* UNUSED(s),int argc,
+ t_atom*argv)
{
int a,b;
- switch(argc){
+ switch(argc) {
case 2:
a=atom_getint(argv);
b=atom_getint(argv+1);
@@ -128,14 +131,16 @@ static void tabminmax_helper(void)
void tabminmax_setup(void)
{
- tabminmax_class = class_new(gensym("tabminmax"), (t_newmethod)tabminmax_new,
- 0, sizeof(t_tabminmax), 0, A_DEFSYM, 0);
+ tabminmax_class = class_new(gensym("tabminmax"),
+ (t_newmethod)tabminmax_new,
+ 0, sizeof(t_tabminmax), 0, A_DEFSYM, 0);
class_addbang(tabminmax_class, (t_method)tabminmax_bang);
class_addlist(tabminmax_class, (t_method)tabminmax_list);
class_addmethod(tabminmax_class, (t_method)tabminmax_set, gensym("set"),
- A_SYMBOL, 0);
+ A_SYMBOL, 0);
- class_addmethod(tabminmax_class, (t_method)tabminmax_helper, gensym("help"), 0);
+ class_addmethod(tabminmax_class, (t_method)tabminmax_helper,
+ gensym("help"), 0);
zexy_register("tabminmax");
}