~ubuntu-branches/ubuntu/trusty/pd-smlib/trusty

« back to all changes in this revision

Viewing changes to vpow.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
/*--------------- vpow ----------------*/
 
4
 
 
5
static t_class *vpow_class;
 
6
 
 
7
typedef struct _vpow
 
8
{
 
9
    t_object x_obj;
 
10
        float m_y;
 
11
} t_vpow;
 
12
 
 
13
 
 
14
static void vpow_perform(t_vpow *x, t_symbol *s, int argc, t_atom *argv)
 
15
{
 
16
        int i;
 
17
        float y;
 
18
        t_atom *ap,*app;
 
19
    ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
 
20
        app=ap;
 
21
        y=x->m_y;
 
22
        if (y==0.0f)
 
23
                y=1.0f;
 
24
        for (i = 0; i < argc; i++)
 
25
        {
 
26
                float x=atom_getfloat(argv++);
 
27
                if (x>0) 
 
28
                        x=(float)powf(x,y);
 
29
                else
 
30
                        x=-1000.;
 
31
                SETFLOAT(app, x);
 
32
                app++;
 
33
        }
 
34
        outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
 
35
    freebytes(ap,argc);
 
36
}
 
37
 
 
38
static void *vpow_new(t_float y)
 
39
{
 
40
        t_vpow *x=(t_vpow *)pd_new(vpow_class);
 
41
 
 
42
    floatinlet_new(&x->x_obj, &x->m_y);
 
43
 
 
44
        outlet_new(&x->x_obj, gensym("list"));
 
45
        if (y==0.0f)
 
46
                y=1.0f;
 
47
        x->m_y=y;
 
48
        return (void *)x;
 
49
}
 
50
 
 
51
void vpow_setup(void)
 
52
{
 
53
    vpow_class = class_new(gensym("vpow"),
 
54
        (t_newmethod)vpow_new, 0,
 
55
                sizeof(t_vpow), 
 
56
                CLASS_DEFAULT,
 
57
            A_DEFFLOAT,A_DEFFLOAT,0);
 
58
    class_addlist(vpow_class, (t_method)vpow_perform);
 
59
}
 
60