I’m not familiar with the library you’re using, but when I initialize myBus in the same way it’s done in the basic example, the error doesn’t occur. So it has something to do with the values you pass in the constructor.
myBus = new MidiBus(this, -1, "Java Sound Synthesizer");
ps. When working with user input such as key presses or mouse clicks, my suggestion is to take care of it outside draw(). There are methods within Processing such as keyPressed() which make that possible.
Unfortunately I tried changing the values going through the constructor previously and encountered the same problem. If I change the values to unassigned integers then I don’t have the issue - it only happens when either the 2nd or 3rd values in the constructor are utilised.
I’ve also tried using the actual tags as you have in yours with the “Java Sound Synthesizer” but unsurprisingly that made no difference.
Alright, so we get the same warning. In my case that’s different from the error I got from the code in your original post, where the entire sketch crashed when I pressed a button:
The MidiBus Warning: The chosen input device numbered [3] was not added because it doesn't exist
java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because the return value of "java.util.Map.get(Object)" is null
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1334)
at processing.core.PApplet.handleMethods(PApplet.java:1488)
at processing.core.PApplet.dispose(PApplet.java:3529)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:405)
NullPointerException
Unfortunately I know nothing about this library so I can’t be of much more help, but my suggestion is to search online for people with similar warnings.
An alternative —but it might be a tough nut to crack— is to study the source code and see if it gives you any insights. The code below is the method where the error originates from, including a short description.
/**
* Adds a new MIDI output device specified by the name device_name. If the MIDI output device has already been added, it will not be added again.
* <p>
* If two or more MIDI outputs have the same name, whichever appears first when {@link #list()} is called will be added. If this behavior is problematic use {@link #addOutput(int device_num)} instead.
*
* @param device_name the name of the MIDI output device to be added.
* @return true if and only if the output device was successfully added.
* @see #addOutput(int device_num)
* @see #list()
*/
public boolean addOutput(String device_name) {
if (device_name.equals("")) return false;
MidiDevice.Info[] devices = availableOutputsMidiDeviceInfo();
for (int i = 0;i < devices.length;i++) {
if (devices[i].getName().equals(device_name)) return addOutput(devices[i]);
}
System.err.println("\nThe MidiBus Warning: No available input MIDI devices named: \""+device_name+"\" were found");
return false;
}
Did you check the Midi device list? My sketch also crashed after I had upgraded Mac OS, guess the index changed by doing this. So you might have to change the integers here according to the device you want to use.