From: Norbert S. <Nor...@ir...> - 2012-11-17 19:52:28
|
Hi Alexander, On 17 Nov 2012, at 16:26, Alexander Droste wrote: > Hi everyone, > > in a previous mail the ways of getting a ref of a fts object to a c external were already named. > - sending them in a message to your external > - giving them as arguments (like $myfmat $yourfmat) of your external > - obtaining them from the current "FTM scope" > > Now I'd like to know how one of these ways can be realised in detail. Ok, here are some hints for the three options. ________________________________ OPTION 1 Using the FTMEXT API, external arguments (symbols) starting with $ are automatically transformed from the $-lead name into references to FTM objects – a special FTM-only type of atoms – that can be retrieved with the functions fts_is_object(argv) and fts_get_object(argv). FTM hereby assures the reinstantiation of an external whenever the definition of a name (by ftm.object) that it depends of changes – in local or global scope. The function fts_get_object() returns a pointer to an FTM object (fts_object_t *). ________________________________ OPTION 2 Incoming messages also can include these special atoms and you can apply the same functions also directly to the arguments of a message defined with A_GIMME. This is the easiest, but far from the most elegant solution. The FTM name ($myobj) in this case is typically resolved by the FTM message box where you compose the message that you send to your external. ________________________________ OPTION 3 For the third option you need the pointer to the patcher of your object: - fts_scope_t *maxpat_get_scope(t_object *pat) ... returns the FTM scope of a given Max patcher (ftmexternals.h) - fts_hashtable_t *fts_scope_get_values(fts_scope_t *scope) ... returns an hashtable with the names defined in this scope (ftmexternals.h) - fts_hashtable_get( const fts_hashtable_t *self, const fts_atom_t *key, fts_atom_t *value) ... gives you an atom bound to a name by ftm.object (hashtable.h) - fts_object_t *atom.h: fts_object_t *fts_get_object(const fts_atom_t *atom) ... returns a pointer to the FTM object of the atom as mentioned above (atom.h) ... and than you can inspect your object. BUT: you must do this in the right moment AFTER the definition of the name by ftm.object. SO: You have to implement a listener callback: - void my_name_callback(void *listener, fts_symbol_t name); ... and install a listener (namedef.h) using: - void fts_name_add_listener(fts_scope_t *patcher, fts_symbol_t name, void *listener, fts_name_listener_callback_t callback) This listener is called as soon as the ftm.object defines the name and each time the name is redefined or removed. In the callback you retrieve your object defined by an ftm.object using the sequence of functions given above. I hope one of that works for you. > To give some background information: The patches where I would like to get the refs contain a static constellation of objects. > All of these patches contain a ref collector-object which collects the references of the objects needed. > At the moment this ref collection is limited to standart max types which I get through iteration in the patch identifying them by scripting name. > This iteration is done with a standart (non-ftm) max external but my xcode project is succesfully linked against the ftm-sdk2.6 so if needed i could switch that. > > Since all required objects are in the same patcher maybe "FTM scope" sounds like a good option > or would it be a lot easier to build the external as a ftm external and give them as arguments? > > In detail I need refs to fmats, mats Ok, until here with the above options. > and ftm.messages, ftm.editors. These are themselves standard (well, sort of) Max externals and not FTM object such as instances of fmat, mat, dict etc. As far as I remember, you can find examples in the Max SDK showing how to get the Max externals of a particular patcher. > Can the last two also be obtained through iteration and scripting name or is it advisable to do it another way? Should work, I guess, but evidently the scripting names have nothing to do with the FTM names... > With ftm.message I only would like to be able to set the string/symbol.(like it can be done in max with #set xy) > So the plan is to get the pointer and then send the "#set" message to the ftm.message object. > Getting a pointer to an editor I hope it is possible to get, set values of attributes, namely: (choose view) interface, (view shape) shape. > Can it be done like with standart max objects with s.th like: object_attr_getvalueof, object_attr_setvalueof ? Probably. > What is not essentially required but would come in handy would be to set the track refs in an editor from an external. Is that possible? Sure you just have to send it an appropriate Max message using the Max API. There is also an fts_set_object(t_atom *atom, fts_object_t *obj) to set a (message) argument to the special FTM-only object atom type. Hope that helps. Cheers Norbert |