Example #1
0
TTErr TTSvf::setMode(const TTValue& newValue)
{
	TTSymbolPtr newMode = newValue;
	
	if (newMode == TT("lowpass")) {
		setProcessMethod(processLowpass);
		setCalculateMethod(calculateLowpass);
	}
	else if (newMode == TT("highpass")) {
		setProcessMethod(processHighpass);
		setCalculateMethod(calculateHighpass);
	}
else if (newMode == TT("bandpass")) {
		setProcessMethod(processBandpass);
		setCalculateMethod(calculateBandpass);
	}
else if (newMode == TT("notch")) {
		setProcessMethod(processNotch);
		setCalculateMethod(calculateNotch);
	}
else if (newMode == TT("peak")) {
		setProcessMethod(processPeak);
		setCalculateMethod(calculatePeak);
	}
	else {
		logError("bad mode specified for TTSvf: %s", newMode->getCString());
		return kTTErrInvalidValue;
	}
	
	mMode = newMode;
	return kTTErrNone;
}
Example #2
0
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);
	}
}
Example #3
0
// C Callback from any Graph Source objects we are observing
void UnpackGraphCallback(UnpackPtr self, TTValue& arg)
{
	TTDictionaryPtr aDictionary = NULL;
	TTValue			v;
	AtomCount		ac;
	AtomPtr			ap;
	TTBoolean		firstItemASymbol = NO;
	TTSymbolPtr		firstItem = NULL;
	
	arg.get(0, (TTPtr*)(&aDictionary));
	aDictionary->getValue(v);
	ac = v.getSize();
	if (ac) {
		ap = new Atom[ac];
		for (int i=0; i<ac; i++) {
			if (v.getType() == kTypeInt8   ||
				v.getType() == kTypeUInt8  ||
				v.getType() == kTypeInt16  ||
				v.getType() == kTypeUInt16 ||
				v.getType() == kTypeInt32  ||
				v.getType() == kTypeUInt32 ||
				v.getType() == kTypeInt64  ||
				v.getType() == kTypeUInt64)
			{
				TTInt32 ival;
				
				v.get(i, ival);
				atom_setlong(ap+i, ival);
			}
			else if (v.getType() == kTypeFloat32 || v.getType() == kTypeFloat64)
			{
				atom_setfloat(ap+i, v.getFloat64(i));
			}
			else if (v.getType() == kTypeSymbol)
			{
				TTSymbolPtr s;
				
				v.get(i, &s);
				atom_setsym(ap+i, gensym((char*)s->getCString()));
				if (i==0) {
					firstItemASymbol = YES;
					firstItem = s;
				}
			}
		}
		
		if (firstItemASymbol)
			outlet_anything(self->graphOutlets[0], gensym((char*)firstItem->getCString()), ac-1, ap+1);
		else if (ac == 1)
			outlet_float(self->graphOutlets[0], atom_getfloat(ap));
		else
			outlet_anything(self->graphOutlets[0], _sym_list, ac, ap);

		delete ap;
	}
}
void wrappedClass_anything(WrappedInstancePtr self, SymbolPtr s, AtomCount argc, AtomPtr argv)
{
	if (argc && argv) {
		TTValue	v;
		
		v.setSize(argc);
		for (AtomCount i=0; i<argc; i++) {
			if (atom_gettype(argv+i) == A_LONG)
				v.set(i, AtomGetInt(argv+i));
			else if (atom_gettype(argv+i) == A_FLOAT)
				v.set(i, atom_getfloat(argv+i));
			else if (atom_gettype(argv+i) == A_SYM)
				v.set(i, TT(atom_getsym(argv+i)->s_name));
			else
				object_error(SELF, "bad type for message arg");
		}
		self->audioGraphObject->mUnitGenerator->sendMessage(TT(s->s_name), v);
		
		// process the returned value for the dumpout outlet
		{
			AtomCount	ac = v.getSize();

			if (ac) {
				AtomPtr		av = (AtomPtr)malloc(sizeof(Atom) * ac);
				
				for (AtomCount i=0; i<ac; i++) {
					if (v.getType() == kTypeSymbol){
						TTSymbolPtr ttSym = NULL;
						v.get(i, &ttSym);
						atom_setsym(av+i, gensym((char*)ttSym->getCString()));
					}
					else if (v.getType() == kTypeFloat32 || v.getType() == kTypeFloat64) {
						TTFloat64 f = 0.0;
						v.get(i, f);
						atom_setfloat(av+i, f);
					}
					else {
						TTInt32 l = 0;
						v.get(i, l);
						atom_setfloat(av+i, l);
					}
				}
				object_obex_dumpout(self, s, ac, av);
			}
		}
	}
	else
		self->audioGraphObject->mUnitGenerator->sendMessage(TT(s->s_name));
}
Example #5
0
NSPStatus 
Namespace::namespaceDisplay(void)
{
	unsigned int i;
	TTValue hk;
	TTSymbolPtr key;

	if (NSPDirectory) {	
		NSPDirectory->getDirectory()->getKeys(hk);

		for (i = 0; i < NSPDirectory->getDirectory()->getSize(); i++) {
			hk.get(i,(TTSymbol**)&key);
			TTLogMessage("%s\n",key->getCString());
		}

		return NSP_NO_ERROR;
	}
	
	//TTLogMessage("NSPDirectory_dump : create a directory before");
	return NSP_INIT_ERROR;
}
Example #6
0
void addAttributeToXml(TTObjectPtr param, XMLNode xmlNode, TTSymbolPtr attrName)
{
	TTValue		v, vDescr;
	TTString	s;
	TTSymbolPtr descr;

	// get the Value of an attribute and format to string
	v.clear();
	param->getAttributeValue(attrName, v);

	param->getAttributeValue(kTTSym_description, vDescr);
	vDescr.get(0, &descr);
 
	if (attrName == kTTSym_type && descr == TTSymbol("filepath")) {
		xmlNode.addAttribute_(attrName->getCString(), "filepath");
	} else {
		v.toString();
		v.get(0, s);
		// add this attribute in xml tree
		xmlNode.addAttribute_(attrName->getCString(), s.data());
	}
}
t_max_err wrappedClass_attrGet(WrappedInstancePtr self, ObjectPtr attr, AtomCount* argc, AtomPtr* argv)
{
	SymbolPtr	attrName = (SymbolPtr)object_method(attr, _sym_getname);
	TTValue		v;
	AtomCount	i;
	TTSymbolPtr	ttAttrName = NULL;
	MaxErr		err;
	
	err = hashtab_lookup(self->wrappedClassDefinition->maxAttrNamesToTTAttrNames, attrName, (ObjectPtr*)&ttAttrName);
	if (err)
		return err;

	self->audioGraphObject->mUnitGenerator->getAttributeValue(ttAttrName, v);

	*argc = v.getSize();
	if (!(*argv)) // otherwise use memory passed in
		*argv = (t_atom *)sysmem_newptr(sizeof(t_atom) * v.getSize());

	for (i=0; i<v.getSize(); i++) {
		if(v.getType(i) == kTypeFloat32 || v.getType(i) == kTypeFloat64){
			TTFloat64	value;
			v.get(i, value);
			atom_setfloat(*argv+i, value);
		}
		else if(v.getType(i) == kTypeSymbol){
			TTSymbolPtr	value = NULL;
			v.get(i, &value);
			atom_setsym(*argv+i, gensym((char*)value->getCString()));
		}
		else{	// assume int
			TTInt32		value;
			v.get(i, value);
			atom_setlong(*argv+i, value);
		}
	}	
	return MAX_ERR_NONE;
}
TTErr wrapAsMaxAudioGraph(TTSymbolPtr ttClassName, char* maxClassName, WrappedClassPtr* c, WrappedClassOptionsPtr options)
{
	TTObject*		o = NULL;
	TTValue			v;
	TTUInt16		numChannels = 1;
	WrappedClass*	wrappedMaxClass = NULL;

	common_symbols_init();
	TTAudioGraphInit();
	
	if(!wrappedMaxClasses)
		wrappedMaxClasses = hashtab_new(0);
	
	wrappedMaxClass = new WrappedClass;
	wrappedMaxClass->maxClassName = gensym(maxClassName);
	wrappedMaxClass->maxClass = class_new(	maxClassName, 
											(method)wrappedClass_new, 
											(method)wrappedClass_free, 
											sizeof(WrappedInstance), 
											(method)0L, 
											A_GIMME, 
											0);
	wrappedMaxClass->ttClassName = ttClassName;
	wrappedMaxClass->validityCheck = NULL;
	wrappedMaxClass->validityCheckArgument = NULL;
	wrappedMaxClass->options = options;
	wrappedMaxClass->maxAttrNamesToTTAttrNames = hashtab_new(0);
	
	// Create a temporary instance of the class so that we can query it.
	TTObjectInstantiate(ttClassName, &o, numChannels);

	o->getMessageNames(v);
	for(TTUInt16 i=0; i<v.getSize(); i++){
		TTSymbolPtr			name = NULL;
		
		v.get(i, &name);
		if(name == TT("updateMaxNumChannels") || name == TT("updateSr"))
			continue;	// don't expose these attributes to Max users

		class_addmethod(wrappedMaxClass->maxClass, (method)wrappedClass_anything, (char*)name->getCString(), A_GIMME, 0);
	}
	
	o->getAttributeNames(v);
	for (TTUInt16 i=0; i<v.getSize(); i++) {
		TTSymbolPtr		name = NULL;
		TTAttributePtr	attr = NULL;
		SymbolPtr		maxType = _sym_long;
		TTCString		nameCString = NULL;
		SymbolPtr		nameMaxSymbol = NULL;
		TTUInt32		nameSize = 0;
		
		v.get(i, &name);
		if(name == TT("maxNumChannels") || name == TT("processInPlace"))
			continue;	// don't expose these attributes to Max users
		
		o->findAttribute(name, &attr);
		
		if (attr->type == kTypeFloat32)
			maxType = _sym_float32;
		else if (attr->type == kTypeFloat64)
			maxType = _sym_float64;
		else if (attr->type == kTypeSymbol || attr->type == kTypeString)
			maxType = _sym_symbol;
		
		// convert first letter to lower-case if it isn't already
		nameSize = name->getString().length();
		nameCString = new char[nameSize+1];
		strncpy_zero(nameCString, name->getCString(), nameSize+1);
		if (nameCString[0]>64 && nameCString[0]<91)
			nameCString[0] += 32;
		nameMaxSymbol = gensym(nameCString);
		
		hashtab_store(wrappedMaxClass->maxAttrNamesToTTAttrNames, nameMaxSymbol, ObjectPtr(name));
		class_addattr(wrappedMaxClass->maxClass, attr_offset_new(nameCString, maxType, 0, (method)wrappedClass_attrGet, (method)wrappedClass_attrSet, NULL));
		
		// Add display styles for the Max 5 inspector
		if (attr->type == kTypeBoolean)
			CLASS_ATTR_STYLE(wrappedMaxClass->maxClass, (char*)name->getCString(), 0, "onoff");
		if (name == TT("fontFace"))
			CLASS_ATTR_STYLE(wrappedMaxClass->maxClass,	"fontFace", 0, "font");
	}
	
	TTObjectRelease(&o);
	
	class_addmethod(wrappedMaxClass->maxClass, (method)MaxAudioGraphReset,		"audio.reset",		A_CANT, 0);
	class_addmethod(wrappedMaxClass->maxClass, (method)MaxAudioGraphSetup,		"audio.setup",		A_CANT, 0);
	class_addmethod(wrappedMaxClass->maxClass, (method)MaxAudioGraphConnect,		"audio.connect",	A_OBJ, A_LONG, 0);
    class_addmethod(wrappedMaxClass->maxClass, (method)object_obex_dumpout, 	"dumpout",				A_CANT, 0); 
	class_addmethod(wrappedMaxClass->maxClass, (method)wrappedClass_assist, 	"assist",				A_CANT, 0L);
	class_addmethod(wrappedMaxClass->maxClass, (method)stdinletinfo,			"inletinfo",			A_CANT, 0);
	
	class_register(_sym_box, wrappedMaxClass->maxClass);
	if (c)
		*c = wrappedMaxClass;
	
	hashtab_store(wrappedMaxClasses, wrappedMaxClass->maxClassName, ObjectPtr(wrappedMaxClass));
	return kTTErrNone;
}