How to get the ofParameter from the ofEvent of parameterChangedE()

How can I get the related ofParameter from the ofAbstractParameter created by the ofParameterGroup.parameterChangedE() when i add a eventListener in the event method?
Yeai straight question so let’s break it up.
ofAddListener(ParametersClass.parameterChangedE(),this,&ofApp::guiEvent);
and then
ofApp::guiEvent(ofAbstractParameter &e){}
in the guiEvent there will be the call to my oscSender class and i have about 15 different ofParameterGroups in this call and i don’t want to write for every group the same method again.

So my solution is to use ofAbstractParameter.toString() and then convert it back to int/bool/float.
But this gets difficult with ofVec2f and ofColor.
I could also Group all ofParameters that i use to one Group and do a search in there with the .getBool(name) but i think this is cpu-intense and unnecessary.
Is there another way to implement this or can we add a function to ofParameterGroup which sends the ofParameter?

this is a limitation of c++ where there’s no introspection or similar mechanism. the only way to do this is to check explicitly for every type and convert it to that type like:

ofApp::guiEvent(ofAbstractParameter &e){
    if(e.type() == typeid(ofParatemer<int>).name()){
        ofParameter<int> p = e.cast<int>();
        ...
    }else if(e.type() == typeid(ofParameter<float>).name(){
        ofParameter<float> p = e.cast<float>();
        ...
    }else if(e.type() == typeid(ofParameter<ofVec3f>).name(){
        ofParameter<ofVec3f> p = e.cast<ofVec3f>();
        ...
    }
    ...

4 Likes

Thanks a lot, this reduces my code around 1000 lines :grinning: