# The MIDI Bus array of devices

**URL:** <https://discourse.processing.org/t/the-midi-bus-array-of-devices/42126>\
**Category:** Libraries\
**Created:** [June 2, 2023, 8:19pm UTC](https://discourse.processing.org/t/the-midi-bus-array-of-devices/42126 "2023-06-02T20:19:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/grumpy_mike/32/14787_2.png) [@Grumpy\_Mike](https://discourse.processing.org/u/Grumpy_Mike)\
**Post date:** [June 2, 2023, 8:19pm UTC](https://discourse.processing.org/t/the-midi-bus-array-of-devices/42126/1 "2023-06-02T20:19:08Z")

</div>

I like to search for specific interfaces when I use the serial port, I have examples of how an array can be created with all the available serial devices.

Is there something similar for the MIDI Bus? This is so my code can link with the correct device, rather than just relying on it’s position in a list and having to modify that position as the number of devices changes, in Processing 4.

Thanks

---

<div class="post-metadata">

**Author:** ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)\
**Post date:** [June 2, 2023, 11:17pm UTC](https://discourse.processing.org/t/the-midi-bus-array-of-devices/42126/2 "2023-06-02T23:17:04Z")

</div>

Hi @Grumpy_Mike  
I don’t use this library but it shows in the documentation to use `MidiBus.list()` [MidiBus.list()](http://www.smallbutdigital.com/docs/themidibus/themidibus/MidiBus.html#list--)  
You could also try: `MidiBus.availableInputs()` or `MidiBus.availableOutputs()` which return strings.  
Good luck!

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/grumpy_mike/32/14787_2.png) [@Grumpy\_Mike](https://discourse.processing.org/u/Grumpy_Mike)\
**Post date:** [June 3, 2023, 6:23am UTC](https://discourse.processing.org/t/the-midi-bus-array-of-devices/42126/3 "2023-06-03T06:23:31Z")

</div>

> [@robertesler](#):
>
> `MidiBus.availableOutputs()`

Thanks a lot, that fixed it  
First I put in the global variables

```auto
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus

String connectTo = "CircuitPython usb_midi.ports[0]"; // the name of the MIDI port to use
String midiOutputs[] = MidiBus.availableOutputs(); 

```

At then at the start of the setup function I used this:-

```auto
// try and open the port named in the "connectTo" variable 
  // MidiBus.list(); // Remove comment to see the list
   int requiredPort = 99; 
   for(int i = 0; i< midiOutputs.length ; i++) {
     if(connectTo.equals(midiOutputs[i])) requiredPort = i;      
    }
    if(requiredPort == 99) requiredPort = 0; // if port not found
    myBus = new MidiBus(this, 1, requiredPort );
    print("Connected to ", midiOutputs[requiredPort]);

```

Thanks again
