# Problem with theMidiBus on Mac mini M2 Pro

**URL:** <https://discourse.processing.org/t/problem-with-themidibus-on-mac-mini-m2-pro/43039>\
**Category:** Libraries\
**Created:** [October 23, 2023, 6:18pm UTC](https://discourse.processing.org/t/problem-with-themidibus-on-mac-mini-m2-pro/43039 "2023-10-23T18:18:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![eltrem](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eltrem/32/3023_2.png) [@eltrem](https://discourse.processing.org/u/eltrem)\
**Post date:** [October 29, 2023, 9:57am UTC](https://discourse.processing.org/t/problem-with-themidibus-on-mac-mini-m2-pro/43039/2 "2023-10-29T09:57:01Z")

</div>

I finally solved the issue dismissing the use of theMidiBus libraty and going stratight to JAVA MIDI. If someone else finds this same problem, i share the helper functions i wrote to have an easy replacement for the midi bus using Java MIDI. Here it goes:

```processing
void setupMIDI() {
  try {
    // List all available MIDI devices
    MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
    
    for (int i = 0; i < infos.length; i++) {
      println("Device " + i + ":");
      println(" Name: " + infos[i].getName());
      println(" Description: " + infos[i].getDescription());
      println(" Vendor: " + infos[i].getVendor());
      println();
    }
    
    // Define the desired device index
    int desiredDeviceIndex = 2; // Replace with the desired index

    // Check if the index is valid
    if (desiredDeviceIndex >= 0 && desiredDeviceIndex < infos.length) {
      midiDevice = MidiSystem.getMidiDevice(infos[desiredDeviceIndex]);
      
      if (!midiDevice.isOpen()) {
        midiDevice.open();
      }
      
      // Initialize receiver
      midiReceiver = midiDevice.getReceiver();
    } else {
      println("Invalid device index!");
      return;
    }
    
  } catch (MidiUnavailableException e) {
    println("Error initializing MIDI devices: " + e.getMessage());
  }
}

void sendMidiMessage(int command, int channel, int note, int velocity) {
  try {
    ShortMessage message = new ShortMessage();
    message.setMessage(command, channel, note, velocity);
    midiReceiver.send(message, -1);
  } catch (InvalidMidiDataException e) {
    e.printStackTrace();
  }
}

```

also, remember to add this to initialization:

```auto
import javax.sound.midi.*;
MidiDevice midiDevice;
Receiver midiReceiver;

```

---

_[View the full topic](https://discourse.processing.org/t/problem-with-themidibus-on-mac-mini-m2-pro/43039)._
