aboutsummaryrefslogtreecommitdiff
path: root/src/mtx_minmax.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-12-15 18:08:32 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-12-15 18:08:32 +0000
commitc14e1f6562ffed9ee93573851ff29a58ac3e7218 (patch)
treedb46c297cd1b13ae48502923ef6db13840352e77 /src/mtx_minmax.c
parent59780470c472c670b73b1c4a76fa6b8f36dea4d6 (diff)
merged functionality for [mtx_min] and [mtx_max] into [mtx_minmax] and rebuilt
the 2 objects using the new one svn path=/trunk/externals/iem/iemmatrix/; revision=4226
Diffstat (limited to 'src/mtx_minmax.c')
-rw-r--r--src/mtx_minmax.c352
1 files changed, 152 insertions, 200 deletions
diff --git a/src/mtx_minmax.c b/src/mtx_minmax.c
index 3886546..a806fbe 100644
--- a/src/mtx_minmax.c
+++ b/src/mtx_minmax.c
@@ -23,242 +23,194 @@ static t_symbol *col_sym2;
typedef struct _MTXminmax_ MTXminmax;
struct _MTXminmax_
{
- t_object x_obj;
- int size;
- int outsize;
- t_symbol *minmax_mode;
- int operator_minimum; // 1 if we are [mtx_min], 0 if we are [mtx_max]
+ t_object x_obj;
+ int size;
+ int outsize;
+ int mode;
+ int operator_minimum; // 1 if we are [mtx_min], 0 if we are [mtx_max]
- t_outlet *list_outlet;
+ t_outlet *min_outlet;
+ t_outlet *max_outlet;
- t_atom *list_out;
- t_atom *list_in;
+ t_atom *minlist_out;
+ t_atom *maxlist_out;
};
static void deleteMTXMinMax (MTXminmax *mtx_minmax_obj)
{
- if (mtx_minmax_obj->list_out)
- freebytes (mtx_minmax_obj->list_out, sizeof(t_atom)*(mtx_minmax_obj->size+2));
+ if (mtx_minmax_obj->maxlist_out)
+ freebytes (mtx_minmax_obj->maxlist_out, sizeof(t_atom)*(mtx_minmax_obj->size));
+ if (mtx_minmax_obj->minlist_out)
+ freebytes (mtx_minmax_obj->minlist_out, sizeof(t_atom)*(mtx_minmax_obj->size));
}
static void mTXSetMinMaxMode (MTXminmax *mtx_minmax_obj, t_symbol *m_sym)
{
- mtx_minmax_obj->minmax_mode = m_sym;
+ int mode=0;
+ if(gensym("row")==m_sym)
+ mode=1;
+ else if((gensym("col")==m_sym) || (gensym("column")==m_sym) || (gensym(":")==m_sym))
+ mode=2;
+
+ mtx_minmax_obj->mode = mode;
}
-static void *newMTXMin (t_symbol *s, int argc, t_atom *argv)
+static void *newMTXMinMax (t_symbol *s)
{
- MTXminmax *mtx_minmax_obj = (MTXminmax *) pd_new (mtx_minmax_class);
- mTXSetMinMaxMode (mtx_minmax_obj, gensym(":"));
+ MTXminmax *mtx_minmax_obj = (MTXminmax *) pd_new (mtx_minmax_class);
- switch ((argc>1)?1:argc) {
- case 1:
- mTXSetMinMaxMode (mtx_minmax_obj, atom_getsymbol (argv));
- }
- mtx_minmax_obj->operator_minimum = 1;
+ mtx_minmax_obj->mode=0;
- mtx_minmax_obj->list_outlet = outlet_new (&mtx_minmax_obj->x_obj, gensym("matrix"));
- return ((void *) mtx_minmax_obj);
-}
-static void *newMTXMax (t_symbol *s, int argc, t_atom *argv)
-{
- MTXminmax *mtx_minmax_obj = (MTXminmax *) pd_new (mtx_minmax_class);
- mTXSetMinMaxMode (mtx_minmax_obj, gensym(":"));
+ mtx_minmax_obj->operator_minimum = 1;
+
+ mtx_minmax_obj->min_outlet = outlet_new (&mtx_minmax_obj->x_obj, gensym("matrix"));
+ mtx_minmax_obj->max_outlet = outlet_new (&mtx_minmax_obj->x_obj, gensym("matrix"));
- switch ((argc>1)?1:argc) {
- case 1:
- mTXSetMinMaxMode (mtx_minmax_obj, atom_getsymbol (argv));
- }
- mtx_minmax_obj->operator_minimum = 0;
+ if((NULL!=s)&&(&s_!=s)&&(NULL!=s->s_name))
+ mTXSetMinMaxMode (mtx_minmax_obj, s);
- mtx_minmax_obj->list_outlet = outlet_new (&mtx_minmax_obj->x_obj, gensym("matrix"));
- return ((void *) mtx_minmax_obj);
+ return ((void *) mtx_minmax_obj);
}
static void mTXMinMaxBang (MTXminmax *mtx_minmax_obj)
{
- if (mtx_minmax_obj->list_out)
- outlet_anything(mtx_minmax_obj->list_outlet, gensym("matrix"),
- mtx_minmax_obj->outsize+2, mtx_minmax_obj->list_out);
+ if (mtx_minmax_obj->maxlist_out)
+ outlet_list(mtx_minmax_obj->max_outlet, gensym("list"),
+ mtx_minmax_obj->outsize, mtx_minmax_obj->maxlist_out);
+ if (mtx_minmax_obj->minlist_out)
+ outlet_list(mtx_minmax_obj->min_outlet, gensym("list"),
+ mtx_minmax_obj->outsize, mtx_minmax_obj->minlist_out);
}
-/*
-static void copyList (int size, t_atom *x, t_atom *y)
-{
- while(size--)
- *y++=*x++;
- }
- */
-static t_float minList (int n, t_atom *x)
-{
- t_float min=atom_getfloat(x);
- t_float f;
- for (;n--;x++) {
- f = atom_getfloat(x);
- min = (min < f)?min:f;
- }
- return min;
+static void minmaxList (int n, t_atom *x, t_float*min, t_float*max)
+{
+ t_float min_=atom_getfloat(x);
+ t_float max_=min_;
+ t_float f;
+ for (;n--;x++) {
+ f = atom_getfloat(x);
+ min_ = (min_ < f)?min_:f;
+ max_ = (max_ > f)?max_:f;
+ }
+ *max=max_;
+ *min=min_;
}
-static t_float minListStep (int n, const int step, t_atom *x)
-{
- t_float min=atom_getfloat(x);
- t_float f;
- for (;n--;x+=step) {
- f = atom_getfloat(x);
- min = (min < f)?min:f;
- }
- return min;
+static void minmaxListStep (int n, const int step, t_atom *x, t_float*min, t_float*max)
+{
+ t_float min_=atom_getfloat(x);
+ t_float max_=min_;
+ t_float f;
+ for (;n--;x+=step) {
+ f = atom_getfloat(x);
+ min_ = (min_ < f)?min_:f;
+ max_ = (max_ > f)?max_:f;
+ }
+ *max=max_;
+ *min=min_;
}
-static t_float maxList (int n, t_atom *x)
-{
- t_float max=atom_getfloat(x);
- t_float f;
- for (;n--;x++) {
- f = atom_getfloat(x);
- max = (max > f)?max:f;
- }
- return max;
-}
-static t_float maxListStep (int n, const int step, t_atom *x)
+static void minmaxListColumns (const int rows, const int columns, t_atom *x,
+ t_atom *ap_min, t_atom *ap_max)
{
- t_float max=atom_getfloat(x);
- t_float f;
- for (;n--;x+=step) {
- f = atom_getfloat(x);
- max = (max > f)?max:f;
- }
- return max;
+ int count;
+ t_float min, max;
+ for (count=0; count < columns; count++, x++, ap_min++, ap_max++) {
+ minmaxListStep (rows, columns, x, &min, &max);
+ SETFLOAT(ap_min,min);
+ SETFLOAT(ap_max,max);
+ }
}
-
-static void minListColumns (const int rows, const int columns, t_atom *x, t_atom *y)
-{
- int count;
- t_float f;
- for (count=0; count < columns; count++, x++, y++) {
- f=minListStep (rows, columns, x);
- SETFLOAT(y,f);
- }
-}
-static void minListRows (int rows, int columns, t_atom *x, t_atom *y)
-{
- int count;
- t_float f;
- for (count=0; count < rows; count++, x+=columns, y++) {
- f=minList (columns, x);
- SETFLOAT(y,f);
- }
+static void minmaxListRows (int rows, int columns, t_atom *x,
+ t_atom *ap_min, t_atom*ap_max)
+{
+ int count;
+ t_float min, max;
+ for (count=0; count < rows; count++, x+=columns, ap_min++, ap_max++) {
+ minmaxList (columns, x, &min, &max);
+ SETFLOAT(ap_min, min);
+ SETFLOAT(ap_max,max);
+ }
}
-static void maxListColumns (const int rows, const int columns, t_atom *x, t_atom *y)
-{
- int count;
- t_float f;
- for (count=0; count < columns; count++, x++, y++) {
- f=maxListStep (rows, columns, x);
- SETFLOAT(y,f);
- }
-}
-static void maxListRows (int rows, int columns, t_atom *x, t_atom *y)
-{
- int count;
- t_float f;
- for (count=0; count < rows; count++, x+=columns, y++) {
- f=maxList (columns, x);
- SETFLOAT(y,f);
- }
-}
-
-
static void mTXMinMaxMatrix (MTXminmax *mtx_minmax_obj, t_symbol *s,
- int argc, t_atom *argv)
-{
- int rows = atom_getint (argv++);
- int columns = atom_getint (argv++);
- int size = rows * columns;
- int list_size = argc - 2;
- t_atom *list_in = argv;
- t_atom *list_out = mtx_minmax_obj->list_out;
- int rows_out;
- int columns_out;
-
- // size check
- if (!size) {
- post("mtx_minmax: invalid dimensions");
- return;
- }
- else if (list_size<size) {
- post("mtx_minmax: sparse matrix not yet supported: use \"mtx_check\"");
- return;
- }
+ int argc, t_atom *argv)
+{
+ int rows = atom_getint (argv++);
+ int columns = atom_getint (argv++);
+ int size = rows * columns;
+ t_atom *maxlist_out = mtx_minmax_obj->maxlist_out;
+ t_atom *minlist_out = mtx_minmax_obj->minlist_out;
+ int elements_out;
+
+ // size check
+ if (!size) {
+ post("mtx_minmax: invalid dimensions");
+ return;
+ }
+ else if ((argc-2)<size) {
+ post("mtx_minmax: sparse matrix not yet supported: use \"mtx_check\"");
+ return;
+ }
- if (size != mtx_minmax_obj->size) {
- if (!list_out)
- list_out = (t_atom *) getbytes (sizeof (t_atom) * (size + 2));
- else
- list_out = (t_atom *) resizebytes (list_out,
- sizeof (t_atom) * (mtx_minmax_obj->size+2),
- sizeof (t_atom) * (size + 2));
- }
-
- mtx_minmax_obj->size = size;
- mtx_minmax_obj->list_out = list_out;
-
- // main part
- list_out += 2;
- //copyList (size, argv, list_out);
- if (mtx_minmax_obj->minmax_mode == row_sym) {
- rows_out = rows;
- columns_out = 1;
- if (mtx_minmax_obj->operator_minimum)
- minListRows (rows, columns, list_in, list_out);
- else
- maxListRows (rows, columns, list_in, list_out);
- }
- else if ((mtx_minmax_obj->minmax_mode == col_sym) ||
- (mtx_minmax_obj->minmax_mode == col_sym2)) {
- rows_out = 1;
- columns_out = columns;
- if (mtx_minmax_obj->operator_minimum)
- minListColumns (rows, columns, list_in, list_out);
- else
- maxListColumns (rows, columns, list_in, list_out);
- }
- else {
- columns_out = 1;
- rows_out = 1;
- if (mtx_minmax_obj->operator_minimum)
- minListRows (1, size, list_in, list_out);
- else
- maxListRows (1, size, list_in, list_out);
- }
- mtx_minmax_obj->outsize = columns_out * rows_out;
- list_out = mtx_minmax_obj->list_out;
-
- SETSYMBOL(list_out, gensym("matrix"));
- SETFLOAT(list_out, rows_out);
- SETFLOAT(&list_out[1], columns_out);
- outlet_anything(mtx_minmax_obj->list_outlet, gensym("matrix"),
- mtx_minmax_obj->outsize+2, list_out);
+ if (size != mtx_minmax_obj->size) {
+ if (!minlist_out)
+ minlist_out = (t_atom *) getbytes (sizeof (t_atom) * size);
+ else
+ minlist_out = (t_atom *) resizebytes (minlist_out,
+ sizeof (t_atom) * (mtx_minmax_obj->size),
+ sizeof (t_atom) * size);
+ if (!maxlist_out)
+ maxlist_out = (t_atom *) getbytes (sizeof (t_atom) * size);
+ else
+ maxlist_out = (t_atom *) resizebytes (maxlist_out,
+ sizeof (t_atom) * (mtx_minmax_obj->size),
+ sizeof (t_atom) * size);
+ }
+
+ mtx_minmax_obj->size = size;
+ mtx_minmax_obj->minlist_out = minlist_out;
+ mtx_minmax_obj->maxlist_out = maxlist_out;
+
+ // main part
+
+ switch(mtx_minmax_obj->mode){
+ case 1:
+ elements_out = rows;
+ minmaxListRows (rows, columns, argv, minlist_out, maxlist_out);
+ break;
+ case 2:
+ elements_out = columns;
+ minmaxListColumns (rows, columns, argv, minlist_out, maxlist_out);
+ break;
+ default:
+ elements_out = 1;
+ minmaxListRows (1, size, argv, minlist_out, maxlist_out);
+ }
+ mtx_minmax_obj->outsize = elements_out;
+ maxlist_out = mtx_minmax_obj->maxlist_out;
+ minlist_out = mtx_minmax_obj->minlist_out;
+
+ mTXMinMaxBang(mtx_minmax_obj);
}
void mtx_minmax_setup (void)
{
- mtx_minmax_class = class_new
- (gensym("mtx_min"),
- (t_newmethod) newMTXMin,
- (t_method) deleteMTXMinMax,
- sizeof (MTXminmax),
- CLASS_DEFAULT, A_GIMME, 0);
- class_addbang (mtx_minmax_class, (t_method) mTXMinMaxBang);
- class_addmethod (mtx_minmax_class, (t_method) mTXMinMaxMatrix, gensym("matrix"), A_GIMME,0);
-// class_addmethod (mtx_minmax_class, (t_method) mTXSetMinMaxDimension, gensym("dimension"), A_DEFFLOAT,0);
- class_addmethod (mtx_minmax_class, (t_method) mTXSetMinMaxMode, gensym("mode"), A_DEFSYMBOL ,0);
- class_addcreator ((t_newmethod) newMTXMax, gensym("mtx_max"), A_GIMME,0);
- class_sethelpsymbol (mtx_minmax_class, gensym("iemmatrix/mtx_minmax"));
- row_sym = gensym("row");
- col_sym = gensym("col");
- col_sym2 = gensym("column");
+ mtx_minmax_class = class_new (
+ gensym("mtx_minmax"),
+ (t_newmethod) newMTXMinMax,
+ (t_method) deleteMTXMinMax,
+ sizeof (MTXminmax),
+ CLASS_DEFAULT, A_DEFSYM, 0);
+
+ class_addbang (mtx_minmax_class, (t_method) mTXMinMaxBang);
+ class_addmethod (mtx_minmax_class, (t_method) mTXMinMaxMatrix, gensym("matrix"), A_GIMME,0);
+ class_addmethod (mtx_minmax_class, (t_method) mTXSetMinMaxMode, gensym("mode"), A_DEFSYMBOL ,0);
+
+ class_sethelpsymbol (mtx_minmax_class, gensym("iemmatrix/mtx_minmax"));
+
+ row_sym = gensym("row");
+ col_sym = gensym("col");
+ col_sym2 = gensym("column");
}
void iemtx_minmax_setup(void){