Problem with theMidiBus on Mac mini M2 Pro

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:

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:

import javax.sound.midi.*;
MidiDevice midiDevice;
Receiver midiReceiver;
1 Like