Cycling74 / min-devkit

Tools, documentation, and reference implementation of a Max Package built using the Min-API.
MIT License
158 stars 31 forks source link

Objects in 'extensions' folder are not instantiated at Max startup #129

Closed pixsperdavid closed 5 years ago

tap commented 5 years ago

For context see #128

tap commented 5 years ago

It's true that objects are in extensions have their classes registered but that they are not instantiated.

I haven't tried this (yet) but it seems like you could instantiate an instance after the MIN_EXTERNAL macro call at the bottom of your source file?

tap commented 5 years ago

Actually, here is the solution I've used in another extension...

class sampler_extension;
static minwrap<sampler_extension>* s_sampler_extension_instance {};

static symbol s_global_sampler { "global_sampler" };

class sampler_extension : public object<sampler_extension>
{

...

private:
    message<> maxclass_setup = { this, "maxclass_setup", MIN_FUNCTION {
        s_sampler_extension_instance = (minwrap<sampler_extension>*)c74::max::object_new_typed(symbol("nobox"), symbol("sampler.extension"), 0, nullptr);
        s_global_sampler = s_sampler_extension_instance->maxobj();
        return {};
    }};
};

MIN_EXTERNAL(sampler_extension);
pixsperdavid commented 5 years ago

Thanks Tim. Looking back at the source code of my old extension objects (using the C API), I was mistaken in thinking the class was being instantiated automatically, I had actually made the instantiation the responsibility of the connecting objects.

Closing the issue as this the behaviour is the same as the previous API.