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

Synthesizer receiver should not use instanceof checks on message

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0
    • client-libs
    • b53
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Sending messages to a receiver from the Java Sound Synthesizer does not always work because it appears to assume that the message
      will always be one of the three standard subclasses of MidiMessage. However, in my application, I don't always know what type of message I am sending to the receiver and I would rather not have to parse it myself. So I have created a GenericMidiMessage class that directly extends MidiMessage. Receivers from all of my MIDI output devices accept messages from this class except the Java Sound Synthesizer. Whereas there is no documented requirement for MIDI messages to be of any specific class, the synthesizer should process messages using the status byte instead of the message class type.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Directly extend from MidiMessage
      2. Open the Java Sound Synthesizer and get a receiver.
      3. Send a note on message of the newly extended MidiMessage class to the synthesizer's receiver.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected to hear a note played on the Java Sound Synthesizer.
      ACTUAL -
      Silence.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package ivory;

      import javax.sound.midi.MidiMessage;
      import javax.sound.midi.MidiSystem;
      import javax.sound.midi.ShortMessage;
      import javax.sound.midi.Synthesizer;

      public class SynthTest
      {

        public static void main(String[] args)
        {
          Synthesizer synth = null;
          try
          {
            synth = MidiSystem.getSynthesizer();
            System.out.println("Got synthesizer: " + synth.getDeviceInfo());
            synth.open();
            MidiMessage msg = new GenericMidiMessage(0x90, 0x3C, 0x40);
      // ShortMessage msg = new ShortMessage();
      // msg.setMessage(0x90, 0x3C, 0x40);
            synth.getReceiver().send(msg, 0);
            Thread.sleep(2000);
          }
          catch (Exception ex)
          {
            ex.printStackTrace();
            System.exit(1);
          }
          finally
          {
            if (synth != null && synth.isOpen()) synth.close();
          }
        }

        private static class GenericMidiMessage extends MidiMessage
        {

          GenericMidiMessage(int... message)
          {
            super(new byte[message.length]);
            for (int i = 0; i < data.length; i++)
            {
              data[i] = (byte)(0xFF & message[i]);
            }
          }

          GenericMidiMessage(byte... message)
          {
            super(message);
          }

          public Object clone()
          {
            return new GenericMessage((byte[]) data.clone());
          }
       
       }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Parse into ShortMessage, SysexMessage, and MetaMessage classes
      or use another device.
      ###@###.### 10/29/04 06:17 GMT

            amenkov Alex Menkov
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: