I’m working on a project that reads MIDI-data from an external USB-device. I don’t want to get too specific here, but this is roughly how it looks like:
I’ve got all my incoming MIDI-events stacked inside an object, let’s call it “in”. Now, to get the next MIDI-event from the stack, I first have to check if “in” has at least one event on the stack using a member function.
Is there a way to automatically process all the events on the stack as soon as there are new ones, without having to check everytime?
I’m thinking of something similar to an event-listener (sorry if this sounds stupid, I’m a beginner).
When your are using stack the code may look like:
Instead of using the stack as a communication queue the producer can keep a pointer to the consumer (callback interface) and push the event directly to consumer like this:
Boost.signals library is designed for this kind of problem and has a nice tutorial on the subject.