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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#include "m_pd.h"
static t_class *increment_class;
static t_class *increment_inlet2_class;
struct _increment_inlet2;
typedef struct _increment {
t_object x_obj;
int reset;
t_float value;
t_float inc;
t_outlet* outlet1;
//t_float start;
struct _increment_inlet2* inlet2;
//t_outlet* outlet2;
} t_increment;
typedef struct _increment_inlet2 {
t_object x_obj;
t_increment *x;
} t_increment_inlet2;
static void increment_bang(t_increment *x)
{
if ( x->reset) {
x->reset = 0;
} else {
x->value = x->value + x->inc;
}
outlet_float(x->outlet1,x->value);
}
/*
static void increment_float(t_increment *x, t_float f)
{
x->inc = f;
increment_bang(x);
}
*/
static void increment_float(t_increment *x, t_float f)
{
x->inc = f;
increment_bang(x);
}
static void increment_inlet2_bang(t_increment_inlet2 *x)
{
x->x->value = 0;
x->x->reset = 1;
}
static void increment_set(t_increment *x, t_float f)
{
x->value = f;
x->reset = 1;
}
static void increment_inlet2_float(t_increment_inlet2 *x, t_float f)
{
//post("before");
// post("start:%d",(int)x->start);
// post("value:%d",(int)x->value);
increment_set(x->x, f);
// post("after");
//post("start:%d",(int)x->start);
//post("value:%d",(int)x->value);
}
/*
void increment_list(t_increment *x,t_symbol *s, int argc, t_atom *argv)
{
if ( argc >= 2) {
x->value = atom_getfloat(argv);
x->inc = atom_getfloat(argv+1);
}
}
*/
static void increment_free(t_increment *x)
{
}
void *increment_new(t_symbol *s, int argc, t_atom *argv)
{
t_increment *x = (t_increment *)pd_new(increment_class);
x->reset = 1;
x->value = 0;
if ( argc >= 2) {
x->value = atom_getfloat(argv);
x->inc = atom_getfloat(argv+1);
} else if ( argc == 1) {
x->value = atom_getfloat(argv);
x->inc = 1;
} else {
x->value = 0;
x->inc = 1;
}
//x->start = x->value;
//post("start:%d",(int)x->start);
//post("value:%d",(int)x->value);
//inlet_new(&x->x_obj, &x->x_obj.ob_pd,
// gensym("float"), gensym("set"));
//floatinlet_new(&x->x_obj, &x->inc);
//inlet_new(&x->x_obj, &x->x_obj.ob_pd,
// gensym("bang"), gensym("reset"));
t_increment_inlet2 *inlet2 = (t_increment_inlet2 *)pd_new(increment_inlet2_class);
inlet2->x = x;
x->inlet2 = inlet2;
inlet_new((t_object *)x, (t_pd *)inlet2, 0, 0);
x->outlet1 = outlet_new(&x->x_obj, &s_float);
//x->outlet2 = outlet_new(&x->x_obj, &s_float);
return (void *)x;
}
void increment_setup(void) {
increment_class = class_new(gensym("increment"),
(t_newmethod)increment_new,
(t_method)increment_free, sizeof(t_increment),
CLASS_DEFAULT,
A_GIMME, 0);
class_addbang (increment_class, increment_bang);
class_addfloat (increment_class, increment_float);
class_addmethod(increment_class,
(t_method)increment_set, gensym("set"),
A_DEFFLOAT, 0);
increment_inlet2_class = class_new(gensym("increment_inlet2"),
0, 0, sizeof(t_increment_inlet2), CLASS_PD | CLASS_NOINLET, 0);
class_addbang(increment_inlet2_class, increment_inlet2_bang);
class_addfloat(increment_inlet2_class, increment_inlet2_float);
/*
class_addmethod(increment_class,
(t_method)increment_step, gensym("step"),
A_DEFFLOAT, 0);
class_addmethod(increment_class,
(t_method)increment_reset, gensym("reset"),
0);
*/
//class_addlist (increment_class, increment_list);
}
|