aboutsummaryrefslogtreecommitdiff
path: root/vmin.c
blob: a0b578e8eb3fa2ef0a47ea40653026066cfa33ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "defines.h"

/*--------------- vmin ---------------*/
/* maximum value in a list of float
   and its location (index)
*/

static t_class *vmin_class;

typedef struct _vmin
{
    t_object x_obj;
	t_outlet *m_out_maxi;
} t_vmin;


static void vmin_perform(t_vmin *x, t_symbol *s, int argc, t_atom *argv)
{
	int i;
	int mini;
	float min=MAXFLOAT;
	for (i = 0; i < argc; i++)
	{
		float f=atom_getfloat(&argv[i]);
		if (f<min)
		{ 
			min=f;
			mini=i;
		}
	}
	outlet_float(x->x_obj.ob_outlet, min);
	outlet_float(x->m_out_maxi, (float)(mini+1));
}

static void *vmin_new( t_float halfDecayTime)
{
	t_vmin *x=(t_vmin *)pd_new(vmin_class);
	outlet_new(&x->x_obj, gensym("float"));
	x->m_out_maxi=outlet_new(&x->x_obj, gensym("float"));
	return (void *)x;
}

void vmin_setup(void)
{
    vmin_class = class_new(gensym("vmin"),
    	(t_newmethod)vmin_new, 0,
		sizeof(t_vmin), 
		CLASS_DEFAULT,
	    0);
    class_addlist(vmin_class, (t_method)vmin_perform);
}