Does TheMidibus Library work in Processing 4?

Well, for some mysterious reasons, the fix doesn’t work on one of the computers I use (a Macbook Air 2015 with Mac OS 10.14.6 Mojave): I still have the NullPointerException when running a simple example with the MidiBus, with Processing 4.3 (I don’t have that problem with Processing 3.5 though, but I’m pretty sure it’s better to upgrade anyway). Also, the MidiBus has other issues. For instance, when registering a MIDI/USB device, it gets the name field, where other softwares that detect synths correctly seem to use the description field, and as a result I have a Blofeld synth that it detects as “Unknown name”, which is not really useful. I’ve read somewhere that MidiBus also has issues with other stuff I might try to use later, as sysex messages or something.
I then resolved to use Java Midi to manage MIDI receivers, AND the MidiBus to manage transmitters, in the same program, so I could get the right device names but also be able to detect when a MIDI controller sends some MIDI message…
But 1) that’s quite complicated and unelegant and 2) it works only with Processing 3.5, not 4.3.
So yeah, switching for good to Java Midi sounds like a much better solution than using that hybrid Java Midi/MidiBus thing. Except for that one missing piece: I don’t know how to detect noteOn/noteOff/midiMessage events the way MidiBus does. And I’m pretty sure it’s possible through some Java code integration into my Processing code, but, alas, from all the documentation I’ve been reading, I couldn’t find how to do that. I found many pages talking about connecting transmitters to receivers, recording sequences or writing MIDI files, but nothing about simply getting MIDI event data from a transmitter to put it in a variable. I’ve been on this for months and it’s quite frustrating… :wink:

Hi @BBellamy. I have an example how to use Java.sound.midi.
The trick is to filter the midi messages using the correct Hex codes. Here is a resource for that,

Otherwise this example will get you started.

Good luck.

Well @BBellamy I just tried with the basic example from TheMidibus library
This is what I get when I run it and get a list of available devices

Available MIDI Devices:
----------Input----------
[0] “Real Time Sequencer”
[1] “IAC Bus 1”
[2] “IAC Bus 2”
[3] “Out”
[4] “EDITOR Out”
----------Output----------
[0] “Gervill”
[1] “Real Time Sequencer”
[2] “IAC Bus 1”
[3] “IAC Bus 2”
[4] “In”
[5] “EDITOR In”

So my keyboard is being labeled as “in”, sure it is not the correct name but what do I care.
If I run MIDI Monitor it shows up as “from VMini Out” and I can see the note on / off MIDI messages.
Then I take the Basic MIDI example and comment out this line:-

myBus = new MidiBus(this, -1, "Java Sound Synthesizer")

and comment in this line:-

 myBus = new MidiBus(this, 3, 4); // Create a new MidiBus using the device index to select the Midi input and output devices respectively.

The input is a keyboard so I don’t want to send anything to it so I comment out this section:-

// it is a keyboard so we don't have to send it a note
/*
  myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
  delay(200);
  myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff

  int number = 0;
  int value = 90;

  myBus.sendControllerChange(channel, number, value); // Send a controllerChange
  delay(2000);
  */

And when I press a key on my Alesis vmini keyboard I get printed out in the console window:-

Note On:

Channel:0
Pitch:48
Velocity:43

Note Off:

Channel:0
Pitch:48
Velocity:43

This is using Processing V4.2, on a Mac laptop, running OS 10.14.6 Mojave.

You might want to use the solution above, but I leave it here for others searching the forum threads to show how I would do things.