17 #include "TTClassWrapperMax.h"
21 typedef struct _unit {
25 t_symbol* attr_dataspace;
26 t_symbol* attr_unit_active;
27 t_symbol* attr_unit_native;
32 void* unit_new(t_symbol *name,
long argc, t_atom *argv);
33 void unit_free(t_unit *
self);
34 void unit_assist(t_unit *
self,
void *b,
long m,
long a,
char *s);
35 void unit_getDataspaces(t_unit *
self);
36 void unit_getUnits(t_unit *
self);
37 void unit_perform64(t_unit *
self, t_object *dsp64,
double **ins,
long numins,
double **outs,
long numouts,
long sampleframes,
long flags,
void *userparam);
38 void unit_dsp64(t_unit *
self, t_object *dsp64,
short *count,
double samplerate,
long maxvectorsize,
long flags);
39 t_max_err unit_setDataspace(t_unit *
self,
void *attr,
long argc, t_atom *argv);
40 t_max_err unit_setDataspaceActive(t_unit *
self,
void *attr,
long argc, t_atom *argv);
41 t_max_err unit_setDataspaceNative(t_unit *
self,
void *attr,
long argc, t_atom *argv);
45 static t_class* unit_class;
46 static TTSymbol kTTSym_convert(
"convert");
59 common_symbols_init();
62 c = class_new(
"j.unit~",(method)unit_new, (method)unit_free,
sizeof(t_unit), (method)0L, A_GIMME, 0);
65 class_addmethod(c, (method)unit_getDataspaces,
"dataspaces.get", 0);
66 class_addmethod(c, (method)unit_getUnits,
"units.get", A_GIMME, 0);
67 class_addmethod(c, (method)unit_assist,
"assist", A_CANT, 0);
68 class_addmethod(c, (method)object_obex_dumpout,
"dumpout", A_CANT, 0);
69 class_addmethod(c, (method)unit_dsp64,
"dsp64", A_CANT, 0);
71 class_addattr(c, attr_offset_new(
"dataspace", _sym_symbol, 0, (method)0, (method)unit_setDataspace, calcoffset(t_unit, attr_dataspace)));
73 CLASS_ATTR_SYM(c,
"input", 0, t_unit, attr_unit_active);
74 CLASS_ATTR_ACCESSORS(c,
"input", NULL, unit_setDataspaceActive);
76 CLASS_ATTR_SYM(c,
"output", 0, t_unit, attr_unit_native);
77 CLASS_ATTR_ACCESSORS(c,
"output", NULL, unit_setDataspaceNative);
81 class_register(CLASS_BOX, c);
88 #pragma mark life cycle
92 void *unit_new(t_symbol *name,
long argc, t_atom *argv)
97 self = (t_unit *)object_alloc(unit_class);
99 object_obex_store((
void*)
self, _sym_dumpout, (
object*)outlet_new(
self, NULL));
106 dsp_setup((t_pxobject*)
self, 1);
108 self->outlet = outlet_new(
self,
"signal");
111 attr_args_process(
self, argc, argv);
112 if (!self->dataspace)
113 object_attr_setsym(
self, gensym(
"dataspace"), gensym(
"temperature"));
119 void unit_free(t_unit *
self)
132 void unit_assist(t_unit *
self,
void *b,
long msg,
long arg,
char *dst)
138 case 0: strcpy(dst,
"y=f(x)");
break;
139 default: strcpy(dst,
"dumpout");
break;
182 void unit_getDataspaces(t_unit *
self)
187 atom_setsym(a+0, gensym(
"clear"));
188 object_obex_dumpout(
self, gensym(
"DataspacesMenu"), 1, a);
190 self->dataspace->sendMessage(
TT(
"getAvailableDataspaces"), v, v);
194 atom_setsym(a+0, gensym(
"append"));
195 atom_setsym(a+1, gensym(name.
c_str()));
196 object_obex_dumpout(
self, gensym(
"DataspacesMenu"), 2, a);
201 void unit_getUnits(t_unit *
self)
206 atom_setsym(a+0, gensym(
"clear"));
207 object_obex_dumpout(
self, gensym(
"UnitMenu"), 1, a);
209 self->dataspace->sendMessage(
TT(
"getAvailableUnits"), v, v);
213 atom_setsym(a+0, gensym(
"append"));
214 atom_setsym(a+1, gensym(name.
c_str()));
215 object_obex_dumpout(
self, gensym(
"UnitMenu"), 2, a);
220 void unit_perform64(t_unit *
self, t_object *dsp64,
double **ins,
long numins,
double **outs,
long numouts,
long sampleframes,
long flags,
void *userparam)
223 double *out = outs[0];
226 while (sampleframes--){
228 self->dataspace->sendMessage(kTTSym_convert, v, v);
234 void unit_dsp64(t_unit *
self, t_object *dsp64,
short *count,
double samplerate,
long maxvectorsize,
long flags)
236 object_method(dsp64, gensym(
"dsp_add64"), (t_object*)
self, unit_perform64, 0, NULL);
241 #pragma mark attributes
243 t_max_err unit_setDataspace(t_unit *
self,
void *attr,
long argc, t_atom *argv)
248 self->attr_dataspace = atom_getsym(argv);
249 self->dataspace->setAttributeValue(
TT(
"dataspace"),
TT(self->attr_dataspace->s_name));
251 self->dataspace->getAttributeValue(
TT(
"inputUnit"), v);
253 self->attr_unit_active = gensym(s.
c_str());
255 self->dataspace->getAttributeValue(
TT(
"outputUnit"), v);
257 self->attr_unit_native = gensym(s.
c_str());
263 t_max_err unit_setDataspaceActive(t_unit *
self,
void *attr,
long argc, t_atom *argv)
265 self->attr_unit_active = atom_getsym(argv);
266 self->dataspace->setAttributeValue(
TT(
"inputUnit"),
TT(self->attr_unit_active->s_name));
271 t_max_err unit_setDataspaceNative(t_unit *
self,
void *attr,
long argc, t_atom *argv)
273 self->attr_unit_native = atom_getsym(argv);
274 self->dataspace->setAttributeValue(
TT(
"outputUnit"),
TT(self->attr_unit_native->s_name));
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
size_type size() const noexcept
Return the number of elements.
Base class for all first-class Jamoma objects.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
void * TTPtr
A generic pointer.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
const char * c_str() const
Return a pointer to the internal string as a C-string.
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
std::uint32_t TTUInt32
32 bit unsigned integer
[doxygenAppendixC_copyExample]