20 #include "jpatcher_api.h"
28 typedef struct outlet {
29 struct tinyobject o_ob;
34 typedef struct extra {
47 #define EXTRA ((t_extra*)x->extra)
55 void WrapTTViewerClass(WrappedClassPtr c);
56 void WrappedViewerClass_new(
TTPtr self,
long argc, t_atom *argv);
57 void WrappedViewerClass_free(
TTPtr self);
58 void WrappedViewerClass_anything(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
60 void remote_assist(
TTPtr self,
void *b,
long msg,
long arg,
char *dst);
62 void remote_return_value(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
63 void remote_return_model_address(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
64 void remote_return_description(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
66 void remote_bang(
TTPtr self);
67 void remote_int(
TTPtr self,
long value);
68 void remote_float(
TTPtr self,
double value);
69 TTErr remote_list(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
71 void remote_set(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
73 void remote_address(
TTPtr self, t_symbol *address);
75 void remote_attach(
TTPtr self,
int attach_output_id);
76 void remote_mousemove(
TTPtr self, t_object *patcherview, t_pt pt,
long modifiers);
77 void remote_mouseleave(
TTPtr self, t_object *patcherview, t_pt pt,
long modifiers);
78 void remote_mousedown(
TTPtr self, t_object *patcherview, t_pt pt,
long modifiers);
80 void remote_subscribe(
TTPtr self);
82 void remote_ui_queuefn(
TTPtr self);
86 ModularSpec *spec =
new ModularSpec;
87 spec->_wrap = &WrapTTViewerClass;
88 spec->_new = &WrappedViewerClass_new;
89 spec->_free = &WrappedViewerClass_free;
90 spec->_any = &WrappedViewerClass_anything;
95 void WrapTTViewerClass(WrappedClassPtr c)
97 class_addmethod(c->maxClass, (method)remote_assist,
"assist", A_CANT, 0L);
99 class_addmethod(c->maxClass, (method)remote_mousemove,
"mousemove", A_CANT, 0);
100 class_addmethod(c->maxClass, (method)remote_mouseleave,
"mouseleave", A_CANT, 0);
101 class_addmethod(c->maxClass, (method)remote_mousedown,
"mousedown", A_CANT, 0);
103 class_addmethod(c->maxClass, (method)remote_return_value,
"return_value", A_CANT, 0);
104 class_addmethod(c->maxClass, (method)remote_return_model_address,
"return_model_address", A_CANT, 0);
105 class_addmethod(c->maxClass, (method)remote_return_description,
"return_description", A_CANT, 0);
107 class_addmethod(c->maxClass, (method)remote_bang,
"bang", 0L);
108 class_addmethod(c->maxClass, (method)remote_int,
"int", A_LONG, 0L);
109 class_addmethod(c->maxClass, (method)remote_float,
"float", A_FLOAT, 0L);
110 class_addmethod(c->maxClass, (method)remote_list,
"list", A_GIMME, 0L);
112 class_addmethod(c->maxClass, (method)remote_set,
"set", A_GIMME, 0L);
114 class_addmethod(c->maxClass, (method)remote_address,
"address", A_SYM, 0);
117 void WrappedViewerClass_new(
TTPtr self,
long argc, t_atom *argv)
121 long attrstart = attr_args_offset(argc, argv);
124 if (attrstart > 0 && argv)
125 address = atom_getsym(argv);
127 address = _sym_nothing;
136 if (attrstart == 2 && argv)
137 EXTRA->name =
TTAddress(atom_getsym(argv+1)->s_name);
139 EXTRA->name = kTTAdrsEmpty;
141 EXTRA->connected = NULL;
144 EXTRA->color0 = (t_atom*)sysmem_newptr(
sizeof(t_atom) * 4);
145 atom_setfloat(EXTRA->color0, 0);
146 atom_setfloat(EXTRA->color0+1, 0.);
147 atom_setfloat(EXTRA->color0+2, 0.);
148 atom_setfloat(EXTRA->color0+3, 1.);
150 EXTRA->color1 = (t_atom*)sysmem_newptr(
sizeof(t_atom) * 4);
151 atom_setfloat(EXTRA->color1, 0.62);
152 atom_setfloat(EXTRA->color1+1, 0.);
153 atom_setfloat(EXTRA->color1+2, 0.36);
154 atom_setfloat(EXTRA->color1+3, 0.70);
161 x->
outlets = (TTHandle)sysmem_newptr(
sizeof(
TTPtr) * 3);
162 x->
outlets[attach_out] = outlet_new(x, NULL);
163 x->
outlets[value_out] = outlet_new(x, NULL);
164 x->
outlets[set_out] = outlet_new(x, NULL);
167 EXTRA->ui_qelem = qelem_new(x, (method)remote_ui_queuefn);
174 attr_args_process(x, argc, argv);
179 defer_low((t_object*)x, (method)remote_subscribe, NULL, 0, 0);
183 void remote_assist(
TTPtr self,
void *b,
long msg,
long arg,
char *dst)
186 strcpy(dst,
"input: forwarded to node");
190 strcpy(dst,
"set: connect to ui object");
193 strcpy(dst,
"value");
196 strcpy(dst,
"attach: connect this outlet to ui object if the set or the value outlets are not directly connected to it");
199 strcpy(dst,
"dumpout");
205 void WrappedViewerClass_free(
TTPtr self)
209 qelem_free(EXTRA->ui_qelem);
216 void remote_subscribe(
TTPtr self)
222 TTAddress absoluteAddress, returnedAddress;
228 if (x->
address == kTTAdrsEmpty)
234 remote_attach(
self, set_out);
244 makeInternals_receiver(x, absoluteAddress,
TTSymbol(
":description"), gensym(
"return_description"), anObject, YES);
258 if (EXTRA->name == kTTAdrsEmpty)
299 contextAddress = v[0];
302 makeInternals_receiver(x, contextAddress,
TTSymbol(
"model:address"), gensym(
"return_model_address"), anObject, x->
patcherContext == kTTSym_view);
309 contextAddress = kTTAdrsRoot;
313 atom_setsym(a, gensym((
char*)absoluteAddress.
c_str()));
314 object_obex_dumpout((t_object*)x, gensym(
"address"), 1, a);
319 makeInternals_receiver(x, absoluteAddress,
TTSymbol(
":description"), gensym(
"return_description"), anObject, YES);
339 if (x->
index > 100) {
340 object_error((t_object*)x,
"couldn't bind to j.parameter %s", x->
address.
c_str());
341 object_obex_dumpout((t_object*)x, gensym(
"error"), 0, NULL);
348 defer_low((t_object*)x, (method)remote_subscribe, NULL, 0, 0);
351 void remote_return_value(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
356 if (EXTRA->setting) {
362 if (msg == _sym_nothing)
363 outlet_atoms(x->
outlets[value_out], argc, argv);
365 outlet_anything(x->
outlets[value_out], msg, argc, argv);
370 qelem_set(EXTRA->ui_qelem);
373 void remote_ui_queuefn(
TTPtr self)
377 if (x->argc && x->argv)
378 outlet_anything(x->
outlets[set_out], _sym_set, x->argc, x->argv);
381 void remote_bang(
TTPtr self)
383 remote_list(
self, _sym_bang, 0, NULL);
386 void remote_int(
TTPtr self,
long value)
390 atom_setlong(&a, value);
391 remote_list(
self, _sym_int, 1, &a);
394 void remote_float(
TTPtr self,
double value)
398 atom_setfloat(&a, value);
399 remote_list(
self, _sym_float, 1, &a);
402 TTErr remote_list(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
409 void remote_set(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
413 EXTRA->setting = YES;
415 if (remote_list(
self, _sym_nothing, argc, argv))
420 void WrappedViewerClass_anything(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
428 void remote_return_model_address(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
447 makeInternals_receiver(x, absoluteAddress,
TTSymbol(
":description"), gensym(
"return_description"), anObject, YES);
454 atom_setsym(a, gensym((
char*)absoluteAddress.
c_str()));
455 object_obex_dumpout((t_object*)x, gensym(
"address"), 1, a);
457 JamomaDebug object_post((t_object*)x,
"binds on %s", absoluteAddress.
c_str());
461 void remote_return_description(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
466 if (EXTRA->connected)
469 object_attr_setvalueof(EXTRA->connected, _sym_annotation , argc, argv);
472 void remote_address(
TTPtr self, t_symbol *address)
482 remote_subscribe(
self);
485 void remote_attach(
TTPtr self,
int attach_output_id)
488 t_outlet *myoutlet = NULL;
489 t_dll *connecteds = NULL;
490 t_object *object, *box;
491 t_symbol *maxclass = NULL;
496 object_obex_lookup(x, _sym_pound_B, &box);
498 myoutlet = (t_outlet*)jbox_getoutlet((t_jbox*)box, attach_output_id);
500 connecteds = (t_dll*)myoutlet->o_dll;
504 object = (t_object*)connecteds->d_x1;
508 maxclass = object_attr_getsym(
object, _sym_maxclass);
510 EXTRA->connected = object;
511 if (EXTRA->connected && maxclass) {
516 object_attr_getvalueof(EXTRA->connected, _sym_presentation_rect , &ac, &av);
518 EXTRA->x = atom_getlong(av+0);
519 EXTRA->y = atom_getlong(av+1);
520 EXTRA->w = atom_getlong(av+2);
521 EXTRA->h = atom_getlong(av+3);
525 if (EXTRA->name == kTTAdrsEmpty) {
529 editName += maxclass->s_name;
538 if (!connecteds || !
object || !maxclass) {
541 if (attach_output_id == set_out)
544 return remote_attach(
self, value_out);
547 else if (attach_output_id == value_out)
550 return remote_attach(
self, attach_out);
561 void remote_mousemove(
TTPtr self, t_object *patcherview, t_pt pt,
long modifiers)
571 if (EXTRA->connected) {
574 if (modifiers & eShiftKey) {
578 object_attr_setvalueof(EXTRA->connected, _sym_hidden, 1, &a);
585 object_obex_lookup(x, gensym(
"#P"), &patcher);
586 EXTRA->label = newobject_sprintf(patcher,
"@maxclass comment @presentation 1 @textcolor 1. 1. 1. 1.");
587 object_attr_getvalueof(EXTRA->connected, _sym_presentation_rect , &ac, &av);
588 if (ac && av && EXTRA->label) {
589 object_method_long(EXTRA->label, _sym_fontsize, 10, &a);
590 object_method_sym(EXTRA->label, _sym_set, gensym((
char*)x->
address.
c_str()), &a);
591 object_method_typed(EXTRA->label, _sym_presentation_rect, ac, av, &a);
601 object_attr_setvalueof(EXTRA->label, _sym_bgcolor, 4, (t_atom*)EXTRA->color1);
603 object_attr_setvalueof(EXTRA->label, _sym_bgcolor, 4, (t_atom*)EXTRA->color0);
612 object_attr_setvalueof(EXTRA->connected, _sym_hidden, 1, &a);
616 object_free(EXTRA->label);
624 void remote_mouseleave(
TTPtr self, t_object *patcherview, t_pt pt,
long modifiers)
630 if (pt.x > EXTRA->x && pt.x < EXTRA->x+EXTRA->w && pt.y > EXTRA->y && pt.y < EXTRA->y+EXTRA->h)
638 object_attr_setvalueof(EXTRA->connected, _sym_hidden, 1, &a);
642 object_free(EXTRA->label);
648 void remote_mousedown(
TTPtr self, t_object *patcherview, t_pt pt,
long modifiers)
655 if (modifiers & eShiftKey) {
658 if (pt.x > EXTRA->x && pt.x < EXTRA->x+EXTRA->w && pt.y > EXTRA->y && pt.y < EXTRA->y+EXTRA->h) {
667 object_attr_setvalueof(EXTRA->label, _sym_bgcolor, 4, (t_atom*)EXTRA->color0);
671 object_attr_setvalueof(EXTRA->label, _sym_bgcolor, 4, (t_atom*)EXTRA->color1);
TTAddress appendAddress(const TTAddress &toAppend)
Return a new TTAddress with the appended part.
TTObject subscriberObject
The instance of a TTSubscriber object used to register the wrapped object in the tree structure...
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
TTSymbol & getInstance()
Get the instance part.
TTAddress appendAttribute(TTSymbol anAttribute)
Return a new TTAddress with attribute part.
TTHandle outlets
an array of outlet
TTErr wrapTTModularClassAsMaxClass(TTSymbol &ttblueClassName, const char *maxClassName, WrappedClassPtr *c, ModularSpec *specificities)
Wrap a Jamoma class as a Max class.
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
TTAddress address
sometime external needs to store an address (e.g. send, receive, view, ...)
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
TTAddress getParent()
Get a pointer to the parent address.
TTSymbol patcherClass
the patcher class in which the external is
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Create and use Jamoma object instances.
void * extra
used to keep very specific things
t_object * patcherPtr
the patcher in which the external is (ignoring subpatcher)
TTHashPtr internals
An hash table to store any internal TTObjectBases (like TTData, TTViewer, ...)
void * TTPtr
A generic pointer.
TTErr get(const TTSymbol aName, T &aReturnedValue) const
Get an attribute value for an object.
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
void copy_msg_argc_argv(TTPtr self, t_symbol *msg, long argc, const t_atom *argv)
tools to copy msg, argc and argv into the member msg, argc and argv of the WrappedModularInstance ...
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
TTObject wrappedObject
The instance of the Jamoma object we are wrapping.
TTSymbol & getAttribute()
Get the attribute part.
this flag means that an address have a leading slash
const char * c_str() const
Return a pointer to the internal string as a C-string.
Data Structure for this object.
TTAddressType getType()
Get the type.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Wraps Jamoma Core classes as objects for Max/MSP.
TTSymbol patcherContext
the patcher context in which the external is (model, view)
TTSymbol patcherName
the patcher name in which the external is
The TTString class is used to represent a string.
long index
index of the inlet used
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
TTSymbol & getName()
Get the name part.
WrappedModularInstance * WrappedModularInstancePtr
Pointer to a wrapped instance of our object.
[doxygenAppendixC_copyExample]