Trouble understanding how to send generated midi messages


Having as base the plugin JUCE template from projucer i want to generate a midi message in PluginEditor (on a button click for example) and send it out to wherever my plugin is connected to, making it sort of like the built in juce::MidiKeyboard.

From what i understood all messages pass in PluginAudioProcessor::processBlock, but i wasn’t able to see any message.

Generating midi message

auto message = juce::MidiMessage::noteOn (10, 60, (juce::uint8) 100);

Declared in Editor header:

juce::MidiBuffer midibuffer;
PluginAudioProcessor& audioProcessor;

My processBlock:

void PluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)

    for (const auto metadata : midiMessages)
        const auto msg = metadata.getMessage();
        if      (msg.isNoteOn()){
            DBG("note on!");

My questions are:

  • how does processBlock know a message was generated in a child component
  • if i should use the midibuffer where should it be declared
  • how does juce output these internally generated midi messages since it has no definite “sendmidi(message)” type of command.

I am not concerned about the duration or handling, my goal with this example is to just send a midi note of type ‘on’ and be able to pass it to somewhere (ie. using Audio Plugin Host)

1 Like

It doesn’t, unless you pass that information yourself. The normal way to do this is to have something like a separate midi buffer in the processor that the editor adds to. This can be a bit tricky to write, because the processBlock call will happen on a different thread to callbacks from the editor, so you’ll need to think carefully about thread safety.

Whatever you decide to use, you will probably need to add it to the AudioProcessor. The Editor will have a reference back to the Processor, and so will be able to access the buffer (or alternative) too.

Any messages left in the midi buffer after the call to processBlock finishes are assumed to be the AudioProcessor’s MIDI output.

I’d recommend looking at the AudioPluginDemo to see one approach for sending MIDI messages from a plugin’s editor. This demo’s editor contains a MIDI keyboard that can be used to send MIDI events.


Hello reuk thank you so much for the reply.
I indeed looked at the Demo you referenced and i was left wondering if i can use only the juce::MidiKeyboardState to handle these inputs with the noteOn() and addEvent().

I guess i have to study a little bit more, even tough the Demo is detailed is filled with stuff i dont need and it gets hard to track how everything works on a single overwhelming header file.