write external to access data without patch cords

    Devadvanced

    b woods
    Apr 03 2023 | 4:01 pm
    Can anyone help me understand how to most efficiently share float data across externals and other Max-native objects without using patch cords? I am trying to write an external to access/receive/retrieve data (viz., a float array) from other objects without connecting with patch cords. I have been reading various versions of the API documentation and different forum posts and SDK examples and believe there may be several ways to do this (using, for instance, tables or attributes or dictionaries or the send/receive or pattr or coll systems) but as a beginner (and more a C than C++ writer) I find the documentation to be more of a reference than a how-to and thus the nuts-and-bolts of implementing this elude me. For instance, I see info on "getter and setter" functions and "getvalueof and setvalueof" functions but how would my external object find the pointer or name or handle or symbol to allow it to access data in another object? Do I need to write my own "MakeDictionary" object so that I can a priori set the name and "register" it, then write another external to access that object's registered dictionary? Any help with this would be much appreciated. Cheers.

    • 11OLSEN's icon
      11OLSEN
      Apr 03 2023 | 7:27 pm
      that kind of general question is harder to answer than a specific problem you are facing. Dicts always have a global name no matter if it's created in a patcher or inside your external. There's a dict section in the sdk doc to find out which methods to use. Once created (registered) any other external or [dict] in a patcher can also access the same dict. The easiest way to get a handle to any other object (not a dict) in a patcher is to assign a scripting name to it and:
      t_object* jp;
      
      // get patcher containing your external
      object_obex_lookup(x, gensym("#P"), (t_object**)&jp);
      //find obj by scrpt name
      t_object* yourTarget = (t_object*)object_method(jp, gensym("getnamedbox"), gensym("theName"));
      //now you have a handle for the box, to get the contained object:
      t_object* targetObj = jbox_get_object(yourTarget);
      with the handle you can then use getvalueof method (UI objects) or access attributes. But again you can't expect someone answering with an essay about all topics that you touch on in your question. In general dicts are a good way to share data between externals, I think you don't even have to worry about thread safety with them.
      Share
    • b woods's icon
      b woods's icon
      b woods
      Apr 06 2023 | 4:19 pm
      Thanks, 110L532. I kept on searching through the forums and found the answer in this one. Not sure how I missed it, but there is code for this in the examples that come with the SDK. It is under the "misc" folder and comprises the "master" and "servant" routines. I was able to modify their _anything and _notify routines to send a float array pointer from the master to the servant.