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

MidiMessage.getLength and .getData return wrong values

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 5.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      generic, x86
    • OS:
      generic, windows_2000

      Description



      Name: rmT116609 Date: 04/18/2003


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

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]
      (german, SP2)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      SoundBlaster Live with kxAudio drivers.

      A DESCRIPTION OF THE PROBLEM :
      For the class javax.sound.midi.MidiMessage, the methods .getLength() and getData()
      return wrong values:
      The return value for getLength() is always one too small
      (e.g. for ActiveSensing 0, for ProgramChange 1, for NoteOn 2)
      and the array returned by getData is one byte too short,
      for an ActiveSensing it is actually a zero byte length array.

      As I noticed by a cross check, JDK1.4.1 is suffering the same bug,
      but the other ShortMessage-Bug prevented me from investigating it......

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached test program,
      attach a keyboard to a MIDI-In port and play a little bit.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Correct length and arrays as return values.

      Something like this (faked output from test program):

      Got message, length 1, data [ -2 ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 3, data [ -112 60 63 ]
      Is a Short Message, Status: 144 Data1: 60 Data2: 63
      NOTE_ON

      Got message, length 2, data [ -64 8 ]
      Is a Short Message, Status: 192 Data1: 8 Data2: 0
      PROGRAM_CHANGE


      This is the result of a test run:

      Number of Devices :10
      Inspecting device:Java Sound Synthesizer
      ...Adding to list.
      Inspecting device:Java Sound Sequencer
      ...Adding to list.
      Inspecting device:Microsoft MIDI-Mapper
      Inspecting device:kX Control CT4832 10k1 [e400]
      Inspecting device:kX Synth CT4832 10k1 [e400]
      Inspecting device:kX Synth2 CT4832 10k1 [e400]
      Inspecting device:kX Uart CT4832 10k1 [e400]
      Inspecting device:Microsoft GS Wavetable SW Synth
      Inspecting device:kX Control CT4832 10k1 [e400]
      ...Adding to list.
      Inspecting device:kX Uart CT4832 10k1 [e400]
      ...Adding to list.
      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 2, data [ -112 60 ]
      Is a Short Message, Status: 144 Data1: 60 Data2: 63
      NOTE_ON

      Got message, length 2, data [ -112 59 ]
      Is a Short Message, Status: 144 Data1: 59 Data2: 56
      NOTE_ON

      Got message, length 2, data [ -128 60 ]
      Is a Short Message, Status: 128 Data1: 60 Data2: 21
      NOTE_OFF

      Got message, length 2, data [ -112 57 ]
      Is a Short Message, Status: 144 Data1: 57 Data2: 66
      NOTE_ON

      Got message, length 2, data [ -128 59 ]
      Is a Short Message, Status: 128 Data1: 59 Data2: 24
      NOTE_OFF

      Got message, length 2, data [ -112 55 ]
      Is a Short Message, Status: 144 Data1: 55 Data2: 73
      NOTE_ON

      Got message, length 2, data [ -128 57 ]
      Is a Short Message, Status: 128 Data1: 57 Data2: 1
      NOTE_OFF

      Got message, length 2, data [ -112 57 ]
      Is a Short Message, Status: 144 Data1: 57 Data2: 70
      NOTE_ON

      Got message, length 2, data [ -128 55 ]
      Is a Short Message, Status: 128 Data1: 55 Data2: 31
      NOTE_OFF

      Got message, length 2, data [ -80 123 ]
      Is a Short Message, Status: 176 Data1: 123 Data2: 0

      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 1, data [ -64 ]
      Is a Short Message, Status: 192 Data1: 0 Data2: 0
      PROGRAM_CHANGE

      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING

      Got message, length 1, data [ -64 ]
      Is a Short Message, Status: 192 Data1: 8 Data2: 0
      PROGRAM_CHANGE

      Got message, length 0, data [ ]
      Is a Short Message, Status: 254 Data1: 0 Data2: 0
      ACTIVE_SENSING


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      /*
       * MidiMessageTest.java
       *
       * Created on 9. April 2003, 08:44
       */
      import javax.sound.midi.*;
      import java.io.*;
      /**
       *
       * @author Gerrit Gehnen
       */
      public class MidiMessageTest {
          
          class PrintReceiver implements Receiver {
              
              public void close() {
                  // Do nothing
              }
              
              public void send(javax.sound.midi.MidiMessage midiMessage, long param) {
                  System.out.print("Got message, length "+midiMessage.getLength()+", data [");
                  for (int i=0;i<midiMessage.getMessage().length;i++) {
                      System.out.print(" "+midiMessage.getMessage()[i]);
                  }
                  System.out.println(" ]");
                  // Compare to the values of the ShortMessage-class
                  if (midiMessage instanceof ShortMessage) {
                      
                      System.out.println("Is a Short Message, Status: "+((ShortMessage)midiMessage).getStatus()+
                                         " Data1: "+((ShortMessage)midiMessage).getData1()+
                                         " Data2: "+((ShortMessage)midiMessage).getData2());
                      switch (((ShortMessage)midiMessage).getStatus())
                      {
                          case ShortMessage.ACTIVE_SENSING: System.out.println("ACTIVE_SENSING");
                          break;
                          case ShortMessage.NOTE_ON:System.out.println("NOTE_ON");
                          break;
                          case ShortMessage.NOTE_OFF:System.out.println("NOTE_OFF");
                          break;
                          case ShortMessage.PROGRAM_CHANGE:System.out.println("PROGRAM_CHANGE");
                              
                      }
                  }
                  System.out.println();
              }
              
          }
          
          /** Creates a new instance of MidiMessageTest */
          public MidiMessageTest() {
              MidiDevice devi;
              MidiDevice.Info[] info;
              int i;
              System.out.println("Number of Devices :"+MidiSystem.getMidiDeviceInfo().length);
              info=MidiSystem.getMidiDeviceInfo();
              for (i=0;i<info.length;i++) {
                  try{
                      System.out.println("Inspecting device:"+info[i].getName());
                      devi=MidiSystem.getMidiDevice(info[i]);
                      if (devi.getMaxTransmitters()!=0) {
                          try {
                              System.out.println("...Adding to list.");
                              devi.open();
                              devi.getTransmitter().setReceiver(new PrintReceiver());
                          }
                          catch (Exception e) {
                              e.printStackTrace();
                          }
                      }
                  }
                  catch (Exception e) {
                      e.printStackTrace();
                  }
                  
              }
          }
          
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              MidiMessageTest t=new MidiMessageTest();
          }
      }


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


      (Review ID: 183820)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              fbomerssunw Florian Bomers (Inactive)
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: