25 typedef struct extra {
28 TTListPtr objectsSorted;
31 #define EXTRA ((t_extra*)x->extra)
35 void WrapTTDataClass(WrappedClassPtr c);
36 void WrappedDataClass_new(
TTPtr self,
long argc, t_atom *argv);
37 void WrappedDataClass_free(
TTPtr self);
41 void data_array_build(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv);
43 void data_address(
TTPtr self, t_symbol *name);
45 void data_array_return_value(
const TTValue& baton,
const TTValue& v);
48 void WrappedDataClass_anything(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv);
52 void data_list(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv);
54 void data_array(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv);
56 void data_inc(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv);
57 void data_dec(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv);
61 ModularSpec *spec =
new ModularSpec;
62 spec->_wrap = &WrapTTDataClass;
63 spec->_new = &WrappedDataClass_new;
64 spec->_free = &WrappedDataClass_free;
65 spec->_any = &WrappedDataClass_anything;
82 void WrapTTDataClass(WrappedClassPtr c)
84 class_addmethod(c->maxClass, (method)data_assist,
"assist", A_CANT, 0L);
86 class_addmethod(c->maxClass, (method)data_bang,
"bang", 0L);
87 class_addmethod(c->maxClass, (method)
data_int,
"int", A_LONG, 0);
88 class_addmethod(c->maxClass, (method)data_float,
"float", A_FLOAT, 0);
89 class_addmethod(c->maxClass, (method)data_list,
"list", A_GIMME, 0);
91 class_addmethod(c->maxClass, (method)data_array,
"array", A_GIMME, 0);
93 class_addmethod(c->maxClass, (method)data_inc,
"+", A_GIMME, 0);
94 class_addmethod(c->maxClass, (method)data_dec,
"-", A_GIMME, 0);
96 class_addmethod(c->maxClass, (method)data_address,
"address", A_SYM,0);
99 void WrappedDataClass_new(
TTPtr self,
long argc, t_atom *argv)
102 t_symbol *relativeAddress;
103 long attrstart = attr_args_offset(argc, argv);
107 relativeAddress = _sym_nothing;
108 if (attrstart && argv)
109 if (atom_gettype(argv) == A_SYM)
110 relativeAddress = atom_getsym(argv);
112 if (relativeAddress == _sym_nothing) {
113 object_error((t_object*)x,
"needs a name as first argument");
119 x->
inlets = (TTHandle)sysmem_newptr(
sizeof(
TTPtr) * 1);
126 x->
outlets = (TTHandle)sysmem_newptr(
sizeof(
TTPtr) * 2);
127 x->
outlets[index_out] = outlet_new(x, NULL);
128 x->
outlets[data_out] = outlet_new(x, NULL);
135 x->arrayAddress = kTTAdrsEmpty;
137 x->arrayAttrFormat = gensym(
"single");
142 EXTRA->changingAddress = NO;
143 EXTRA->objectsSorted =
new TTList();
149 attr_args_process(x, argc, argv);
157 x->arrayAddress = relativeAddress->s_name;
160 x->arrayAddress = kTTAdrsEmpty;
161 object_error((t_object*)x,
"can't register because %s is not a relative address", relativeAddress->s_name);
165 atom_setlong(&number,
jamoma_parse_bracket(relativeAddress, x->arrayFormatInteger, x->arrayFormatString));
170 defer_low((t_object*)x, (method)data_array_build, _sym_nothing, 1, &number);
173 void WrappedDataClass_free(
TTPtr self)
179 delete EXTRA->objectsSorted;
184 void data_array_build(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv)
188 t_symbol *instanceAddress;
191 TTUInt32 newSize = atom_getlong(argv);
194 if (newSize > MAX_ARRAY_SIZE)
196 object_error((t_object*)x,
"the size is greater than the maximum array size (%d)", MAX_ARRAY_SIZE);
200 x->arraySize = newSize;
207 if (newSize > lastSize)
209 for (
TTUInt32 i = lastSize + 1; i <= newSize; i++)
215 data_array_build_index(
self, anObject, kTTSym_message, i);
219 data_array_build_index(
self, anObject, kTTSym_return, i);
224 data_array_build_index(
self, anObject, kTTSym_parameter, i);
229 cache.append(
TTSymbol(instanceAddress->s_name));
234 EXTRA->objectsSorted->insert(0, anObject);
241 for (
TTUInt32 i = lastSize; i > newSize; i--)
253 EXTRA->objectsSorted->getIndex(0, cache);
254 EXTRA->objectsSorted->remove(cache);
258 object_error((t_object*)x,
"there are still unreleased reference of a %s wrappedObject(refcount = %d)", instanceAddress->s_name, anObject.
instance()->
getReferenceCount() - 1);
271 attr_args_process(x, ac, av);
277 for (
TTUInt32 i = lastSize + 1; i <= newSize; i++)
294 if (aSubscriber.
valid())
299 cache.
append(aSubscriber);
305 anObject.
send(
"Init");
313 if (x->arraySize > 0)
314 wrappedModularClass_ArraySelect(
self, gensym(
"*"), 0, NULL);
323 returnedData =
TTObject(kTTSym_Data, service);
328 returnedData.
set(kTTSym_baton, baton);
329 returnedData.
set(kTTSym_function,
TTPtr(&data_array_return_value));
332 void data_address(
TTPtr self, t_symbol *address)
337 if (!EXTRA->changingAddress)
339 EXTRA->changingAddress = YES;
342 if (!(x->arrayAddress ==
TTAddress(address->s_name)))
347 x->arrayAddress = address->s_name;
350 x->arrayAddress = kTTAdrsEmpty;
351 object_error((t_object*)x,
"can't register because %s is not a relative address", address->s_name);
357 atom_setlong(&number,
jamoma_parse_bracket(address, newArrayFormatInteger, newArrayFormatString));
360 if (newArrayFormatInteger != x->arrayFormatInteger &&
361 newArrayFormatString != x->arrayFormatString &&
366 atom_setlong(&zero, 0);
367 defer(
self,(method)data_array_build, _sym_nothing, 1, &zero);
370 x->arrayFormatInteger = newArrayFormatInteger;
371 x->arrayFormatString = newArrayFormatString;
374 defer(
self,(method)data_array_build, _sym_nothing, 1, &number);
377 if (x->arrayAttrFormat == gensym(
"array"))
385 data_edit_array(
self, array);
390 if (msg == _sym_nothing)
391 outlet_atoms(x->
outlets[data_out], argc, argv);
393 outlet_anything(x->
outlets[data_out], msg, argc, argv);
397 sysmem_freeptr(argv);
402 EXTRA->changingAddress = NO;
406 object_error((t_object*)x,
"can't change to %s address. Please defer low", address->s_name);
415 strcpy(dst,
"set the value of the selected instance(s)");
418 strcpy(dst,
"index (use * to bind all instances)");
425 strcpy(dst,
"direct: values");
428 strcpy(dst,
"index");
431 strcpy(dst,
"dumpout");
445 object_error((t_object*)x,
"bang : the array is empty");
453 if (proxy_getinlet((t_object*)x)) {
454 atom_setlong(&a, value);
455 wrappedModularClass_ArraySelect(
self, _sym_nothing, 1, &a);
459 atom_setlong(&a, value);
463 object_error((t_object*)x,
"int : the array is empty");
473 atom_setfloat(&a, value);
477 object_error((t_object*)x,
"float : the array is empty");
480 void data_list(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv)
488 if (x->arrayIndex == 0) {
509 object_error((t_object*)x,
"list : the array is empty");
512 void WrappedDataClass_anything(
TTPtr self, t_symbol *msg,
long argc, t_atom *argv)
517 if (proxy_getinlet((t_object*)x))
518 wrappedModularClass_ArraySelect(
self, msg, argc, argv);
523 void data_array(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv)
527 t_symbol *instanceAddress;
534 d = argc / x->arraySize;
535 if ((d * x->arraySize) == argc) {
539 for (i = 1; i <= (
TTInt32) x->arraySize; i++) {
550 object_error((t_object*)x,
"array : the array message size have to be a multiple of the array size");
554 object_error((t_object*)x,
"array : the array is empty");
557 void data_inc(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv)
563 selectedObject->sendMessage(
TTSymbol(
"Inc"), v, none);
566 void data_dec(
TTPtr self, t_symbol *msg,
long argc,
const t_atom *argv)
572 selectedObject->sendMessage(
TTSymbol(
"Dec"), v, none);
575 void data_array_return_value(
const TTValue& baton,
const TTValue& v)
590 if (x->arrayIndex == 0)
593 outlet_int(x->
outlets[index_out], i);
597 if (x->arrayAttrFormat == gensym(
"array")) {
600 if (EXTRA->changingAddress)
603 data_edit_array(x, array);
612 if (msg == _sym_nothing)
613 outlet_atoms(x->
outlets[data_out], argc, argv);
615 outlet_anything(x->
outlets[data_out], msg, argc, argv);
619 sysmem_freeptr(argv);
630 for (EXTRA->objectsSorted->begin();
631 EXTRA->objectsSorted->end();
632 EXTRA->objectsSorted->next()) {
634 aData = EXTRA->objectsSorted->current()[0];
637 if (aData.
get(kTTSym_value, grab))
638 aData.
get(kTTSym_valueDefault, grab);
641 if (grab.
size() == 0) {
643 aData.
get(kTTSym_type, t);
647 if (type == kTTSym_string)
657 t_max_err data_get_format(
TTPtr self,
TTPtr attr,
long *ac, t_atom **av)
666 if (!(*av = (t_atom*)getbytes(
sizeof(t_atom)*(*ac)))) {
668 return MAX_ERR_OUT_OF_MEM;
672 atom_setsym(*av, x->arrayAttrFormat);
677 t_max_err data_set_format(
TTPtr self,
TTPtr attr,
long ac,
const t_atom *av)
682 x->arrayAttrFormat = atom_getsym(av);
685 x->arrayAttrFormat = gensym(
"single");
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
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.
void data_int(TTPtr self, long value)
Process an incoming integer value.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Create and use Jamoma object instances.
size_type size() const noexcept
Return the number of elements.
void * extra
used to keep very specific things
this flag means that an address have no leading slash
TTErr getKeys(TTValue &hashKeys)
Get an array of all of the keys for the hash table.
TTHashPtr internals
An hash table to store any internal TTObjectBases (like TTData, TTViewer, ...)
void prepend(const TTValue &aValueToPrepend)
Insert another TTValue before the first element.
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
void * TTPtr
A generic pointer.
TTErr get(const TTSymbol aName, T &aReturnedValue) const
Get an attribute value for an object.
void data_inc(TTPtr self, t_symbol *msg, long argc, t_atom *argv)
Increase parameter value in steps.
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
TTHandle inlets
an array of inlets
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
TTBoolean iterateInternals
The flag is true when an iteration is done on the internals.
TTBoolean isEmpty()
Return true if the hash has nothing stored in it.
void data_list(TTPtr self, t_symbol *msg, long argc, t_atom *argv)
Process an incoming message containing a list.
std::int32_t TTInt32
32 bit signed integer
void data_bang(TTPtr self)
Process an incoming 'bang' message.
void clear()
Clear all values from the vector, leaving with size of 0.
Data Structure for this object.
TTErr remove(const TTSymbol key)
Remove an item from the hash table.
Wraps Jamoma Core classes as objects for Max/MSP.
std::uint32_t TTUInt32
32 bit unsigned integer
TTBoolean useInternals
The hash table can be used as an array of wrappedObject.
void data_dec(TTPtr self, t_symbol *msg, long argc, t_atom *argv)
Decrease parameter value in steps.
TTObjectBase * instance() const
Return a direct pointer to the internal instance.
The TTString class is used to represent a string.
long index
index of the inlet used
TTSymbol cursor
to select an entry in x->internals
void data_float(TTPtr self, double value)
Process an incoming float value.
void data_assist(TTPtr self, TTPtr b, long msg, long arg, char *dst)
Provide assistance on input and output while patching.
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
WrappedModularInstance * WrappedModularInstancePtr
Pointer to a wrapped instance of our object.
[doxygenAppendixC_copyExample]
TTUInt16 getReferenceCount()
Query an object to get its current reference count.