TTErr TTObjectBase::extendAttribute(const TTSymbol name, const TTObjectBasePtr extendedObject, const TTSymbol extendedName) { TTAttributePtr extendedAttribute = NULL; TTAttributePtr newAttribute; TTErr err = extendedObject->findAttribute(extendedName, &extendedAttribute); if (!err) { newAttribute = new TTAttribute(extendedAttribute, extendedObject); attributes->append(name, TTPtr(newAttribute)); return kTTErrNone; } else return err; }
TTErr wrapAsMaxGraph(TTSymbol& ttClassName, char* maxClassName, WrappedClassPtr* c, WrappedClassOptionsPtr options) { TTObjectBasePtr o = NULL; TTValue v; TTUInt16 numChannels = 1; WrappedClass* wrappedMaxClass = NULL; TTSymbol name; TTCString nameCString = NULL; t_symbol* nameMaxSymbol = NULL; TTUInt32 nameSize = 0; common_symbols_init(); TTGraphInit(); 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->maxNamesToTTNames = hashtab_new(0); // Create a temporary instance of the class so that we can query it. TTObjectBaseInstantiate(ttClassName, &o, numChannels); o->getMessageNames(v); for (TTUInt16 i=0; i<v.size(); i++) { name = v[i]; nameSize = strlen(name.c_str()); nameCString = new char[nameSize+1]; strncpy_zero(nameCString, name.c_str(), nameSize+1); nameMaxSymbol = gensym(nameCString); hashtab_store(wrappedMaxClass->maxNamesToTTNames, nameMaxSymbol, (t_object*)name.rawpointer()); class_addmethod(wrappedMaxClass->maxClass, (method)wrappedClass_anything, nameCString, A_GIMME, 0); delete nameCString; nameCString = NULL; } o->getAttributeNames(v); for (TTUInt16 i=0; i<v.size(); i++) { TTAttributePtr attr = NULL; t_symbol* maxType = _sym_long; name = v[i]; nameSize = strlen(name.c_str()); nameCString = new char[nameSize+1]; strncpy_zero(nameCString, name.c_str(), nameSize+1); nameMaxSymbol = gensym(nameCString); if (name == TT("MaxNumChannels")) continue; // don't expose these attributes to Max users if (name == TT("Bypass")) { if (wrappedMaxClass->options && !wrappedMaxClass->options->lookup(TT("generator"), v)) continue; // generators don't have inputs, and so don't really provide a bypass } 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; hashtab_store(wrappedMaxClass->maxNamesToTTNames, nameMaxSymbol, (t_object*)name.rawpointer()); class_addattr(wrappedMaxClass->maxClass, attr_offset_new(nameCString, maxType, 0, (method)wrappedClass_attrGet, (method)wrappedClass_attrSet, 0)); // Add display styles for the Max 5 inspector if (attr->type == kTypeBoolean) CLASS_ATTR_STYLE(wrappedMaxClass->maxClass, (char*)name.c_str(), 0, "onoff"); if (name == TT("fontFace")) CLASS_ATTR_STYLE(wrappedMaxClass->maxClass, "fontFace", 0, "font"); delete nameCString; nameCString = NULL; } TTObjectBaseRelease(&o); class_addmethod(wrappedMaxClass->maxClass, (method)MaxGraphReset, "graph.reset", A_CANT, 0); class_addmethod(wrappedMaxClass->maxClass, (method)MaxGraphSetup, "graph.setup", A_CANT, 0); class_addmethod(wrappedMaxClass->maxClass, (method)MaxGraphConnect, "graph.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, (t_object*)wrappedMaxClass); return kTTErrNone; }