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); } }
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; }
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; }