Hello! I am struggling a little bit with Polymorphism. Trying to switch over my mind from Java still.
Here is how my classes are currently set up. (Please forgive the crude diagram)
I would love for there to be only one OSC Class. This class should only be setup once, since it is networking with other devices. In theory, I would love for my classes to look something like this.
Where ofApp can call the setup function of the OSC class, but the subclasses can also call functions in OSC.
I have the openFrameworks ball example downloaded, and I think the solution may involve polymorphism - but I am unsure if thatâs exactly what I need.
I have tried it so that the OSC class is in the GUI class, but that gives me issues with having the children talk back to the parent - which then talks to the OSC class.
What i would is to have a instance of âyour oscâ in ofApp at the same level as gui, and in those gui elements put a callback that you listen on ofApp and inside those callbacks you call your osc⌠hope that makes sense
So I am looking into this solution, however, I am still unsure how it works with multiple sub classes⌠Would that involve adding a listener per parent class?
Is only my opinion but i have the feeling that you are complicating things, sometimes i better to start from the begining⌠what you want to do? the schema you posted works perfectly with the option i told you.
I have an OSC class that holds all my setup and network functions. Currently (for example) my sliders all have different IDâs given to them in their setup. In the sliders.mouseMoved I have it calculating the output then sending a function to itâs child OSC class.
osc.sendShutter(ID, output)
I think I am having issues with understanding the events. Before, I had a similar solution without using listeners but was having issues of only wanting to call the osc function when that slider was moved. That is when I created multiple OSC sub-classes, but I am trying to get away from that now.
Except when I do this, the GUI Class gives me the error:
â9. In instantiation of function template specialization âofAddListener<ofEvent<float, std::__1::recursive_mutex>, std::__1::basic_string, GUI>â requested hereâ
I mean yes, it started out as a GUI but then has morphed. Probably need to refactor soon. Unfortunately, im away from the computer for a while and the code is messy (as you can probably guess). What would you say needs looking at so I know what to include?
I love using ofEventListener objects to do the listening. Since theyâre objects, theyâre destroyed when they go out of scope, and you donât have to delete the listener like with ofAddListener. You can use lambda functions with ofEventListener, and Iâm thinking that the lambda can capture multiple arguments to pass to its function. If you capture ofParamter types, they have to be const if I remember correctly.