Replies: 8 comments 6 replies
-
I'm far from being a c/c++ expert but this is how we do it in our project. We handle the whole playstate ourselves... https://github.com/seisfeld/TonUINO/blob/60a75f9cb10261ba1296d2e75b43b470cbaebce4/tonuino.ino#L1307 and onwards for the function... Dunno if that is what you were looking for though (probably not ;)). Merry Xmas! |
Beta Was this translation helpful? Give feedback.
-
I'm escaping the static callback by using a message property along with a getter function - see here my unfinished project https://github.com/Schallbert/Tonuino_UseEncoder/blob/d46ef63dfb1776a93ee6e23ad03a5acae6b6c0aa/lib/Mp3/DfMiniMp3/DFMiniMp3_implementation.h#L80 Merry Christmas! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the input guys. There are various (I would call them work arounds) and I am also just using an external to escape the scope. I am basically wondering if there is a particular reason the original author went this way. But now - back to preparing the food for later :-) |
Beta Was this translation helpful? Give feedback.
-
This started as an "Issues", which it is not, and I moved it here to "Discussions" which it is. What do you mean by delegate approach? C++ does not inherently support delegates (unmanaged c++) so you have approach in mind, please provide the context; code snippet example of a use pattern. You need to understand the core goal of this library. Use as little memory and code space to achieve the functionality. This is due to being able to run on AVR Tiny model of chips with very little ram at all. Storing a context and/or callback takes memory. The template model used takes NO memory. If you the sketch writer want to consume the memory to make it cleaner, you can layer it to achieve it; but not every consumer of this library needs nor wants to do that. There are some interesting techniques using STL; but STL is not available on many Arduinos. |
Beta Was this translation helpful? Give feedback.
-
@Makuna I personally don't see as clear cut (see below) - but as you like.
There are many ways https://stackoverflow.com/questions/9568150/what-is-a-c-delegate and I don't claim to know what is best in this situation. Seems like we all found ways around it. But it would be great to have an example where the notifications are handled more on an instance level and not in the static scope. Just imagine how you would approach multiple players per system. Maybe consider this a feature request to expand the examples. |
Beta Was this translation helpful? Give feedback.
-
@tcurdt On the quick topic of Issues versus Discussions. This has always been problematic for users to understand, but "issues" is meant for what I will call "BUGS" as most people understand that term more clearly. They are not questions, but a clear "this is wrong with the code", and include ALL the details to reproduce and what is expected. Note I stated "code", not design of code or API which is relative/opinionated. Now back to this topic: Now other techniques, like virtual functions also require the same pointer, but is hidden from user in the vtable which is RAM based. Originally in my first draft, you passed the callback as you called |
Beta Was this translation helpful? Give feedback.
-
This your view on issue tracking.
So how would you handle multiple players on a single system? |
Beta Was this translation helpful? Give feedback.
-
Did you find something that didn't work with multiple instances in a single sketch? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the library and Merry Xmas.
Maybe it's my C++ that got so rusty but why would you use the template approach and static callbacks for the notifications?
As far as I can tell this makes it very hard to escape the static scope of the notifier class.
Usage wise a normal delegation seems like a much more user friendly approach.
Maybe you could expand in the example how you imagine this to work?
To continue playing I would need to trigger the next track here:
https://github.com/Makuna/DFMiniMp3/blob/master/examples/PlayMp3/PlayMp3.ino#L45
but for me that's not available in that scope.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions