For VST: Just append
MidiMessage's to the incoming
processBlock, whenever you detect events in the incoming audio. See the Arpeggiator example on how to output MIDI from the audio callback.
Configure your JUCE project with
Plugin produces midi output but – in this case – not as a MIDI effect.
But keep in mind, it strongly depends on the host/plugin format whether this will actually work as intended. For example, in Ableton Live/VST it does (MIDI output from audio tracks can be selected as MIDI source in MIDI tracks), in Logic/AU, MIDI output from plugins on audio tracks seems to be ignored. For this to work in AU, set up a custom
MidiOutput device and send messages to it instead of filling the incoming
MidiBuffer (N.B., directly accessing MIDI devices in a plugin callback has been discouraged in other threads, though I don’t know of any other solution to accomplish the goal here).