-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathomax_pd_proxy.c
128 lines (107 loc) · 3.69 KB
/
omax_pd_proxy.c
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
#ifdef OMAX_PD_VERSION
#include "m_pd.h"
#include "m_imp.h"
#include "omax_pd_proxy.h"
#include "osc_mem.h"
#include <string.h>
void omax_pd_proxydispatchanything(t_object *xx, t_symbol *msg, int argc, t_atom *argv);
void omax_pd_proxydispatchfloat(t_object *xx, t_float ff);
void omax_pd_proxydispatchbang(t_object *xx);
void omax_pd_proxydispatchmethod(t_object *xx, t_symbol *msg, int argc, t_atom *argv);
void omax_pd_proxydispatchsymbol(t_object *xx, t_symbol *msg);
void omax_pd_class_addmethod(t_omax_pd_proxy_class *c, t_method fp, t_symbol *msg)
{
osc_hashtab_store(c->ht, strlen(msg->s_name), msg->s_name, (void *)fp);
class_addmethod(c->class, (t_method)omax_pd_proxydispatchmethod, msg, A_GIMME, 0);
}
void omax_pd_class_addsymbol(t_omax_pd_proxy_class *c, t_method fp)
{
char *msg = "symbol";
osc_hashtab_store(c->ht, strlen(msg), msg, (void *)fp);
class_addsymbol(c->class, (t_method)omax_pd_proxydispatchsymbol);
}
void omax_pd_class_addfloat(t_omax_pd_proxy_class *c, t_method fp)
{
char *msg = "float";
osc_hashtab_store(c->ht, strlen(msg), msg, (void *)fp);
class_addfloat(c->class, (t_method)omax_pd_proxydispatchfloat);
}
void omax_pd_class_addbang(t_omax_pd_proxy_class *c, t_method fp)
{
char *msg = "bang";
osc_hashtab_store(c->ht, strlen(msg), msg, (void *)fp);
class_addbang(c->class, (t_method)omax_pd_proxydispatchbang);
}
void omax_pd_class_addanything(t_omax_pd_proxy_class *c, t_method fp)
{
char *msg = "anything";
osc_hashtab_store(c->ht, strlen(msg), msg, (void *)fp);
class_addanything(c->class, (t_method)omax_pd_proxydispatchanything);
}
t_omax_pd_proxy *omax_pd_proxynew(t_object *x, long inletnum, long *inletloc, t_omax_pd_proxy_class *class)
{
t_omax_pd_proxy *p = (t_omax_pd_proxy *)pd_new(class->class);
p->x = x;
p->class = class;
p->inletnum = inletnum;
p->inletloc = inletloc;
inlet_new(p->x, &p->pd, 0, 0);
return p;
}
void *omax_pd_getfunctionforsymbol(t_object *x, t_symbol *msg)
{
t_omax_pd_proxy_class *c = ((t_omax_pd_proxy *)x)->class;
void *f = osc_hashtab_lookup(c->ht, strlen(msg->s_name), msg->s_name);
return f;
}
void omax_pd_proxydispatchmethod(t_object *xx, t_symbol *msg, int argc, t_atom *argv)
{
t_omax_pd_proxy *x = (t_omax_pd_proxy *)xx;
void (*f)(t_object *, t_symbol *, int, t_atom *) = (void (*)(t_object *, t_symbol *, int, t_atom *))omax_pd_getfunctionforsymbol(xx, msg);
if(f){
*(x->inletloc) = x->inletnum;
f(x->x, msg, argc, argv);
}
}
void omax_pd_proxydispatchanything(t_object *xx, t_symbol *msg, int argc, t_atom *argv)
{
t_omax_pd_proxy *x = (t_omax_pd_proxy *)xx;
void (*f)(t_object *, t_symbol *, int, t_atom *) = (void (*)(t_object *, t_symbol *, int, t_atom *))omax_pd_getfunctionforsymbol(xx, gensym("anything"));
if(f){
*(x->inletloc) = x->inletnum;
f(x->x, msg, argc, argv);
}
}
void omax_pd_proxydispatchfloat(t_object *xx, t_float ff)
{
t_omax_pd_proxy *x = (t_omax_pd_proxy *)xx;
void (*f)(t_object *, double) = (void (*)(t_object *, double))omax_pd_getfunctionforsymbol(xx, gensym("float"));
if(f){
*(x->inletloc) = x->inletnum;
f(x->x, (double)ff);
}
}
void omax_pd_proxydispatchsymbol(t_object *xx, t_symbol *msg)
{
t_omax_pd_proxy *x = (t_omax_pd_proxy *)xx;
void (*f)(t_object *, t_symbol *) = (void (*)(t_object *, t_symbol *))omax_pd_getfunctionforsymbol(xx, gensym("symbol"));
if(f){
*(x->inletloc) = x->inletnum;
f(x->x, msg);
}
}
void omax_pd_proxydispatchbang(t_object *xx)
{
t_omax_pd_proxy *x = (t_omax_pd_proxy *)xx;
void (*f)(t_object *) = (void (*)(t_object *))omax_pd_getfunctionforsymbol(xx, gensym("bang"));
if(f){
*(x->inletloc) = x->inletnum;
f(x->x);
}
}
int omax_pd_proxygetinlet(t_object *xx)
{
t_omax_pd_proxy *x = (t_omax_pd_proxy *)xx;
return *(x->inletloc);
}
#endif