Creating A Callback to Process Raw Data to Midi

What JUCE class would be best to use to give myself a loop or callback that continuously processes some data?

Overview of my Goal

I have an external controller that will input raw data (not MIDI) into my application via a 3rd party API. I want my application to take this raw data and turn it into MIDI Messages to send to a MidiOuptut that can be accessed by my DAW.
In my MainComponent I need some kind of callback that will continuously pull in the raw data from the controller, convert it, and send it to a MidiOutput.

Potential Solutions

I see that Timer works on the Message Thread and could potentially be blocked, so I don’t think I should use that.
I also see HighResolutionTimer, which seems promising since it’s running its own threads to achieve the callback. I’d just implement the callback to process my data.
My other option could be the Thread class. And I guess I would just set it to be a high priority thread and then implement the run() function to process my data.

Would the HighResolutionTimer or Thread classes be what I am looking for? Or is there a different class better suited to this?

Also, Merry Christmas!

On what socket is your controller hooked to?

If it is an ethernet connection, have a look at InterProcessConnection. It also works on named pipes.

It might not be what you are looking for out of the box, because it expects each packet to start with a magic number and the packet size, but you can get inpsiration in their source code…

Or there is OSCReceiver to receive UDP packets.

They all work about like you described, spawn a thread to poll for input and call a callback on a listener interface. In InterProcessConnection you can even define, if your callback is called on the polling or the message thread, which is very handy…

1 Like