17 #include "TTClassWrapperMax.h"
21 typedef struct _dataspace{
25 t_symbol* attr_dataspace;
26 t_symbol* attr_dataspace_active;
27 t_symbol* attr_dataspace_native;
32 void* dataspace_new(t_symbol *name,
long argc, t_atom *argv);
33 void dataspace_free(t_dataspace *
self);
34 void dataspace_assist(t_dataspace *
self,
void *b,
long m,
long a,
char *s);
35 void dataspace_int(t_dataspace *
self,
long x);
36 void dataspace_float(t_dataspace *
self,
double x);
37 void dataspace_list(t_dataspace *
self, t_symbol *msg,
long argc, t_atom *argv);
38 void dataspace_getDataspaces(t_dataspace *
self);
39 void dataspace_getUnits(t_dataspace *
self);
40 t_max_err dataspace_setDataspace(t_dataspace *
self,
void *attr,
long argc, t_atom *argv);
41 t_max_err dataspace_setDataspaceActive(t_dataspace *
self,
void *attr,
long argc, t_atom *argv);
42 t_max_err dataspace_setDataspaceNative(t_dataspace *
self,
void *attr,
long argc, t_atom *argv);
46 static t_class* dataspace_class;
59 common_symbols_init();
62 c = class_new(
"j.unit",(method)dataspace_new, (method)dataspace_free,
sizeof(t_dataspace), (method)0L, A_GIMME, 0);
65 class_addmethod(c, (method)dataspace_int,
"int", A_LONG, 0);
66 class_addmethod(c, (method)dataspace_float,
"float", A_FLOAT, 0);
67 class_addmethod(c, (method)dataspace_list,
"list", A_GIMME, 0);
68 class_addmethod(c, (method)dataspace_getDataspaces,
"dataspaces.get", 0);
69 class_addmethod(c, (method)dataspace_getUnits,
"units.get", A_GIMME, 0);
70 class_addmethod(c, (method)dataspace_assist,
"assist", A_CANT, 0);
71 class_addmethod(c, (method)object_obex_dumpout,
"dumpout", A_CANT, 0);
74 attr_offset_new(
"dataspace", _sym_symbol, 0,
75 (method)0, (method)dataspace_setDataspace, calcoffset(t_dataspace, attr_dataspace)));
77 CLASS_ATTR_SYM(c,
"input", 0, t_dataspace, attr_dataspace_active);
78 CLASS_ATTR_ACCESSORS(c,
"input", NULL, dataspace_setDataspaceActive);
80 CLASS_ATTR_SYM(c,
"output", 0, t_dataspace, attr_dataspace_native);
81 CLASS_ATTR_ACCESSORS(c,
"output", NULL, dataspace_setDataspaceNative);
84 class_register(CLASS_BOX, c);
91 #pragma mark life cycle
95 void *dataspace_new(t_symbol *name,
long argc, t_atom *argv)
100 self = (t_dataspace *)object_alloc(dataspace_class);
102 object_obex_store((
void*)
self, _sym_dumpout, (
object*)outlet_new(
self, NULL));
109 self->outlet_native = outlet_new(
self, 0);
112 attr_args_process(
self, argc, argv);
113 if (!self->dataspace)
114 object_attr_setsym(
self, gensym(
"dataspace"), gensym(
"temperature"));
120 void dataspace_free(t_dataspace *
self)
133 void dataspace_assist(t_dataspace *
self,
void *b,
long msg,
long arg,
char *dst)
139 case 0: strcpy(dst,
"y=f(x)");
break;
140 default: strcpy(dst,
"dumpout");
break;
146 void dataspace_int(t_dataspace *
self,
long x)
148 dataspace_float(
self, (
double)x);
152 void dataspace_float(t_dataspace *
self,
double x)
156 self->dataspace->sendMessage(
TT(
"convert"), v, v);
157 outlet_float(self->outlet_native, v.getFloat64(0));
161 void dataspace_list(t_dataspace *
self, t_symbol *msg,
long argc, t_atom *argv)
166 for (
int i=0; i<argc; i++)
167 v.
set(i, atom_getfloat(argv+i));
170 self->dataspace->sendMessage(
TT(
"convert"), v, v);
173 t_atom* rv =
new t_atom[argc];
175 for (
int i=0; i<argc; i++)
178 outlet_anything(self->outlet_native, _sym_list, argc, rv);
182 void dataspace_getDataspaces(t_dataspace *
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);
191 for (
int i=0; i < v.
getSize(); i++) {
195 atom_setsym(a+0, gensym(
"append"));
196 atom_setsym(a+1, gensym(name.
c_str()));
197 object_obex_dumpout(
self, gensym(
"DataspacesMenu"), 2, a);
202 void dataspace_getUnits(t_dataspace *
self)
207 atom_setsym(a+0, gensym(
"clear"));
208 object_obex_dumpout(
self, gensym(
"UnitMenu"), 1, a);
210 self->dataspace->sendMessage(
TT(
"getAvailableUnits"), v, v);
211 for (
int i=0; i < v.
getSize(); i++) {
215 atom_setsym(a+0, gensym(
"append"));
216 atom_setsym(a+1, gensym(name.
c_str()));
217 object_obex_dumpout(
self, gensym(
"UnitMenu"), 2, a);
224 #pragma mark attributes
226 t_max_err dataspace_setDataspace(t_dataspace *
self,
void *attr,
long argc, t_atom *argv)
231 self->attr_dataspace = atom_getsym(argv);
232 self->dataspace->setAttributeValue(
TT(
"dataspace"),
TT(self->attr_dataspace->s_name));
234 self->dataspace->getAttributeValue(
TT(
"inputUnit"), v);
236 self->attr_dataspace_active = gensym(s.
c_str());
238 self->dataspace->getAttributeValue(
TT(
"outputUnit"), v);
240 self->attr_dataspace_native = gensym(s.
c_str());
246 t_max_err dataspace_setDataspaceActive(t_dataspace *
self,
void *attr,
long argc, t_atom *argv)
248 self->attr_dataspace_active = atom_getsym(argv);
249 self->dataspace->setAttributeValue(
TT(
"inputUnit"),
TT(self->attr_dataspace_active->s_name));
254 t_max_err dataspace_setDataspaceNative(t_dataspace *
self,
void *attr,
long argc, t_atom *argv)
256 self->attr_dataspace_native = atom_getsym(argv);
257 self->dataspace->setAttributeValue(
TT(
"outputUnit"),
TT(self->attr_dataspace_native->s_name));
TTUInt16 getSize() const
DEPRECATED.
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
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.
void get(const TTUInt16 index, T &returnedElementValue) const
DEPRECATED.
const char * c_str() const
Return a pointer to the internal string as a C-string.
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
TTFloat64 getFloat64(TTUInt16 index=0) const
DEPRECATED.
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]