Hello all,

I still dont know exactly the right way to code the midiInputCallback. Here’s basically my small program

int main()
MidiInput* piano;
MidiInputCallback* pianoMessages;
piano = MidiInput::openDevice(2, pianoMessages);

//Start listening for midi messages from the piano
piano ->start();


void handleIncomingMidiMessage(MidiInput* source,const MidiMessage& m){

According to my understanding, the handleIncomingMidimessage function is automatically called whenever input is recieved from our midiInput. But according to documentation my midiInputcallBack pianomessages should be the one that gets the input , so how is it related to the handleIncomingMidimessage fucntion? did i code it correctly

can anyone help me fix this small piece of code so it could read events correclty.



Create a subclass of MidiInputCallback, and pass that to the input! This is all very basic c++ stuff, so sorry if I’ve no time to walk you through it!


So my inner class has to be named MidiInputcallback and the function handleIncomingmessage should be declared inside it?

is it possible if u provide a template about the structure of the program?

thank you


are you familiar with sliders/buttons etc? with those you have Listener classes, which you subclass to allow you to respond to something. You don’t have to CALL your class SliderListener to listen to a Slider - you have to MAKE your class a SliderListener by inheritance.

It’s the same idea with MidiInputCallback. You want to respond to the messages somewhere - there’s no better place than inside a class of your own (as it can have various members to determine what should be done with the messages, or what other parts should be informed, etc…). So you make a class that IS a MidiInputCallback, and define the function handleIncomingMidiMessage to do what you want. You provide a pointer to the instance of this class that you wish to recieve the messages in the MidiInput::openDevice() function.

If all of what I’ve just said has still gone over your head, I suggest you read up on multiple inheritance, as it’s a pretty fundamental technique you will use thoroughly when coding with Juce! I can appreciate how the use of the word ‘callback’ in the class name may have confused you though.