is there a way to retrieve from inputs[] the TPortWidget type?

I’m doing some cable manipulation on the gui thread, iterating the std::vector<Input> inputs array of the Module.

Is there a way, from that array (or from list of PortWidget, if any) to understand which kind of PortWidget class type is? Because I’m inherit some Port class from standard:

struct MyNicePort : SvgPort {
	MyNicePort();
};

static_cast probably would work, since those objects won’t change at runtime.

Any clues? Thanks

You’ll need dynamic_cast to test the type. I’m on my phone at the moment, so I can’t tell if you can get from inputs to the widgets they’re bound to.

When I need to access widgets after construction. I usually keep a reference in the moduleWidget, but I’ll sometimes enumerate moduleWidget.children.

Also, keep in mind that there’s no ui, hence no ui thread or ModuleWidget when running Rack in headless mode.

1 Like

I’ll wait, no problem :slight_smile: Write later when you can, thanks.

I’m not finding a direct way to get from inputs to widgets that reference them, so you’re left with the methods I mentioned. Easiest to keep your own reference and not pay the cost of recursively iterating widget children. Plus you can keep the most-derived type pointer and not need to dynamic_cast.

1 Like

ModuleWidget has these three methods

 /** Scans children widgets recursively for a ParamWidget with the given paramId. */
        ParamWidget* getParam(int paramId);
        PortWidget* getInput(int portId);
        PortWidget* getOutput(int portId);

and you can see the core used to do the recursive scan if you want a more constrained type.

PortWidget* ModuleWidget::getInput(int portId) {
        return getFirstDescendantOfTypeWithCondition<PortWidget>(this, [&](PortWidget* pw) -> bool {
                return pw->type == engine::Port::INPUT && pw->portId == portId;
        });
}
2 Likes