JDK-4558747 : setMicrosecondPosition() does not work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-12-07
  • Updated: 2004-03-12
  • Resolved: 2003-09-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description
Name: vtR10009			Date: 12/07/2001


  setMicrosecondPosition() method does not set position in the sequence.
  getMicrosecondPosition() returns 0.
This bug causes failure of JCK test:
api/javax_sound/midi/Sequencer/index.html#Sequencer

To reproduce the bug run the following test with JDK 1.4.0-rc-b88 build:
------------------------------- test.java --------------------------------
import javax.sound.midi.*;
import java.io.File;
import java.io.IOException;
public class test{
    public static void main(String args[])
    {
        boolean failed = false;
        Sequencer seq = null;
        File seqfile = null;

        try {
            seq = MidiSystem.getSequencer();
            seq.open();
            seqfile = new File("metatest.mid");
            seq.setSequence(MidiSystem.getSequence(seqfile));
            seq.setMicrosecondPosition(seq.getMicrosecondLength() - 1);
            if (seq.getMicrosecondPosition() != (seq.getMicrosecondLength() - 
1)) {
                System.out.println("getMicrosecondLength() was : " 
                        + seq.getMicrosecondLength());
                System.out.println("getMicrosecondPosition() return wrong value 
: " 
                        + seq.getMicrosecondPosition());
                failed = true;
            }
            seq.setSequence(MidiSystem.getSequence(seqfile));
            seq.setTickPosition(seq.getTickLength() - 1);
            if (seq.getTickPosition() != (seq.getTickLength() - 1)) {
                System.out.println("getTickLength() was : " + 
seq.getTickLength());
                System.out.println("getTickPosition() return wrong value : " 
                        + seq.getTickPosition());
                failed = true;
            }
        } catch (MidiUnavailableException mue) {
            System.out.println("MidiUnavailableException was thrown: " + mue);
            System.out.println("could not test.");
            return;
        } catch (InvalidMidiDataException imEx) {
            imEx.printStackTrace();
            System.out.println("InvalidMidiDataException was thrown.");
            failed = true;
        } catch (IOException ioe) {
            System.out.println("Could not open the midi file.");
            failed = true;
        } finally {
            if (seq != null) seq.close();
        }

        if (failed == true) {
            System.out.println("test failed");
        } else {
            System.out.println("OKAY");
       }
    }
}
---------------------------Logs-------------------------------------------
$ java -version
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b88)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b88, mixed mode)
$ javac test.java
$ java test
getMicrosecondLength() was : 31904280
getMicrosecondPosition() return wrong value : 0
getTickLength() was : 980138
getTickPosition() return wrong value : 0
test failed

--------------------------------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b22 VERIFIED IN: tiger-b41
14-06-2004

PUBLIC COMMENTS setMicrosecondPosition() does not work
10-06-2004

EVALUATION ###@###.### 2002-11-01 Scheduled to be fixed with new sequencer implementation in tiger. ###@###.### 2003-09-26 Fixed with new sequencer. However, the test should be modified to allow slight derivations of set vs. get microsecond position. The implementation should *not* hide if it is not capable of setting it to the exact microsecond, or the exact tick. I suggest a window of 2 milli seconds for setMicrosecondPosition, and 10 ticks for setTickPosition. See below for an excerpt of the modified code: long expected = seq.getMicrosecondLength() - 1; seq.setMicrosecondPosition(expected); long actual = seq.getMicrosecondPosition(); if (Math.abs(expected - actual) > 2000) { // 2 milli seconds System.out.println("getMicrosecondLength() was : " + expected); System.out.println("getMicrosecondPosition() return wrong value : " + actual); failed = true; } seq.setSequence(MidiSystem.getSequence(seqfile)); seq.setTickPosition(seq.getTickLength() - 1); if (Math.abs(seq.getTickPosition() - seq.getTickLength()) > 10) { System.out.println("getTickLength() was : " + seq.getTickLength()); System.out.println("getTickPosition() return wrong value : " + seq.getTickPosition()); failed = true; } New evaluation shows that it should be OK that the microsecond position can only be set within the resolution of a tick. That is because a sequencer may operate internally on ticks as master time reference (which is the highest precision available in a sequence anyway). So the test should in fact be changed to allow the equivalent of one tick derivation: long expected = seq.getMicrosecondLength() - 1; seq.setMicrosecondPosition(expected); long actual = seq.getMicrosecondPosition(); // allow 1 tick un-precision long epsilon = (long) (seq.getTempoInMPQ() / seq.getSequence().getResolution()); if (Math.abs(actual - expected) > epsilon) { // failed } ###@###.### 2003-10-21
21-10-2003