TTErr makeInternals_data(TTPtr self, TTAddress address, TTSymbol name, t_symbol *callbackMethod, TTPtr context, TTSymbol service, TTObject& returnedData, TTBoolean deferlow) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTValue baton, v, out; TTAddress dataAddress, dataRelativeAddress; TTNodePtr dataNode; returnedData = TTObject(kTTSym_Data, service); baton = TTValue(TTPtr(x), TTPtr(callbackMethod), deferlow); returnedData.set(kTTSym_baton, baton); returnedData.set(kTTSym_function, TTPtr(&jamoma_callback_return_value)); // absolute registration dataAddress = address.appendAddress(TTAddress(name)); v = TTValue(dataAddress, returnedData, context); out = MaxApplication.send("ObjectRegister", v); // retreive relative effective address dataAddress = out[0]; dataNode = TTNodePtr((TTPtr)out[1]); dataNode->getAddress(dataRelativeAddress, address); // absolute registration case : set the address in second position (see in unregister method) v = TTValue(returnedData, dataAddress); x->internals->append(dataRelativeAddress, v); JamomaDebug object_post((t_object*)x, "makes internal \"%s\" %s at : %s", dataRelativeAddress.c_str(), service.c_str(), dataAddress.c_str()); return kTTErrNone; }
void snapshot(XMLNode xmlNode, TTNodePtr ttNode) { TTSymbolPtr OSCaddress; TTValue v, attributeNames; TTList childList; TTNodePtr p_node; TTString s; ttNode->getOscAddress(&OSCaddress); ttNode->getChildren(S_WILDCARD, S_WILDCARD, childList); const char* address = OSCaddress->getCString(); char* nodeName; XMLNode childNode = xmlNode; // don't write the first node AppName in xml because already written in application xml header // don't write the node name if is an instance, don't want it in xml file, replaced by dynamic instances attribute if (strcmp(address, AppName.c_str()) != 0 && strrchr(address, '.') == NULL) { // get the substring representing the last node name if (strlen(address) > 1) { const char* c = strrchr(address, '/'); int start = c-address+1; int end = strlen(address)-1; nodeName = str_sub(address, start, end); childNode = xmlNode.addChild(nodeName); } if (childList.isEmpty()) { // get the Data object of the Node TTObjectPtr param = ttNode->getObject(); if (param != NULL) { addAttributeToXml(param, childNode, kTTSym_type); addAttributeToXml(param, childNode, kTTSym_valueDefault); addAttributeToXml(param, childNode, kTTSym_rangeBounds); addAttributeToXml(param, childNode, kTTSym_rangeClipmode); addAttributeToXml(param, childNode, kTTSym_valueStepsize); addAttributeToXml(param, childNode, TTSymbol("dynamicInstances")); addAttributeToXml(param, childNode, TTSymbol("instanceBounds")); addAttributeToXml(param, childNode, kTTSym_priority); addAttributeToXml(param, childNode, kTTSym_description); addAttributeToXml(param, childNode, kTTSym_repetitionsFilter); addAttributeToXml(param, childNode, kTTSym_readonly); } } } // repeat recursively for each child for (childList.begin(); childList.end(); childList.next()) { childList.current().get(0,(TTPtr*)&p_node); snapshot(childNode, p_node); } }
void out_subscribe(TTPtr self) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTAddress signalAddress; TTAddress outputAddress; TTAddress inputAddress; TTValue v, args; TTNodePtr returnedNode = NULL; TTNodePtr returnedContextNode = NULL; TTAddress returnedAddress, parentAddress; TTString formatDescription, sInstance; t_object *modelOrView = NULL; #ifdef J_OUT_TILDE signalAddress = TTAddress("audio"); #endif #ifdef J_OUT_MULTI signalAddress = TTAddress("audio"); #endif #ifndef J_OUT_TILDE #ifndef J_OUT_MULTI signalAddress = TTAddress("data"); #endif #endif // edit "signal/out.instance" address outputAddress = signalAddress.appendAddress(TTAddress("out")).appendInstance(EXTRA->instance); // if the subscription is successful if (!jamoma_subscriber_create((t_eobj*)x, x->wrappedObject, outputAddress, x->subscriberObject, returnedAddress, &returnedNode, &returnedContextNode)) { // get patcher x->patcherPtr = ((t_eobj*)x)->o_canvas; // update instance symbol in case of duplicate instance EXTRA->instance = returnedAddress.getInstance(); // observe /parent/in address in order to link/unlink with an Input object below returnedNode->getParent()->getAddress(parentAddress); inputAddress = parentAddress.appendAddress(TTAddress("in")).appendInstance(EXTRA->instance); x->wrappedObject.set("inputAddress", inputAddress); // get model or view object jamoma_patcher_get_model_or_view(x->patcherPtr, &modelOrView); // notify the model there is something new concerning signal processing if (modelOrView) object_method_typed(modelOrView, gensym("output_created"), 0, NULL, NULL); } }
int Namespace::namespaceParameterGetInstanceNumber(std::string address) { TTList returnedChildrenInstance; TTNodePtr parentNode; std::string parentAddress, childAddress; // split the address size_t lastSlashPos = address.find_last_of("/"); parentAddress = address.substr(0, lastSlashPos); childAddress = address.substr(lastSlashPos+1, std::string::npos); // get the parent node at the given address NSPDirectory->getTTNodeForOSC(TT(AppName + parentAddress), &parentNode); // get the list of children instances parentNode->getChildrenInstance(TT(childAddress), returnedChildrenInstance); return returnedChildrenInstance.getSize(); }
NSPStatus Namespace::namespaceAttributeSet(std::string address, TTSymbolPtr attribute, TTValue value, int instance) { TTErr err, err1; TTList returnedTTNodes; TTNodePtr firstReturnedTTNode; if (NSPDirectory) { // add Application name to the address std::string absAddress = AppName + address; // add instance number if (instance != 0) { absAddress += "."; stringstream st; st << instance; absAddress += st.str(); } err = NSPDirectory->Lookup(TT(absAddress), returnedTTNodes, &firstReturnedTTNode); if (err != kTTErrNone) { return NSP_INVALID_ADDRESS; } TTObjectPtr param = firstReturnedTTNode->getObject(); if (param != NULL) { err1 = param->setAttributeValue(attribute, value); } if (err1 != kTTErrNone) { return NSP_INVALID_ATTRIBUTE; } return NSP_NO_ERROR; } return NSP_INIT_ERROR; }
NSPStatus Namespace::namespaceAttributeGet(std::string address, TTSymbolPtr attribute, TTValue& value, int instance) { TTList aNodeList; TTNodePtr aNode; TTErr err; // add Application name to the address std::string absAddress = AppName + address; // add instance number if (instance != 0) { absAddress += "."; stringstream st; st << instance; absAddress += st.str(); } // get the node which represent our data at the given address err = NSPDirectory->Lookup(TT(absAddress), aNodeList, &aNode); if (err != kTTErrNone) { //TTLogMessage("Invalid address \n"); return NSP_INVALID_ADDRESS; } // get the object stored in the node TTObjectPtr anObject = aNode->getObject(); // get the attribute value of the data value.clear(); err = anObject->getAttributeValue(attribute, value); if (err != kTTErrNone) { return NSP_INVALID_ATTRIBUTE; } return NSP_NO_ERROR; }
TTErr TTProtocolDirectoryCallback(const TTValue& baton, const TTValue& data) { TTObject aProtocol; TTSymbol anApplicationName; TTAddress anAddress; TTNodePtr aNode; TTUInt8 flag; TTObject anObserver; TTValue v; // unpack baton aProtocol = baton[0]; anApplicationName = baton[1]; // unpack data (anAddress, aNode, flag, anObserver) anAddress = data[0]; aNode = TTNodePtr((TTPtr)data[1]); flag = data[2]; anObserver = data[3]; if (flag == kAddressCreated) { if (aNode->getObject().valid()) v.append(aNode->getObject().name()); else v.append(kTTSym_none); } else if (flag == kAddressDestroyed) { v.append(TTSymbol("delete")); } if (TTProtocolPtr(aProtocol.instance())->mRunning) return TTProtocolPtr(aProtocol.instance())->SendListenAnswer(anApplicationName, anAddress.appendAttribute(TTSymbol("life")), v); else return kTTErrGeneric; }
void in_subscribe(TTPtr self) { WrappedModularInstancePtr x = (WrappedModularInstancePtr)self; TTAddress inputAddress; TTAddress outputAddress; TTValue v, args; TTNodePtr returnedNode = NULL; TTNodePtr returnedContextNode = NULL; TTAddress returnedAddress, parentAddress; TTDataPtr aData; TTString formatDescription, sInstance; SymbolPtr inDescription; inputAddress = TTAddress("in").appendInstance(EXTRA->instance); // if the subscription is successful if (!jamoma_subscriber_create((ObjectPtr)x, x->wrappedObject, inputAddress, &x->subscriberObject, returnedAddress, &returnedNode, &returnedContextNode)) { // get patcher x->patcherPtr = jamoma_patcher_get((ObjectPtr)x); // update instance symbol in case of duplicate instance EXTRA->instance = returnedAddress.getInstance(); // observe /parent/out address in order to link/unlink with an Input object below returnedNode->getParent()->getAddress(parentAddress); outputAddress = parentAddress.appendAddress(TTAddress("out")).appendInstance(EXTRA->instance); x->wrappedObject->setAttributeValue(TTSymbol("outputAddress"), outputAddress); #ifdef JCOM_IN_TILDE // make internal data to return amplitude v = TTValue(0., 1.); formatDescription = "instant amplitude of %s input"; sInstance = EXTRA->instance.c_str(); jamoma_edit_string_instance(formatDescription, &inDescription, sInstance); makeInternals_data(x, returnedAddress, TTSymbol("amplitude"), NULL, x->patcherPtr, kTTSym_return, (TTObjectBasePtr*)&aData); aData->setAttributeValue(kTTSym_type, kTTSym_decimal); aData->setAttributeValue(kTTSym_tag, kTTSym_generic); aData->setAttributeValue(kTTSym_rangeBounds, v); aData->setAttributeValue(kTTSym_description, TTSymbol(inDescription->s_name)); aData->setAttributeValue(kTTSym_dataspace, TTSymbol("gain")); aData->setAttributeValue(kTTSym_dataspaceUnit, TTSymbol("linear")); // make internal data to parameter in/amplitude/active makeInternals_data(x, returnedAddress, TTSymbol("amplitude/active"), gensym("return_amplitude_active"), x->patcherPtr, kTTSym_parameter, (TTObjectBasePtr*)&aData); aData->setAttributeValue(kTTSym_type, kTTSym_integer); aData->setAttributeValue(kTTSym_tag, kTTSym_generic); v = TTValue((int)EXTRA->pollInterval); aData->setAttributeValue(kTTSym_valueDefault, v); v = TTValue(0, 1000); aData->setAttributeValue(kTTSym_rangeBounds, v); aData->setAttributeValue(kTTSym_rangeClipmode, kTTSym_low); aData->setAttributeValue(kTTSym_description, TTSymbol("set the sample rate of the amplitude follower")); // launch the clock to update amplitude regulary EXTRA->clock = clock_new(x, (method)in_update_amplitude); if (EXTRA->pollInterval) clock_delay(EXTRA->clock, EXTRA->pollInterval); #endif // expose bypass and mute attributes of TTInput as TTData in the tree structure x->subscriberObject->exposeAttribute(x->wrappedObject, kTTSym_bypass, kTTSym_parameter, &aData); aData->setAttributeValue(kTTSym_type, kTTSym_boolean); aData->setAttributeValue(kTTSym_tag, kTTSym_generic); aData->setAttributeValue(kTTSym_description, TTSymbol("When active, this attribute bypasses the model's processing algtorithm, letting incoming signal pass through unaffected")); v = TTValue(0); aData->setAttributeValue(kTTSym_valueDefault, v); x->subscriberObject->exposeAttribute(x->wrappedObject, kTTSym_mute, kTTSym_parameter, &aData); aData->setAttributeValue(kTTSym_type, kTTSym_boolean); aData->setAttributeValue(kTTSym_tag, kTTSym_generic); aData->setAttributeValue(kTTSym_description, TTSymbol("When active, this attribute turns off model's inputs.")); v = TTValue(0); aData->setAttributeValue(kTTSym_valueDefault, v); } }