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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/*
* param.c
*
* Copyright 2009 Thomas O Fredericks <tom@hp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "tof.h"
#include "param.h"
extern int sys_noloadbang;
static t_class *param_class;
static t_class *param_inlet2_class;
struct _param_inlet2;
typedef struct _param
{
t_object x_obj;
struct _param_inlet2 *x_param_inlet2;
//t_symbol *x_path;
t_symbol *s_PARAM;
//t_symbol *x_update_gui;
t_symbol *s_set;
struct param *x_param;
int noloadbang;
} t_param;
typedef struct _param_inlet2
{
t_object x_obj;
t_param *p_owner;
} t_param_inlet2;
static void param_bang(t_param *x)
{
if ( x->x_param) {
param_output(x->x_param,x->x_obj.ob_outlet);
//if (PARAMECHO) param_send_prepend(x->x_param, x->s_PARAM ,x->x_param->path );
if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_param->send ,x->s_set );
}
}
static void param_loadbang(t_param *x)
{
if (!sys_noloadbang && !x->noloadbang)
param_bang(x);
}
static void param_anything(t_param *x, t_symbol *s, int ac, t_atom *av)
{
#ifdef PARAMDEBUG
post("RECEIVING SOMETHING");
#endif
if ( x->x_param) set_param_anything(x->x_param,s,ac,av);
param_bang(x);
}
// SECOND INLET METHOD
static void param_inlet2_anything(t_param_inlet2 *p, t_symbol *s, int ac, t_atom *av)
{
if ( p->p_owner->x_param ) set_param_anything(p->p_owner->x_param, s,ac,av);
}
// DECONSTRUCTOR
static void param_free(t_param *x)
{
if(x->x_param_inlet2) pd_free((t_pd *)x->x_param_inlet2);
if (x->x_param) {
pd_unbind(&x->x_obj.ob_pd, x->x_param->receive);
param_unregister(x->x_param);
}
}
// CONSTRUCTOR
static void *param_new(t_symbol *s, int ac, t_atom *av)
{
t_param *x = (t_param *)pd_new(param_class);
t_param_inlet2 *p = (t_param_inlet2 *)pd_new(param_inlet2_class);
// Stuff
x->s_set = gensym("set");
x->s_PARAM = gensym("PARAM");
// Set up second inlet proxy
x->x_param_inlet2 = p;
p->p_owner = x;
// GET THE CURRENT CANVAS
t_canvas* canvas=tof_get_canvas();
// GET THE NAME
t_symbol* name = param_get_name(ac,av);
if (name) {
t_symbol* path = param_get_path(canvas,name);
t_symbol* root = tof_get_dollarzero(tof_get_root_canvas(canvas));
// FIND PARAM VALUE
// A. In canvas' arguments
// B. In object's arguments
// C. Defaults to a bang
int ac_p = 0;
t_atom* av_p = NULL;
// A. In canvas' arguments
int ac_c = 0;
t_atom* av_c = NULL;
t_canvas * before = tof_get_canvas_before_root(canvas);
tof_get_canvas_arguments(before,&ac_c , &av_c);
tof_find_tagged_argument('/',name, ac_c, av_c,&ac_p,&av_p);
// B. I object's arguments
if ( ac_p == 0 && ac > 1) {
int ac_a = 0;
t_atom* av_a = NULL;
tof_find_tagged_argument('/',name, ac, av,&ac_p,&av_p);
//tof_get_tagged_argument('/',ac,av,&start,&count);
//if (count > 1) {
// ac_p = ac_a;
// av_p = av_a + 1;
//}
}
// FIND THE NO LOADBANG TAG: /nlb
int i;
x->noloadbang = 0;
for ( i =0; i < ac; i++) {
if ( IS_A_SYMBOL(av,i) && (strcmp("/nlb",atom_getsymbol(av+i)->s_name) == 0)) {
x->noloadbang = 1;
break;
}
}
//FIND THE GUI OPTIONS: /g
int ac_g = 0;
t_atom* av_g = NULL;
// There could be a problem if the the name is also /g
tof_find_tagged_argument('/',gensym("/g"), ac, av,&ac_g,&av_g);
x->x_param = param_register(root,path,ac_p,av_p,ac_g,av_g);
#ifdef PARAMDEBUG
post("receive:%s",x->x_param->receive->s_name);
post("send:%s",x->x_param->send->s_name);
#endif
// BIND RECEIVER
pd_bind(&x->x_obj.ob_pd, x->x_param->receive );
// CREATE INLETS AND OUTLETS
inlet_new((t_object *)x, (t_pd *)p, 0, 0);
outlet_new(&x->x_obj, &s_list);
} else {
pd_error(x,"Could not create param. See possible errors above.");
}
return (x);
}
void param_setup(void)
{
param_class = class_new(gensym("param"),
(t_newmethod)param_new, (t_method)param_free,
sizeof(t_param), 0, A_GIMME, 0);
class_addanything(param_class, param_anything);
class_addbang(param_class, param_bang);
class_addmethod(param_class, (t_method)param_loadbang, gensym("loadbang"), 0);
param_inlet2_class = class_new(gensym("_param_inlet2"),
0, 0, sizeof(t_param_inlet2), CLASS_PD | CLASS_NOINLET, 0);
class_addanything(param_inlet2_class, param_inlet2_anything);
}
|