Sending MIDI from processBlock


#1

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;
midiMessages.addEvent(MidiMessage::noteOn(1,n,(juce::uint8)100),0);
midiMessages.addEvent(MidiMessage::noteOff(1,n),1000);
}


#2

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


#3

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.


#4

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…


#5

ouch!

That’s a pain.


#6

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.


#7

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.

Odd.


#8

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


#9

You might want to look at

JUCE\examples\Plugins\ArpeggiatorPluginDemo.h

to get some ideas.


#10

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()