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);
}
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…
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()