0

I am trying to parse the input from a midi device connected to my laptop. So I want to locate the device, connect to it and receive the input from it.

I started with select midi device in java, but I am having some trouble getting my way around this one. I considered jFugue that offers a way to access the java sound API but since I don't have their book, there was no resource. Also, jMusic offers some functionality but it's mostly for midi file IO and not a midi device IO. So a do you know of any practical tutorial on the subject(probably using directly the Java sound API).

As always, any help more than appreciated!

Community
  • 1
  • 1
Potney Switters
  • 2,902
  • 4
  • 33
  • 51

1 Answers1

2

Have look at Java Sound tutorial: http://docs.oracle.com/javase/tutorial/sound/accessing-MIDI.html It contains nice explanation of Java MIDI API and also contains example source code on how to enumerate devices.

There is following sample source code:

// Obtain information about all the installed synthesizers.
Vector synthInfos;
MidiDevice device;
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < infos.length; i++) {
  try {
    device = MidiSystem.getMidiDevice(infos[i]);
  } catch (MidiUnavailableException e) {
      // Handle or throw exception...
  }
  if (device instanceof Synthesizer) {
    synthInfos.add(infos[i]);
  }
}
// Now, display strings from synthInfos list in GUI. 

When you acquire MIDI device, you can (in previous source code)

  • get device name by calling infos[i].getName
  • get device vendor by calling infos[i].getVendor()
  • check if this is input or output device (if one "physical" device offers input and output ports, they will be seen as two devices in Java, one for input, second for output) by calling device.getMaxReceivers() and device.getMaxTransmitters().

For more details, see API docs: - http://docs.oracle.com/javase/1.5.0/docs/api/javax/sound/midi/MidiDevice.html - http://docs.oracle.com/javase/1.5.0/docs/api/javax/sound/midi/MidiDevice.Info.html

Aries
  • 353
  • 1
  • 10