my plugin generates Midi messages to output to a physical Midi output.
To do so, I use a public MidiBuffer to what I add all the messages to output and let a
background thread then swaps this public MidiBuffer with the background
thread its private MidiBuffer. Then the thread iterates that private buffer to sends its messages
to the physical output and clears the public MidiBuffer afterwards.
Since I also have to THRU incoming Midi events, another thread (Midi input callback) is involved
and will probably add some incoming events to the public MidiBuffer while
this buffer is being iterated or cleared or swapped. Aslo the user will probably add Midimessages
to the buffer at the same time when he drag a slider of the UI.
So I have to make the whole thing thread safe….
Can’t use MidiMessageCollector here (which has thread safe methods) because Non Realtime Messages
i.e. Sysex can go to the MidiBuffer as well.
My first idea was to create my own buffer class inherited from MidiBuffer and Critical Section
because I read in another C++ forum that this is a possible way.
What does the Juce experts say about this? Is it a common way or rather a stupid thing to do
and if so, would you please point me to the right way?