openAVproductions / openAV-Luppp

Luppp is a live performance tool, created by OpenAV productions.
http://openavproductions.com/luppp
GNU General Public License v3.0
258 stars 44 forks source link

Event made with templates #208

Closed georgkrause closed 6 years ago

georgkrause commented 6 years ago

@vale981

BTW. All those events could be created very nicely with templates.

I checked this. We could do this, but would need an templated class for the events but still one class per Event for the Information which should be transported because all events carry different information. I am not sure if this is really better, but I am just a nooby :D So lets discuss this ;)

vale981 commented 6 years ago

It looked like a lot of boilerplate to me. At least the getType() method could be done via templates. -> but hey, that wouldn't worth the hazzle.

But there were many subtle differences which i've overlooked :).

(I am even more of a nooby.)

One could just create data containers as events dynamically via a very terse syntax, but that's very complicated.

harryhaaren commented 6 years ago

The reason to use simple structs instead of C++ templates and fancy goodness is that the Event struct is POD (Plain Old Data). The exact binary layout of each event is known, and can be easily inspected. Try that with a C++ class that has virtual functions - it won't work. Templates might - but at the cost of complexity.

There is immense value in keeping it simple - for example, creating a Python wrapper to the POD data structures would be trivial - it may take effort, but it is simple, Python's CTypes module already provides the required parts.

If I was to re-work this, I'd take inspiration from the LV2 Atom infrastructure, and find a way to enhance that to be easier to use. (Long story short, you build up the Event struct dynamically using all high-performance data types like int float char, but it can be de-serialized back into human readable events easily). Dynamic events like that (if easy to use from the code) would enable us to add events new events with less effort - that would be nice.

I know message-passing "async" style coding can be hard - but it pays off because the DSP is known to be real-time safe, and assuming the design of the Events is sane, it scales pretty well...

Opinions and thoughts welcome - but so far I don't think there is sufficient value in changing from the current solution. The only thing I see as a worthy candidate is LV2 Atom type infrastructure, however that adds a lot of complexity for the dev right now :/

georgkrause commented 6 years ago

Some thoughts from me, please take with care.

  1. This isn't an urgent topic of Luppp, there are other Bugs and needed features, so we should not change if we could spend time better. I just looked into this because it was an idea to check and a nice way to get into the code.
  2. Currently i am reading the book "A tour of C++" from Bjarne Stroustrup and he says, since templates are "rendered" at compile time there are cheap at execution time. I don't know if there are any special aspects about this but i guess the change wouldn't add any costs.
vale981 commented 6 years ago

But templates would obfuscate the pod's. There wouldn't be a canonical way to easily know how the data types are structured.

georgkrause commented 6 years ago

Need to think about why, but nice input to learn. If i am getting this right, there is nothing to be changed no, so i am going to close this and keep learning. thank you both :)