# MIDI Out events from a standalone plugin

**URL:** <https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245>\
**Category:** Audio Plugins\
**Created:** [April 6, 2013, 10:23am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245 "2013-04-06T10:23:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![lelepar](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lelepar](https://forum.juce.com/u/lelepar)\
**Post date:** [April 6, 2013, 10:23am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/1 "2013-04-06T10:23:10Z")

</div>

Hi all,

I’m working on a standalone plugin; I’ve made it using StandaloneFilterWindow, so I used the same processing code I wrote for a VST/AU plugin.  
The plugin produces MIDI events; so in the StandaloneFilterWindow I have enabled the Midi Output selector. Then I use something like MIDI Yoke or LoopBe to route MIDI events to other apps, so I choose the proper MIDI stream from the Midi Output selector (for example MIDI Yoke).  
I’m monitoring the MIDI events passing through MIDI Yoke, but no events are received.

It works good as audio-to-midi plugin in a host, but it does not work as standalone application.

Could someone help me?

Thanks in advance  
Lele

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [April 6, 2013, 11:48am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/2 "2013-04-06T11:48:26Z")

</div>

I think you need to handle the midi output yourself when working in standalone mode. MidiOutput::openDevice(int index) will return a midi output device that you can send notes to.

---

<div class="post-metadata">

**Author:** ![lelepar](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lelepar](https://forum.juce.com/u/lelepar)\
**Post date:** [April 6, 2013, 1:19pm UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/3 "2013-04-06T13:19:47Z")

</div>

StandaloneFilterWindow creates an AudioDeviceSelectorComponent (here I enabled the Midi Out selector), passing its AudioDeviceManager.  
The AudioDeviceSelectorComponent already selects the default MidiOutput and assigns it to the AudioDeviceManager.

```auto
else if (comboBoxThatHasChanged == midiOutputSelector)
    {
        deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
    }
```

Now, the AudioDeviceManager adds an AudioProcessorPlayer as callback for audio and Midi Input:

```auto
deviceManager->addAudioCallback ( &player);
deviceManager->addMidiInputCallback (String::empty, &player);
```

But nothing related to Midi Output.

I found this post [http://www.juce.com/viewtopic.php?t=1362&p=7476](http://www.juce.com/viewtopic.php?t=1362&p=7476) dated Jan 08 2007, but I think that nothing has been done.

Is there any sample code that deals with Midi Out, for example a simple juce host that sends Midi Out to a Midi Out device?

Cheers  
Lele

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [April 7, 2013, 8:03am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/4 "2013-04-07T08:03:42Z")

</div>

Sorry, I don’t have any code for this, nor have I ever tried to do it myself. Perhaps I’m over simplifying this, but if you call AudioDeviceManager::getDefaultMidiOutput() after the midi device has been selected it will return the current MidiOutput object. Once you have this can’t you just call one of its send midi methods to output some midi notes?

---

<div class="post-metadata">

**Author:** ![Salvator](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@Salvator](https://forum.juce.com/u/Salvator)\
**Post date:** [April 10, 2013, 9:48am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/5 "2013-04-10T09:48:58Z")

</div>

Hello,

Well, to open a MidiOut in stand alone app, you may not even need to go thru DeviceManager; it’s could just be a matter of

[code] StringArray midiOutNames;  
midiOutNames = MidiOutput::getDevices();

ScopedPointer midiOut;  
midiOut = MidiOutput::openDevice(midiOutNames.indexOf(name));  
[/code]  
then :

`if (midiOut != nullptr)
            midiOut->sendMessageNow(midiMessage);
`  
Works for me.

BTW : Did you made that standalone plugin to workaround the fact that plugin’s can’t output midi when inside a DAW by any chance ?

Salvator

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [April 10, 2013, 10:04am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/6 "2013-04-10T10:04:30Z")

</div>

What do you mean by “fact that plugin’s can’t output midi when inside a DAW by any chance”. They certainly can as far as I’m aware? Just make sure you enable MIDI out in your AppConfig.h file.

---

<div class="post-metadata">

**Author:** ![lelepar](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lelepar](https://forum.juce.com/u/lelepar)\
**Post date:** [April 10, 2013, 11:47am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/7 "2013-04-10T11:47:36Z")

</div>

Salvador, thank you for your snippet, I’ll give it a try.

I’m building a standalone plugin because I need it 😉 ; as I stated in my first post:

> [@](#):
>
> It works good as audio-to-midi plugin in a host, but it does not work as standalone application.

As Rory said, I’ve just enabled the MIDI out in AppConfig.h file and returned “true” in producesMidi() method.

Lele

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [April 10, 2013, 2:38pm UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/8 "2013-04-10T14:38:18Z")

</div>

It’s a complicated subject, MIDI OUT from a plugin to the Host is possible in the latest AU and VST (i have no idea bout AAX), it’s not available in some previous AU specifications.  
You can always talk to MIDI devices directly but you must watch out for timing and threading, you should never produce MIDI events from within the Editor class (your GUI events will cause big delays in MIDI events),  
you should produce MIDI events in a different thread or in the audio thread. You will never get correct time sync between your host and the external device, there is no way of knowing when to transmit MIDI events  
to the external device from the Audio thread, it’s not possible because of latencies inside the host.

If you plan to send devices from your own classes on the UI thread, use the startBackgroundThread () method and send the vents using sendBlockOfMessages() method, all the threading stuff will be handled by JUCE.

---

<div class="post-metadata">

**Author:** ![lelepar](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lelepar](https://forum.juce.com/u/lelepar)\
**Post date:** [May 2, 2013, 12:03pm UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/9 "2013-05-02T12:03:07Z")

</div>

This is how I solved.

My AudioProcessor class is MyFilter; I’ve added two members:

```auto
AudioDeviceManager* devManager;
MidiOutput* midiOut;
```

At the beginning of processBlock():

```auto
	if(devManager) {
		midiOut = devManager->getDefaultMidiOutput();
		
		if( midiOut ) midiOut->startBackgroundThread();
	}
```

at the end of end of processBlock():

```auto

       if (midiOut != nullptr) {
		midiOut->sendBlockOfMessages(	
			midiMessages,
			Time::getMillisecondCounter(),
			this->getSampleRate()
		);	
	}
```

I created my own Standalone Window copying it from StandaloneFilterWindow and I’ve passed the DeviceManager to the filter:

```auto
    filter = (MyFilter*)createPluginFilterOfType (AudioProcessor::wrapperType_Standalone);
    filter->devManager = deviceManager;
```

I know, it is not the best way to do it, but it works as a charme.

Best  
Lele

---

<div class="post-metadata">

**Author:** ![mashu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mashu/32/579_2.png) [@mashu](https://forum.juce.com/u/mashu)\
**Post date:** [March 26, 2016, 4:34am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/10 "2016-03-26T04:34:35Z")

</div>

i know this is an old post, but i'm trying to setup midi output in a standalone, and want to follow this advice.  
  
Where should i put these lines of code? &nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![lelepar](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lelepar](https://forum.juce.com/u/lelepar)\
**Post date:** [April 20, 2016, 9:18am UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/11 "2016-04-20T09:18:22Z")

</div>

When I wrote my example, I used JUCE 2; don’t know if there is something different with JUCE 4.  
Anyway:

myfilter.h:

```
class MyFilter:AudioProcessor {
...
AudioDeviceManager* devManager;
MidiOutput* midiOut;
...
}

```

myfilter.cpp:

```
void MyFilter::processBlock(...){

if(devManager) {
		midiOut = devManager->getDefaultMidiOutput();
		if( midiOut ) midiOut->startBackgroundThread();
	}
...

if (midiOut != nullptr) {
	midiOut->sendBlockOfMessages(	
		midiMessages,
		Time::getMillisecondCounter(),
		this->getSampleRate()
	);
}

```

I’ve copied the entire juce\_StandaloneFilterWindow.h in my source directory, renaming it to myStandaloneFilterWindow.h and renaming all occurrences of StandaloneFilterWindow to MyStandaloneFilterWindow.

myStandaloneFilterWindow.h:

```
...

JUCE_TRY
        {
// explicit cast to MyFilter*
            filter = (MyFilter*)createPluginFilterOfType (AudioProcessor::wrapperType_Standalone);
        }
JUCE_CATCH_ALL
...

deviceManager = new AudioDeviceManager();
deviceManager->addAudioCallback (&player);
deviceManager->addMidiInputCallback (String::empty, &player);
				
player.setProcessor (filter);
// added:
filter->devManager = deviceManager;

....

```

Hope it is clearer now.

---

<div class="post-metadata">

**Author:** ![erteash](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@erteash](https://forum.juce.com/u/erteash)\
**Post date:** [September 24, 2017, 7:52pm UTC](https://forum.juce.com/t/midi-out-events-from-a-standalone-plugin/10245/12 "2017-09-24T19:52:12Z")

</div>

My standalone MIDI effect (no audio channels needed) unlike the plugin, doesn’t receive or send midi messages by default…  
Is this has been taken care of in JUCE 5 or its something that we need to do it manually like the example above?
