Integrating Tracktion Engine into another event loop

Hi, folks!

I would like to integrate the audio features of the Tracktion Engine into a Qt application. This is the code for the runDispatchLoop() method:

void MessageManager::runDispatchLoop()
{
    jassert (isThisTheMessageThread()); // must only be called by the message thread

    while (quitMessageReceived.get() == 0)
    {
        JUCE_TRY
        {
            if (! dispatchNextMessageOnSystemQueue (false))
                Thread::sleep (1);
        }
        JUCE_CATCH_EXCEPTION
    }
}

I couldn’t find any public method that would poll and dispatch the queued messages and then return, so I was wondering if something like:

void MessageManager::dispatchQueuedMessages()
{
    jassert (isThisTheMessageThread()); // must only be called by the message thread

    dispatchNextMessageOnSystemQueue (true);
}

would do the trick, because this way I could call that from my main Qt thread (or any other non-juce event loop really) and wouldn’t need to deal with the two different threads accessing the same set of data.

Thanks!

You shouldn’t need to run your own message loop, the Qt message loop should handle everything as long as you call initialiseJuce_GUI() / shutdownJuce_GUI() before / after using the engine.

Think of it kinda like a plugin, the host runs the message loop and the hidden juce window gets sent the messages it needs.

I haven’t tried it however, this is probably a use case we should test.

Well, I have just tried it and it works like a charm, sooo much simpler than I thought.

That makes sense.
Thanks a lot, @G-Mon!

1 Like