# MIDI into audio plugin

**URL:** <https://forum.juce.com/t/midi-into-audio-plugin/42972>\
**Category:** Audio Plugins\
**Created:** [November 28, 2020, 8:52am UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972 "2020-11-28T08:52:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![danngonz3](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@danngonz3](https://forum.juce.com/u/danngonz3)\
**Post date:** [November 28, 2020, 8:52am UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/1 "2020-11-28T08:52:10Z")

</div>

Is there anyway to create a plug-in that affects an audio track, but can also take in MIDI as input? MIDI would be used for neat things that aren’t relevant to the question. Just need the input into the plugin.

Plan would be to use the plugin in Logic Pro.

Thank you for any help!

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [November 28, 2020, 10:08am UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/2 "2020-11-28T10:08:48Z")

</div>

in the projucer you can tell your plugin that it is able to receive midi input. then it’s given to you as the 2nd argument of processBlock

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [November 29, 2020, 7:13pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/3 "2020-11-29T19:13:39Z")

</div>

I’m a bit new to JUCE, but my understanding is that JUCE itself is capable of being set up this way, but where you may run into problems is how the _ **host** _ handles I/O. For example, I know that in Ableton this will work just fine, you just set up your VST as an audio effect on an audio track, then set up a MIDI track and route its MIDI output to your plugin on the audio track. But I believe that Logic makes this more difficult, if not impossible…

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [December 6, 2020, 11:38pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/4 "2020-12-06T23:38:20Z")

</div>

In Logic, you have to add the plugin to an Instrument track as an Input, and then set your Audio track as its sidechain input.

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [December 17, 2020, 9:50pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/5 "2020-12-17T21:50:35Z")

</div>

@HowardAntares I’m making a plugin that needs to accept both audio & MIDI… If I want to make sure that Logic users will be able to use it the way you describe, do I need to do anything special to my JUCE code to allow it to accept sidechain? Currently I’m not using or dealing with sidechaining at all, because for the “normal” use of the plugin in a DAW like Ableton it’s not needed…

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [December 17, 2020, 11:12pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/6 "2020-12-17T23:12:07Z")

</div>

I _think_ this addition of the second withInput here was needed, in the initialization of my Processor class:

```
: AudioProcessor( BusesProperties()	.withInput("Input", AudioChannelSet::stereo()).withOutput("Output", AudioChannelSet::stereo()).withInput ("Sidechain", AudioChannelSet::stereo(), true)
```

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [December 17, 2020, 11:22pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/7 "2020-12-17T23:22:21Z")

</div>

okay, thanks!.. so my plugin’s audio input (to the actual processBlock() ) is only ever supposed to be a mono channel of audio (it’s a pitch shifter), so if I add this .withInput(“Sidechain”), would I also need to add some sort of input selector somewhere in my code, to determine if it’s reading from the “normal” inputs or the “sidechain” input?

if so, could/should I have the plugin do this automatically by detecting the DAW being used…?

Ideally, if the user is in Ableton, I wouldn’t want my plugin to show a sidechain selector in the host because it doesn’t _actually_ need a sidechain input… I hope this makes sense.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [December 18, 2020, 9:43am UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/8 "2020-12-18T09:43:30Z")

</div>

> [@benvining](#):
>
> would I also need to add some sort of input selector somewhere in my code, to determine if it’s reading from the “normal” inputs or the “sidechain” input?

No, it’s not necessary. I have a couple of audio effect plugins that accept MIDI notes and my `processBlock` is only ever just getting a pointer to the audio buffer with `SampleType* channelData = buffer.getWritePointer(channel);`, no conditionals to check for DAW and/or sidechain usage.

> [@benvining](#):
>
> if the user is in Ableton, I wouldn’t want my plugin to show a sidechain selector in the host because it doesn’t _actually_ need a sidechain input

This is a good point, I just confirmed that my plugins do indeed show a needless sidechain input selector in Ableton, I assume that it should be possible to set the `BusProperties` up according to DAW being used.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [December 18, 2020, 6:58pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/9 "2020-12-18T18:58:17Z")

</div>

> [@asimilon](#):
>
> I assume that it should be possible to set the `BusProperties` up according to DAW being used.

Yep. Here’s how to get that information:

```
if (pluginHostType.isAbletonLive())

```

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [December 18, 2020, 7:16pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/10 "2020-12-18T19:16:06Z")

</div>

Awesome, thank you both!

So in my audio processor’s constructor I have

```auto
AudioProcessor::AudioProcessor(): (BusesProperties()
                       .withInput ("Input", juce::AudioChannelSet::mono(), true)
                       .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
                       )
{
if(! host.isAbletonLive()) // where host is a pluginHostType object that's a member of my AudioProcessor class
		BusesProperties().withInput("Sidechain", juce::AudioChannelSet::mono(), true);
}

```

It seems like this works! My only question left is if I need to put the `.withInput ("Input"...)` in a conditional in the body of the constructor as well, like

```auto
if(! host.isAbletonLive()) // where host is a pluginHostType object that's a member of my AudioProcessor class
		BusesProperties().withInput("Sidechain", juce::AudioChannelSet::mono(), true);
else
        BusesProperties().withInput ("Input", juce::AudioChannelSet::mono(), true)
}

```

or should I leave it as it is now?

Thanks again!

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [December 18, 2020, 8:38pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/11 "2020-12-18T20:38:42Z")

</div>

I’m somewhat surprised that works, I would have thought you would need a little helper function to create the `BusProperties` in the constructor parameters, something like:

```auto
BusProperties AudioProcessor::makeBusProperties()
{
    auto pluginHost = PluginHostType();
    if(pluginHost.isLogic() || pluginHost.isGarageBand())
    {
        // only add the side-chain to hosts that need it
        return BusesProperties().withInput("Input", AudioChannelSet::stereo())
                                .withInput ("Sidechain", AudioChannelSet::stereo()
                                .withOutput("Output", AudioChannelSet::stereo());
    }
    else
    {
        // every other host needs no sidechain
        return BusesProperties().withInput("Input", AudioChannelSet::stereo())
                                .withOutput("Output", AudioChannelSet::stereo());
    }   
}

AudioProcessor::AudioProcessor(makeBusProperties(), true)
{
    // ...
}

```

This is completely untested, but something like that is what I imagine is needed.

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [December 18, 2020, 9:05pm UTC](https://forum.juce.com/t/midi-into-audio-plugin/42972/12 "2020-12-18T21:05:25Z")

</div>

This is much cleaner, thanks! It works, with some minor syntax alterations. For anyone else finding this, here’s how I got it to work:

```auto
YourPluginAudioProcessor::YourPluginAudioProcessor(): AudioProcessor(makeBusProperties())

```

```auto
AudioProcessor::BusesProperties YourPluginAudioProcessor::makeBusProperties()
{
	PluginHostType host;
	if(host.isLogic() || host.isGarageBand())
		return BusesProperties().withInput("Input", AudioChannelSet::mono(), false)
								.withInput("Sidechain", AudioChannelSet::mono(), true)
								.withOutput("Output", AudioChannelSet::stereo(), true);
	else
		return BusesProperties().withInput("Input", AudioChannelSet::mono(), true)
								.withOutput("Output", AudioChannelSet::stereo(), true);
}

```
