Path: blob/master/test/jdk/javax/sound/midi/Sequence/SMPTEDuration.java
41152 views
/*1* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.midi.InvalidMidiDataException;24import javax.sound.midi.MidiEvent;25import javax.sound.midi.Sequence;26import javax.sound.midi.ShortMessage;27import javax.sound.midi.Track;2829/**30* @test31* @bug 470232832* @summary Wrong time in sequence for SMPTE based types33*/34public class SMPTEDuration {3536public static void main(String args[]) throws Exception {37int[][] dataMes = { {ShortMessage.NOTE_ON, 10, 0x24, 0x50} ,38{ ShortMessage.NOTE_OFF, 10, 0x24, 0x44 },39{ ShortMessage.NOTE_ON, 10, 0x24, 0x50 },40{ ShortMessage.NOTE_ON, 10, 0x26, 0x50 },41{ ShortMessage.NOTE_OFF, 10, 0x26, 0x53 } };42long[] ticks = { 0, 68, 240, 240, 286};43int res = 240;44ShortMessage msg;45Sequence midiData = null;46Track track;47boolean failed = false;484950try {51midiData = new Sequence(Sequence.SMPTE_24 , res);52} catch (InvalidMidiDataException invMidiEx) {53invMidiEx.printStackTrace(System.out);54System.out.println("Unexpected InvalidMidiDataException: "55+ invMidiEx.getMessage());56failed = true;57}58track = midiData.createTrack();59for (int i = 0; i < dataMes.length; i++) {60msg = new ShortMessage();61try {62msg.setMessage(dataMes[i][0], dataMes[i][1], dataMes[i][2],63dataMes[i][3]);64} catch (InvalidMidiDataException invMidiEx) {65invMidiEx.printStackTrace(System.out);66System.out.println("Unexpected InvalidMidiDataException: "67+ invMidiEx.getMessage());68failed = true;69}70track.add(new MidiEvent(msg, ticks[i]));71}72// lengthInMs = (tickLength*1000000)/(divType*Res)73long micros = (long) ((midiData.getTickLength() * 1000000) / (res * Sequence.SMPTE_24));74if (midiData.getMicrosecondLength() != micros) {75failed = true;76System.out.println("getMicrosecondLength() returns wrong length: "77+ midiData.getMicrosecondLength());78System.out.println("getMicrosecondLength() must return length: "79+ micros);80}81if (midiData.getTickLength() != 286) {82failed = true;83System.out.println("getTickLength() returns wrong length: "84+ midiData.getTickLength());85}8687if( failed == true ) {88throw new Exception("test failed");89} else {90System.out.println("Passed.");91}92}93}949596