Path: blob/master/test/jdk/javax/sound/midi/Sequencer/SequencerCacheValues.java
41155 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.MidiDevice;24import javax.sound.midi.MidiSystem;25import javax.sound.midi.MidiUnavailableException;26import javax.sound.midi.Sequencer;2728/**29* @test30* @bug 471674031* @summary default sequencer does not set the tempo factor32*/33public class SequencerCacheValues {3435static boolean failed = false;3637public static void main(String args[]) throws Exception {38Sequencer seq = null;39int totalNumberOfSequencers = 0;4041MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();42for (int device=0; device<infos.length; device++) {43//seq = MidiSystem.getSequencer();44MidiDevice dev = MidiSystem.getMidiDevice(infos[device]);45if (dev instanceof Sequencer) {46seq = (Sequencer) dev;47totalNumberOfSequencers++;48System.out.println("Opening sequencer "+infos[device]);49try {50seq.open();51try {52doTest(seq);53} finally {54if (seq != null) {55seq.close();56seq = null;57}58}59} catch (MidiUnavailableException mue) {60System.err.println("MidiUnavailableException was thrown: " + mue);61System.err.println("could not test this sequencer.");62}63}64}65if (totalNumberOfSequencers == 0) {66System.out.println("No sequencers installed!");67failed = true;68}69if (failed) {70throw new Exception("FAILED");71} else {72System.out.println("test OK");73}74}7576public static boolean equalsFloat(float f1, float f2) {77return (f1-f2<0.0001) && (f2-f1<0.0001);78}7980public static void doTest(Sequencer seq) throws Exception {81seq.setTempoInMPQ(3.0f);82System.out.println("Setting tempo in MPQ to "+3.0f);83if (!equalsFloat(seq.getTempoInMPQ(), 3.0f)) {84System.err.println("getTempoInMPQ() returns wrong value : "85+ seq.getTempoInMPQ());86failed = true;87}8889System.out.println("Setting tempo factor to "+2.0f);90seq.setTempoFactor(2.0f);91if (!equalsFloat(seq.getTempoFactor(), 2.0f)) {92System.err.println("getTempoFactor() returns: " + seq.getTempoFactor());93failed = true;94}9596float bpmTempo = 120.0f;97System.out.println("Setting tempo to "+120.0f+"bpm");98seq.setTempoInBPM(bpmTempo);99if (!equalsFloat(seq.getTempoInMPQ(), (60000000.0f/seq.getTempoInBPM()))) {100System.err.println("getTempoInMPQ() returns: " + seq.getTempoInMPQ());101System.err.println("getTempoInBPM() returns: " + seq.getTempoInBPM());102failed = true;103}104}105}106107108