template< class T >
T* createParamWithMyBinding(rack::Vec v, MyModuleClass * m, paramId )
{
Auto res = createParam<T>(v,m,id);
Res->doMyCustomStuff(m); // no static cast needed
Return res;
}
Where MyModuleClass is - well - your module class or (probably more pragmatically if you are writing multiple modules) a subclass of engine::Module which you then subclass to make all your modules.
Void step() {
MyModule *m = static_cast<MyModule *>(module);
If( m && m->flag )
{
// do whatever it is you want
}
}
If you do that enough you will probably want a class you put in your inheritance hierarchy with some helper methods for widget only which could also contain a little inline function to do that for you so you could do
Void step() {
Auto m = asMyModule();
If( m && m->flag )
{
}
}
Ok, this seems to definitely resolve the situation, without external event emitter! Thanks dudes for your efforts and help Really appreciated.
Another fancy question: what if I also need (once I close/save patch) to save the status of some flags within each CustomKnob? I don’t see any to/from json override there.
As before, I’d like to avoid store the reference of each widget in an array and interate once I need (i.e. in the moment of de/serialization).
But in that case is different. I won’t have 1 flag shared across all widgets, but a specific flag on each widget to be stored.
For example, I could have 20 Knobs, each with a bool flag “selected”, that can be true or false differently in each widget. Once I reopen the patch, I need to restore, on each widget, its state.
Sounds more (again) a sort of “array” of parameters… which I’d like to avoid.
I‘m not sure how to avoid that, when you have 20 widgets you’ll need some sort of array.
I‘d give each widget some sort of id, with that id each widget can look at module->flags[id] for its own flag.
Besides that, I guess each knob is bound to a parameter of the module and these are stored to the patchfile by Rack, you don’t need to save parameters yourself.
Yeah so it really seems that your desire to not store stuff on the module is adding complexity. The answer here is “the nodule is the thing that streams so get your data onto it”.
Perhaps you could outline why you want to approach the problem without referencing either members on your module or params?
But you are correct there is no to/from Json on the widgets. The widgets are (logically) stateless idempotent renders and editors of the module state by design.
So can you sketch out the problem you want to solve?