Outputting Midi according to UI animation


Im designing a plugin that will output Midi. Instead of accepting a Midi input from a controller I would like the midi note on and midi note values to come from with the code it self. My plugin has an animation of moving circles drawn to its UI, when the circles collide with each other I would like this event to trigger a note on and send a note value to be outputted to the DAW.

I have no previous experience with the Midi buffer, and Im finding it difficult to deduce exactly how to go implementing my idea going by the existing documentation. I found this video helpful.

This code from the video seems like a good jumping off point, even if its specificly an example that is needs Midi input from a controller.

void Mandelbrot_pluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
    processedBuffer.clear(); // processedBuffer is separate instance of the MidiBufffer class
    juce::MidiBuffer::Iterator it(midiMessages);
    juce::MidiMessage currentMessage;
    int samplePos;
    while (it.getNextEvent(currentMessage, samplePos))
        if (currentMessage.isNoteOnOrOff())
        processedBuffer.addEvent(currentMessage, samplePos);

In my code, inside my pluginEditor.cpp Iā€™m handling all the positions and logic of the colliding circles inside a timerCallback method, when two of the circles collide a method returns a value, I would like to send this value as a midi note message paired with a note on message to the MidiBuffer inside the process block.

So my two questions are. How might I get the desired midi note value / note on trigger sent to the MidiBuffer from the pluginEditor.cpp? And is the code above in the right ball park for what Im trying to achieve?

1 Like