Add MIDI Event to a plugin’s MIDI Input Buffer?

In a plugin, processBlock() is called with a MidiBuffer containing incoming MIDI events passed from the host.

I’m wondering if there is a way to add a Midi Event directly into this MidiBuffer so that processBlock() can process it same as any other incoming MIDI?

I can add MIDI Events into the buffer after it has already arrived, inside processBlock(), but I’m wondering if you can do it before it gets to processBlock().

what is the difference between doing it on entry and doing it before entry?

Let’s say, for example, I have a button that is to inject a chord of notes into the MIDI stream. I want to press the button, and add the notes into the MidiBuffer, so that when it arrives in processBlock(), it already contains them and the code there can handle it just like other incoming MIDI from a host.

EDIT: I guess I could put those events into a separate MidiBuffer, and then “merge” them at the head of processBlock, although that seems more work than just putting them in the incoming MidiBuffer - if that is possible…

it sounds like the work would be the same, just in a different place… and, as I said, I don’t think the other is possible. unless it were another plugin prior to yours which inserted the events (but, again, that is just moving the task). If you make a function (or lambda in processBlock) that takes a MidiBuffer, you could just call it twice, once with your buffer, and once with the incoming hosts buffer

I don’t think so, at least not without outputting MIDI (from the previous processBlock). That MIDI buffer is provided by the host just before calling our processBlock function (via the appropriate wrapper code), so there is no buffer for you to insert data into. Easier to just have your own buffer of MIDI data available to the Processor and process that in processBlock along with the given buffer. (Don’t see why you’d need to “merge” them, though. Why not just process one and then the other?)

Well, there’s already a bunch of code written that operates on the incoming MidiBuffer, so I don’t want to do that twice, or make a function out of it and operate it on two buffers; I just want the new events in the same buffer and do it once. :slight_smile:

You can’t get much simpler than void MidiBuffer::addEvents ( const MidiBuffer & otherBuffer, int startSample, int numSamples, int sampleDeltaToAdd )

2 Likes

Right… missed that for some reason. :flushed: Thanks!

1 Like