The MIDI Bus array of devices

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.


Hi @Grumpy_Mike
I don’t use this library but it shows in the documentation to use MidiBus.list() MidiBus.list()
You could also try: MidiBus.availableInputs() or MidiBus.availableOutputs() which return strings.
Good luck!

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

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:-

// 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

1 Like