Themidibus - can't receive input

Hello everyone,
I’m trying to connect my digital piano to processing, with the themidibus library. I have no problem for sending messages to my piano but I can’t receive any information from it. I used the example code from the Github page (https://github.com/sparks/themidibus/blob/master/examples/Basic/Basic.pde) and didn’t change anything except one thing : I replaced the line 24
myBus = new MidiBus(this, -1, “Java Sound Synthesizer”);
with
myBus = new MidiBus(myBus, 1, 4);
where 1 and 4 correspond respectively to my piano as input device and output device. I had to replace “this” by “myBus” otherwise I had a null pointer exception.
How is it possible that I can send outputs but not receive any input ?
As you can see from my message, I’m really new to this field so please take it easy ^^
Thank you very much for reading and hope you can help me !

Hey, looks like I have the same problem. I’m trying to use a nanoKONTROL Studio with Processing and themidibus library, but no luck, can’t get any info out of it.

I found this stackoverflow thread with a probably similar problem (I’m no java expert at all). After compiling and running the java code with all 3 java versions on my machine, all of them show maxTransmitters=0 so I guess that might be the problem? Java does not see the input port?

Any pointers on what to do with this?

macOS 14.1.1, Processing 4.3, OpenJDK 11/20/21

This driver may or may not be helpful:
https://www.korg.com/us/support/download/driver/0/552/1357/

What do you see in the console when you run this code:

import themidibus.*;

void setup() {
  surface.setVisible(false);
  // List all our MIDI devices
  MidiBus.list();
}

Do you have a minimal example that you could post? It would be helpful to see the code that you are using.

1 Like

Thanks, tried to install the driver, but it gave an error at the last step, probably the os version is not supported. However, something did change, as running your code now shows:

Available MIDI Devices:
----------Input----------
[0] "IAC Driver - Bus 1"
[1] "nanoKONTROL Studio - CTRL"
[2] "Real Time Sequencer"
[3] "Bus 1"
[4] "CTRL"
----------Output----------
[0] "IAC Driver - Bus 1"
[1] "nanoKONTROL Studio - CTRL"
[2] "Gervill"
[3] "Real Time Sequencer"
[4] "Bus 1"
[5] "CTRL"

Yesterday, the "nanoKONTROL Studio - CTRL" did not show up, only the rest.

Minimal example:

import themidibus.*;

MidiBus myBus; 

void setup() {
  size(400, 400);
  
  MidiBus.list(); 
    
  myBus = new MidiBus(myBus, 1, 1);
  // or 4, 5
  // still nothing

}

void draw() {
  background(0);
}

void controllerChange(int channel, int number, int value) {
  println();
  println("Controller Change:");
  println("--------");
  println("Channel:"+channel);
  println("Number:"+number);
  println("Value:"+value);
}

The same MIDI controller on the same machine works without any problem with Supercollider and SonicPI.

Try changing the output to 2 or 3. I use:

myBus = new MidiBus(this, 1, 2); // Parent, In, Out

The following source code works for a Qmini:

import themidibus.*;
import processing.sound.*;

MidiBus myBus;
float freq = 0;
TriOsc triOsc;
Env env;

int channel = 0;
int pitch = 0;
int velocity = 0;
String name = "";

// Times and levels for the ASR envelope
float attackTime = 0.0010;
float sustainTime = 0.014;
float sustainLevel = 0.3;
float releaseTime = 0.2;

void setup() {
  size(400, 400);
  surface.setLocation(200, 100);
  MidiBus.list();
  myBus = new MidiBus(this, 1, 2); // (Parent, In, Out)  
  triOsc = new TriOsc(this);
  env = new Env(this);
}

void draw() {
  background(209);
  myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
  delay(100);
  // myBus.sendNoteOff(channel, note, velocity); // Send a Midi nodeOff
  // delay(100);
}

float midiToFreq(int note) {
  return (pow(2, ((note-69)/12.0))) * 440;
}

void noteOn(int channel, int pitch, int velocity) {
  freq = midiToFreq(pitch);
  name = pitchMap[pitch%12];
  println("========================================");
  println("note = " + pitch + " : name = " + name +" : freq =", freq  );
  triOsc.play(freq, 1);
  env.play(triOsc, attackTime, sustainTime, sustainLevel, releaseTime);
  fill(255);
  circle(30, 30, 20);
}

void delay(int time) {
  int current = millis();
  while (millis () < current+time) Thread.yield();
}

static String[] pitchMap = new String[] {
    "C",
    "C#",
    "D",
    "D#",
    "E",
    "F",
    "F#",
    "G",
    "G#",
    "A",
    "A#",
    "B"
  };

Changing the output channel did not help, but I just discovered that Processing is installing version 008 when using the library manager. However, there is a 009 release, that fixes some issues. The jar is not available in the original github repo, but one of the forks has it. If I replace the library manager installed jar with the one from the fork, everything starts working!