aboutsummaryrefslogtreecommitdiff
path: root/test/param.c
blob: 576379f0dba7dd1deecdf0f563668a8088e10638 (plain)
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
/*
 *      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"




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;
} t_param;

typedef struct _param_inlet2
{
  t_object        x_obj;
  t_param  *p_owner;
} t_param_inlet2;

/*
static void output_param(t_param *x) {
	if (x->x_param) {
		if((x->x_param->selector == &s_bang) ) {
			outlet_bang(x->x_obj.ob_outlet);
		} else {
			outlet_anything(x->x_obj.ob_outlet, x->x_param->selector, x->x_param->ac, x->x_param->av);
		}
	}	
}
*/
/*
static void send_param(t_param *x, t_symbol* s,t_symbol* prepend ) {
	if (x->x_param) {
	   if((x->x_param->selector == &s_bang)) {
			 if (s->s_thing) 
			     pd_bang(s->s_thing);
	  } else {
		if (s->s_thing) {
			if ( x->x_param->selector == &s_list || x->x_param->selector == &s_float || x->x_param->selector == &s_symbol ) {
				typedmess(s->s_thing, prepend, x->x_param->ac, x->x_param->av);
			} else {
			int ac = x->x_param->ac + 1;
			t_atom *av = getbytes(ac*sizeof(*av));	
			tof_copy_atoms(x->x_param->av,av+1,x->x_param->ac);
			SETSYMBOL(av, x->x_param->selector);
			typedmess(s->s_thing, prepend, ac, av);
			freebytes(av, ac*sizeof(*av));
		}
		}
	  }
	}
	
}
*/

static void param_bang(t_param *x)
{
	param_output(x->x_param,x->x_obj.ob_outlet);
	
	param_send_prepend(x->x_param, x->s_PARAM ,x->x_path );
    if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_update_gui ,x->s_set );
 
}

static void param_anything(t_param *x, t_symbol *s, int ac, t_atom *av)
{
 
  if ( x->x_param) set_param_anything(x->x_param,s,ac,av);
  
  param_bang(x);
  
  /*
  param_output(x->x_param,x->x_obj.ob_outlet);
 
  param_send_prepend(x->x_param, x->s_PARAM ,x->x_path );
  if(x->x_param->selector != &s_bang ) param_send_prepend(x->x_param, x->x_update_gui ,x->s_set );
  */
  
}




// 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) unregister_param(x->x_param);
	
	if ( x->x_path) pd_unbind(&x->x_obj.ob_pd, x->x_path);
    
}

// 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;
  

   x->x_param = NULL;


	// GET THE CURRENT CANVAS
	t_canvas *canvas=tof_get_canvas();
   
   struct param_build_info build_info;
   get_param_build_info(canvas,ac,av,&build_info,1);
	
 
  if ( build_info.path  ) {
	x->x_path = build_info.path;
	x->x_update_gui = build_info.path_g;
	// BIND RECEIVER
  	pd_bind(&x->x_obj.ob_pd, build_info.path );
	// REGISTER PARAM
	x->x_param = register_param(&build_info);
    // 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,"[param] requires a name(first argument) that starts with a /");
   }
  
  
  
  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);
  
  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);
  
}