Overloading the getNextAudioBlock to receive incoming midi

I have a GUI standalone application that inherits from the AudioAppComponent class.

I want the incoming midi to be processed together with the audio, however the getNextAudioBlock method only takes the audio buffer i.e. " void MainComponent::getNextAudioBlock(const juce::AudioSourceChannelInfo& bufferToFill) . "

I have already set up a midiInput instance and the midiInputCallback, so when i trigger any midi note, i receive a message with the " void MainComponent::handleIncomingMidiMessage(juce::MidiInput source, const juce::MidiMessage& message)* " method.

how can i pass the midi event data inside the audio block?

You need to use the MidiMessageCollector as an intermediary object between the MIDI callback and the audio callback.

1 Like

Thanks a lot. Got it to work.

Wondering… how could you got to know that?

Is there something I could do to know faster what class or method I need to get in order to achieve a desired goal??

I’m pretty new to Juce and C++ however, I’m planning to use this framework to build solutions and applications in the long run.

The JUCE docs are a useful resource.

You can search by module:


Or, for example, enter “midi” in the search box, which will take you to “midi_io”:


…where you will see:

class MidiMessageCollector
Collects incoming realtime MIDI messages and turns them into blocks suitable for processing by a block-based audio callback.

True! Thank you!