TTErr removeInternals_data(TTPtr self, TTAddress address, TTAddress name) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTValue v; TTAddress dataAddress; TTErr err; err = x->internals->lookup(name, v); if (!err) { dataAddress = v[1]; JamomaDebug object_post((t_object*)x, "Remove internal %s object at : %s", name.c_str(), dataAddress.c_str()); MaxApplication.send("ObjectUnregister", dataAddress); x->internals->remove(name); } return kTTErrNone; }
TTErr makeInternals_sender(TTPtr self, TTAddress address, TTSymbol name, TTObject& returnedSender, TTBoolean appendNameAsAttribute) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTValue v; TTAddress adrs; // check the internals do not exist yet if (!x->internals->lookup(name, v)) { returnedSender = v[0]; JamomaDebug object_post((t_object*)x, "makeInternals_sender : \"%s\" internal already exists", name.c_str()); return kTTErrNone; } returnedSender = TTObject(kTTSym_Sender); // edit address if (appendNameAsAttribute) adrs = address.appendAttribute(name); else adrs = address.appendAddress(TTAddress(name.c_str())); // default registration case : store object only (see in unregister method) x->internals->append(name, returnedSender); // set address attribute returnedSender.set(kTTSym_address, adrs); JamomaDebug object_post((t_object*)x, "makes internal \"%s\" sender to bind on : %s", name.c_str(), adrs.c_str()); return kTTErrNone; }
TTErr makeInternals_receiver(TTPtr self, TTAddress address, TTSymbol name, t_symbol *callbackMethod, TTObject& returnedReceiver, TTBoolean deferlow, TTBoolean appendNameAsAttribute) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTValue v, args, baton; TTObject returnValueCallback, empty; TTAddress adrs; // check the internals do not exist yet if (!x->internals->lookup(name, v)) { returnedReceiver = v[0]; JamomaDebug object_post((t_object*)x, "makeInternals_receiver : \"%s\" internal already exists", name.c_str()); returnedReceiver.send("Get"); return kTTErrNone; } // prepare arguments // we don't want the address back args.append(empty); returnValueCallback = TTObject("callback"); baton = TTValue(TTPtr(x), TTPtr(callbackMethod), deferlow); returnValueCallback.set(kTTSym_baton, baton); returnValueCallback.set(kTTSym_function, TTPtr(&jamoma_callback_return_value)); args.append(returnValueCallback); returnedReceiver = TTObject(kTTSym_Receiver, args); // edit address if (appendNameAsAttribute) adrs = address.appendAttribute(name); else adrs = address.appendAddress(TTAddress(name.c_str())); // default registration case : store object only (see in unregister method) x->internals->append(name, returnedReceiver); // set address attribute (after registration as the value can be updated in the same time) returnedReceiver.set(kTTSym_address, adrs); JamomaDebug object_post((t_object*)x, "makes internal \"%s\" receiver to bind on : %s", name.c_str(), adrs.c_str()); return kTTErrNone; }
void wrappedModularClass_unregister(WrappedModularInstancePtr x) { TTValue keys, v; TTSymbol name; TTAddress objectAddress; TTErr err; #ifndef ARRAY_EXTERNAL x->subscriberObject = TTObject(); // check the wrappedObject is still valid because it could have been released in spec->_free method if (x->wrappedObject.valid()) { // don't release the local application if (!(x->wrappedObject.instance() == accessApplicationLocal)) { if (x->wrappedObject.instance()->getReferenceCount() > 1) object_error((t_object*)x, "there are still unreleased reference of the wrappedObject (refcount = %d)", x->wrappedObject.instance()->getReferenceCount() - 1); // this line should release the last instance of the wrapped object // otherwise there is something wrong x->wrappedObject = TTObject(); } } #endif if (!x->internals->isEmpty()) { err = x->internals->getKeys(keys); if (!err) { x->iterateInternals = YES; for (int i = 0; i < (TTInt32) keys.size(); i++) { name = keys[i]; err = x->internals->lookup(name, v); if (!err) { TTObject o = v[0]; if (o.name() == kTTSym_Sender || o.name() == kTTSym_Receiver || o.name() == kTTSym_Viewer) o.set(kTTSym_address, kTTAdrsEmpty); // absolute registration case : remove the address if (v.size() == 2) { objectAddress = v[1]; JamomaDebug object_post((t_object*)x, "Remove internal %s object at : %s", name.c_str(), objectAddress.c_str()); MaxApplication.send("ObjectUnregister", objectAddress); } } } x->iterateInternals = NO; } x->internals->clear(); } }
TTErr makeInternals_viewer(TTPtr self, TTAddress address, TTSymbol name, t_symbol *callbackMethod, TTObject& returnedViewer, TTBoolean deferlow) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTValue v, baton; TTAddress adrs; // check the internals do not exist yet if (!x->internals->lookup(name, v)) { returnedViewer = v[0]; JamomaDebug object_post((t_object*)x, "makeInternals_viewer : \"%s\" internal already exists", name.c_str()); return kTTErrNone; } returnedViewer = TTObject(kTTSym_Viewer); baton = TTValue(TTPtr(x), TTPtr(callbackMethod), deferlow); returnedViewer.set(kTTSym_baton, baton); returnedViewer.set(kTTSym_function, TTPtr(&jamoma_callback_return_value)); // edit address adrs = address.appendAddress(TTAddress(name)); // default registration case : store object only (see in unregister method) x->internals->append(name, returnedViewer); // set address attribute (after registration as the value can be updated in the same time) returnedViewer.set(kTTSym_address, adrs); JamomaDebug object_post((t_object*)x, "makes internal \"%s\" viewer to bind on : %s", name.c_str(), adrs.c_str()); return kTTErrNone; }