19 class SnapshotParameterValue {
22 (t_object*) parameter;
24 SnapshotParameterValue(
TTFloat64& f, (t_object*) o):
33 typedef vector<SnapshotParameterValue> Snapshot;
34 typedef Snapshot::iterator SnapshotIter;
35 typedef Snapshot* SnapshotPtr;
38 typedef vector<SnapshotPtr> SnapshotCollection;
39 typedef SnapshotCollection::iterator SnapshotCollectionIter;
40 typedef SnapshotCollection* SnapshotCollectionPtr;
46 SnapshotCollectionPtr snapshots;
47 SymbolPtr excludes[128];
50 typedef TTModSnapshot* TTModSnapshotPtr;
54 TTPtr TTModSnapshotNew (SymbolPtr name,
long argc, t_atom* argv);
55 void TTModSnapshotFree (TTModSnapshotPtr
self);
56 t_max_err TTModSnapshotNotify (TTModSnapshotPtr
self, SymbolPtr s, SymbolPtr msg,
void *sender,
void *data);
57 void TTModSnapshotAssist (TTModSnapshotPtr
self,
void *b,
long m,
long a,
char *s);
58 void TTModSnapshotDump (TTModSnapshotPtr
self);
59 void TTModSnapshotStore (TTModSnapshotPtr
self, SymbolPtr s,
long argc, t_atom* argv);
60 void TTModSnapshotRecall (TTModSnapshotPtr
self, SymbolPtr s,
long argc, t_atom* argv);
64 static t_class* sMaxClass;
68 int JAMOMA_EXPORT_MAXOBJ
main(
void)
70 t_class* c = class_new(
"j.snapshot",
71 (method)TTModSnapshotNew,
72 (method)TTModSnapshotFree,
73 sizeof(TTModSnapshot),
77 common_symbols_init();
79 class_addmethod(c, (method)TTModSnapshotNotify,
"notify", A_CANT, 0);
80 class_addmethod(c, (method)TTModSnapshotAssist,
"assist", A_CANT, 0);
81 class_addmethod(c, (method)TTModSnapshotDump,
"dump", 0);
82 class_addmethod(c, (method)TTModSnapshotStore,
"store", A_GIMME, 0);
83 class_addmethod(c, (method)TTModSnapshotRecall,
"recall", A_GIMME, 0);
85 CLASS_ATTR_SYM_VARSIZE(c,
"excludes", 0, TTModSnapshot, excludes, excludeSize, 128);
87 class_register(_sym_box, c);
95 #pragma mark Life Cycle
98 TTPtr TTModSnapshotNew(SymbolPtr name,
long argc, t_atom* argv)
100 TTModSnapshotPtr
self = (TTModSnapshotPtr)object_alloc(sMaxClass);
105 self->snapshots =
new SnapshotCollection;
106 self->tree = JamomaDirectory;
108 self->excludes[i++] = gensym(
"ch");
109 self->excludes[i++] = gensym(
"view");
110 self->excludes[i++] = gensym(
"documentation");
111 self->excludeSize = i;
113 attr_args_process(
self, argc, argv);
118 void TTModSnapshotFree(TTModSnapshotPtr
self)
121 delete self->snapshots;
130 t_max_err TTModSnapshotNotify(TTModSnapshotPtr
self, SymbolPtr s, SymbolPtr msg,
TTPtr sender,
TTPtr data)
132 object_post(SELF,
"notification : %s", msg->s_name);
137 void TTModSnapshotAssist(TTModSnapshotPtr
self,
void* b,
long msg,
long arg,
char* dst)
139 if (msg == ASSIST_INLET) {
141 strcpy(dst,
"inlet");
145 strcpy(dst,
"outlet");
150 void TTModSnapshotDump(TTModSnapshotPtr
self)
156 void TTModSnapshotStore(TTModSnapshotPtr
self, SymbolPtr s,
long argc, t_atom* argv)
158 TTNodePtr rootNode =
self->tree->getRoot();
161 TTList returnedChildren;
163 SnapshotPtr snapshot = NULL;
168 snapshotIndex = atom_getlong(argv) - 1;
169 if (snapshotIndex < 0)
172 if (snapshotIndex >= self->snapshots->size()) {
173 if (snapshotIndex >= self->snapshots->capacity()) {
174 self->snapshots->reserve(snapshotIndex+1);
176 self->snapshots->resize(snapshotIndex+1);
179 snapshot =
self->snapshots->at(snapshotIndex);
183 snapshot =
new Snapshot;
186 err = rootNode->
getChildren(S_WILDCARD, S_WILDCARD, returnedChildren);
188 returnedChildren.assignToValue(moduleNodes);
189 numModules = moduleNodes.
getSize();
190 for (
TTUInt32 i=0; i<numModules; i++) {
194 moduleNodes.
get(i, (
TTPtr*)(&module));
199 if (type ==
TTSymbol(
"Container")) {
204 err = module->
getChildren(S_WILDCARD, S_WILDCARD, returnedChildren);
205 returnedChildren.assignToValue(parameterNodes);
206 numParameters = parameterNodes.
getSize();
207 for (
TTUInt32 i=0; i<numParameters; i++) {
211 parameterNodes.
get(i, (
TTPtr*)(¶meter));
213 bool exclude =
false;
215 for (
TTInt32 e=0; e <
self->excludeSize; e++) {
229 childType = parameter->
getObject()->getName();
230 if (childType ==
TTSymbol(
"Data")) {
231 ObjectPtr maxObject = (t_object*)parameter->
getObject();
232 SymbolPtr maxType = object_attr_getsym(maxObject, SymbolGen(
"type"));
235 if (maxType == SymbolGen(
"decimal") || maxType == SymbolGen(
"integer")) {
236 TTFloat64 value = object_attr_getfloat(maxObject, SymbolGen(
"value"));
237 SnapshotParameterValue spv(value, maxObject);
239 snapshot->push_back(spv);
240 post(
" parameter: %s -- value: %lf", parameter->
getName().
c_str(), value);
244 else if (childType ==
TTSymbol(
"container")) {
247 TTList containerChildren;
251 containerChildren.assignToValue(containerNodes);
252 numParameters2 = containerNodes.
getSize();
253 for (
TTUInt32 i=0; i<numParameters2; i++) {
257 containerNodes.
get(i, (
TTPtr*)(¶meter2));
259 bool exclude =
false;
261 for (
TTInt32 e=0; e <
self->excludeSize; e++) {
274 childType2 = parameter2->getType();
275 if (childType2 ==
TTSymbol(
"subscribe_parameter")) {
276 ObjectPtr maxObject = (t_object*)parameter2->
getObject();
277 SymbolPtr maxType = object_attr_getsym(maxObject, SymbolGen(
"type"));
280 if (maxType == SymbolGen(
"decimal") || maxType == SymbolGen(
"integer")) {
281 TTFloat64 value = object_attr_getfloat(maxObject, SymbolGen(
"value"));
282 SnapshotParameterValue spv(value, maxObject);
284 snapshot->push_back(spv);
285 post(
" parameter: %s -- value: %lf", parameter2->
getName().
c_str(), value);
297 (*
self->snapshots)[snapshotIndex] = snapshot;
301 void TTModSnapshotRecallOne(
const SnapshotParameterValue& spv)
303 object_method(spv.parameter, _sym_float, spv.value);
307 void TTModSnapshotRecall(TTModSnapshotPtr
self, SymbolPtr s,
long argc, t_atom* argv)
314 SnapshotPtr snapshot;
315 TTUInt32 snapshotIndex = atom_getlong(argv) - 1;
317 if (snapshotIndex < 0)
320 if (snapshotIndex >= self->snapshots->size()) {
321 object_error(SELF,
"preset recall out of range");
324 snapshot = (*
self->snapshots)[snapshotIndex];
326 for_each((*snapshot).begin(), (*snapshot).end(), TTModSnapshotRecallOne);
328 object_error(SELF,
"invalid preset recall requested");
332 else if (argc == 3) {
333 SnapshotPtr snapshotA;
334 SnapshotPtr snapshotB;
335 TTUInt32 snapshotIndexA = atom_getlong(argv+0) - 1;
336 TTUInt32 snapshotIndexB = atom_getlong(argv+1) - 1;
337 TTUInt32 snapshotSizeA = atom_getlong(argv+0);
338 TTUInt32 snapshotSizeB = atom_getlong(argv+1);
339 TTFloat32 position = atom_getfloat(argv+2);
341 if (snapshotIndexA < 0)
343 if (snapshotIndexB < 0)
346 if (snapshotIndexA >= self->snapshots->size() ||
347 snapshotIndexB >=
self->snapshots->size())
349 object_error(SELF,
"preset recall out of range");
353 snapshotA = (*
self->snapshots)[snapshotIndexA];
354 snapshotB = (*
self->snapshots)[snapshotIndexB];
355 snapshotSizeA = snapshotA->size();
356 snapshotSizeB = snapshotB->size();
358 if (snapshotSizeA != snapshotSizeB) {
359 object_error(SELF,
"preset recall -- cannot interpolate between snapshots of unequal size");
363 for (
TTUInt32 i=0; i<snapshotSizeA; i++) {
364 if ( (*snapshotA)[i].parameter == (*snapshotB)[i].parameter ) {
365 TTFloat32 f = ((*snapshotA)[i].value * (1.0 - position)) + ((*snapshotB)[i].value * (position));
366 object_method((*snapshotA)[i].parameter, _sym_float, f);
375 bool boundsCheckFailed =
false;
376 SnapshotPtr snapshot;
377 Snapshot interpolatedResult;
381 if (ac > self->snapshots->size()) {
382 object_error(SELF,
"recall can not interpolate -- not enough snapshots for provided weights");
386 snapshot = (*
self->snapshots)[0];
388 object_error(SELF,
"recall can not interpolate -- bogus initial snapshot");
392 size = snapshot->size();
393 for (
int i=1; i<argc; i++) {
394 if (!(*self->snapshots)[i] || (*self->snapshots)[i]->size() != size) {
395 boundsCheckFailed =
true;
399 if (boundsCheckFailed) {
400 object_error(SELF,
"recall can not interpolate -- snapshots are of unequal size, or there is a missing snapshot in the sequence");
404 interpolatedResult.reserve(size);
405 for (
int i=0; i<argc; i++) {
406 snapshot = (*
self->snapshots)[i];
407 weight = atom_getfloat(argv+i);
409 interpolatedResult.insert(interpolatedResult.begin(), snapshot->begin(), snapshot->end());
412 interpolatedResult[j].value *= weight;
418 interpolatedResult[j].value += ((*snapshot)[j].value * weight);
422 for_each(interpolatedResult.begin(), interpolatedResult.end(), TTModSnapshotRecallOne);
TTUInt16 getSize() const
DEPRECATED.
TTSymbol & getName()
Get the name of the node.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
TTObject & getObject()
Get the object binded by this node.
double TTFloat64
64 bit floating point number
void * TTPtr
A generic pointer.
int JAMOMA_EXPORT_MAXOBJ main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
float TTFloat32
32 bit floating point number
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.
std::int32_t TTInt32
32 bit signed integer
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
std::uint32_t TTUInt32
32 bit unsigned integer
TTErr getChildren(TTSymbol &name, TTSymbol &instance, TTList &returnedChildren)
Get a linklist of children of the node : select them by name and instance (use wilcards to select the...
We build a tree of TTNodes, and you can request a pointer for any TTNode, or add an observer to any T...
[doxygenAppendixC_copyExample]