~ubuntu-branches/ubuntu/saucy/pd-smlib/saucy

« back to all changes in this revision

Viewing changes to vnmax.c

  • Committer: Bazaar Package Importer
  • Author(s): Hans-Christoph Steiner
  • Date: 2010-11-10 15:17:58 UTC
  • Revision ID: james.westby@ubuntu.com-20101110151758-3acjf69kiudo3gh4
Tags: upstream-0.12.1
ImportĀ upstreamĀ versionĀ 0.12.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "defines.h"
 
2
 
 
3
/*--------------- vnmax ---------------*/
 
4
/* maximum n values in a list of float
 
5
   and their locations (indices)
 
6
*/
 
7
 
 
8
//// UNCOMPLETE
 
9
 
 
10
 
 
11
static t_class *vnmax_class;
 
12
 
 
13
typedef struct _vnmax
 
14
{
 
15
    t_object x_obj;
 
16
        t_outlet *m_out_maxi;
 
17
} t_vnmax;
 
18
 
 
19
 
 
20
static void vnmax_perform(t_vnmax *x, t_symbol *s, int argc, t_atom *argv)
 
21
{
 
22
        int i;
 
23
        int maxi;
 
24
        float max=-MAXFLOAT;
 
25
        for (i = 0; i < argc; i++)
 
26
        {
 
27
                float f=atom_getfloat(&argv[i]);
 
28
                if (f>max)
 
29
                { 
 
30
                        max=f;
 
31
                        maxi=i;
 
32
                }
 
33
        }
 
34
        outlet_float(x->x_obj.ob_outlet, max);
 
35
        outlet_float(x->m_out_maxi, (float)(maxi+1));
 
36
}
 
37
 
 
38
static void *vnmax_new( t_float halfDecayTime)
 
39
{
 
40
        t_vnmax *x=(t_vnmax *)pd_new(vnmax_class);
 
41
        outlet_new(&x->x_obj, gensym("list"));
 
42
        x->m_out_maxi=outlet_new(&x->x_obj, gensym("list"));
 
43
        return (void *)x;
 
44
}
 
45
 
 
46
void vnmax_setup(void)
 
47
{
 
48
    vnmax_class = class_new(gensym("vnmax"),
 
49
        (t_newmethod)vnmax_new, 0,
 
50
                sizeof(t_vnmax), 
 
51
                CLASS_DEFAULT,
 
52
            0);
 
53
    class_addlist(vnmax_class, (t_method)vnmax_perform);
 
54
}
 
55