(
MessageManager::MessageBase::post() adds the object to a queue[inherited by CallbackMessage]
The MessageManager class will eventually find this object in the queue and call the IncomingMessageCallback::messageCallback() function on the message thread. Once this function has been called, the IncomingMessageCallback object will be deleted.
class IncomingMessageCallback : public juce::CallbackMessage
{
public:
IncomingMessageCallback (MainContentComponent* o, const juce::MidiMessage& m, const juce::String& s)
: owner (o), message (m), source (s)
{}
void messageCallback() override
{
if (owner != nullptr)
owner->addMessageToList (message, source); //below
}
Component::SafePointer<MainContentComponent> owner;
//automatically becomes null if the component is deleted. [must be component type]
juce::MidiMessage message;
juce::String source;
};
Didn’t know this existed - thanks!
Looks like the purpose of this is to be able to do GUI updates after receiving a MIDI message from an external device - if you try to update the GUI off the back of receiving a MIDI message you won’t be on the message thread which is not allowed, so this will get you onto the message thread where you can deal with the update.
I’ve been doing this using postCommandMessage() but this looks much cleaner.
an application has a “main thread” - this is often referred to as the message thread as it has a message pump on it that delivers messages in an event driven system. you can create other threads for async processing - one is created to handle incoming MIDI messages when you open a MIDI port. messages coming in on these “worker threads” need to be handled by the message thread if they’re to do GUI updates (amongst other things).