File: vpow.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 (60 lines) | stat: -rw-r--r-- 1,107 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
56
57
58
59
60
#include "defines.h"

/*--------------- vpow ----------------*/

static t_class *vpow_class;

typedef struct _vpow
{
    t_object x_obj;
	t_float m_y;
} t_vpow;


static void vpow_perform(t_vpow *x, t_symbol *s, int argc, t_atom *argv)
{
	int i;
	t_float y;
	t_atom *ap,*app;
    ap = (t_atom *)getbytes(sizeof(t_atom)*argc);
	app=ap;
	y=x->m_y;
	if (y==0.0f)
		y=1.0f;
	for (i = 0; i < argc; i++)
	{
		t_float x=atom_getfloat(argv++);
		if (x>0) 
			x=(t_float)powf(x,y);
		else
			x=-1000.;
		SETFLOAT(app, x);
		app++;
	}
	outlet_list(x->x_obj.ob_outlet,gensym("list"),argc,ap);
    freebytes(ap,argc);
}

static void *vpow_new(t_float y)
{
	t_vpow *x=(t_vpow *)pd_new(vpow_class);

    floatinlet_new(&x->x_obj, &x->m_y);

	outlet_new(&x->x_obj, gensym("list"));
	if (y==0.0f)
		y=1.0f;
	x->m_y=y;
	return (void *)x;
}

void vpow_setup(void)
{
    vpow_class = class_new(gensym("vpow"),
    	(t_newmethod)vpow_new, 0,
		sizeof(t_vpow), 
		CLASS_DEFAULT,
	    A_DEFFLOAT,A_DEFFLOAT,0);
    class_addlist(vpow_class, (t_method)vpow_perform);
}