Sending MIDI from processBlock

In an attempt to debug my current project I’ve fallen back to a very simple test sending of notes out via Midi from inside processBlock :

Does this code look like it should work? And send messages to a synth listening on midi channel 1?

If not, what’s wrong with it?

if (rand() % 3000 < 50) {
int n = (rand()%12)+64;

Have you confirmed your host is configured correctly to process plugins that send out MIDI?

Actually the problem seems to be the noteOff.

If I send the messages without the noteOff, then it works as expected. But obviously all notes that are sent stay playing.

I think you need to keep track of the note offs separately, if the note off is supposed to happen past the current processing buffer length, it needs to be sent in a later processBlock call etc…



That’s a pain.

I am not very familiar with processing MIDI messages in JUCE, though, so maybe someone else can confirm how it is supposed to be done.

1 Like

Although if it was just losing the noteOff you’d expect the notes to stay on.

As it is, without the noteOff, the notes are played, but not stopped. But with the noteOff, I don’t hear anything.


And it doesn’t make any difference whether the sampleNumber is 10, 100 or 1000

You might want to look at


to get some ideas.

in your processBlock:
int numSamples = buffer.getNumSamples(); mine is 512
So as a test if you set the note on sample to 0 and the note off to numSamples-1 your note on and off will both be rendered.

What is it you are trying to do? If your trying to play back a midi sequence your probably going to want to use an AudioPlayHead and manage ppqPosition and utilize at least timeInSamples from getCurrentPosition()