This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmax.jit.gl.hap.c
209 lines (164 loc) · 5.58 KB
/
max.jit.gl.hap.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
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
// max.jit.gl.hap.c
#include "ext.h"
#ifdef C74_X64
C74_EXTERNAL_NOT_ON_X64("jit.gl.hap")
#else
#include "jit.common.h"
#include "jit.gl.h"
static const char versionstring[] = "1.0.3";
typedef struct _max_jit_gl_hap
{
t_object ob;
void *obex;
void *texout;
} t_max_jit_gl_hap;
t_jit_err jit_gl_hap_init(void);
void max_jit_gl_hap_version(t_max_jit_gl_hap *x);
void max_jit_gl_hap_assist(t_max_jit_gl_hap *x, void *b, long io, long index, char *s);
void max_jit_gl_hap_notify(t_max_jit_gl_hap *x, t_symbol *s, t_symbol *msg, void *ob, void *data);
void max_jit_gl_hap_bang(t_max_jit_gl_hap *x);
void max_jit_gl_hap_draw(t_max_jit_gl_hap *x, t_symbol *s, long argc, t_atom *argv);
void *max_jit_gl_hap_new(t_symbol *s, long argc, t_atom *argv);
void max_jit_gl_hap_free(t_max_jit_gl_hap *x);
t_class *max_jit_gl_hap_class;
t_symbol *ps_jit_gl_texture;
t_symbol *ps_draw;
t_symbol *ps_out_name;
t_symbol *ps_typedmess;
t_symbol *ps_framereport;
t_symbol *ps_loopreport;
t_symbol *ps_loopnotify;
int C74_EXPORT main(void)
{
t_class *maxclass, *jitclass;
jit_gl_hap_init();
maxclass = class_new("jit.gl.hap", (method)max_jit_gl_hap_new, (method)max_jit_gl_hap_free, sizeof(t_max_jit_gl_hap), NULL, A_GIMME, 0);
max_jit_class_obex_setup(maxclass, calcoffset(t_max_jit_gl_hap, obex));
jitclass = jit_class_findbyname(gensym("jit_gl_hap"));
max_jit_class_wrap_standard(maxclass, jitclass, 0);
// override default ob3d bang/draw methods
max_jit_class_addmethod_defer_low(maxclass, (method)max_jit_gl_hap_bang, "bang");
max_jit_class_addmethod_defer_low(maxclass, (method)max_jit_gl_hap_draw, "draw");
max_jit_class_addmethod_defer_low(maxclass, (method)max_jit_gl_hap_version, "version");
class_addmethod(maxclass, (method)max_jit_gl_hap_assist, "assist", A_CANT, 0);
// add methods for 3d drawing
//max_jit_class_ob3d_wrap(maxclass);
max_ob3d_setup();
// override the default ob3d notify with our own. must come after max_jit_class_ob3d_wrap
class_addmethod(maxclass, (method)max_jit_gl_hap_notify, "notify", A_CANT, 0);
// register our class with max
class_register(CLASS_BOX, maxclass);
max_jit_gl_hap_class = maxclass;
ps_jit_gl_texture = gensym("jit_gl_texture");
ps_draw = gensym("draw");
ps_out_name = gensym("out_name");
ps_typedmess = gensym("typedmess");
ps_framereport = gensym("framereport");
ps_loopreport = gensym("loopreport");
ps_loopnotify = gensym("loopnotify");
return 0;
}
void max_jit_gl_hap_assist(t_max_jit_gl_hap *x, void *b, long io, long index, char *s)
{
if (io == 1) { //input
if(index == 0)
sprintf(s,"messages to this 3d object");
//else
// sprintf(s,"texture or matrix input");
}
else { //output
if(index == 0)
sprintf(s,"texture output");
else
sprintf(s, "dumpout");
}
}
void max_jit_gl_hap_notify(t_max_jit_gl_hap *x, t_symbol *s, t_symbol *msg, void *ob, void *data)
{
t_atom a;
if (msg==ps_draw) {
jit_atom_setsym(&a, jit_attr_getsym(max_jit_obex_jitob_get(x), ps_out_name));
outlet_anything(x->texout,ps_jit_gl_texture,1,&a);
}
else if (msg == ps_loopreport) {
max_jit_obex_dumpout(x, ps_loopnotify, 0, NULL);
}
else if (msg == ps_typedmess && data) {
long ac = 0;
t_atom *av = NULL;
object_getvalueof(data, &ac, &av);
if (ac && av) {
msg = jit_atom_getsym(av);
max_jit_obex_dumpout(x, msg, ac - 1, av + 1);
freebytes(av, sizeof(t_atom) * ac);
}
}
}
void max_jit_gl_hap_version(t_max_jit_gl_hap *x)
{
post("jit.gl.hap: version %s", versionstring);
}
void max_jit_gl_hap_bang(t_max_jit_gl_hap *x)
{
typedmess((t_object *)x,ps_draw,0,NULL);
}
void max_jit_gl_hap_draw(t_max_jit_gl_hap *x, t_symbol *s, long argc, t_atom *argv)
{
t_atom a;
// get the jitter object
t_jit_object *jitob = (t_jit_object*)max_jit_obex_jitob_get(x);
// call the jitter object's draw method
jit_object_method(jitob,s,s,argc,argv);
// query the texture name and send out the texture output
jit_atom_setsym(&a,jit_attr_getsym(jitob,ps_out_name));
outlet_anything(x->texout,ps_jit_gl_texture,1,&a);
}
void max_jit_gl_hap_free(t_max_jit_gl_hap *x)
{
void * jitob = max_jit_obex_jitob_get(x);
jit_object_detach(jit_attr_getsym(jitob, _jit_sym_name),x);
// lookup our internal Jitter object instance and free
jit_object_free(jitob);
// free resources associated with our obex entry
max_jit_object_free(x);
}
void *max_jit_gl_hap_new(t_symbol *s, long argc, t_atom *argv)
{
t_max_jit_gl_hap *x;
void *jit_ob;
long attrstart;
t_symbol *dest_name_sym = _jit_sym_nothing;
if ((x = (t_max_jit_gl_hap *)max_jit_object_alloc(max_jit_gl_hap_class, gensym("jit_gl_hap"))))
{
// get first normal arg, the destination name
attrstart = max_jit_attr_args_offset(argc,argv);
if (attrstart&&argv)
{
jit_atom_arg_getsym(&dest_name_sym, 0, attrstart, argv);
}
// instantiate Jitter object with dest_name arg
if ((jit_ob = jit_object_new(gensym("jit_gl_hap"), dest_name_sym)))
{
// set internal jitter object instance
max_jit_obex_jitob_set(x, jit_ob);
// add a general purpose outlet (rightmost)
max_jit_obex_dumpout_set(x, outlet_new(x,NULL));
// process attribute arguments
max_jit_attr_args(x, argc, argv);
x->texout = outlet_new(x, "jit_gl_texture");
//attach max object(client) with jit object(server)
jit_object_attach(jit_attr_getsym(jit_ob, _jit_sym_name),x);
// attach the jit object's ob3d to a new outlet
// this outlet is used in matrixoutput mode
//max_jit_ob3d_attach(x, jit_ob, outlet_new(x, "jit_matrix"));
}
else
{
error("jit.gl.hap: could not allocate object");
freeobject((t_object *)x);
x = NULL;
}
}
return (x);
}
#endif