C SDK: how to provide multiple objects from one external code base?

Iain Duncan's icon

Hi Max hackers, I'm trying to add a UI object to Scheme for Max. It's dependent on s4m, and shares a global (or module level) hashtable declared and created in s4m. I'm stuck figuring out how to share code between two different object classes that I'm providing. I've tried putting it all in one file, with the ext_main setting up two separate classes. This seems to compile fine, but when I run it, the second class is not detected - if I try to make an s4mgrid object, I get the "no such object" error message.

I would prefer to add this object from the s4m external code base as it makes no sense for it to be installed without s4m there, but I haven't found any good examples on how to do this. If anyone has done something similar and can help, or tell me a better way to go about it, that would be most appreciated!

11OLSEN's icon

Hi, did you find a solution? Facing the same problem while trying to create an object that contains multiple UI objects. It has to be possible as for example all live.UI objects are combined in live.guilib.mxe.

So my main looks like this:

        //######### 1st obj
    
    t_class* c;
    c = class_new("obj1", (method)obj1_new, (method)obj1_free, sizeof(t_obj1), 0L, A_GIMME, 0);
    c->c_flags |= CLASS_FLAG_NEWDICTIONARY;
    jbox_initclass(c, 0); //JBOX_FIXWIDTH | JBOX_COLOR
    
    //add obj1 methods ...
 
    CLASS_ATTR_DEFAULT(c, "patching_rect", 0, "0. 0. 20. 20.");
    class_register(CLASS_BOX, c);
    s_obj1_class = c;
    
    //######### 2nd obj
    
    t_class *d;
    d = class_new("obj2", (method)obj2_new, (method)obj2_free, sizeof(t_obj1), 0L, A_GIMME, 0);
    
    d->c_flags |= CLASS_FLAG_NEWDICTIONARY;
    jbox_initclass(d, 0); //JBOX_FIXWIDTH | JBOX_COLOR
    
    //obj2 methods ...
    
    CLASS_ATTR_DEFAULT(d, "patching_rect", 0, "0. 0. 20. 20.");
    class_register(CLASS_BOX, d);
    s_obj2_class = d;
    
11OLSEN's icon

I have done it before and don't see the difference except that these are both UI boxes.?

11OLSEN's icon

Ok, it seems that if one class name of the created objects matches the source file name it works for now, but I would still like to know how to do it independently.

Edit: No, still only one name works to call this main, only after that I can create instances of the other obj. So how do we register multiple names for an object before the main() has even been called by Max.?

Iain Duncan's icon

Hi I did get it to work by making a Max extension. I can't recall the details as it was a year ago, but you are welcome to look at my source! https://github.com/iainctduncan/scheme-for-max