How do we output MIDI from an audio plugin

We are working on an audio plugin that extracts some features from the audio. We want to output these values as MIDI.

We were hoping we would have another MIDI track which will receive MIDI generated by the plugin on our audio track.

Does anyone have an idea how to achieve this?

I did this a few months ago, and it was straight forward. But I didn’t manage to use this in different hosts:
In ProTools in an Instrument track I could select the plugin as input for midi, was perfect.
In CuBase I didn’t manage to get any other input than the one on that track, that spoilt the party.
I tried to get help from Steinberg, but they were unable to get me into contact of anybody, who knows their software :wink: Well, we know them…
If you figure this how it works in Cubase I would be very interested.
Btw, I did this last year, so then it was Juce 3.2, I didn’t check, if it still works (went into the learning playground folder)…

Are you asking how to write the code that generates midi, or how to set up your host?

@daniel

Thanks for your inputs. I just figured out a way to do this using MidiOutput

MidiOutput *midiOutput;
midiOutput = MidiOutput::createNewDevice("FeatureOutput");

This created ->

Now, whenever we shoot out midi using the following statement we receive it in the device we created.

midiOutput->sendMessageNow(MidiMessage::noteOn(1, 60, 0.8f));

However, their documentation says createDevice doesn’t work on Windows.

It will be nice to have some inputs from you for achieving the cross-platform reliability here.

You shouldn’t be talking to the MIDI output directly! Plugins send MIDI from their processBlock method by just returning the events in the MidiBuffer object - see the JUCE Arpeggiator example project!

Thanks for pointing that out. I quoted the piece of code out of context for simplicity’s sake. It is indeed called from inside the processBlock()

…ok, but then that’s wrong on two counts. You shouldn’t talk to the output device directly, and you definitely shouldn’t call OS functions like that in your audio callback.

Like I said, we have an example to show how to send MIDI - have a look at it.

If I had to outputMIDI from a MIDI plugin then I’d refer the example.

What I am trying to do here is output MIDI from a plugin that is processing audio (and not MIDI). In this case, if I do what the example says there’s no way to retrieve the MIDI messages I am sending out (or is there? this was my original question) since the plugin is loaded in an audio track.

Do you see any alternative way than talking to the output device directly to achieve this?

Why do you think I’m repeatedly telling you to look at the example if it wouldn’t do what you need?

There’s no such thing as a “MIDI plugin”. There are just plugins that have some combination of audio and/or MIDI busses. If you want to produce MIDI, just give your plugin a MIDI output bus. (Obviously some hosts may not have a mechanism to deal with the output MIDI data, but the plugin architecture supports this)

That was exactly my point. In ProTools this one works:

void MidiSidechainAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
    /* calculate your value as you like, I used RMS of the audio */
    MidiMessage message (MidiMessage::controllerEvent (midiChannel, ccNumber, (int)floor(value * 127)));
    message.setTimeStamp (timestamp);
    midiMessages.addEvent (message, timestamp);
}

I can add an instrument track and in the input selector I can select the plugin as source of midi events. But I found no way in Cubase to select a plugin as midi source. But you see, I’m completely unexperienced on Cubase.

Just seeing Jules simultaneous post… seems to be the case…

Okay, thanks for driving the point home. I have been looking into the Arpeggiator example without understanding/making much sense and I came to a the wrong conclusion that it wouldn’t do what I need it to.

What you and daniel just said makes it way clearer. I’ll try this first thing tomorrow and get back. Thanks again.

The ability to create new MIDI ports with this function also on Windows would be an absolutely awesome addition to the library, but probably needs a driver backend. Maybe a 3rd party solution could be integrated in future.

Here’s a screenshot how it works on ProTools

Did you find a propper solution to this in ableton? I am also working on a plug-in that takes Audio input and outputs Midi. Ableton has a way to deal with it buy my plug-in just doesn’t show up in the drop down list.

cubase is known not to support midi plugins, but you can send midi out from vst instruments and then receive that midi on other tracks. like in the plugin bluearp