MIDI OUT transmitter unavailable

I hit my head about it all day, read everything I could find, followed the source of the JDK, was not lucky to find out details about HOW or WHERE is looking for Java on a MIDI device and determines what is what.

I am trying to capture midi messages through the NI Audio 8 DJ MIDI IN port, but java does not β€œsee” the MIDI IN port, but only the one that I successfully used to send midi. I also get the same results using the M-Audio USB UNO MIDI device: MidiSystem.getMidiDeviceInfo() only β€œsees” the output port.

I checked the operation of the MIDI IN port with:

 amidi -p hw:2,0 -d 

and sending him some signals. It works great.

getMaxTransmitters() returns zero. MidiSystem.getMidiDeviceInfo() shows only one entry for both devices: Audio8DJ [hw:2,0] or Interface [hw:2,0]

The code below works fine for the receiver, and I think this is just the bit I need to check that getTransmitter() captures the port, since it works only for the other, and everything works fine, I get a MidiUnavailableException / Transmitter exception thrown .

I even took the getMaxReceivers() trap because I was just trying to see if the device only offered one entry and parsed it, but not.

 public static Transmitter getMidiIn () { if (midiIn == null){ devices = MidiSystem.getMidiDeviceInfo(); for(MidiDevice.Info info: devices){ System.out.println("device class " + info.getClass()); MidiDevice device; try{ device = MidiSystem.getMidiDevice(info); if (info.toString().equals("Audio8DJ [hw:2,0]")){ if (device.getMaxTransmitters() != 0){ try{ device.open(); System.out.println("max transmitters:" + device.getMaxTransmitters()); midiIn = device.getTransmitter(); System.out.println("Found a transmitter: "+ midiIn); break; } catch (Exception e){ e.printStackTrace(); } } } } catch (MidiUnavailableException e1){ e1.printStackTrace(); } } } return midiIn; } 

So, here is what I need here: alsa only lists one entry in amidi -l , and when I specify that as the port for the dump, it works fine. Java receives the same text and cannot sort MIDI IN by assigning it the class com.sun.media.sound.MidiOutDeviceProvider , so I wondered how to do this or where Java finds out what the device has to offer and why not? seeing the input port that alsa sees.

I am coding with eclipse Version: 3.8.1 IDE with JDK1.6, on Linux operating system.

I will be happy to provide everything that they ask. Thank you for reading!

+5
source share
1 answer

The java solution, which sees the transmitter, was used in the JDK version, although, unfortunately, at this time I did not have an answer why, for failure, only one version worked and corresponded to my needs for the time being. If I find this answer, I will edit this answer.

Of the three versions that I switched for testing, jdk1.8.0_60, jdk1.7.0_80, jdk1.6.0_45, 1.7 did not experience errors and successfully received the transmitter from my device. I found out about this, and these privileges were not the cause of my specific problem, compiling and running the code I found suitable for executing the command line, which attempts to get the transmitter print the midi data sent to it and slightly modify it ...

 import javax.sound.midi.MidiDevice; import javax.sound.midi.MidiMessage; import javax.sound.midi.MidiSystem; import javax.sound.midi.MidiUnavailableException; import javax.sound.midi.Receiver; public class MidiInputTest { public MidiDevice input; public MidiDevice output; public static void main(String[] args) { new MidiInputTest().start(); } public void start() { init(); // initialize your midi input device // system dependent try { output.open(); // From midi device MyReceiver myrcvr = new MyReceiver(); MidiSystem.getTransmitter().setReceiver(myrcvr); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } private class MyReceiver implements Receiver { Receiver rcvr; public MyReceiver() { try { this.rcvr = MidiSystem.getReceiver(); } catch (MidiUnavailableException mue) { mue.printStackTrace(); } } @Override public void send(MidiMessage message, long timeStamp) { byte[] b = message.getMessage(); if (b[0] != (byte)254) { System.out.println((b[0] & 0xff) + " " + (b[1] & 0xff)); } //rcvr.send(message, timeStamp); // will send out what ever you receive } @Override public void close() { rcvr.close(); } } public void init() { MidiDevice.Info[] devices; devices = MidiSystem.getMidiDeviceInfo(); try{ for (MidiDevice.Info info: devices) { MidiDevice device; device = MidiSystem.getMidiDevice(info); System.out.println("MidiDevice.Info="+info + "\n" + "maxTransmitters="+device.getMaxTransmitters()); // I put the specific device I want to connect to behind an if gate here to avoid connecting to something I do not if (info.toString().equals("Interface [hw:2,0,0]") && device.getMaxTransmitters() != 0) { System.out.println(" Name: " + info.toString() + ", Decription: " + info.getDescription() + ", Vendor: " + info.getVendor()); output = MidiSystem.getMidiDevice(info); if (! output.isOpen()) { output.open(); } } } } catch (MidiUnavailableException mue) { mue.printStackTrace(); } } } 

To run this from the command line, select the version of JDK that you installed, compile and run with these specific versions, replacing jdk1.7.0_80 for the distribution you want to check.

 /opt/java-jdk/jdk1.7.0_80/bin/javac MidiInputTest.java /opt/java-jdk/jdk1.7.0_80/bin/java -cp . MidiInputTest 

Although I could not verify this, Java Sound is apparently responsible for figuring out what is available for using java from your MIDI architecture.

Thanks to Mike Harris for sending me the correct test path on the command line and jim829 on top of java-forums.org for example code for the command line.

+3
source

Source: https://habr.com/ru/post/1239936/


All Articles