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

Unexcepted exception thrown "java.lang.IllegalArgumentException: invalid loop start point: 30389"

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 6
    • 6
    • client-libs
    • None

      import javax.sound.midi.*;
      import java.io.*;

      public class test302 extends TRTest {

          private int failed = 0;
          private Sequence s = null;
          private Sequencer seq = null;

          public test302() {
      theTestFocus = "MIDI sequencer";
      theTestDescription = "Verify that sequencer looping works correctly (4204105).";
              printTestInfo();
          }


          // returns if the sequencer looped back or continued past the endpoint
          private boolean waitForEndPoint() throws Exception {
      long endPoint = seq.getLoopEndPoint();
      if (endPoint == -1) {
                  endPoint = seq.getTickLength() - 1;
      }
              long pos = seq.getTickPosition();
      int noMovement = 0;
      long oldPos = pos;
      while (true) {
                  long thisPos = seq.getTickPosition();
                  if (thisPos < oldPos) {
      // looped back
      return true;
                  }
                  else if (thisPos >= endPoint) {
      // reached end point
      return false;
                  }
                  sleep(10);
                  if (oldPos == thisPos) {
      noMovement++;
      if (noMovement > 100) {
      out("ERROR: Sequencer did not advance for a long time!");
      failed++;
      break;
      }
                  } else {
      oldPos = thisPos;
                  }
      }
      return false;
          }

          private void loopTest(long start, long end, int times) throws Exception {
      out("Loop: start="+start+" end="+end+" loopCount="+times);
      seq.setLoopStartPoint(start);
      seq.setLoopEndPoint(end);
      seq.setLoopCount(times);
      seq.setTickPosition(start);
      if (!seq.isRunning()) {
      out("Starting sequencer");
      seq.start();
      }
      boolean loopedBack = false;
      for (int i = times; i > 0; i--) {
      out("Loop "+i+"... waiting...");
      loopedBack = waitForEndPoint();
      if (!loopedBack) {
      out(" ERROR: Did not loop back!");
      failed++;
      break;
      }
      }
          }

          private void loopTest() throws Exception {
      int start = 45 * 4 *120 - 10;
      loopTest(start, start + (120 * 12), 3);
      loopTest(start, start + (120 * 12), 0);
      seq.stop();
      loopTest(start, start + (120 * 12), 1);
      loopTest(start, start + (120 * 12), 1);
      loopTest(0, 120 * 12, 2);
      seq.stop();
      loopTest(0, 120 * 6, 6);
      long end = seq.getTickLength();
      loopTest(end-(120*12), end-1, 3);
      loopTest(end-(120*8), -1, 3);
      //This is the line where the test failed. 'end' is equal to 30389
      loopTest(end-(120*12), end, 3);
          }

          public boolean runTest() {
      Transmitter transmitter = null;
      Receiver testReceiver = null;
      Synthesizer syn = null;
      Receiver synReceiver = null;
              try {
                  // dvorak9.mid is 1:44 min:sec long -- should be enough for all kinds of testing
      File file = SoundFinder.getSoundFile("MIDI/dvorak9.mid");
      s = MidiSystem.getSequence(file);
      seq = MidiSystem.getSequencer(false);
      seq.open();
      seq.setSequence(s);

      transmitter = seq.getTransmitter();
      try {
      syn = MidiSystem.getSynthesizer();
      syn.open();
      synReceiver = syn.getReceiver();
      transmitter.setReceiver(synReceiver);
      } catch(Exception e) {
      out("Cannot get synthesizer: "+e);
      if (synReceiver != null) {
      synReceiver.close();
      synReceiver = null;
      }
      if (syn != null) {
      syn.close();
      syn = null;
      }
                  }
      if (synReceiver == null) {
      out("No synthesizer available. Using test Receiver.");
      testReceiver = new TestReceiver();
      transmitter.setReceiver(testReceiver);
                  }

      out("Starting sequence.");
      seq.start();
      out("Waiting for 1 second");
      sleep(1000);

      loopTest();

      } catch (Throwable t) {
      t.printStackTrace();
      out("Exception caused this test to fail.");
      failed++;
              }
      out("Closing devices");
      if (synReceiver != null) synReceiver.close();
      if (syn != null) syn.close();
      if (testReceiver != null) testReceiver.close();
              if (transmitter != null) transmitter.close();
      if (seq != null) seq.close();
      return (failed==0);
          }

          private static Object lock = new Object();
          private static void sleep(int milliseconds) {
      // prevent locking forever
      if (milliseconds <= 0) {
      milliseconds = 10;
      }
      try {
      Thread.sleep(milliseconds);
      } catch (InterruptedException e) {
      e.printStackTrace();
                  }
          }

          private static void out(String s) {
      System.out.println(s);
      System.out.flush();
          }


          private static class TestReceiver implements Receiver {
      public void send(MidiMessage message, long timestamp) {
              }

      public void close() {
              }
          }


          //_______________________________________________
          // Method: main
          //_______________________________________________
          public static void main(String[] args) {
      TRTest thisTest = new test302();

      boolean result = thisTest.runTest();
      if (result) {
      System.out.println("Passed");
      } else {
      System.out.println("FAILED!");
              }
      if (result) {
      System.exit(0);
      } else {
      System.exit(1);
              }
          }

            amenkov Alex Menkov
            dleansunw Danny Lean (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: