How to create MidiInput that represents every note contained in the MidiBuffer midiMessages?

Hi, I am currently developing a poly synth Plug-In where all the DSP part is coded in Faust.
I followed the tutorial on the faust website about how to incorporate it into a JUCE project.

For those who might not know how it works, faust provides a .h file containing a FaustPolyEngine class that can be instanciated to do the DSP work.
For example in the processBlock function of the AudioProcessor, by running :

faustObject->compute(buffer.getNumSamples(),NULL,outputs);
for (int channel = 0; channel < totalNumOutputChannels; ++channel)
{
for(int i=0; i<buffer.getNumSamples(); i++)
{
*buffer.getWritePointer(channel,i) = outputs[channel][i];
}
}

we copy the generated audio in the AudioBuffer. Where faustObject is of type FaustPolyEngine, and output is a float array containing the generated samples.

But the “tricky” part is that the faustObject doesn’t use the MidiBuffer “midiMessages” to retrieve which note must be played.
Instead, every time a note is pressed or released, we must call on of those functions:

faustObject->keyOn(pitch,velocity);
faustObject->keyOff(pitch);

This makes it easy to link an external midi input using MidiInputCallback and MidiKeyboardStateListener.
However, by doing so, only the notes that are actually played on that midi input will be considered.
So when I load the plugin in Ableton for example, I can’t play with the computer keyboard, and the midi clip on the track do not produce any sound.

Since those note are in the MidiBuffer “midiMessages”, I am wondering if there is a way to create some sort of MidiInput from everything that is in the MidiBuffer “midiMessages”.

This is probably not the only way of solving this problem so I am open to anything that could help me.

Thank you fo your help.

Romain

Juce MidiInputs are meant to be used with hardware inputs, in a plugin you have to handle the MIDI messages (in the MidiBuffer) you get with the processBlock call.

It looks like the Faust tutorial skips over how to work with the processBlock block provided MidiBuffer, which is a bit odd, since that’s how you would get the plugin working with the host provided MIDI messages. Basically what you need to : iterate over the messages in the MidiBuffer and call the Faust note on and note off methods as needed, but I don’t know how for example the message time stamps would be handled with Faust.

Thank you, it works!