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

« back to all changes in this revision

Viewing changes to vmin.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
/*--------------- vmin ---------------*/
 
4
/* maximum value in a list of float
 
5
   and its location (index)
 
6
*/
 
7
 
 
8
static t_class *vmin_class;
 
9
 
 
10
typedef struct _vmin
 
11
{
 
12
    t_object x_obj;
 
13
        t_outlet *m_out_maxi;
 
14
} t_vmin;
 
15
 
 
16
 
 
17
static void vmin_perform(t_vmin *x, t_symbol *s, int argc, t_atom *argv)
 
18
{
 
19
        int i;
 
20
        int mini;
 
21
        float min=MAXFLOAT;
 
22
        for (i = 0; i < argc; i++)
 
23
        {
 
24
                float f=atom_getfloat(&argv[i]);
 
25
                if (f<min)
 
26
                { 
 
27
                        min=f;
 
28
                        mini=i;
 
29
                }
 
30
        }
 
31
        outlet_float(x->x_obj.ob_outlet, min);
 
32
        outlet_float(x->m_out_maxi, (float)(mini+1));
 
33
}
 
34
 
 
35
static void *vmin_new( t_float halfDecayTime)
 
36
{
 
37
        t_vmin *x=(t_vmin *)pd_new(vmin_class);
 
38
        outlet_new(&x->x_obj, gensym("float"));
 
39
        x->m_out_maxi=outlet_new(&x->x_obj, gensym("float"));
 
40
        return (void *)x;
 
41
}
 
42
 
 
43
void vmin_setup(void)
 
44
{
 
45
    vmin_class = class_new(gensym("vmin"),
 
46
        (t_newmethod)vmin_new, 0,
 
47
                sizeof(t_vmin), 
 
48
                CLASS_DEFAULT,
 
49
            0);
 
50
    class_addlist(vmin_class, (t_method)vmin_perform);
 
51
}
 
52