Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8058119

MIDI input receiver no longer working for MIDI interfaces

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 9
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.9.4
      uname -a:
      Darwin Peter-MacBook.local 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      This problem is exhibited using any of the following:
      MOTU micro lite, M-Audio MIDISPORT 2x2, MOTU 828mkII, M-Audio Axiom-61 (USB)

      A DESCRIPTION OF THE PROBLEM :
      I can successfully open a MidiDevice for any of my MIDI input devices but input events are NEVER actually received into java.

      This seems to be specific to running java under the most recent releases of OS X and not specific to a particular version of JAVA. Since upgrading to 10.9.4 I get this problem on java SE 1.6, 1.7 and 1.8.

      My test code still works with Java SE 1.8 on Windows 7.

      My test code does not work on a second macbook pro running OS X 10.9.4

      I have no problems at all using these interfaces with commercial software products that I use (e.g. Native Instruments Complete, Ableton LIve) on this same macbook pro.

      I have been using javax.sound.midi software for many years with no problems.

      A MIDI monitor program I use shows the input MIDI events are actually happening and seen by the computer.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      plug in a MIDI interface (USB or Firewire) with a MIDI controller connected to a MIDI In port on the interface.

      play a note on the controller to see that it is registering on the interface (i.e. look at the input LED)

      run either of the simple test programs included below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      with test program 1 I expect to see the note echoed on the MIDI out port on the MIDI interface.

      with test program 2 I expect to see the input event data printed to standard output.
      ACTUAL -
      I see neither of the expect results from the test programs

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      test program 1:
      package miditest;

      import javax.sound.midi.MidiDevice;
      import javax.sound.midi.MidiSystem;
      import javax.sound.midi.MidiUnavailableException;
      import javax.sound.midi.Receiver;
      import javax.sound.midi.Transmitter;

      public class MidiTest {
      static MidiDevice inputDevice = null;
      static MidiDevice outputDevice = null;

      public static void main(String[] args) {
      try {
      inputDevice = findDeviceByNameAndType("Port 1", false, true);
      outputDevice = findDeviceByNameAndType("Port 1", true, false);
      init();

      } catch (Exception x) {System.err.println("bummer");}
      try {
      System.in.read();
      } catch (Exception x) {
      System.err.println("Exception in main loop: " + x.getClass().getName() + " " + x.getMessage());
      }

      }
      public static MidiDevice findDeviceByNameAndType(String name, boolean isOutputDevice, boolean isInputDevice)
      throws MidiUnavailableException {
      MidiDevice.Info[] midiDeviceInfo = MidiSystem.getMidiDeviceInfo();
      for (int i = 0; i < midiDeviceInfo.length; i++) {
      MidiDevice d = MidiSystem.getMidiDevice(midiDeviceInfo[i]);
      System.out.println(midiDeviceInfo[i].getName());
      if (midiDeviceInfo[i].getName().equalsIgnoreCase(name))
      try {
      d.close(); // in case it was left open
      d.open();
      if ((!isInputDevice || d.getMaxTransmitters() != 0) &&
      (!isOutputDevice || d.getMaxReceivers() != 0)) {
      d.close();
      return d;
      }
      System.out.println("wrong device type");
      d.close();
      } catch (Exception x) {
      System.out.println("error getting device info");
      }
      }
      throw new MidiUnavailableException("Device " + name + " not found.");
      }
      public static void init() throws Exception {
      if (!inputDevice.isOpen()) inputDevice.open();
      if (!outputDevice.isOpen()) outputDevice.open();
      Transmitter transmitter = inputDevice.getTransmitter();
      Receiver receiver = outputDevice.getReceiver();
      transmitter.setReceiver(receiver);
      }
      }

      test program 2:
      package miditest;

      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 MidiTest2 {

      public MidiDevice input;
      public MidiDevice output;

      public static void main(String[] args) {
      new MidiTest2().start();
      }


      public void start() {
      init(); // initialize your midi input device
      // system dependent


      try {
      output.open(); // From midi device
      input.open();
      Receiver rcvr = new MyReceiver();
      input.getTransmitter().setReceiver(rcvr);
      }
      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);
      }
      rcvr.send(message, timeStamp);
      }

      @Override
      public void close() {
      rcvr.close();
      }

      }
      public void init() {
      try {
      input = findDeviceByNameAndType("Port 1", false, true);
      output = findDeviceByNameAndType("Port 1", true, false);
      } catch (MidiUnavailableException x) {

      }
      }
      public MidiDevice findDeviceByNameAndType(String name, boolean isOutputDevice, boolean isInputDevice)
      throws MidiUnavailableException {
      MidiDevice.Info[] midiDeviceInfo = MidiSystem.getMidiDeviceInfo();
      for (int i = 0; i < midiDeviceInfo.length; i++) {
      MidiDevice d = MidiSystem.getMidiDevice(midiDeviceInfo[i]);
      System.out.println(midiDeviceInfo[i].getName());
      if (midiDeviceInfo[i].getName().equalsIgnoreCase(name))
      try {
      d.close(); // in case it was left open
      d.open();
      if ((!isInputDevice || d.getMaxTransmitters() != 0) &&
      (!isOutputDevice || d.getMaxReceivers() != 0)) {
      d.close();
      return d;
      }
      System.out.println("wrong device type");
      d.close();
      } catch (Exception x) {
      System.out.println("error getting device info");
      }
      }
      throw new MidiUnavailableException("Device " + name + " not found.");
      }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      run it on Windows 7. My theory which I cannot test is that it will work with earlier version of OS X.

      SUPPORT :
      YES

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: