File: vnmax.c

package info (click to toggle)
pd-smlib 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 828 kB
  • ctags: 642
  • sloc: ansic: 2,982; makefile: 345
file content (55 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (2)
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
53
54
55
#include "defines.h"

/*--------------- vnmax ---------------*/
/* maximum n values in a list of float
   and their locations (indices)
*/

//// UNCOMPLETE


static t_class *vnmax_class;

typedef struct _vnmax
{
    t_object x_obj;
	t_outlet *m_out_maxi;
} t_vnmax;


static void vnmax_perform(t_vnmax *x, t_symbol *s, int argc, t_atom *argv)
{
	int i;
	int maxi;
	t_float max=-MAXFLOAT;
	for (i = 0; i < argc; i++)
	{
		t_float f=atom_getfloat(&argv[i]);
		if (f>max)
		{ 
			max=f;
			maxi=i;
		}
	}
	outlet_float(x->x_obj.ob_outlet, max);
	outlet_float(x->m_out_maxi, (t_float)(maxi+1));
}

static void *vnmax_new( t_float halfDecayTime)
{
	t_vnmax *x=(t_vnmax *)pd_new(vnmax_class);
	outlet_new(&x->x_obj, gensym("list"));
	x->m_out_maxi=outlet_new(&x->x_obj, gensym("list"));
	return (void *)x;
}

void vnmax_setup(void)
{
    vnmax_class = class_new(gensym("vnmax"),
    	(t_newmethod)vnmax_new, 0,
		sizeof(t_vnmax), 
		CLASS_DEFAULT,
	    0);
    class_addlist(vnmax_class, (t_method)vnmax_perform);
}