# 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:** 3
**Page:** 1

<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 23, 2023, 6:18pm UTC](https://discourse.processing.org/t/problem-with-themidibus-on-mac-mini-m2-pro/43039/1 "2023-10-23T18:18:58Z")

</div>

I just made a fresh install of Processing 4.3 on a new M2 Mac mini running Ventura 13.6,  
just to find that my old sketches using theMidiBus library do not work.

I also tried with the basic examples coming with the libraries, and I’m seeing the same problem as well: **NullPointerException** when loading a midi device on the setup. It doesn’t matter which of the listed devices I choose, it will throw the error before ending the setup.

Has anyone else found this problem? any chance to find a solution to have midi working on this new m2 machines?

thanks!!!

---

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

```

---

<div class="post-metadata">

### Author: ![justin\_lincoln](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/justin_lincoln/32/53_2.png) [@justin\_lincoln](https://discourse.processing.org/u/justin_lincoln)
#### Post date: [June 24, 2025, 7:17pm UTC](https://discourse.processing.org/t/problem-with-themidibus-on-mac-mini-m2-pro/43039/3 "2025-06-24T19:17:27Z")

</div>

> [@eltrem](#):
>
> ```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();
> }
> }
> 
> ```

Thank you so much! I missed my midi controller after themidibus library went wonky.
