# Multiple MIDI Devices with the AudioProcessorGraph

**URL:** <https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870>\
**Category:** General JUCE discussion\
**Created:** [July 27, 2013, 5:11pm UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870 "2013-07-27T17:11:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [July 27, 2013, 5:11pm UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/1 "2013-07-27T17:11:20Z")

</div>

Hi  
This is, as usual probably very simple for the experienced Jucers but I need some guidance:  
If you have a AudioProcessorGraph and a Player, like in the HostDemo, You can route MIDI from hardware inputs just like audio.  
As far as I have figured out the common way of doing this is by adding a AudioGraphIOProcessor node with the IODeviceType set to midiInputNode.

Now, how do you know which actual MIDI device the messages are coming from?  
If you enable two midi devices, can you send messages from MIDI device 1 to node A and device 2 to node B?

Is this possible out of the box or would I need to create my own AudioGraphIOProcessors?

As far as I can tell from looking through the classes, the only place where you can filter messages by device (in a setup like this) is in handleIncomingMidiMessage in AudioProcessorPlayer.

Anyone else done this and found a clever way?

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [October 18, 2013, 6:20pm UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/2 "2013-10-18T18:20:58Z")

</div>

Anyone got any bright ideas?

---

<div class="post-metadata">

**Author:** ![graeme-2](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@graeme-2](https://forum.juce.com/u/graeme-2)\
**Post date:** [October 19, 2013, 2:07am UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/3 "2013-10-19T02:07:51Z")

</div>

There is only one global midi channel as far as the graph is concerned. &nbsp;You might want to try MidiMessage getChannel(). &nbsp;I haven't done much midi stuff but I'm guessing the channel data that you're looking for is passed in with the midi data and not as separate device channels like for&nbsp;audio streams.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [October 19, 2013, 5:27pm UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/4 "2013-10-19T17:27:00Z")

</div>

If you want to have control over specific&nbsp;connections from multiple&nbsp;MIDI devices, your best bet is to wrap each MIDI device in its own subclass of juce::AudioProcessor.

---

<div class="post-metadata">

**Author:** ![lucem](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@lucem](https://forum.juce.com/u/lucem)\
**Post date:** [October 20, 2013, 11:51am UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/5 "2013-10-20T11:51:28Z")

</div>

Second that, although I’d subclass the AudioProcessorGraph to accomodate for this and auto-populate the input device processors.

---

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [October 21, 2013, 11:54am UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/6 "2013-10-21T11:54:57Z")

</div>

Thank you guys!

Then I'm already on the right track. I was just affraid that I was missing something in the docs.

I have created midi input and midi output processors, that I add in my custom graph.

This also serves as a nice layer between the actuall hardware device and what the user selects in the app.

---

<div class="post-metadata">

**Author:** ![joeduf](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@joeduf](https://forum.juce.com/u/joeduf)\
**Post date:** [June 4, 2017, 4:51pm UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/7 "2017-06-04T16:51:52Z")

</div>

I’m trying desperately to understand this wonderful library and specific topic…If I subclass AudioProcessorGraph so that i can filter out MIDI messages for a single specific MIDI input device, and I have multiple instances of AudioProcessorGraphs; one for each MIDI input device each of which will feed a VSTi plugin, how do I… 1.) combine the audio outputs for each separate graph into a single (ASIO) audio output device?..2.) “drive” / trigger the separate AudoProcessorGraphs to process MIDI input and send that to the VSTi plugins?

I’ve tried a few experiments all of which have failed miserably in trying to separate two MIDI input keyboards destined for two separate VSTis…both of which should be merged to a single audio output device.

I’d be happy to share incorrect code I’ve tried so far. Trying to understand this but I’m only about three months into using JUCE.

---

<div class="post-metadata">

**Author:** ![joeduf](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@joeduf](https://forum.juce.com/u/joeduf)\
**Post date:** [June 4, 2017, 5:36pm UTC](https://forum.juce.com/t/multiple-midi-devices-with-the-audioprocessorgraph/10870/8 "2017-06-04T17:36:30Z")

</div>

Please ignore my last post in this thread…I must be having “one of those” days.

i just reset my MIDI controllers, did a clean build and everything works! I didn’t even need to subclass AudioGraphProcessor with the current JUCE 5.0.2 code.

Sharing object usage here in case this helps anyone else with this topic. (If there’s a better way please let me know!)

One AudioDeviceManager instance which connects to my ASIO audio output.  
Three AudioProcessorPlayer Objects - one for each instrument, plus a master to drive the device manager.  
Three AudioProcessorGraph Objects - one for each instrument, plus a master to combine / connect them.

Add a master audio in and out to the master AudioProcessorGraph.

Add an audio output and MIDI input to each instrument AudioProcessorGraph

Wire it all up correctly with addConnection calls.

it works! i shocked myself! Willing to share code if anyone wants it but I’m still sorting out leaking objects myself.

I know I’ve said this before but I L O V E JUCE!
